From 7cca3bdbec289328b537c8256b43dcfedc5d56b8 Mon Sep 17 00:00:00 2001 From: Peter Fors Date: Tue, 27 May 2025 15:03:30 +0200 Subject: renaming --- memory.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'memory.c') diff --git a/memory.c b/memory.c index 90ae8b6..55c7015 100644 --- a/memory.c +++ b/memory.c @@ -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) { -- cgit v1.2.3