summaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
authorPeter Fors <peter.fors@mindkiller.com>2025-03-31 20:31:05 +0200
committerPeter Fors <peter.fors@mindkiller.com>2025-03-31 20:31:05 +0200
commita386ef64f6376b3ef8434a6cdf456495287fcbca (patch)
treee2da9f72ce0a565b4fac2fc8be19ab3497286b36 /memory.c
parentd5486a5af100fb37fac08b60d862ac14943853ce (diff)
currently 90% working
Diffstat (limited to 'memory.c')
-rw-r--r--memory.c21
1 files changed, 10 insertions, 11 deletions
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;