9 extern uint32 nes_registers[0x10];
10 extern uint32 pc_base;
11 extern uint8 nes_internal_ram[0x800];
12 extern uint32 timestamp_a;
13 extern uint32 framecount;
14 static uint32 framecount_d;
15 uint32 PC_prev = 0xcccccc, OP_prev = 0xcccccc;
18 static int pending_add_cycles = 0, pending_rebase = 0, pending_irq = 0;
21 uint32 dwrites_c[2], dwrites_a[2];
22 int dread_count_c, dread_count_a, dwrite_count_c, dwrite_count_a;
23 int mapirq_cyc_c, mapirq_cyc_a;
25 static void leave(void)
27 printf("\nA: %02x, X: %02x, Y: %02x, S: %02x\n", X.A, X.X, X.Y, X.S);
28 printf("PC = %04x, OP=%02X\n", PC_prev, OP_prev);
29 printf("rest = %08x\n", nes_registers[4]);
33 static void compare_state(void)
38 if ((nes_registers[0] >> 24) != X.A) {
39 printf("A: %02x vs %02x\n", nes_registers[0] >> 24, X.A);
43 if ((nes_registers[1] & 0xff) != X.X) {
44 printf("X: %02x vs %02x\n", nes_registers[1] & 0xff, X.X);
48 if ((nes_registers[2] & 0xff) != X.Y) {
49 printf("Y: %02x vs %02x\n", nes_registers[2] & 0xff, X.Y);
53 if (nes_registers[3] - pc_base != X.PC) {
54 printf("PC: %04x vs %04x\n", nes_registers[3] - pc_base, X.PC);
58 if ((nes_registers[4] >> 24) != X.S) {
59 printf("S: %02x vs %02x\n", nes_registers[4] >> 24, X.S);
63 if (((nes_registers[4]>>8)&0xff) != X.IRQlow) {
64 printf("IRQlow: %02x vs %02x\n", ((nes_registers[4]>>8)&0xff), X.IRQlow);
69 nes_flags = nes_registers[4] & 0x5d;
70 if ( nes_registers[5]&0x80000000) nes_flags |= 0x80; // N
71 if (!(nes_registers[5]&0x000000ff)) nes_flags |= 0x02; // Z
72 // nes_flags |= 0x20; // U, not set in C core (set only when pushing)
74 if (nes_flags != (X.P&~0x20)) {
75 printf("flags: %02x vs %02x\n", nes_flags, (X.P&~0x20));
79 if (((int32)nes_registers[7] >> 16) != X.count) {
80 printf("cycles: %i vs %i\n", (int32)nes_registers[7] >> 16, X.count);
84 if (dread_count_a != dread_count_c) {
85 printf("dread_count: %i vs %i\n", dread_count_a, dread_count_c);
89 if (dwrite_count_a != dwrite_count_c) {
90 printf("dwrite_count: %i vs %i\n", dwrite_count_a, dwrite_count_c);
94 for (i = dwrite_count_a - 1; !fail && i >= 0; i--)
95 if (dwrites_a[i] != dwrites_c[i]) {
96 printf("dwrites[%i]: %06x vs %06x\n", dwrite_count_a, dwrites_a[i], dwrites_c[i]);
100 if (mapirq_cyc_a != mapirq_cyc_c) {
101 printf("mapirq_cyc: %i vs %i\n", mapirq_cyc_a, mapirq_cyc_c);
105 if (timestamp_a != timestamp) {
106 printf("timestamp: %u vs %u\n", timestamp_a, timestamp);
114 static void compare_ram(void)
117 for (i = 0; i < 0x800/4; i++)
119 if (((int *)nes_internal_ram)[i] != ((int32 *)RAM)[i]) {
122 for (u = i*4; u < i*4+4; u++)
123 if (nes_internal_ram[u] != RAM[u])
124 printf("RAM[%03x]: %02x vs %02x\n", u, nes_internal_ram[u], RAM[u]);
132 void TriggerIRQ_d(void)
135 pending_irq |= 0x100;
138 void TriggerNMI_d(void)
146 void TriggerNMINSF_d(void)
150 void X6502_Run_d(int32 c)
152 int32 cycles = c << 4; /* *16 */
153 if (PAL) cycles -= c; /* *15 */
155 //printf("-- %06i: run(%i)\n", (int)g_cnt, (int)c);
158 if (framecount != framecount_d) {
160 framecount_d = framecount;
163 timestamp_a = timestamp;
168 if (pending_irq & 0x100) {
172 if (pending_irq & 0xff) {
175 X6502_IRQBegin_c(pending_irq & 0xff);
176 X6502_IRQBegin_a(pending_irq & 0xff);
181 nes_registers[7]=1<<16;
184 dread_count_c = dread_count_a = dwrite_count_c = dwrite_count_a = 0;
185 mapirq_cyc_a = mapirq_cyc_c = 0;
186 //timestamp_a = timestamp;
193 g_cnt -= 1 - X.count;
194 if (pending_add_cycles) {
195 g_cnt -= pending_add_cycles*48;
196 //X6502_AddCycles_c(pending_add_cycles);
197 //X6502_AddCycles_a(pending_add_cycles);
198 timestamp += pending_add_cycles;
199 timestamp_a += pending_add_cycles;
200 pending_add_cycles = 0;
202 if (pending_rebase) {
208 //printf("-- run_end\n");
211 void X6502_Reset_d(void)
213 printf("-- reset\n");
220 void X6502_Power_d(void)
222 printf("-- power\n");
223 if (nes_internal_ram == RAM) printf("nes_internal_ram == RAM!!\n");
224 dread_count_c = dread_count_a = dwrite_count_c = dwrite_count_a = 0;
225 mapirq_cyc_c = mapirq_cyc_a = 0;
232 void X6502_AddCycles_d(int x)
234 printf("-- AddCycles(%i|%i)\n", x, x*48);
236 pending_add_cycles = x; // *48;
237 // printf("can't use this in debug\n");
239 //X6502_AddCycles_c(x);
240 //X6502_AddCycles_a(x);
244 void X6502_IRQBegin_d(int w)
246 printf("-- IRQBegin(%02x)\n", w);
248 // X6502_IRQBegin_c(w);
249 // X6502_IRQBegin_a(w);
253 void X6502_IRQEnd_d(int w)
255 printf("-- IRQEnd(%02x)\n", w);
262 void X6502_Rebase_d(void)