summaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
authorPeter Fors <peter.fors@mindkiller.com>2025-05-29 19:19:59 +0200
committerPeter Fors <peter.fors@mindkiller.com>2025-05-29 19:19:59 +0200
commit3d70e69f6c9fbdcb890c6986096330e4f6611a32 (patch)
tree9f1ce34365ec376f10f6c6e68c1ca64fa4d4d63d /memory.c
parent7cca3bdbec289328b537c8256b43dcfedc5d56b8 (diff)
added mapper_tick() functionality, regressed 200fps, and optimized it back up to ~1940fps
Diffstat (limited to 'memory.c')
-rw-r--r--memory.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/memory.c b/memory.c
index 55c7015..096189b 100644
--- a/memory.c
+++ b/memory.c
@@ -6,18 +6,18 @@ static inline uint8_t memory_read(struct nes_state *state, uint32_t offset) {
ppu_tick(state);
// apu_tick(state);
- if(LIKELY(offset >= 0x6000)) { // MOST
- if(UNLIKELY(offset < 0x8000)) {
- return state->mapper_function.prg_ram_read(state, offset);
- }
+ if(offset >= 0x8000) { // MOST
return state->mapper_function.prg_rom_read(state, offset);
- } else if(LIKELY(offset < 0x2000)) { // SECOND
+ } else if((offset < 0x2000)) { // SECOND
return state->ram[offset & 0x07ff];
} else if(offset < 0x4000) { // THIRD
return ppu_read(state, offset);
+ } else if(offset >= 0x6000) {
+ return 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;
@@ -29,12 +29,24 @@ static inline uint8_t memory_read(struct nes_state *state, uint32_t offset) {
}
__attribute__((hot))
+static inline uint8_t memory_read_dummy(struct nes_state *state, uint32_t offset) {
+ state->cpu.cycles++;
+ ppu_tick(state);
+ // apu_tick(state);
+
+ if(offset >= 0x2000 && offset < 0x4000) {
+ return ppu_read(state, offset);
+ }
+ return 0;
+}
+
+__attribute__((hot))
static inline void memory_write(struct nes_state *state, uint32_t offset, uint8_t value) {
state->cpu.cycles++;
ppu_tick(state);
// apu_tick(state);
- if(LIKELY(offset < 0x2000)) {
+ if(offset < 0x2000) {
state->ram[offset & 0x07ff] = value;
} else if(offset < 0x4000) {
@@ -78,20 +90,8 @@ static inline void memory_write(struct nes_state *state, uint32_t offset, uint8_
}
}
-
+__attribute__((hot, flatten))
static inline uint8_t memory_read_dma(struct nes_state *state, uint32_t offset) {
- // Do not tick CPU/PPU/APU — caller handles timing
+ // NOTE(peter): DO NOT tick CPU/PPU/APU — caller handles timing
return state->ram[offset & 0x07ff];
}
-
-static inline uint8_t memory_read_dummy(struct nes_state *state, uint32_t offset) {
- state->cpu.cycles++;
- ppu_tick(state);
- // apu_tick(state);
-
- if(UNLIKELY(offset >= 0x2000 && offset < 0x4000)) {
- return ppu_read(state, offset);
- }
- return 0;
-}
-