summaryrefslogtreecommitdiff
path: root/cpu.c
diff options
context:
space:
mode:
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 @@
5#include <stdlib.h> 5#include <stdlib.h>
6#include <string.h> 6#include <string.h>
7 7
8#include "apu.h"
8#include "cpu.h" 9#include "cpu.h"
9#include "opcodes.h" 10#include "opcodes.h"
10#include "rom.h"
11#include "ppu.h" 11#include "ppu.h"
12#include "rom.h"
12 13
13#define MAX(a, b) ((a > b) ? a : b) 14#define MAX(a, b) ((a > b) ? a : b)
14 15
@@ -53,9 +54,10 @@ peek(uint16_t addr)
53 return rom.prg_rom[addr - 0x8000]; 54 return rom.prg_rom[addr - 0x8000];
54 else 55 else
55 fprintf(stderr, "PRG ROG size is not 0x4000 nor 0x8000\n"), exit(1); 56 fprintf(stderr, "PRG ROG size is not 0x4000 nor 0x8000\n"), exit(1);
56 } else { 57 } else if ((addr >= 0x4000 && addr <= 0x4013) || addr == 0x4015 || addr == 0x4017)
58 return apu_read(addr);
59 else
57 return memory[addr]; 60 return memory[addr];
58 }
59} 61}
60 62
61static uint16_t 63static uint16_t
@@ -68,6 +70,11 @@ peek16(uint16_t addr)
68static void 70static void
69memwrite(uint16_t addr, uint8_t byte) 71memwrite(uint16_t addr, uint8_t byte)
70{ 72{
73 if (addr >= 0x4000 && addr <= 0x4017) {
74 apu_write(addr, byte);
75 return;
76 }
77
71 MEMORY_MIRROR(addr); 78 MEMORY_MIRROR(addr);
72 79
73 memory[addr] = byte; 80 memory[addr] = byte;