summaryrefslogtreecommitdiff
path: root/cpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpu.c')
-rw-r--r--cpu.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/cpu.c b/cpu.c
index 8df2bf9..621fe5b 100644
--- a/cpu.c
+++ b/cpu.c
@@ -8,6 +8,7 @@
8#include "cpu.h" 8#include "cpu.h"
9#include "opcodes.h" 9#include "opcodes.h"
10#include "rom.h" 10#include "rom.h"
11#include "ppu.h"
11 12
12#define MAX(a, b) ((a > b) ? a : b) 13#define MAX(a, b) ((a > b) ? a : b)
13 14
@@ -146,14 +147,23 @@ opcode_mem(enum addressing_mode mode)
146} 147}
147 148
148static void 149static void
150tick(void)
151{
152 cycles++;
153 ppu_tick();
154 ppu_tick();
155 ppu_tick();
156}
157
158static void
149branch(uint16_t addr, bool cond) 159branch(uint16_t addr, bool cond)
150{ 160{
151 if (!cond) 161 if (!cond)
152 return; 162 return;
153 cycles++; 163 tick();
154 164
155 if (((regs.pc + 1) & 0xFF00) != (addr & 0xFF00)) 165 if (((regs.pc + 1) & 0xFF00) != (addr & 0xFF00))
156 cycles++; 166 tick();
157 167
158 regs.pc = addr; 168 regs.pc = addr;
159} 169}
@@ -946,18 +956,21 @@ interpret(void)
946 956
947 while (spaces--) putchar(' '); 957 while (spaces--) putchar(' ');
948 958
949 printf("A:%02X X:%02X Y:%02X P:%02X SP:%02X CYC:%d\n", 959 printf("A:%02X X:%02X Y:%02X P:%02X SP:%02X PPU:%3d,%3d CYC:%d\n",
950 regs.a, regs.x, regs.y, STATUS_TO_INT(), regs.sp, cycles); 960 regs.a, regs.x, regs.y, STATUS_TO_INT(), regs.sp,
961 ppu.scanlines, ppu.cycles, cycles);
951 962
952 if (opcodes[op].memread) 963 if (opcodes[op].memread)
953 opcodes[op].instr(peek(arg)); 964 opcodes[op].instr(peek(arg));
954 else 965 else
955 opcodes[op].instr(arg); 966 opcodes[op].instr(arg);
956 967
957 cycles += opcodes[op].cycles; 968 for (uint8_t i = 0; i < opcodes[op].cycles; i++)
969 tick();
970
958 if (page_crossed) { 971 if (page_crossed) {
959 if (opcodes[op].page_cross) 972 if (opcodes[op].page_cross)
960 cycles++; 973 tick();
961 page_crossed = false; 974 page_crossed = false;
962 } 975 }
963 } 976 }
@@ -976,6 +989,8 @@ cpu_init(void)
976 regs.status.unused = 1; 989 regs.status.unused = 1;
977 990
978 cycles += 7; 991 cycles += 7;
992 for (uint8_t i = 0; i < 7 * 3; i++)
993 ppu_tick();
979} 994}
980 995
981int 996int