From 39715ca6bf65d2e2dd889cdef4b39d584464d9e7 Mon Sep 17 00:00:00 2001 From: Peter Fors Date: Sun, 6 Apr 2025 12:27:12 +0200 Subject: added more mappers (buggy) --- memory.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'memory.c') 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); } -- cgit v1.2.3