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 @@
#include "cpu.h"
#include "opcodes.h"
#include "rom.h"
+#include "ppu.h"
#define MAX(a, b) ((a > b) ? a : b)
@@ -146,14 +147,23 @@ opcode_mem(enum addressing_mode mode)
}
static void
+tick(void)
+{
+ cycles++;
+ ppu_tick();
+ ppu_tick();
+ ppu_tick();
+}
+
+static void
branch(uint16_t addr, bool cond)
{
if (!cond)
return;
- cycles++;
+ tick();
if (((regs.pc + 1) & 0xFF00) != (addr & 0xFF00))
- cycles++;
+ tick();
regs.pc = addr;
}
@@ -946,18 +956,21 @@ interpret(void)
while (spaces--) putchar(' ');
- printf("A:%02X X:%02X Y:%02X P:%02X SP:%02X CYC:%d\n",
- regs.a, regs.x, regs.y, STATUS_TO_INT(), regs.sp, cycles);
+ printf("A:%02X X:%02X Y:%02X P:%02X SP:%02X PPU:%3d,%3d CYC:%d\n",
+ regs.a, regs.x, regs.y, STATUS_TO_INT(), regs.sp,
+ ppu.scanlines, ppu.cycles, cycles);
if (opcodes[op].memread)
opcodes[op].instr(peek(arg));
else
opcodes[op].instr(arg);
- cycles += opcodes[op].cycles;
+ for (uint8_t i = 0; i < opcodes[op].cycles; i++)
+ tick();
+
if (page_crossed) {
if (opcodes[op].page_cross)
- cycles++;
+ tick();
page_crossed = false;
}
}
@@ -976,6 +989,8 @@ cpu_init(void)
regs.status.unused = 1;
cycles += 7;
+ for (uint8_t i = 0; i < 7 * 3; i++)
+ ppu_tick();
}
int