GB I/O: Fix JOYP IRQs
Vicki Pfau vi@endrift.com
Sat, 23 Jun 2018 16:34:35 -0700
1 files changed,
14 insertions(+),
7 deletions(-)
jump to
M
src/gb/io.c
→
src/gb/io.c
@@ -104,6 +104,8 @@ [REG_SVBK] = 0xF8,
[REG_IE] = 0xE0, }; +static uint8_t _readKeys(struct GB* gb); + static void _writeSGBBits(struct GB* gb, int bits) { if (!bits) { gb->sgbBit = -1;@@ -394,10 +396,12 @@ gb->audio.ch3.wavedata8[gb->audio.ch3.window >> 1] = value;
} break; case REG_JOYP: + gb->memory.io[REG_JOYP] = value | 0x0F; + _readKeys(gb); if (gb->model == GB_MODEL_SGB) { _writeSGBBits(gb, (value >> 4) & 3); } - break; + return; case REG_TIMA: if (value && mTimingUntil(&gb->timing, &gb->timer.irq) > 1) { mTimingDeschedule(&gb->timing, &gb->timer.irq);@@ -522,7 +526,8 @@ uint8_t keys = *gb->keySource;
if (gb->sgbCurrentController != 0) { keys = 0; } - switch (gb->memory.io[REG_JOYP] & 0x30) { + uint8_t joyp = gb->memory.io[REG_JOYP]; + switch (joyp & 0x30) { case 0x30: keys = gb->sgbCurrentController; break;@@ -535,7 +540,12 @@ case 0x00:
keys |= keys >> 4; break; } - return (0xC0 | (gb->memory.io[REG_JOYP] | 0xF)) ^ (keys & 0xF); + gb->memory.io[REG_JOYP] = (0xCF | joyp) ^ (keys & 0xF); + if (joyp & ~gb->memory.io[REG_JOYP] & 0xF) { + gb->memory.io[REG_IF] |= (1 << GB_IRQ_KEYPAD); + GBUpdateIRQs(gb); + } + return gb->memory.io[REG_JOYP]; } uint8_t GBIORead(struct GB* gb, unsigned address) {@@ -639,10 +649,7 @@ return gb->memory.io[address] | _registerMask[address];
} void GBTestKeypadIRQ(struct GB* gb) { - if (_readKeys(gb)) { - gb->memory.io[REG_IF] |= (1 << GB_IRQ_KEYPAD); - GBUpdateIRQs(gb); - } + _readKeys(gb); } struct GBSerializedState;