summaryrefslogtreecommitdiff
path: root/cpu.c
diff options
context:
space:
mode:
authorvin <git@vineetk.net>2024-08-31 22:24:33 -0400
committervin <git@vineetk.net>2024-09-01 01:49:37 -0400
commit279478f16f8ea4fcc3c8765ff964954368664106 (patch)
treea3c3c1bb28d26f9040a3afec7f519c92fc7ac5a0 /cpu.c
parentc0679b404d3bd9c20133a1868113f200eae2cf9f (diff)
add preliminary apu register support
Diffstat (limited to 'cpu.c')
-rw-r--r--cpu.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/cpu.c b/cpu.c
index 509f7a8..97ece60 100644
--- a/cpu.c
+++ b/cpu.c
@@ -5,10 +5,11 @@
#include <stdlib.h>
#include <string.h>
+#include "apu.h"
#include "cpu.h"
#include "opcodes.h"
-#include "rom.h"
#include "ppu.h"
+#include "rom.h"
#define MAX(a, b) ((a > b) ? a : b)
@@ -53,9 +54,10 @@ peek(uint16_t addr)
return rom.prg_rom[addr - 0x8000];
else
fprintf(stderr, "PRG ROG size is not 0x4000 nor 0x8000\n"), exit(1);
- } else {
+ } else if ((addr >= 0x4000 && addr <= 0x4013) || addr == 0x4015 || addr == 0x4017)
+ return apu_read(addr);
+ else
return memory[addr];
- }
}
static uint16_t
@@ -68,6 +70,11 @@ peek16(uint16_t addr)
static void
memwrite(uint16_t addr, uint8_t byte)
{
+ if (addr >= 0x4000 && addr <= 0x4017) {
+ apu_write(addr, byte);
+ return;
+ }
+
MEMORY_MIRROR(addr);
memory[addr] = byte;