diff options
Diffstat (limited to 'memory.c')
| -rw-r--r-- | memory.c | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -1,6 +1,5 @@ - __attribute__((hot)) static inline uint8_t memory_read(struct nes_state *state, uint32_t offset) { state->cpu.cycles++; @@ -8,7 +7,10 @@ static inline uint8_t memory_read(struct nes_state *state, uint32_t offset) { // apu_tick(state); if(LIKELY(offset >= 0x6000)) { // MOST - return state->mapper.prg_read(state, offset); + if(UNLIKELY(offset < 0x8000)) { + return state->mapper_function.prg_ram_read(state, offset); + } + return state->mapper_function.prg_rom_read(state, offset); } else if(LIKELY(offset < 0x2000)) { // SECOND return state->ram[offset & 0x07ff]; @@ -66,21 +68,20 @@ static inline void memory_write(struct nes_state *state, uint32_t offset, uint8_ // state->apu.irq_pending = 0; // } } - } else if(offset >= 0x6000) { - state->mapper.prg_write(state, offset, value); + + } else if(offset >= 0x6000) { // NOTE(peter): Might need to move this upwards when we implement a mapper that has prg_ram_* + if(offset < 0x8000) { + state->mapper_function.prg_ram_write(state, offset, value); + } else { + state->mapper_function.prg_rom_write(state, offset, value); + } } } + static inline uint8_t memory_read_dma(struct nes_state *state, uint32_t offset) { // Do not tick CPU/PPU/APU — caller handles timing - if(LIKELY(offset < 0x2000)) { - return state->ram[offset & 0x07ff]; - - } else if(offset >= 0x6000) { - return state->mapper.prg_read(state, offset); - - } - return 0; + return state->ram[offset & 0x07ff]; } static inline uint8_t memory_read_dummy(struct nes_state *state, uint32_t offset) { |
