stupid sprite limit bug fixed
[picodrive.git] / Pico / Debug.c
CommitLineData
cc68a136 1#include "PicoInt.h"\r
2\r
3typedef unsigned char u8;\r
4\r
5static unsigned int pppc, ops=0;\r
6extern unsigned int lastread_a, lastread_d[16], lastwrite_cyc_d[16], lastwrite_mus_d[16];\r
7extern int lrp_cyc, lrp_mus, lwp_cyc, lwp_mus;\r
b5e5172d 8unsigned int old_regs[16], old_sr, ppop, have_illegal = 0;\r
9int dbg_irq_level = 0, dbg_irq_level_sub = 0;\r
aa15fda8 10\r
11#undef dprintf\r
12#define dprintf(f,...) printf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__)\r
cc68a136 13\r
03e4f2a3 14#if defined(EMU_C68K)\r
99464b62 15static struct Cyclone *currentC68k = NULL;\r
16#define other_set_sub(s) currentC68k=(s)?&PicoCpuCS68k:&PicoCpuCM68k;\r
17#define other_get_sr() CycloneGetSr(currentC68k)\r
18#define other_dar(i) currentC68k->d[i]\r
19#define other_osp currentC68k->osp\r
20#define other_get_irq() currentC68k->irq\r
21#define other_set_irq(i) currentC68k->irq=i\r
22#define other_is_stopped() (currentC68k->state_flags&1)\r
23#define other_is_tracing() ((currentC68k->state_flags&2)?1:0)\r
03e4f2a3 24#elif defined(EMU_F68K)\r
b5e5172d 25#define other_set_sub(s) g_m68kcontext=(s)?&PicoCpuFS68k:&PicoCpuFM68k;\r
26#define other_get_sr() g_m68kcontext->sr\r
27#define other_dar(i) ((unsigned int*)g_m68kcontext->dreg)[i]\r
28#define other_osp g_m68kcontext->asp\r
29#define other_get_irq() g_m68kcontext->interrupts[0]\r
30#define other_set_irq(irq) g_m68kcontext->interrupts[0]=irq\r
31#define other_is_stopped() ((g_m68kcontext->execinfo&FM68K_HALTED)?1:0)\r
32#define other_is_tracing() ((g_m68kcontext->execinfo&FM68K_EMULATE_TRACE)?1:0)\r
03e4f2a3 33#else\r
34#error other core missing, don't compile this file\r
35#endif\r
36\r
37static int otherRun(void)\r
38{\r
39#if defined(EMU_C68K)\r
99464b62 40 currentC68k->cycles=1;\r
41 CycloneRun(currentC68k);\r
42 return 1-currentC68k->cycles;\r
03e4f2a3 43#elif defined(EMU_F68K)\r
8022f53d 44 return fm68k_emulate(1, 0);\r
03e4f2a3 45#endif\r
46}\r
47\r
cc68a136 48//static\r
b5e5172d 49void dumpPCandExit(int is_sub)\r
cc68a136 50{\r
51 char buff[128];\r
52 int i;\r
53\r
54 m68k_disassemble(buff, pppc, M68K_CPU_TYPE_68000);\r
55 dprintf("PC: %06x: %04x: %s", pppc, ppop, buff);\r
aa15fda8 56 dprintf(" this | prev");\r
cc68a136 57 for(i=0; i < 8; i++)\r
03e4f2a3 58 dprintf("d%i=%08x, a%i=%08x | d%i=%08x, a%i=%08x", i, other_dar(i), i, other_dar(i+8), i, old_regs[i], i, old_regs[i+8]);\r
59 dprintf("SR: %04x | %04x (??s? 0iii 000x nzvc)", other_get_sr(), old_sr);\r
cc68a136 60 dprintf("last_read: %08x @ %06x", lastread_d[--lrp_cyc&15], lastread_a);\r
b5e5172d 61 dprintf("ops done: %i, is_sub: %i", ops, is_sub);\r
cc68a136 62 exit(1);\r
63}\r
64\r
b5e5172d 65int CM_compareRun(int cyc, int is_sub)\r
cc68a136 66{\r
67 char *str;\r
b5e5172d 68 int cyc_done=0, cyc_other, cyc_musashi, *irq_level, err=0;\r
69 unsigned int i, pc, mu_sr;\r
cc68a136 70\r
b5e5172d 71 m68ki_cpu_p=is_sub?&PicoCpuMS68k:&PicoCpuMM68k;\r
72 other_set_sub(is_sub);\r
cc68a136 73 lrp_cyc = lrp_mus = 0;\r
74\r
b5e5172d 75 while (cyc_done < cyc)\r
aa15fda8 76 {\r
77 if (have_illegal && m68k_read_disassembler_16(m68ki_cpu.pc) != 0x4e73) // not rte\r
78 {\r
79 have_illegal = 0;\r
80 m68ki_cpu.pc += 2;\r
03e4f2a3 81#ifdef EMU_C68K\r
99464b62 82 currentC68k->pc=currentC68k->checkpc(currentC68k->pc + 2);\r
03e4f2a3 83#endif\r
aa15fda8 84 }\r
85 // hacks for test_misc2\r
86 if (m68ki_cpu.pc == 0x0002e0 && m68k_read_disassembler_16(m68ki_cpu.pc) == 0x4e73)\r
87 {\r
88 // get out of "priviledge violation" loop\r
89 have_illegal = 1;\r
90 //m68ki_cpu.s_flag = SFLAG_SET;\r
99464b62 91 //currentC68k->srh|=0x20;\r
aa15fda8 92 }\r
cc68a136 93\r
b5e5172d 94 pppc = is_sub ? SekPcS68k : SekPc;\r
aa15fda8 95 ppop = m68k_read_disassembler_16(pppc);\r
03e4f2a3 96 memcpy(old_regs, &other_dar(0), 4*16);\r
97 old_sr = other_get_sr();\r
aa15fda8 98\r
0af33fe0 99#if 0\r
aa15fda8 100 {\r
101 char buff[128];\r
102 dprintf("---");\r
103 m68k_disassemble(buff, pppc, M68K_CPU_TYPE_68000);\r
104 dprintf("PC: %06x: %04x: %s", pppc, ppop, buff);\r
99464b62 105 //dprintf("A7: %08x", currentC68k->a[7]);\r
0af33fe0 106 }\r
107#endif\r
108\r
b5e5172d 109 irq_level = is_sub ? &dbg_irq_level_sub : &dbg_irq_level;\r
110 if (*irq_level)\r
0af33fe0 111 {\r
b5e5172d 112 other_set_irq(*irq_level);\r
113 m68k_set_irq(*irq_level);\r
114 *irq_level=0;\r
aa15fda8 115 }\r
116\r
03e4f2a3 117 cyc_other=otherRun();\r
99464b62 118 // Musashi takes irq even if it hasn't got cycles left, let othercpu do it too\r
119 if (other_get_irq() && other_get_irq() > ((other_get_sr()>>8)&7))\r
120 cyc_other+=otherRun();\r
aa15fda8 121 cyc_musashi=m68k_execute(1);\r
122\r
03e4f2a3 123 if (cyc_other != cyc_musashi) {\r
124 dprintf("cycles: %i vs %i", cyc_other, cyc_musashi);\r
aa15fda8 125 err=1;\r
126 }\r
127\r
03e4f2a3 128 if (lrp_cyc != lrp_mus) {\r
aa15fda8 129 dprintf("lrp: %i vs %i", lrp_cyc&15, lrp_mus&15);\r
130 err=1;\r
131 }\r
132\r
03e4f2a3 133 if (lwp_cyc != lwp_mus) {\r
aa15fda8 134 dprintf("lwp: %i vs %i", lwp_cyc&15, lwp_mus&15);\r
135 err=1;\r
136 }\r
137\r
03e4f2a3 138 for (i=0; i < 16; i++) {\r
139 if (lastwrite_cyc_d[i] != lastwrite_mus_d[i]) {\r
aa15fda8 140 dprintf("lastwrite: [%i]= %08x vs %08x", i, lastwrite_cyc_d[i], lastwrite_mus_d[i]);\r
03e4f2a3 141 err=1;\r
aa15fda8 142 break;\r
143 }\r
144 }\r
145\r
146 // compare PC\r
b5e5172d 147 pc = is_sub ? SekPcS68k : SekPc;\r
aa15fda8 148 m68ki_cpu.pc&=~1;\r
b5e5172d 149 if (pc != m68ki_cpu.pc) {\r
150 dprintf("PC: %06x vs %06x", pc, m68ki_cpu.pc);\r
aa15fda8 151 err=1;\r
152 }\r
cc68a136 153\r
154#if 0\r
aa15fda8 155 if( SekPc > Pico.romsize || SekPc < 0x200 ) {\r
156 dprintf("PC out of bounds: %06x", SekPc);\r
157 err=1;\r
158 }\r
cc68a136 159#endif\r
160\r
161 // compare regs\r
03e4f2a3 162 for (i=0; i < 16; i++) {\r
163 if (other_dar(i) != m68ki_cpu.dar[i]) {\r
aa15fda8 164 str = (i < 8) ? "d" : "a";\r
03e4f2a3 165 dprintf("reg: %s%i: %08x vs %08x", str, i&7, other_dar(i), m68ki_cpu.dar[i]);\r
aa15fda8 166 err=1;\r
167 }\r
168 }\r
169\r
170 // SR\r
03e4f2a3 171 if (other_get_sr() != (mu_sr = m68k_get_reg(NULL, M68K_REG_SR))) {\r
172 dprintf("SR: %04x vs %04x (??s? 0iii 000x nzvc)", other_get_sr(), mu_sr);\r
aa15fda8 173 err=1;\r
174 }\r
175\r
176 // IRQl\r
03e4f2a3 177 if (other_get_irq() != (m68ki_cpu.int_level>>8)) {\r
178 dprintf("IRQ: %i vs %i", other_get_irq(), (m68ki_cpu.int_level>>8));\r
aa15fda8 179 err=1;\r
180 }\r
181\r
182 // OSP/USP\r
03e4f2a3 183 if (other_osp != m68ki_cpu.sp[((mu_sr>>11)&4)^4]) {\r
184 dprintf("OSP: %06x vs %06x", other_osp, m68ki_cpu.sp[((mu_sr>>11)&4)^4]);\r
aa15fda8 185 err=1;\r
186 }\r
187\r
188 // stopped\r
03e4f2a3 189 if ((other_is_stopped() && !m68ki_cpu.stopped) || (!other_is_stopped() && m68ki_cpu.stopped)) {\r
190 dprintf("stopped: %i vs %i", other_is_stopped(), m68ki_cpu.stopped);\r
0af33fe0 191 err=1;\r
192 }\r
193\r
194 // tracing\r
03e4f2a3 195 if((other_is_tracing() && !m68ki_tracing) || (!other_is_tracing() && m68ki_tracing)) {\r
196 dprintf("tracing: %i vs %i", other_is_tracing(), m68ki_tracing);\r
aa15fda8 197 err=1;\r
198 }\r
cc68a136 199\r
b5e5172d 200 if(err) dumpPCandExit(is_sub);\r
cc68a136 201\r
0af33fe0 202#if 0\r
99464b62 203 if (m68ki_cpu.dar[15] < 0x00ff0000 || m68ki_cpu.dar[15] >= 0x01000000)\r
2270612a 204 {\r
99464b62 205 other_dar(15) = m68ki_cpu.dar[15] = 0xff8000;\r
2270612a 206 }\r
0af33fe0 207#endif\r
cc68a136 208#if 0\r
209 m68k_set_reg(M68K_REG_SR, ((mu_sr-1)&~0x2000)|(mu_sr&0x2000)); // broken\r
99464b62 210 CycloneSetSr(currentC68k, ((mu_sr-1)&~0x2000)|(mu_sr&0x2000));\r
211 currentC68k->stopped = m68ki_cpu.stopped = 0;\r
212 if(SekPc > 0x400 && (currentC68k->a[7] < 0xff0000 || currentC68k->a[7] > 0xffffff))\r
213 currentC68k->a[7] = m68ki_cpu.dar[15] = 0xff8000;\r
cc68a136 214#endif\r
215\r
03e4f2a3 216 cyc_done += cyc_other;\r
aa15fda8 217 ops++;\r
cc68a136 218 }\r
219\r
220 return cyc_done;\r
221}\r