minor adjustments
[picodrive.git] / Pico / Pico.c
CommitLineData
cc68a136 1// This is part of Pico Library\r
2\r
3// (c) Copyright 2004 Dave, All rights reserved.\r
4// (c) Copyright 2006 notaz, All rights reserved.\r
5// Free for non-commercial use.\r
6\r
7// For commercial use, separate licencing terms must be obtained.\r
8\r
9\r
10#include "PicoInt.h"\r
cc68a136 11#include "sound/ym2612.h"\r
12\r
69996cb7 13int PicoVer=0x0133;\r
cc68a136 14struct Pico Pico;\r
602133e1 15int PicoOpt = 0;\r
16int PicoSkipFrame = 0; // skip rendering frame?\r
17int emustatus = 0; // rapid_ym2612, multi_ym_updates\r
18int PicoPad[2]; // Joypads, format is SACB RLDU\r
9037e45d 19int PicoAHW = 0; // active addon hardware: scd_active, 32x_active, svp_active, pico_active\r
cc68a136 20int PicoRegionOverride = 0; // override the region detection 0: Auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe\r
51a902ae 21int PicoAutoRgnOrder = 0;\r
602133e1 22int z80startCycle, z80stopCycle; // in 68k cycles\r
23struct PicoSRAM SRam = {0,};\r
24\r
f8ef8ff7 25void (*PicoWriteSound)(int len) = NULL; // called at the best time to send sound buffer (PsndOut) to hardware\r
26void (*PicoResetHook)(void) = NULL;\r
0ffefdb8 27void (*PicoLineHook)(int count) = NULL;\r
cc68a136 28\r
cc68a136 29// to be called once on emu init\r
30int PicoInit(void)\r
31{\r
32 // Blank space for state:\r
33 memset(&Pico,0,sizeof(Pico));\r
34 memset(&PicoPad,0,sizeof(PicoPad));\r
35\r
36 // Init CPUs:\r
37 SekInit();\r
38 z80_init(); // init even if we aren't going to use it\r
39\r
cc68a136 40 PicoInitMCD();\r
e807ac75 41 PicoSVPInit();\r
cc68a136 42\r
cc68a136 43 SRam.data=0;\r
cc68a136 44\r
45 return 0;\r
46}\r
47\r
48// to be called once on emu exit\r
49void PicoExit(void)\r
50{\r
602133e1 51 if (PicoAHW & PAHW_MCD)\r
4f265db7 52 PicoExitMCD();\r
cc68a136 53 z80_exit();\r
54\r
1cb1584b 55 if (SRam.data) free(SRam.data); SRam.data=0;\r
cc68a136 56}\r
57\r
1cb1584b 58void PicoPower(void)\r
59{\r
583ab72c 60 unsigned char sram_reg=Pico.m.sram_reg; // must be preserved\r
61\r
1cb1584b 62 // clear all memory of the emulated machine\r
63 memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram);\r
64\r
65 memset(&Pico.video,0,sizeof(Pico.video));\r
66 memset(&Pico.m,0,sizeof(Pico.m));\r
67\r
68 Pico.video.pending_ints=0;\r
69 z80_reset();\r
70\r
71 // default VDP register values (based on Fusion)\r
72 Pico.video.reg[0] = Pico.video.reg[1] = 0x04;\r
73 Pico.video.reg[0xc] = 0x81;\r
74 Pico.video.reg[0xf] = 0x02;\r
75\r
602133e1 76 if (PicoAHW & PAHW_MCD)\r
1cb1584b 77 PicoPowerMCD();\r
78\r
583ab72c 79 Pico.m.sram_reg=sram_reg;\r
1cb1584b 80 PicoReset();\r
81}\r
82\r
1e6b5e39 83PICO_INTERNAL void PicoDetectRegion(void)\r
cc68a136 84{\r
1e6b5e39 85 int support=0, hw=0, i;\r
cc68a136 86 unsigned char pal=0;\r
cc68a136 87\r
1e6b5e39 88 if (PicoRegionOverride)\r
cc68a136 89 {\r
90 support = PicoRegionOverride;\r
91 }\r
92 else\r
93 {\r
94 // Read cartridge region data:\r
1e6b5e39 95 int region=PicoRead32(0x1f0);\r
cc68a136 96\r
97 for (i=0;i<4;i++)\r
98 {\r
99 int c=0;\r
100\r
101 c=region>>(i<<3); c&=0xff;\r
102 if (c<=' ') continue;\r
103\r
51a902ae 104 if (c=='J') support|=1;\r
105 else if (c=='U') support|=4;\r
106 else if (c=='E') support|=8;\r
107 else if (c=='j') {support|=1; break; }\r
108 else if (c=='u') {support|=4; break; }\r
109 else if (c=='e') {support|=8; break; }\r
cc68a136 110 else\r
111 {\r
112 // New style code:\r
113 char s[2]={0,0};\r
114 s[0]=(char)c;\r
115 support|=strtol(s,NULL,16);\r
116 }\r
117 }\r
118 }\r
119\r
51a902ae 120 // auto detection order override\r
121 if (PicoAutoRgnOrder) {\r
122 if (((PicoAutoRgnOrder>>0)&0xf) & support) support = (PicoAutoRgnOrder>>0)&0xf;\r
123 else if (((PicoAutoRgnOrder>>4)&0xf) & support) support = (PicoAutoRgnOrder>>4)&0xf;\r
124 else if (((PicoAutoRgnOrder>>8)&0xf) & support) support = (PicoAutoRgnOrder>>8)&0xf;\r
125 }\r
126\r
cc68a136 127 // Try to pick the best hardware value for English/50hz:\r
128 if (support&8) { hw=0xc0; pal=1; } // Europe\r
129 else if (support&4) hw=0x80; // USA\r
130 else if (support&2) { hw=0x40; pal=1; } // Japan PAL\r
131 else if (support&1) hw=0x00; // Japan NTSC\r
132 else hw=0x80; // USA\r
133\r
134 Pico.m.hardware=(unsigned char)(hw|0x20); // No disk attached\r
135 Pico.m.pal=pal;\r
1e6b5e39 136}\r
137\r
138int PicoReset(void)\r
139{\r
140 unsigned char sram_reg=Pico.m.sram_reg; // must be preserved\r
141\r
142 if (Pico.romsize<=0) return 1;\r
143\r
144 /* must call now, so that banking is reset, and correct vectors get fetched */\r
145 if (PicoResetHook) PicoResetHook();\r
146\r
147 PicoMemReset();\r
148 SekReset();\r
149 // s68k doesn't have the TAS quirk, so we just globally set normal TAS handler in MCD mode (used by Batman games).\r
150 SekSetRealTAS(PicoAHW & PAHW_MCD);\r
151 SekCycleCntT=0;\r
152\r
153 if (PicoAHW & PAHW_MCD)\r
154 // needed for MCD to reset properly, probably some bug hides behind this..\r
155 memset(Pico.ioports,0,sizeof(Pico.ioports));\r
156 emustatus = 0;\r
157\r
158 Pico.m.dirtyPal = 1;\r
159\r
160 PicoDetectRegion();\r
161 Pico.video.status = 0x3408 | Pico.m.pal; // 'always set' bits | vblank | pal\r
cc68a136 162\r
9d917eea 163 PsndReset(); // pal must be known here\r
cc68a136 164\r
1cb1584b 165 // create an empty "dma" to cause 68k exec start at random frame location\r
602133e1 166 if (Pico.m.dma_xfers == 0 && !(PicoOpt&POPT_DIS_VDP_FIFO))\r
1cb1584b 167 Pico.m.dma_xfers = rand() & 0x1fff;\r
168\r
602133e1 169 if (PicoAHW & PAHW_MCD) {\r
1cb1584b 170 PicoResetMCD();\r
cc68a136 171 return 0;\r
172 }\r
173\r
1dceadae 174 // reset sram state; enable sram access by default if it doesn't overlap with ROM\r
175 Pico.m.sram_reg=sram_reg&0x14;\r
176 if (!(Pico.m.sram_reg&4) && Pico.romsize <= SRam.start) Pico.m.sram_reg |= 1;\r
cc68a136 177\r
1dceadae 178 elprintf(EL_STATUS, "sram: det: %i; eeprom: %i; start: %06x; end: %06x",\r
179 (Pico.m.sram_reg>>4)&1, (Pico.m.sram_reg>>2)&1, SRam.start, SRam.end);\r
cc68a136 180\r
181 return 0;\r
182}\r
183\r
1dceadae 184\r
69996cb7 185// dma2vram settings are just hacks to unglitch Legend of Galahad (needs <= 104 to work)\r
186// same for Outrunners (92-121, when active is set to 24)\r
48df6e9e 187// 96 is VR hack\r
69996cb7 188static const int dma_timings[] = {\r
48df6e9e 18996, 167, 166, 83, // vblank: 32cell: dma2vram dma2[vs|c]ram vram_fill vram_copy\r
4f672280 190102, 205, 204, 102, // vblank: 40cell:\r
69996cb7 19116, 16, 15, 8, // active: 32cell:\r
19224, 18, 17, 9 // ...\r
4f672280 193};\r
194\r
69996cb7 195static const int dma_bsycles[] = {\r
48df6e9e 196(488<<8)/96, (488<<8)/167, (488<<8)/166, (488<<8)/83,\r
312e9ce1 197(488<<8)/102, (488<<8)/205, (488<<8)/204, (488<<8)/102,\r
69996cb7 198(488<<8)/16, (488<<8)/16, (488<<8)/15, (488<<8)/8,\r
199(488<<8)/24, (488<<8)/18, (488<<8)/17, (488<<8)/9\r
312e9ce1 200};\r
201\r
eff55556 202PICO_INTERNAL int CheckDMA(void)\r
4f672280 203{\r
69996cb7 204 int burn = 0, xfers_can, dma_op = Pico.video.reg[0x17]>>6; // see gens for 00 and 01 modes\r
205 int xfers = Pico.m.dma_xfers;\r
312e9ce1 206 int dma_op1;\r
4f672280 207\r
312e9ce1 208 if(!(dma_op&2)) dma_op = (Pico.video.type==1) ? 0 : 1; // setting dma_timings offset here according to Gens\r
209 dma_op1 = dma_op;\r
210 if(Pico.video.reg[12] & 1) dma_op |= 4; // 40 cell mode?\r
211 if(!(Pico.video.status&8)&&(Pico.video.reg[1]&0x40)) dma_op|=8; // active display?\r
69996cb7 212 xfers_can = dma_timings[dma_op];\r
213 if(xfers <= xfers_can) {\r
4f672280 214 if(dma_op&2) Pico.video.status&=~2; // dma no longer busy\r
215 else {\r
69996cb7 216 burn = xfers * dma_bsycles[dma_op] >> 8; // have to be approximate because can't afford division..\r
4f672280 217 }\r
69996cb7 218 Pico.m.dma_xfers = 0;\r
4f672280 219 } else {\r
220 if(!(dma_op&2)) burn = 488;\r
69996cb7 221 Pico.m.dma_xfers -= xfers_can;\r
4f672280 222 }\r
223\r
69996cb7 224 elprintf(EL_VDPDMA, "~Dma %i op=%i can=%i burn=%i [%i]", Pico.m.dma_xfers, dma_op1, xfers_can, burn, SekCyclesDone());\r
312e9ce1 225 //dprintf("~aim: %i, cnt: %i", SekCycleAim, SekCycleCnt);\r
226 return burn;\r
4f672280 227}\r
228\r
bf5fbbb4 229static __inline void SekRunM68k(int cyc)\r
cc68a136 230{\r
231 int cyc_do;\r
232 SekCycleAim+=cyc;\r
4f672280 233 if((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return;\r
03e4f2a3 234#if defined(EMU_CORE_DEBUG)\r
235 // this means we do run-compare\r
b5e5172d 236 SekCycleCnt+=CM_compareRun(cyc_do, 0);\r
cc68a136 237#elif defined(EMU_C68K)\r
3aa1e148 238 PicoCpuCM68k.cycles=cyc_do;\r
239 CycloneRun(&PicoCpuCM68k);\r
240 SekCycleCnt+=cyc_do-PicoCpuCM68k.cycles;\r
cc68a136 241#elif defined(EMU_M68K)\r
242 SekCycleCnt+=m68k_execute(cyc_do);\r
70357ce5 243#elif defined(EMU_F68K)\r
8022f53d 244 SekCycleCnt+=fm68k_emulate(cyc_do+1, 0);\r
cc68a136 245#endif\r
246}\r
247\r
248static __inline void SekStep(void)\r
249{\r
250 // this is required for timing sensitive stuff to work\r
251 int realaim=SekCycleAim; SekCycleAim=SekCycleCnt+1;\r
03e4f2a3 252#if defined(EMU_CORE_DEBUG)\r
b5e5172d 253 SekCycleCnt+=CM_compareRun(1, 0);\r
cc68a136 254#elif defined(EMU_C68K)\r
3aa1e148 255 PicoCpuCM68k.cycles=1;\r
256 CycloneRun(&PicoCpuCM68k);\r
257 SekCycleCnt+=1-PicoCpuCM68k.cycles;\r
cc68a136 258#elif defined(EMU_M68K)\r
259 SekCycleCnt+=m68k_execute(1);\r
70357ce5 260#elif defined(EMU_F68K)\r
8022f53d 261 SekCycleCnt+=fm68k_emulate(1, 0);\r
cc68a136 262#endif\r
263 SekCycleAim=realaim;\r
264}\r
265\r
266static int CheckIdle(void)\r
267{\r
fad24893 268 int i, state[0x24];\r
cc68a136 269\r
270 // See if the state is the same after 2 steps:\r
fad24893 271 SekState(state); SekStep(); SekStep(); SekState(state+0x12);\r
272 for (i = 0x11; i >= 0; i--)\r
273 if (state[i] != state[i+0x12]) return 0;\r
cc68a136 274\r
3aa1e148 275 return 1;\r
cc68a136 276}\r
277\r
fa283c9a 278\r
cc68a136 279// to be called on 224 or line_sample scanlines only\r
280static __inline void getSamples(int y)\r
281{\r
03a265e5 282#if SIMPLE_WRITE_SOUND\r
e0978fa8 283 if (y != 224) return;\r
03a265e5 284 PsndRender(0, PsndLen);\r
285 if (PicoWriteSound) PicoWriteSound(PsndLen);\r
286 PsndClear();\r
287#else\r
7a93adeb 288 static int curr_pos = 0;\r
289\r
cc68a136 290 if(y == 224) {\r
cc68a136 291 if(emustatus & 2)\r
9d917eea 292 curr_pos += PsndRender(curr_pos, PsndLen-PsndLen/2);\r
293 else curr_pos = PsndRender(0, PsndLen);\r
cc68a136 294 if (emustatus&1) emustatus|=2; else emustatus&=~2;\r
7a93adeb 295 if (PicoWriteSound) PicoWriteSound(curr_pos);\r
cc68a136 296 // clear sound buffer\r
9d917eea 297 PsndClear();\r
cc68a136 298 }\r
299 else if(emustatus & 3) {\r
300 emustatus|= 2;\r
301 emustatus&=~1;\r
9d917eea 302 curr_pos = PsndRender(0, PsndLen/2);\r
cc68a136 303 }\r
03a265e5 304#endif\r
cc68a136 305}\r
306\r
69996cb7 307\r
69996cb7 308#include "PicoFrameHints.c"\r
cc68a136 309\r
9a8ffeee 310// helper z80 runner. Runs only if z80 is enabled at this point\r
311// (z80WriteBusReq will handle the rest)\r
cc68a136 312static void PicoRunZ80Simple(int line_from, int line_to)\r
313{\r
9a8ffeee 314 int line_from_r=line_from, line_to_r=line_to, line=0;\r
cc68a136 315 int line_sample = Pico.m.pal ? 68 : 93;\r
cc68a136 316\r
602133e1 317 if (!(PicoOpt&POPT_EN_Z80) || Pico.m.z80Run == 0) line_to_r = 0;\r
9a8ffeee 318 else {\r
319 extern const unsigned short vcounts[];\r
320 if (z80startCycle) {\r
321 line = vcounts[z80startCycle>>8];\r
322 if (line > line_from)\r
323 line_from_r = line;\r
324 }\r
325 z80startCycle = SekCyclesDone();\r
326 }\r
cc68a136 327\r
602133e1 328 if (PicoOpt&POPT_EN_FM) {\r
cc68a136 329 // we have ym2612 enabled, so we have to run Z80 in lines, so we could update DAC and timers\r
9a8ffeee 330 for (line = line_from; line < line_to; line++) {\r
9d917eea 331 Psnd_timers_and_dac(line);\r
9a8ffeee 332 if ((line == 224 || line == line_sample) && PsndOut) getSamples(line);\r
333 if (line == 32 && PsndOut) emustatus &= ~1;\r
334 if (line >= line_from_r && line < line_to_r)\r
b542be46 335 z80_run_nr(228);\r
cc68a136 336 }\r
9a8ffeee 337 } else if (line_to_r-line_from_r > 0) {\r
b542be46 338 z80_run_nr(228*(line_to_r-line_from_r));\r
cc68a136 339 // samples will be taken by caller\r
340 }\r
341}\r
342\r
343// Simple frame without H-Ints\r
344static int PicoFrameSimple(void)\r
345{\r
346 struct PicoVideo *pv=&Pico.video;\r
347 int y=0,line=0,lines=0,lines_step=0,sects;\r
348 int cycles_68k_vblock,cycles_68k_block;\r
349\r
e849512f 350 // split to 16 run calls for active scan, for vblank split to 2 (ntsc), 3 (pal 240), 4 (pal 224)\r
8ab3e3c1 351 if (Pico.m.pal && (pv->reg[1]&8)) {\r
cc68a136 352 if(pv->reg[1]&8) { // 240 lines\r
e849512f 353 cycles_68k_block = 7329; // (488*240+148)/16.0, -4\r
354 cycles_68k_vblock = 11640; // (72*488-148-68)/3.0, 0\r
cc68a136 355 lines_step = 15;\r
356 } else {\r
e849512f 357 cycles_68k_block = 6841; // (488*224+148)/16.0, -4\r
358 cycles_68k_vblock = 10682; // (88*488-148-68)/4.0, 0\r
cc68a136 359 lines_step = 14;\r
360 }\r
361 } else {\r
362 // M68k cycles/frame: 127840.71\r
e849512f 363 cycles_68k_block = 6841; // (488*224+148)/16.0, -4\r
364 cycles_68k_vblock = 9164; // (38*488-148-68)/2.0, 0\r
cc68a136 365 lines_step = 14;\r
366 }\r
367\r
fad24893 368 // a hack for VR, to get it running in fast mode\r
602133e1 369 if (PicoAHW & PAHW_SVP)\r
fad24893 370 Pico.ram[0xd864^1] = 0x1a;\r
371\r
69996cb7 372 // we don't emulate DMA timing in this mode\r
373 if (Pico.m.dma_xfers) {\r
374 Pico.m.dma_xfers=0;\r
375 Pico.video.status&=~2;\r
376 }\r
377\r
378 // VDP FIFO too\r
379 pv->lwrite_cnt = 0;\r
380 Pico.video.status|=0x200;\r
381\r
cc68a136 382 Pico.m.scanline=-1;\r
9a8ffeee 383 z80startCycle=0;\r
cc68a136 384\r
385 SekCyclesReset();\r
386\r
cc68a136 387 // 6 button pad: let's just say it timed out now\r
388 Pico.m.padTHPhase[0]=Pico.m.padTHPhase[1]=0;\r
389\r
390 // ---- Active Scan ----\r
69996cb7 391 pv->status&=~0x88; // clear V-Int, come out of vblank\r
cc68a136 392\r
393 // Run in sections:\r
394 for(sects=16; sects; sects--)\r
395 {\r
396 if (CheckIdle()) break;\r
397\r
398 lines += lines_step;\r
bf5fbbb4 399 SekRunM68k(cycles_68k_block);\r
cc68a136 400\r
401 PicoRunZ80Simple(line, lines);\r
0ffefdb8 402 if (PicoLineHook) PicoLineHook(lines_step);\r
cc68a136 403 line=lines;\r
404 }\r
405\r
406 // run Z80 for remaining sections\r
407 if(sects) {\r
408 int c = sects*cycles_68k_block;\r
409\r
9a8ffeee 410 // this "run" is for approriate line counter, etc\r
cc68a136 411 SekCycleCnt += c;\r
412 SekCycleAim += c;\r
9a8ffeee 413\r
414 lines += sects*lines_step;\r
415 PicoRunZ80Simple(line, lines);\r
0ffefdb8 416 if (PicoLineHook) PicoLineHook(sects*lines_step);\r
cc68a136 417 }\r
418\r
fad24893 419 // another hack for VR (it needs hints to work)\r
602133e1 420 if (PicoAHW & PAHW_SVP) {\r
fad24893 421 Pico.ram[0xd864^1] = 1;\r
422 pv->pending_ints|=0x10;\r
423 if (pv->reg[0]&0x10) SekInterrupt(4);\r
424 SekRunM68k(160);\r
425 }\r
426\r
cc68a136 427 // render screen\r
e849512f 428 if (!PicoSkipFrame)\r
429 {\r
602133e1 430 if (!(PicoOpt&POPT_ALT_RENDERER))\r
fad24893 431 {\r
cc68a136 432 // Draw the screen\r
433#if CAN_HANDLE_240_LINES\r
e849512f 434 if (pv->reg[1]&8) {\r
cc68a136 435 for (y=0;y<240;y++) PicoLine(y);\r
436 } else {\r
437 for (y=0;y<224;y++) PicoLine(y);\r
438 }\r
439#else\r
440 for (y=0;y<224;y++) PicoLine(y);\r
441#endif\r
fad24893 442 }\r
cc68a136 443 else PicoFrameFull();\r
8ab3e3c1 444#ifdef DRAW_FINISH_FUNC\r
445 DRAW_FINISH_FUNC();\r
446#endif\r
447 }\r
448\r
449 // here we render sound if ym2612 is disabled\r
602133e1 450 if (!(PicoOpt&POPT_EN_FM) && PsndOut) {\r
9d917eea 451 int len = PsndRender(0, PsndLen);\r
8ab3e3c1 452 if (PicoWriteSound) PicoWriteSound(len);\r
453 // clear sound buffer\r
9d917eea 454 PsndClear();\r
cc68a136 455 }\r
456\r
e849512f 457 // a gap between flags set and vint\r
458 pv->pending_ints|=0x20;\r
459 pv->status|=8; // go into vblank\r
bf5fbbb4 460 SekRunM68k(68+4);\r
e849512f 461\r
cc68a136 462 // ---- V-Blanking period ----\r
463 // fix line counts\r
464 if(Pico.m.pal) {\r
465 if(pv->reg[1]&8) { // 240 lines\r
466 lines = line = 240;\r
467 sects = 3;\r
468 lines_step = 24;\r
469 } else {\r
470 lines = line = 224;\r
471 sects = 4;\r
472 lines_step = 22;\r
473 }\r
474 } else {\r
475 lines = line = 224;\r
476 sects = 2;\r
477 lines_step = 19;\r
478 }\r
479\r
cc68a136 480 if (pv->reg[1]&0x20) SekInterrupt(6); // Set IRQ\r
602133e1 481 if (Pico.m.z80Run && (PicoOpt&POPT_EN_Z80))\r
cc68a136 482 z80_int();\r
483\r
602133e1 484 while (sects)\r
485 {\r
cc68a136 486 lines += lines_step;\r
487\r
bf5fbbb4 488 SekRunM68k(cycles_68k_vblock);\r
cc68a136 489\r
490 PicoRunZ80Simple(line, lines);\r
0ffefdb8 491 if (PicoLineHook) PicoLineHook(lines_step);\r
cc68a136 492 line=lines;\r
493\r
494 sects--;\r
e849512f 495 if (sects && CheckIdle()) break;\r
cc68a136 496 }\r
497\r
498 // run Z80 for remaining sections\r
e849512f 499 if (sects) {\r
cc68a136 500 lines += sects*lines_step;\r
501 PicoRunZ80Simple(line, lines);\r
0ffefdb8 502 if (PicoLineHook) PicoLineHook(sects*lines_step);\r
cc68a136 503 }\r
504\r
505 return 0;\r
506}\r
507\r
508int PicoFrame(void)\r
509{\r
510 int acc;\r
511\r
8c1952f0 512 Pico.m.frame_count++;\r
513\r
602133e1 514 if (PicoAHW & PAHW_MCD) {\r
cc68a136 515 PicoFrameMCD();\r
516 return 0;\r
517 }\r
518\r
519 // be accurate if we are asked for this\r
602133e1 520 if (PicoOpt&POPT_ACC_TIMING) acc=1;\r
cc68a136 521 // don't be accurate in alternative render mode, as hint effects will not be rendered anyway\r
602133e1 522 else if (PicoOpt&POPT_ALT_RENDERER) acc = 0;\r
cc68a136 523 else acc=Pico.video.reg[0]&0x10; // be accurate if hints are used\r
524\r
525 //if(Pico.video.reg[12]&0x2) Pico.video.status ^= 0x10; // change odd bit in interlace mode\r
526\r
602133e1 527 if (!(PicoOpt&POPT_ALT_RENDERER))\r
cc68a136 528 PicoFrameStart();\r
529\r
602133e1 530 if (acc)\r
cc68a136 531 PicoFrameHints();\r
532 else PicoFrameSimple();\r
533\r
534 return 0;\r
535}\r
536\r
a12e0116 537void PicoFrameDrawOnly(void)\r
538{\r
539 int y;\r
540 PicoFrameStart();\r
541 for (y=0;y<224;y++) PicoLine(y);\r
542}\r
543\r
8e5427a0 544int PicoGetStat(pstat_t which)\r
545{\r
546 switch (which)\r
547 {\r
548 case PS_PAL: return Pico.m.pal;\r
549 case PS_40_CELL: return Pico.video.reg[12]&1;\r
550 case PS_240_LINES: return Pico.m.pal && (Pico.video.reg[1]&8);\r
551 }\r
552 return 0;\r
553}\r
554\r
66fdc0f0 555// callback to output message from emu\r
556void (*PicoMessage)(const char *msg)=NULL;\r
cc68a136 557\r
1820b5a7 558#if 1 // defined(__DEBUG_PRINT)\r
cc68a136 559// tmp debug: dump some stuff\r
560#define bit(r, x) ((r>>x)&1)\r
561void z80_debug(char *dstr);\r
0af33fe0 562char *debugString(void)\r
cc68a136 563{\r
564#if 1\r
565 static char dstr[1024];\r
0af33fe0 566 struct PicoVideo *pv=&Pico.video;\r
567 unsigned char *reg=pv->reg, r;\r
568 char *dstrp;\r
569\r
570 dstrp = dstr;\r
571 sprintf(dstrp, "mode set 1: %02x\n", (r=reg[0])); dstrp+=strlen(dstrp);\r
572 sprintf(dstrp, "display_disable: %i, M3: %i, palette: %i, ?, hints: %i\n", bit(r,0), bit(r,1), bit(r,2), bit(r,4));\r
573 dstrp+=strlen(dstrp);\r
574 sprintf(dstrp, "mode set 2: %02x\n", (r=reg[1])); dstrp+=strlen(dstrp);\r
575 sprintf(dstrp, "SMS/gen: %i, pal: %i, dma: %i, vints: %i, disp: %i, TMS: %i\n", bit(r,2), bit(r,3), bit(r,4),\r
576 bit(r,5), bit(r,6), bit(r,7)); dstrp+=strlen(dstrp);\r
577 sprintf(dstrp, "mode set 3: %02x\n", (r=reg[0xB])); dstrp+=strlen(dstrp);\r
578 sprintf(dstrp, "LSCR: %i, HSCR: %i, 2cell vscroll: %i, IE2: %i\n", bit(r,0), bit(r,1), bit(r,2), bit(r,3)); dstrp+=strlen(dstrp);\r
579 sprintf(dstrp, "mode set 4: %02x\n", (r=reg[0xC])); dstrp+=strlen(dstrp);\r
580 sprintf(dstrp, "interlace: %i%i, cells: %i, shadow: %i\n", bit(r,2), bit(r,1), (r&0x80) ? 40 : 32, bit(r,3));\r
581 dstrp+=strlen(dstrp);\r
1dceadae 582 sprintf(dstrp, "scroll size: w: %i, h: %i SRAM: %i; eeprom: %i (%i)\n", reg[0x10]&3, (reg[0x10]&0x30)>>4,\r
583 bit(Pico.m.sram_reg, 4), bit(Pico.m.sram_reg, 2), SRam.eeprom_type); dstrp+=strlen(dstrp);\r
7969166e 584 sprintf(dstrp, "sram range: %06x-%06x, reg: %02x\n", SRam.start, SRam.end, Pico.m.sram_reg); dstrp+=strlen(dstrp);\r
0af33fe0 585 sprintf(dstrp, "pend int: v:%i, h:%i, vdp status: %04x\n", bit(pv->pending_ints,5), bit(pv->pending_ints,4), pv->status);\r
586 dstrp+=strlen(dstrp);\r
7d4906bf 587#if defined(EMU_C68K)\r
3aa1e148 588 sprintf(dstrp, "M68k: PC: %06x, st_flg: %x, cycles: %u\n", SekPc, PicoCpuCM68k.state_flags, SekCyclesDoneT());\r
0af33fe0 589 dstrp+=strlen(dstrp);\r
3aa1e148 590 sprintf(dstrp, "d0=%08x, a0=%08x, osp=%08x, irql=%i\n", PicoCpuCM68k.d[0], PicoCpuCM68k.a[0], PicoCpuCM68k.osp, PicoCpuCM68k.irq); dstrp+=strlen(dstrp);\r
591 sprintf(dstrp, "d1=%08x, a1=%08x, sr=%04x\n", PicoCpuCM68k.d[1], PicoCpuCM68k.a[1], CycloneGetSr(&PicoCpuCM68k)); dstrp+=strlen(dstrp);\r
0af33fe0 592 for(r=2; r < 8; r++) {\r
3aa1e148 593 sprintf(dstrp, "d%i=%08x, a%i=%08x\n", r, PicoCpuCM68k.d[r], r, PicoCpuCM68k.a[r]); dstrp+=strlen(dstrp);\r
0af33fe0 594 }\r
7d4906bf 595#elif defined(EMU_M68K)\r
3aa1e148 596 sprintf(dstrp, "M68k: PC: %06x, cycles: %u, irql: %i\n", SekPc, SekCyclesDoneT(), PicoCpuMM68k.int_level>>8); dstrp+=strlen(dstrp);\r
70357ce5 597#elif defined(EMU_F68K)\r
3aa1e148 598 sprintf(dstrp, "M68k: PC: %06x, cycles: %u, irql: %i\n", SekPc, SekCyclesDoneT(), PicoCpuFM68k.interrupts[0]); dstrp+=strlen(dstrp);\r
cc68a136 599#endif\r
0af33fe0 600 sprintf(dstrp, "z80Run: %i, pal: %i, frame#: %i\n", Pico.m.z80Run, Pico.m.pal, Pico.m.frame_count); dstrp+=strlen(dstrp);\r
601 z80_debug(dstrp); dstrp+=strlen(dstrp);\r
602 if (strlen(dstr) > sizeof(dstr))\r
603 printf("warning: debug buffer overflow (%i/%i)\n", strlen(dstr), sizeof(dstr));\r
cc68a136 604\r
605#else\r
606 struct PicoVideo *pvid=&Pico.video;\r
607 int table=0;\r
608 int i,u,n,link=0;\r
609 static char dstr[1024*8];\r
610 dstr[0] = 0;\r
611\r
612 table=pvid->reg[5]&0x7f;\r
613 if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode\r
614 table<<=8; // Get sprite table address/2\r
615\r
616 for (i=u=n=0; u < 80 && n < 20; u++)\r
617 {\r
618 unsigned int *sprite;\r
619 int code, code2, sx, sy, height;\r
620\r
621 sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite\r
622\r
623 // get sprite info\r
624 code = sprite[0];\r
625\r
626 // check if it is on this line\r
627 sy = (code&0x1ff);//-0x80;\r
628 height = ((code>>24)&3)+1;\r
629\r
630 // masking sprite?\r
631 code2 = sprite[1];\r
632 sx = (code2>>16)&0x1ff;\r
633\r
69996cb7 634 printf("#%02i x: %03i y: %03i %ix%i\n", u, sx, sy, ((code>>26)&3)+1, height);\r
cc68a136 635\r
636 link=(code>>16)&0x7f;\r
637 if(!link) break; // End of sprites\r
638 }\r
639#endif\r
640\r
cc68a136 641 return dstr;\r
642}\r
643#endif\r