From a386ef64f6376b3ef8434a6cdf456495287fcbca Mon Sep 17 00:00:00 2001 From: Peter Fors Date: Mon, 31 Mar 2025 20:31:05 +0200 Subject: currently 90% working --- memory.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'memory.c') diff --git a/memory.c b/memory.c index cb29344..d4d2aa6 100644 --- a/memory.c +++ b/memory.c @@ -3,10 +3,9 @@ static uint8_t memory_read(struct nes_state *restrict state, uint32_t offset) { state->cycle++; - for(uint32_t i = 0; i < 3; ++i) { - ppu_tick(state); - } + ppu_tick(state); ppu_tick(state); ppu_tick(state); + // state->ram[0x301] = 0x1; if(offset < 0x2000) { return state->ram[offset & 0x07ff]; } else if(offset < 0x4000) { @@ -28,16 +27,18 @@ static uint8_t memory_read(struct nes_state *restrict state, uint32_t offset) { static void memory_write(struct nes_state *restrict state, uint32_t offset, uint8_t value) { state->cycle++; - for(uint32_t i = 0; i < 3; ++i) { - ppu_tick(state); - } + ppu_tick(state); ppu_tick(state); ppu_tick(state); + +// if(offset == 0x0300) { +// printf("WRITE $0300 = %02x @ PC=%04x\n", value, state->cpu.pc); +// } if(offset < 0x2000) { state->ram[offset & 0x07ff] = value; } else if(offset < 0x4000) { switch(offset & 7) { - case 0: state->ppu.ctrl = value; break; - case 1: state->ppu.mask = value; break; + case 0: ppu_write_2000(state, value); break; + case 1: ppu_write_2001(state, value); break; case 3: ppu_write_2003(state, value); break; case 4: ppu_write_2004(state, value); break; case 5: ppu_write_2005(state, value); break; @@ -73,9 +74,7 @@ static uint8_t memory_read_dma(struct nes_state *restrict state, uint32_t offset static uint8_t memory_read_dummy(struct nes_state *restrict state, uint32_t offset) { state->cycle++; - for(uint32_t i = 0; i < 3; ++i) { - ppu_tick(state); - } + ppu_tick(state); ppu_tick(state); ppu_tick(state); if(offset < 0x2000) { return 0; -- cgit v1.2.3