From a93f3745a8c8b1c2d007c39b9a56b811d093e739 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 28 Sep 2016 12:37:39 -0700 Subject: [PATCH] GBA Memory: Fix several unused I/O register read values --- CHANGES | 1 + src/gba/io.c | 21 +++++++++++++++++---- src/gba/memory.c | 10 +++++----- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index 53791225c..a8dcbb026 100644 --- a/CHANGES +++ b/CHANGES @@ -23,6 +23,7 @@ Bugfixes: - GB MBC: Fix RTC access when no save file is loaded - GB: Properly clear KEY1 bit 0 when switching speeds - GBA Cheats: Fix uninitialized memory getting freed when saving + - GBA Memory: Fix several unused I/O register read values Misc: - All: Only update version info if needed - FFmpeg: Encoding cleanup diff --git a/src/gba/io.c b/src/gba/io.c index 12f53a7bb..9a1efd16d 100644 --- a/src/gba/io.c +++ b/src/gba/io.c @@ -742,26 +742,30 @@ uint16_t GBAIORead(struct GBA* gba, uint32_t address) { case REG_DMA0SAD_HI: case REG_DMA0DAD_LO: case REG_DMA0DAD_HI: - case REG_DMA0CNT_LO: case REG_DMA1SAD_LO: case REG_DMA1SAD_HI: case REG_DMA1DAD_LO: case REG_DMA1DAD_HI: - case REG_DMA1CNT_LO: case REG_DMA2SAD_LO: case REG_DMA2SAD_HI: case REG_DMA2DAD_LO: case REG_DMA2DAD_HI: - case REG_DMA2CNT_LO: case REG_DMA3SAD_LO: case REG_DMA3SAD_HI: case REG_DMA3DAD_LO: case REG_DMA3DAD_HI: - case REG_DMA3CNT_LO: // Write-only register mLOG(GBA_IO, GAME_ERROR, "Read from write-only I/O register: %03X", address); return GBALoadBad(gba->cpu); + case REG_DMA0CNT_LO: + case REG_DMA1CNT_LO: + case REG_DMA2CNT_LO: + case REG_DMA3CNT_LO: + // Write-only register + mLOG(GBA_IO, GAME_ERROR, "Read from write-only I/O register: %03X", address); + return 0; + case REG_SOUNDBIAS: case REG_KEYCNT: case REG_POSTFLG: @@ -832,6 +836,15 @@ uint16_t GBAIORead(struct GBA* gba, uint32_t address) { case REG_MAX: // Some bad interrupt libraries will read from this break; + case 0x66: + case 0x6E: + case 0x76: + case 0x7A: + case 0x7E: + case 0x86: + case 0x8A: + mLOG(GBA_IO, GAME_ERROR, "Read from unused I/O register: %03X", address); + return 0; default: mLOG(GBA_IO, GAME_ERROR, "Read from unused I/O register: %03X", address); return GBALoadBad(gba->cpu); diff --git a/src/gba/memory.c b/src/gba/memory.c index 7cc4dc6df..358f8ff93 100644 --- a/src/gba/memory.c +++ b/src/gba/memory.c @@ -367,7 +367,7 @@ static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t address) { wait += waitstatesRegion[REGION_WORKING_RAM]; #define LOAD_WORKING_IRAM LOAD_32(value, address & (SIZE_WORKING_IRAM - 4), memory->iwram); -#define LOAD_IO value = GBAIORead(gba, (address & (SIZE_IO - 1)) & ~2) | (GBAIORead(gba, (address & (SIZE_IO - 1)) | 2) << 16); +#define LOAD_IO value = GBAIORead(gba, address & OFFSET_MASK & ~2) | (GBAIORead(gba, (address & OFFSET_MASK) | 2) << 16); #define LOAD_PALETTE_RAM \ LOAD_32(value, address & (SIZE_PALETTE_RAM - 4), gba->video.palette); \ @@ -498,7 +498,7 @@ uint32_t GBALoad16(struct ARMCore* cpu, uint32_t address, int* cycleCounter) { LOAD_16(value, address & (SIZE_WORKING_IRAM - 2), memory->iwram); break; case REGION_IO: - value = GBAIORead(gba, address & (SIZE_IO - 2)); + value = GBAIORead(gba, address & (OFFSET_MASK - 1)); break; case REGION_PALETTE_RAM: LOAD_16(value, address & (SIZE_PALETTE_RAM - 2), gba->video.palette); @@ -679,7 +679,7 @@ uint32_t GBALoad8(struct ARMCore* cpu, uint32_t address, int* cycleCounter) { STORE_32(value, address & (SIZE_WORKING_IRAM - 4), memory->iwram); #define STORE_IO \ - GBAIOWrite32(gba, address & (SIZE_IO - 4), value); + GBAIOWrite32(gba, address & (OFFSET_MASK - 3), value); #define STORE_PALETTE_RAM \ STORE_32(value, address & (SIZE_PALETTE_RAM - 4), gba->video.palette); \ @@ -786,7 +786,7 @@ void GBAStore16(struct ARMCore* cpu, uint32_t address, int16_t value, int* cycle STORE_16(value, address & (SIZE_WORKING_IRAM - 2), memory->iwram); break; case REGION_IO: - GBAIOWrite(gba, address & (SIZE_IO - 2), value); + GBAIOWrite(gba, address & (OFFSET_MASK - 1), value); break; case REGION_PALETTE_RAM: STORE_16(value, address & (SIZE_PALETTE_RAM - 2), gba->video.palette); @@ -853,7 +853,7 @@ void GBAStore8(struct ARMCore* cpu, uint32_t address, int8_t value, int* cycleCo ((int8_t*) memory->iwram)[address & (SIZE_WORKING_IRAM - 1)] = value; break; case REGION_IO: - GBAIOWrite8(gba, address & (SIZE_IO - 1), value); + GBAIOWrite8(gba, address & OFFSET_MASK, value); break; case REGION_PALETTE_RAM: GBAStore16(cpu, address & ~1, ((uint8_t) value) | ((uint8_t) value << 8), cycleCounter);