From 943f67937cf00b1f2e40e70d176319960eccf4cf Mon Sep 17 00:00:00 2001 From: normmatt234 Date: Wed, 18 Sep 2013 22:08:42 +0000 Subject: [PATCH] Implement memory mirrors for SRAM/FLASH. Correctly handle 16/32bit reads from SRAM. Removed unaligned handler for CPUReadHalfWordSigned. --- src/gba/GBAinline.h | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/gba/GBAinline.h b/src/gba/GBAinline.h index 1de76508..2a473e02 100644 --- a/src/gba/GBAinline.h +++ b/src/gba/GBAinline.h @@ -119,9 +119,13 @@ static inline u32 CPUReadMemory(u32 address) return eepromRead(address); goto unreadable; case 14: + case 15: if(cpuFlashEnabled | cpuSramEnabled) + { // no need to swap this - return flashRead(address); + value = flashRead(address) * 0x01010101; + break; + } // default default: unreadable: @@ -266,9 +270,13 @@ static inline u32 CPUReadHalfWord(u32 address) return eepromRead(address); goto unreadable; case 14: + case 15: if(cpuFlashEnabled | cpuSramEnabled) + { // no need to swap this - return flashRead(address); + value = flashRead(address) * 0x0101; + break; + } // default default: unreadable: @@ -305,22 +313,17 @@ unreadable: static inline s16 CPUReadHalfWordSigned(u32 address) { - u32 oldAddress = address; - if(address & 1) { - address &= ~0x01; - } - s16 value = (s16)CPUReadHalfWord(address); - if((oldAddress & 1)) + s32 value = (s32)CPUReadHalfWord(address); + if((address & 1)) { - value = (s8)value; #ifdef GBA_LOGGING if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) { - log("Unaligned signed halfword read from: %08x at %08x (%08x)\n", oldAddress, armMode ? + log("Unaligned signed halfword read from: %08x at %08x (%08x)\n", address, armMode ? armNextPC - 4 : armNextPC - 2, value); } #endif } - return value; + return (s16)value; } static inline u8 CPUReadByte(u32 address) @@ -369,6 +372,7 @@ static inline u8 CPUReadByte(u32 address) return eepromRead(address); goto unreadable; case 14: + case 15: if(cpuSramEnabled | cpuFlashEnabled) return flashRead(address); if(cpuEEPROMSensorEnabled) { @@ -486,6 +490,7 @@ static inline void CPUWriteMemory(u32 address, u32 value) } goto unwritable; case 0x0E: + case 0x0F: if((!eepromInUse) | cpuSramEnabled | cpuFlashEnabled) { (*cpuSaveGameFunc)(address, (u8)value); break; @@ -590,6 +595,7 @@ static inline void CPUWriteHalfWord(u32 address, u16 value) } goto unwritable; case 14: + case 15: if((!eepromInUse) | cpuSramEnabled | cpuFlashEnabled) { (*cpuSaveGameFunc)(address, (u8)value); break; @@ -726,6 +732,7 @@ static inline void CPUWriteByte(u32 address, u8 b) } goto unwritable; case 14: + case 15: if ((saveType != 5) && ((!eepromInUse) | cpuSramEnabled | cpuFlashEnabled)) { //if(!cpuEEPROMEnabled && (cpuSramEnabled | cpuFlashEnabled)) {