diff --git a/src/gba/gba-io.c b/src/gba/gba-io.c index 138390635..c4e4cec85 100644 --- a/src/gba/gba-io.c +++ b/src/gba/gba-io.c @@ -109,14 +109,6 @@ void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value) { case REG_IME: GBAWriteIME(gba, value); break; - case REG_HALTCNT: - value &= 0x80; - if (!value) { - GBAHalt(gba); - } else { - GBALog(GBA_LOG_STUB, "Stop unimplemented"); - } - return; default: GBALog(GBA_LOG_STUB, "Stub I/O register write: %03x", address); break; @@ -125,6 +117,21 @@ void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value) { gba->memory.io[address >> 1] = value; } +void GBAIOWrite8(struct GBA* gba, uint32_t address, uint8_t value) { + if (address == REG_HALTCNT) { + value &= 0x80; + if (!value) { + GBAHalt(gba); + } else { + GBALog(GBA_LOG_STUB, "Stop unimplemented"); + } + return; + } + value <<= 8 * (address & 1); + value |= (gba->memory.io[(address & (SIZE_IO - 1)) >> 1]) & ~(0xFF << (8 * (address & 1))); + GBAIOWrite(gba, address, value); +} + void GBAIOWrite32(struct GBA* gba, uint32_t address, uint32_t value) { switch (address) { case REG_DMA0SAD_LO: diff --git a/src/gba/gba-io.h b/src/gba/gba-io.h index d0ff592b9..ab0463701 100644 --- a/src/gba/gba-io.h +++ b/src/gba/gba-io.h @@ -143,6 +143,7 @@ enum GBAIORegisters { void GBAIOInit(struct GBA* gba); void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value); +void GBAIOWrite8(struct GBA* gba, uint32_t address, uint8_t value); void GBAIOWrite32(struct GBA* gba, uint32_t address, uint32_t value); uint16_t GBAIORead(struct GBA* gba, uint32_t address); diff --git a/src/gba/gba-memory.c b/src/gba/gba-memory.c index 753decc81..cf2f1605f 100644 --- a/src/gba/gba-memory.c +++ b/src/gba/gba-memory.c @@ -385,6 +385,7 @@ void GBAStore8(struct ARMMemory* memory, uint32_t address, int8_t value, int* cy ((int8_t*) gbaMemory->iwram)[address & (SIZE_WORKING_IRAM - 1)] = value; break; case BASE_IO: + GBAIOWrite8(gbaMemory->p, address & (SIZE_IO - 1), value); break; case BASE_PALETTE_RAM: break;