higan-emu / higan

higan is a multi-system emulator focused on accuracy, preservation, and configurability.
Other
1.19k stars 112 forks source link

gba: memory.disable is actually memory.biosSwap #176

Closed merryhime closed 3 years ago

merryhime commented 3 years ago

The reason that IWRAM and EWRAM appear to be disabled is because they were swapped with the BIOS.

(Thanks to kevtris for disclosure of this behaviour.)

merryhime commented 3 years ago

While I implemented it as a bit-flip (since this was likely how it was implemented in hardware and first came to mind), one could also modify the main block of if statements like so instead:

         if(addr <  0x0100'0000) word = memory.biosSwap ? readEWRAM(mode, addr) : bios.read(mode, addr);
    else if(addr <  0x0200'0000) word = memory.biosSwap ? readIWRAM(mode, addr) : bios.read(mode, addr);
    else if(addr <  0x0300'0000) word = memory.biosSwap ? bios.read(mode, addr) : readEWRAM(mode, addr);
    else if(addr <  0x0400'0000) word = memory.biosSwap ? bios.read(mode, addr) : readIWRAM(mode, addr);

Which would be preferrable?

merryhime commented 3 years ago

This has been tested to produce a correct BIOS dump when utilizing memory swap with the prefetch exploit: https://gitdab.com/LunarLambda/gba-bios-dump

Screwtapello commented 3 years ago

Thank you for this patch!