summaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
authorPeter Fors <peter.fors@mindkiller.com>2025-04-21 14:06:43 +0200
committerPeter Fors <peter.fors@mindkiller.com>2025-04-21 14:06:43 +0200
commit19f119e49c91580f49bb02f86bb905a05ba90d6b (patch)
tree1fb671eb5bec6cd723e3708e0085280aee926547 /memory.c
parent6321f071ed2ab36242e857a9414b7f4c53092d72 (diff)
back to 2560fps after wrangling the ppu_state into two cachelines
Diffstat (limited to 'memory.c')
-rw-r--r--memory.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/memory.c b/memory.c
index a2e094f..54962a5 100644
--- a/memory.c
+++ b/memory.c
@@ -8,15 +8,19 @@ static uint8_t memory_read(struct nes_state *restrict state, uint32_t offset) {
if(LIKELY(offset < 0x2000)) {
return state->ram[offset & 0x07ff];
+
} else if(offset < 0x4000) {
return ppu_read(state, offset);
+
} else if(offset == 0x4016 || offset == 0x4017) {
uint32_t index = offset & 1;
uint8_t value = (state->input_latch[index] >> state->input_bit[index]) & 1;
state->input_bit[index]++;
return value | 0x40; // Bit 6 open bus high, bit 7 low
+
} else if(LIKELY(offset >= 0x6000)) {
return state->mapper.prg_read(state, offset);
+
}
return 0;
}
@@ -28,10 +32,13 @@ static void memory_write(struct nes_state *restrict state, uint32_t offset, uint
if(LIKELY(offset < 0x2000)) {
state->ram[offset & 0x07ff] = value;
+
} else if(offset < 0x4000) {
ppu_write(state, offset, value);
+
} else if(offset == 0x4014) {
ppu_dma_4014(state, value);
+
} else if(offset == 0x4016) {
uint8_t prev = state->input_strobe;
state->input_strobe = value & 1;
@@ -43,6 +50,7 @@ static void memory_write(struct nes_state *restrict state, uint32_t offset, uint
state->input_bit[0] = 0;
state->input_bit[1] = 0;
}
+
} else if(offset >= 0x6000) {
state->mapper.prg_write(state, offset, value);
}
@@ -53,8 +61,10 @@ static uint8_t memory_read_dma(struct nes_state *restrict 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;
}