From 93fd16dcd4c66ed003363d6e7f0c70bd3d2de92c Mon Sep 17 00:00:00 2001 From: Peter Fors Date: Thu, 29 May 2025 21:41:13 +0200 Subject: rewrite of memory_read() --- memory.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'memory.c') diff --git a/memory.c b/memory.c index 096189b..1eaf489 100644 --- a/memory.c +++ b/memory.c @@ -6,26 +6,28 @@ static inline uint8_t memory_read(struct nes_state *state, uint32_t offset) { ppu_tick(state); // apu_tick(state); + uint8_t result = 0; + if(offset >= 0x8000) { // MOST - return state->mapper_function.prg_rom_read(state, offset); + result = state->mapper_function.prg_rom_read(state, offset); - } else if((offset < 0x2000)) { // SECOND - return state->ram[offset & 0x07ff]; + } else if(offset < 0x2000) { // SECOND + result = state->ram[offset & 0x07ff]; } else if(offset < 0x4000) { // THIRD - return ppu_read(state, offset); + result = ppu_read(state, offset); } else if(offset >= 0x6000) { - return state->mapper_function.prg_ram_read(state, offset); + result = state->mapper_function.prg_ram_read(state, offset); } else if(offset == 0x4016 || offset == 0x4017) { uint32_t index = offset & 1; uint8_t value = (state->ppu.input_latch[index] >> state->ppu.input_bit[index]) & 1; state->ppu.input_bit[index]++; - return value | 0x40; // Bit 6 open bus high, bit 7 low + result = value | 0x40; // Bit 6 open bus high, bit 7 low } - return 0; + return result; } __attribute__((hot)) -- cgit v1.2.3