From 32bed3a06fd0d2207d7da50ee2b30ff96a034438 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 18 Feb 2020 18:24:00 -0800 Subject: [PATCH] GBA Hardware: Scanning now fails successfully --- src/gba/hardware.c | 20 ++++++++++---------- src/gba/memory.c | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/gba/hardware.c b/src/gba/hardware.c index bd23dfa63..b05293eb1 100644 --- a/src/gba/hardware.c +++ b/src/gba/hardware.c @@ -682,7 +682,7 @@ void _eReaderReset(struct GBACartridgeHardware* hw) { hw->eReaderRegisterControl0 = 0; hw->eReaderRegisterControl1 = 0x80; hw->eReaderRegisterLed = 0; - hw->eReaderState = false; + hw->eReaderState = 0; hw->eReaderActiveRegister = 0; } @@ -738,7 +738,7 @@ void _eReaderWriteControl0(struct GBACartridgeHardware* hw, uint8_t value) { ++hw->eReaderActiveRegister; break; default: - mLOG(GBA_HW, ERROR, "Hit undefined state in e-Reader state machine"); + mLOG(GBA_HW, ERROR, "Hit undefined state %02X in e-Reader state machine", hw->eReaderCommand); break; } hw->eReaderState = EREADER_SERIAL_BIT_0; @@ -761,6 +761,8 @@ void _eReaderWriteControl0(struct GBACartridgeHardware* hw, uint8_t value) { hw->eReaderRegisterControl0 = control; if (!EReaderControl0IsScan(oldControl) && EReaderControl0IsScan(control)) { _eReaderReadData(hw); + } else if (EReaderControl0IsLedEnable(control) && EReaderControl1IsScanline(hw->eReaderRegisterControl1)) { + GBARaiseIRQ(hw->p, IRQ_GAMEPAK, 0); } mLOG(GBA_HW, STUB, "Unimplemented e-Reader Control0 write: %02X", value); } @@ -775,15 +777,13 @@ void _eReaderWriteControl1(struct GBACartridgeHardware* hw, uint8_t value) { } void _eReaderReadData(struct GBACartridgeHardware* hw) { - if (!hw->eReaderSource) { - return; + memset(hw->eReaderData, 0xFF, EREADER_BLOCK_SIZE); + if (hw->eReaderSource) { + hw->eReaderSource->readBlock(hw->eReaderSource, hw->eReaderData); } - memset(hw->eReaderData, 0, EREADER_BLOCK_SIZE); - if (hw->eReaderSource->readBlock(hw->eReaderSource, hw->eReaderData)) { - hw->eReaderRegisterControl1 = EReaderControl1FillScanline(hw->eReaderRegisterControl1); - if (EReaderControl0IsLedEnable(hw->eReaderRegisterControl0)) { - GBARaiseIRQ(hw->p, IRQ_GAMEPAK, 0); - } + hw->eReaderRegisterControl1 = EReaderControl1FillScanline(hw->eReaderRegisterControl1); + if (EReaderControl0IsLedEnable(hw->eReaderRegisterControl0)) { + GBARaiseIRQ(hw->p, IRQ_GAMEPAK, -2754); } } diff --git a/src/gba/memory.c b/src/gba/memory.c index c0e665ebb..1a24f6b04 100644 --- a/src/gba/memory.c +++ b/src/gba/memory.c @@ -917,6 +917,7 @@ void GBAStore16(struct ARMCore* cpu, uint32_t address, int16_t value, int* cycle case REGION_CART2_EX: if ((address & 0x0DFC0000) >= 0x0DF80000 && memory->hw.devices & HW_EREADER) { GBAHardwareEReaderWrite(&memory->hw, address, value); + break; } else if (memory->savedata.type == SAVEDATA_AUTODETECT) { mLOG(GBA_MEM, INFO, "Detected EEPROM savegame"); GBASavedataInitEEPROM(&memory->savedata);