2, 5, 5, 2, 4, 4, 6, 2, 2, 4, 4, 2, 4, 4, 6, 2 };
#endif
+#if 0
static uint8_t _6502Cycles[256] = {
7, 6, 2, 8, 3, 3, 5, 5, 3, 2, 2, 2, 4, 4, 6, 6,
2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 6, 7,
2, 5, 5, 2, 4, 4, 6, 2, 2, 4, 3, 2, 4, 4, 6, 2,
2, 6, 2, 2, 3, 3, 5, 2, 2, 2, 2, 2, 4, 4, 6, 2,
2, 5, 5, 2, 4, 4, 6, 2, 2, 4, 4, 2, 4, 4, 6, 2 };
+#endif
#if 0
// ExtraCycles:
#define HANDLE_BRANCH_TAKEN(m) \
{ \
- uint16_t oldpc = regs.pc; \
+ uint16_t oldpc = regs.pc; \
regs.pc += m; \
regs.clock++; \
+\
if ((oldpc ^ regs.pc) & 0xFF00) \
regs.clock++; \
}
while (regs.clock < endCycles)
{
#if 0
+static bool weGo = false;
+if (regs.pc == 0x80AE)
+{
+ dumpDis = true;
+ weGo = true;
+}
+else if (regs.pc == 0xFCA8 && weGo)
+{
+ dumpDis = false;
+ WriteLog("\n*** DELAY (A=$%02X)\n\n", regs.a);
+}
+else if (regs.pc == 0xFCB3 && weGo)
+{
+ dumpDis = true;
+}
+#endif
+#if 0
/*if (regs.pc == 0x4007)
{
dumpDis = true;
//if (!(regs.cpuFlags & V65C02_STATE_ILLEGAL_INST))
//instCount[opcode]++;
- exec_op[opcode](); // Execute that opcode...
+ // We need this because the opcode execute could add 1 or 2 cycles
+ uint64_t clockSave = regs.clock;
+
+ // Execute that opcode...
+ exec_op[opcode]();
regs.clock += CPUCycles[opcode];
+
+ // Tell the timer function how many PHI2s have elapsed
+ if (regs.Timer)
+// regs.Timer(CPUCycles[opcode]);
+ regs.Timer(regs.clock - clockSave);
+
#ifdef __DEBUG__
if (dumpDis)
- WriteLog(" [PC=%04X, SP=%04X, CC=%s%s.%s%s%s%s%s, A=%02X, X=%02X, Y=%02X]\n",
- regs.pc, 0x0100 + regs.sp,
+ WriteLog(" [PC=%04X, SP=01%02X, CC=%s%s.%s%s%s%s%s, A=%02X, X=%02X, Y=%02X]\n",
+ regs.pc, regs.sp,
(regs.cc & FLAG_N ? "N" : "-"), (regs.cc & FLAG_V ? "V" : "-"),
(regs.cc & FLAG_B ? "B" : "-"), (regs.cc & FLAG_D ? "D" : "-"),
(regs.cc & FLAG_I ? "I" : "-"), (regs.cc & FLAG_Z ? "Z" : "-"),
{
// Not sure about this...
regs.sp = 0xFF;
- regs.cc = FLAG_B | FLAG_I; // Reset the CC register
+ regs.cc = FLAG_I; // Reset the CC register
regs.pc = RdMemW(0xFFFC); // And load PC with the RESET vector
-// context->cpuFlags &= ~V65C02_ASSERT_LINE_RESET;
-// regs.cpuFlags &= ~V65C02_ASSERT_LINE_RESET;
context->cpuFlags = 0; // Clear CPU flags...
regs.cpuFlags = 0;
#ifdef __DEBUG__
{
#ifdef __DEBUG__
WriteLog("\n*** IRQ ***\n\n");
+WriteLog("Clock=$%X\n", regs.clock);
+//dumpDis = true;
#endif
regs.WrMem(0x0100 + regs.sp--, regs.pc >> 8); // Save PC and CC
regs.WrMem(0x0100 + regs.sp--, regs.pc & 0xFF);
return regs.clock;
}
+
+//
+// Assert 65C02 line in current context
+//
+void AssertLine(uint16_t flags)
+{
+ regs.cpuFlags |= flags;
+}
+