From eaccd792ed75738603c97fc6367e9bf8bfb41573 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 18 Dec 2021 14:56:33 +0200 Subject: [PATCH] Fixes to safe reads, closes #422 --- Core/memory.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Core/memory.c b/Core/memory.c index 43a9dde..ea9152f 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -434,7 +434,9 @@ static uint8_t read_high_memory(GB_gameboy_t *gb, uint16_t addr) if (addr < 0xFF00) { if (gb->oam_write_blocked && !GB_is_cgb(gb)) { - GB_trigger_oam_bug_read(gb, addr); + if (!gb->disable_oam_corruption) { + GB_trigger_oam_bug_read(gb, addr); + } return 0xff; } @@ -705,6 +707,9 @@ uint8_t GB_read_memory(GB_gameboy_t *gb, uint16_t addr) uint8_t GB_safe_read_memory(GB_gameboy_t *gb, uint16_t addr) { + if (unlikely(addr == 0xFF00 + GB_IO_JOYP)) { + return gb->io_registers[GB_IO_JOYP]; + } gb->disable_oam_corruption = true; uint8_t data = read_map[addr >> 12](gb, addr); gb->disable_oam_corruption = false;