Skip to content

mGBA debug enable register not properly restored #1

@Vulcalien

Description

@Vulcalien
pub fn identify_mgba() -> bool {
    const REG_MGBA_ENABLE: *mut u16 = 0x04FFF780 as *mut u16;
    let original_value = unsafe { read_volatile(REG_MGBA_ENABLE) };

    unsafe {
        write_volatile(REG_MGBA_ENABLE, 0xC0DE);
        let result = read_volatile(REG_MGBA_ENABLE) == 0x1DEA;
        write_volatile(REG_MGBA_ENABLE, original_value); // Restore original value
        result
    }
}

I haven't tested the code, but by looking at it I noticed you're reading the register's value and then writing the same value again. But the debug enable register, when read, does not return '0xc0de', but instead '0x1dea' or any other value.

So when restoring the register, it should look something like this:

if original_value == 0xidea:
    write 0xc0de to REG_MGBA_ENABLE // or do nothing, since the register has just been enabled during the test
else
    write 0 to REG_MGBA_ENABLE

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions