diff options
Diffstat (limited to 'memory.c')
| -rw-r--r-- | memory.c | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -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)) |
