summaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
authorPeter Fors <peter.fors@mindkiller.com>2025-04-06 12:27:12 +0200
committerPeter Fors <peter.fors@mindkiller.com>2025-04-06 12:27:12 +0200
commit39715ca6bf65d2e2dd889cdef4b39d584464d9e7 (patch)
tree39390f6fadd0ddbe913ae66e11847b8b3e7b16bb /memory.c
parentdabd7a5848e6aa55e91cf4c804f6236b4f7fe30e (diff)
added more mappers (buggy)
Diffstat (limited to 'memory.c')
-rw-r--r--memory.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/memory.c b/memory.c
index 28c51ad..a2e094f 100644
--- a/memory.c
+++ b/memory.c
@@ -10,9 +10,11 @@ static uint8_t memory_read(struct nes_state *restrict state, uint32_t offset) {
return state->ram[offset & 0x07ff];
} else if(offset < 0x4000) {
return ppu_read(state, offset);
- // } else if(offset < 0x4020) {
- // // TODO: APU and I/O reads
- // return 0;
+ } 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);
}
@@ -30,8 +32,17 @@ static void memory_write(struct nes_state *restrict state, uint32_t offset, uint
ppu_write(state, offset, value);
} else if(offset == 0x4014) {
ppu_dma_4014(state, value);
- // } else if(offset < 0x4020) {
- // // TODO: APU and I/O writes
+ } else if(offset == 0x4016) {
+ uint8_t prev = state->input_strobe;
+ state->input_strobe = value & 1;
+
+ if(prev == 1 && (value & 1) == 0) {
+ // Latch current inputs
+ state->input_latch[0] = state->input[0];
+ state->input_latch[1] = state->input[1];
+ state->input_bit[0] = 0;
+ state->input_bit[1] = 0;
+ }
} else if(offset >= 0x6000) {
state->mapper.prg_write(state, offset, value);
}