line draw deferment implemented
[picodrive.git] / Pico / VideoPort.c
CommitLineData
cc68a136 1// This is part of Pico Library\r
2\r
3// (c) Copyright 2004 Dave, All rights reserved.\r
6cadc2da 4// (c) Copyright 2006-2007, Grazvydas "notaz" Ignotas\r
cc68a136 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
fa1e5e29 11#include "cd/gfx_cd.h"\r
cc68a136 12\r
13extern const unsigned char hcounts_32[];\r
14extern const unsigned char hcounts_40[];\r
15extern const unsigned short vcounts[];\r
cc68a136 16\r
eff55556 17#ifndef UTYPES_DEFINED\r
ab0607f7 18typedef unsigned char u8;\r
cc68a136 19typedef unsigned short u16;\r
eff55556 20typedef unsigned int u32;\r
21#define UTYPES_DEFINED\r
22#endif\r
cc68a136 23\r
5de27868 24int (*PicoDmaHook)(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp) = NULL;\r
cc68a136 25\r
69996cb7 26static __inline void AutoIncrement(void)\r
cc68a136 27{\r
28 Pico.video.addr=(unsigned short)(Pico.video.addr+Pico.video.reg[0xf]);\r
29}\r
30\r
31static void VideoWrite(u16 d)\r
32{\r
33 unsigned int a=Pico.video.addr;\r
34\r
35 switch (Pico.video.type)\r
36 {\r
37 case 1: if(a&1) d=(u16)((d<<8)|(d>>8)); // If address is odd, bytes are swapped (which game needs this?)\r
38 Pico.vram [(a>>1)&0x7fff]=d;\r
602133e1 39 rendstatus |= PDRAW_DIRTY_SPRITES; break;\r
cc68a136 40 case 3: Pico.m.dirtyPal = 1;\r
cc68a136 41 Pico.cram [(a>>1)&0x003f]=d; break; // wraps (Desert Strike)\r
42 case 5: Pico.vsram[(a>>1)&0x003f]=d; break;\r
d26dc685 43 //default:elprintf(EL_ANOMALY, "VDP write %04x with bad type %i", d, Pico.video.type); break;\r
cc68a136 44 }\r
45\r
46 //dprintf("w[%i] @ %04x, inc=%i [%i|%i]", Pico.video.type, a, Pico.video.reg[0xf], Pico.m.scanline, SekCyclesDone());\r
47 AutoIncrement();\r
48}\r
49\r
69996cb7 50static unsigned int VideoRead(void)\r
cc68a136 51{\r
52 unsigned int a=0,d=0;\r
53\r
54 a=Pico.video.addr; a>>=1;\r
55\r
56 switch (Pico.video.type)\r
57 {\r
58 case 0: d=Pico.vram [a&0x7fff]; break;\r
59 case 8: d=Pico.cram [a&0x003f]; break;\r
60 case 4: d=Pico.vsram[a&0x003f]; break;\r
69996cb7 61 default:elprintf(EL_ANOMALY, "VDP read with bad type %i", Pico.video.type); break;\r
cc68a136 62 }\r
4f672280 63\r
cc68a136 64 AutoIncrement();\r
65 return d;\r
66}\r
67\r
69996cb7 68static int GetDmaLength(void)\r
cc68a136 69{\r
70 struct PicoVideo *pvid=&Pico.video;\r
71 int len=0;\r
72 // 16-bit words to transfer:\r
73 len =pvid->reg[0x13];\r
74 len|=pvid->reg[0x14]<<8;\r
75 // Charles MacDonald:\r
76 if(!len) len = 0xffff;\r
77 return len;\r
78}\r
79\r
80static void DmaSlow(int len)\r
81{\r
82 u16 *pd=0, *pdend, *r;\r
83 unsigned int a=Pico.video.addr, a2, d;\r
84 unsigned char inc=Pico.video.reg[0xf];\r
672ad671 85 unsigned int source;\r
cc68a136 86\r
87 source =Pico.video.reg[0x15]<<1;\r
88 source|=Pico.video.reg[0x16]<<9;\r
89 source|=Pico.video.reg[0x17]<<17;\r
90\r
69996cb7 91 elprintf(EL_VDPDMA, "DmaSlow[%i] %06x->%04x len %i inc=%i blank %i [%i] @ %06x",\r
312e9ce1 92 Pico.video.type, source, a, len, inc, (Pico.video.status&8)||!(Pico.video.reg[1]&0x40),\r
69996cb7 93 SekCyclesDone(), SekPc);\r
cc68a136 94\r
602133e1 95 if (Pico.m.scanline != -1) {\r
69996cb7 96 Pico.m.dma_xfers += len;\r
602133e1 97 if ((PicoAHW & PAHW_MCD) && (PicoOpt & POPT_EN_MCD_PSYNC)) SekCyclesBurn(CheckDMA());\r
7336a99a 98 else SekSetCyclesLeftNoMCD(SekCyclesLeftNoMCD - CheckDMA());\r
672ad671 99 } else {\r
100 // be approximate in non-accurate mode\r
101 SekSetCyclesLeft(SekCyclesLeft - (len*(((488<<8)/167))>>8));\r
102 }\r
103\r
ab0607f7 104 if ((source&0xe00000)==0xe00000) { // Ram\r
105 pd=(u16 *)(Pico.ram+(source&0xfffe));\r
106 pdend=(u16 *)(Pico.ram+0x10000);\r
602133e1 107 }\r
108 else if (PicoAHW & PAHW_MCD)\r
109 {\r
69996cb7 110 elprintf(EL_VDPDMA, "DmaSlow CD, r3=%02x", Pico_mcd->s68k_regs[3]);\r
ab0607f7 111 if(source<0x20000) { // Bios area\r
112 pd=(u16 *)(Pico_mcd->bios+(source&~1));\r
113 pdend=(u16 *)(Pico_mcd->bios+0x20000);\r
fa1e5e29 114 } else if ((source&0xfc0000)==0x200000) { // Word Ram\r
115 source -= 2;\r
ab0607f7 116 if (!(Pico_mcd->s68k_regs[3]&4)) { // 2M mode\r
fa1e5e29 117 pd=(u16 *)(Pico_mcd->word_ram2M+(source&0x3fffe));\r
118 pdend=(u16 *)(Pico_mcd->word_ram2M+0x40000);\r
ab0607f7 119 } else {\r
fa1e5e29 120 if (source < 0x220000) { // 1M mode\r
121 int bank = Pico_mcd->s68k_regs[3]&1;\r
122 pd=(u16 *)(Pico_mcd->word_ram1M[bank]+(source&0x1fffe));\r
123 pdend=(u16 *)(Pico_mcd->word_ram1M[bank]+0x20000);\r
69996cb7 124 } else {\r
fa1e5e29 125 DmaSlowCell(source, a, len, inc);\r
126 return;\r
69996cb7 127 }\r
ab0607f7 128 }\r
129 } else if ((source&0xfe0000)==0x020000) { // Prg Ram\r
130 u8 *prg_ram = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
131 pd=(u16 *)(prg_ram+(source&0x1fffe));\r
132 pdend=(u16 *)(prg_ram+0x20000);\r
133 } else {\r
03e4f2a3 134 elprintf(EL_VDPDMA|EL_ANOMALY, "DmaSlow[%i] %06x->%04x: FIXME: unsupported src", Pico.video.type, source, a);\r
ab0607f7 135 return;\r
136 }\r
602133e1 137 }\r
138 else\r
139 {\r
50483b53 140 // if we have DmaHook, let it handle ROM because of possible DMA delay\r
141 if (PicoDmaHook && PicoDmaHook(source, len, &pd, &pdend));\r
142 else if (source<Pico.romsize) { // Rom\r
ab0607f7 143 pd=(u16 *)(Pico.rom+(source&~1));\r
144 pdend=(u16 *)(Pico.rom+Pico.romsize);\r
f8ef8ff7 145 }\r
f8ef8ff7 146 else {\r
03e4f2a3 147 elprintf(EL_VDPDMA|EL_ANOMALY, "DmaSlow[%i] %06x->%04x: invalid src", Pico.video.type, source, a);\r
ab0607f7 148 return;\r
149 }\r
150 }\r
151\r
152 // overflow protection, might break something..\r
153 if (len > pdend - pd) {\r
154 len = pdend - pd;\r
69996cb7 155 elprintf(EL_VDPDMA|EL_ANOMALY, "DmaSlow overflow");\r
672ad671 156 }\r
cc68a136 157\r
158 switch (Pico.video.type)\r
159 {\r
160 case 1: // vram\r
161 r = Pico.vram;\r
cea65903 162 if (inc == 2 && !(a&1) && a+len*2 < 0x10000)\r
cc68a136 163 {\r
cea65903 164 // most used DMA mode\r
fa1e5e29 165 memcpy16(r + (a>>1), pd, len);\r
166 a += len*2;\r
cea65903 167 }\r
168 else\r
169 {\r
170 for(; len; len--)\r
171 {\r
172 d=*pd++;\r
173 if(a&1) d=(d<<8)|(d>>8);\r
174 r[a>>1] = (u16)d; // will drop the upper bits\r
175 // AutoIncrement\r
176 a=(u16)(a+inc);\r
177 // didn't src overlap?\r
178 //if(pd >= pdend) pd-=0x8000; // should be good for RAM, bad for ROM\r
179 }\r
cc68a136 180 }\r
602133e1 181 rendstatus |= PDRAW_DIRTY_SPRITES;\r
cc68a136 182 break;\r
4f672280 183\r
cc68a136 184 case 3: // cram\r
cc68a136 185 Pico.m.dirtyPal = 1;\r
186 r = Pico.cram;\r
187 for(a2=a&0x7f; len; len--)\r
188 {\r
0a051f55 189 r[a2>>1] = (u16)*pd++; // bit 0 is ignored\r
cc68a136 190 // AutoIncrement\r
191 a2+=inc;\r
192 // didn't src overlap?\r
ab0607f7 193 //if(pd >= pdend) pd-=0x8000;\r
cc68a136 194 // good dest?\r
195 if(a2 >= 0x80) break; // Todds Adventures in Slime World / Andre Agassi tennis\r
196 }\r
197 a=(a&0xff00)|a2;\r
198 break;\r
199\r
200 case 5: // vsram[a&0x003f]=d;\r
201 r = Pico.vsram;\r
202 for(a2=a&0x7f; len; len--)\r
203 {\r
204 r[a2>>1] = (u16)*pd++;\r
205 // AutoIncrement\r
206 a2+=inc;\r
207 // didn't src overlap?\r
ab0607f7 208 //if(pd >= pdend) pd-=0x8000;\r
cc68a136 209 // good dest?\r
210 if(a2 >= 0x80) break;\r
211 }\r
212 a=(a&0xff00)|a2;\r
213 break;\r
69996cb7 214\r
215 default:\r
216 elprintf(EL_VDPDMA|EL_ANOMALY, "DMA with bad type %i", Pico.video.type);\r
217 break;\r
cc68a136 218 }\r
219 // remember addr\r
220 Pico.video.addr=(u16)a;\r
221}\r
222\r
223static void DmaCopy(int len)\r
224{\r
225 u16 a=Pico.video.addr;\r
226 unsigned char *vr = (unsigned char *) Pico.vram;\r
227 unsigned char *vrs;\r
228 unsigned char inc=Pico.video.reg[0xf];\r
229 int source;\r
69996cb7 230 elprintf(EL_VDPDMA, "DmaCopy len %i [%i]", len, SekCyclesDone());\r
4f672280 231\r
69996cb7 232 Pico.m.dma_xfers += len;\r
8c1952f0 233 if(Pico.m.scanline != -1)\r
234 Pico.video.status|=2; // dma busy\r
cc68a136 235\r
236 source =Pico.video.reg[0x15];\r
237 source|=Pico.video.reg[0x16]<<8;\r
238 vrs=vr+source;\r
239\r
240 if(source+len > 0x10000) len=0x10000-source; // clip??\r
241\r
242 for(;len;len--)\r
243 {\r
244 vr[a] = *vrs++;\r
245 // AutoIncrement\r
246 a=(u16)(a+inc);\r
247 }\r
248 // remember addr\r
249 Pico.video.addr=a;\r
602133e1 250 rendstatus |= PDRAW_DIRTY_SPRITES;\r
cc68a136 251}\r
252\r
253// check: Contra, Megaman\r
254// note: this is still inaccurate\r
255static void DmaFill(int data)\r
256{\r
257 int len;\r
258 unsigned short a=Pico.video.addr;\r
259 unsigned char *vr=(unsigned char *) Pico.vram;\r
260 unsigned char high = (unsigned char) (data >> 8);\r
261 unsigned char inc=Pico.video.reg[0xf];\r
4f672280 262\r
cc68a136 263 len=GetDmaLength();\r
69996cb7 264 elprintf(EL_VDPDMA, "DmaFill len %i inc %i [%i]", len, inc, SekCyclesDone());\r
4f672280 265\r
69996cb7 266 Pico.m.dma_xfers += len;\r
8c1952f0 267 if(Pico.m.scanline != -1)\r
268 Pico.video.status|=2; // dma busy (in accurate mode)\r
cc68a136 269\r
270 // from Charles MacDonald's genvdp.txt:\r
271 // Write lower byte to address specified\r
272 vr[a] = (unsigned char) data;\r
273 a=(u16)(a+inc);\r
274\r
275 if(!inc) len=1;\r
276\r
277 for(;len;len--) {\r
278 // Write upper byte to adjacent address\r
279 // (here we are byteswapped, so address is already 'adjacent')\r
280 vr[a] = high;\r
281\r
282 // Increment address register\r
283 a=(u16)(a+inc);\r
284 }\r
285 // remember addr\r
286 Pico.video.addr=a;\r
287 // update length\r
288 Pico.video.reg[0x13] = Pico.video.reg[0x14] = 0; // Dino Dini's Soccer (E) (by Haze)\r
289\r
602133e1 290 rendstatus |= PDRAW_DIRTY_SPRITES;\r
cc68a136 291}\r
292\r
69996cb7 293static void CommandDma(void)\r
cc68a136 294{\r
295 struct PicoVideo *pvid=&Pico.video;\r
296 int len=0,method=0;\r
297\r
298 if ((pvid->reg[1]&0x10)==0) return; // DMA not enabled\r
299\r
300 len=GetDmaLength();\r
301\r
302 method=pvid->reg[0x17]>>6;\r
303 if (method< 2) DmaSlow(len); // 68000 to VDP\r
304 if (method==3) DmaCopy(len); // VRAM Copy\r
305}\r
306\r
69996cb7 307static void CommandChange(void)\r
cc68a136 308{\r
309 struct PicoVideo *pvid=&Pico.video;\r
310 unsigned int cmd=0,addr=0;\r
311\r
312 cmd=pvid->command;\r
313\r
314 // Get type of transfer 0xc0000030 (v/c/vsram read/write)\r
315 pvid->type=(unsigned char)(((cmd>>2)&0xc)|(cmd>>30));\r
316\r
317 // Get address 0x3fff0003\r
318 addr =(cmd>>16)&0x3fff;\r
319 addr|=(cmd<<14)&0xc000;\r
320 pvid->addr=(unsigned short)addr;\r
cc68a136 321\r
322 // Check for dma:\r
323 if (cmd&0x80) CommandDma();\r
324}\r
325\r
b6d7ac70 326static __inline void DrawSync(int blank_on)\r
327{\r
328 if (Pico.m.scanline < 224 && !(PicoOpt & POPT_ALT_RENDERER) &&\r
329 !PicoSkipFrame && DrawScanline <= Pico.m.scanline) {\r
330 elprintf(EL_ANOMALY, "sync");\r
331 PicoDrawSync(Pico.m.scanline, blank_on);\r
332 }\r
333}\r
334\r
eff55556 335PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d)\r
cc68a136 336{\r
337 struct PicoVideo *pvid=&Pico.video;\r
338\r
b6d7ac70 339 if (Pico.m.scanline < 224)\r
340 elprintf(EL_STATUS, "PicoVideoWrite [%06x] %04x", a, d);\r
cc68a136 341 a&=0x1c;\r
342\r
343 if (a==0x00) // Data port 0 or 2\r
4f672280 344 {\r
b6d7ac70 345 // try avoiding the sync..\r
346 if (Pico.m.scanline < 224 && (pvid->reg[1]&0x40) &&\r
347 !(!pvid->pending &&\r
348 ((pvid->command & 0xc00000f0) == 0x40000010 && Pico.vsram[pvid->addr>>1] == d))\r
349 )\r
350 DrawSync(0);\r
351\r
69996cb7 352 if (pvid->pending) {\r
353 CommandChange();\r
354 pvid->pending=0;\r
355 }\r
cc68a136 356\r
357 // If a DMA fill has been set up, do it\r
358 if ((pvid->command&0x80) && (pvid->reg[1]&0x10) && (pvid->reg[0x17]>>6)==2)\r
359 {\r
360 DmaFill(d);\r
361 }\r
362 else\r
363 {\r
69996cb7 364 // preliminary FIFO emulation for Chaos Engine, The (E)\r
b6d7ac70 365 if (!(pvid->status&8) && (pvid->reg[1]&0x40) && Pico.m.scanline!=-1 && !(PicoOpt&POPT_DIS_VDP_FIFO)) // active display, accurate mode?\r
69996cb7 366 {\r
367 pvid->status&=~0x200; // FIFO no longer empty\r
368 pvid->lwrite_cnt++;\r
369 if (pvid->lwrite_cnt >= 4) pvid->status|=0x100; // FIFO full\r
370 if (pvid->lwrite_cnt > 4) {\r
371 SekCyclesBurn(32); // penalty // 488/12-8\r
372 if (SekCycleCnt>=SekCycleAim) SekEndRun(0);\r
373 }\r
374 elprintf(EL_ASVDP, "VDP data write: %04x {%i} #%i @ %06x", d, Pico.video.type, pvid->lwrite_cnt, SekPc);\r
375 }\r
cc68a136 376 VideoWrite(d);\r
377 }\r
378 return;\r
379 }\r
380\r
381 if (a==0x04) // Control (command) port 4 or 6\r
382 {\r
b6d7ac70 383 if (pvid->pending)\r
cc68a136 384 {\r
b6d7ac70 385 if (d & 0x80) DrawSync(0); // only need sync for DMA\r
cc68a136 386 // Low word of command:\r
387 pvid->command&=0xffff0000;\r
388 pvid->command|=d;\r
389 pvid->pending=0;\r
390 CommandChange();\r
602133e1 391 }\r
392 else\r
393 {\r
394 if ((d&0xc000)==0x8000)\r
cc68a136 395 {\r
396 // Register write:\r
397 int num=(d>>8)&0x1f;\r
0ffefdb8 398 int dold=pvid->reg[num];\r
b6d7ac70 399 int update_irq = 0, blank_on = 0;\r
602133e1 400 pvid->type=0; // register writes clear command (else no Sega logo in Golden Axe II)\r
0ffefdb8 401 if (num > 0x0a && !(pvid->reg[1]&4)) {\r
402 elprintf(EL_ANOMALY, "%02x written to reg %02x in SMS mode @ %06x", d, num, SekPc);\r
602133e1 403 return;\r
b6d7ac70 404 }\r
602133e1 405\r
406 switch (num)\r
407 {\r
408 case 0x00:\r
409 elprintf(EL_INTSW, "hint_onoff: %i->%i [%i] pend=%i @ %06x", (dold&0x10)>>4,\r
410 (d&0x10)>>4, SekCyclesDone(), (pvid->pending_ints&0x10)>>4, SekPc);\r
b6d7ac70 411 update_irq = 1;\r
412 break;\r
602133e1 413 case 0x01:\r
414 elprintf(EL_INTSW, "vint_onoff: %i->%i [%i] pend=%i @ %06x", (dold&0x20)>>5,\r
415 (d&0x20)>>5, SekCyclesDone(), (pvid->pending_ints&0x20)>>5, SekPc);\r
b6d7ac70 416 if (!(d&0x40) && SekCyclesLeft > 390) blank_on = 1;\r
417 update_irq = 1;\r
418 break;\r
602133e1 419 case 0x05:\r
420 if (d^dold) rendstatus |= PDRAW_SPRITES_MOVED;\r
421 break;\r
422 case 0x0c:\r
423 // renderers should update their palettes if sh/hi mode is changed\r
424 if ((d^dold)&8) Pico.m.dirtyPal = 2;\r
425 break;\r
426 }\r
b6d7ac70 427 DrawSync(blank_on);\r
428 pvid->reg[num]=(unsigned char)d;\r
429 if (!update_irq) return;\r
602133e1 430\r
03e4f2a3 431#ifndef EMU_CORE_DEBUG\r
b6d7ac70 432 // update IRQ level\r
602133e1 433 if (!SekShouldInterrupt) // hack\r
03e4f2a3 434 {\r
602133e1 435 int lines, pints, irq=0;\r
436 lines = (pvid->reg[1] & 0x20) | (pvid->reg[0] & 0x10);\r
437 pints = (pvid->pending_ints&lines);\r
b6d7ac70 438 if (pints & 0x20) irq = 6;\r
439 else if (pints & 0x10) irq = 4;\r
602133e1 440 SekInterrupt(irq); // update line\r
441\r
442 if (irq && Pico.m.scanline!=-1) SekEndRun(24); // make it delayed\r
cc68a136 443 }\r
cc68a136 444#endif\r
602133e1 445 }\r
446 else\r
447 {\r
cc68a136 448 // High word of command:\r
449 pvid->command&=0x0000ffff;\r
450 pvid->command|=d<<16;\r
451 pvid->pending=1;\r
452 }\r
453 }\r
454 }\r
455}\r
456\r
eff55556 457PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a)\r
cc68a136 458{\r
cc68a136 459 a&=0x1c;\r
460\r
461 if (a==0x00) // data port\r
462 {\r
b6d7ac70 463 return VideoRead();\r
cc68a136 464 }\r
465\r
466 if (a==0x04) // control port\r
467 {\r
69996cb7 468 struct PicoVideo *pv=&Pico.video;\r
b6d7ac70 469 unsigned int d;\r
69996cb7 470 d=pv->status;\r
602133e1 471 if (PicoOpt&POPT_ALT_RENDERER) d|=0x0020; // sprite collision (Shadow of the Beast)\r
472 if (!(pv->reg[1]&0x40)) d|=0x0008; // set V-Blank if display is disabled\r
473 if (SekCyclesLeft < 84+4) d|=0x0004; // H-Blank (Sonic3 vs)\r
69996cb7 474\r
475 d|=(pv->pending_ints&0x20)<<2; // V-int pending?\r
476 if (d&0x100) pv->status&=~0x100; // FIFO no longer full\r
cc68a136 477\r
69996cb7 478 pv->pending=0; // ctrl port reads clear write-pending flag (Charles MacDonald)\r
cc68a136 479\r
69996cb7 480 elprintf(EL_SR, "SR read: %04x @ %06x", d, SekPc);\r
b6d7ac70 481 return d;\r
cc68a136 482 }\r
483\r
484 // H-counter info (based on Generator):\r
485 // frame:\r
486 // | <- hblank? -> |\r
487 // start <416> hint <36> hdisplay <38> end // CPU cycles\r
488 // |---------...---------|------------|-------------|\r
489 // 0 B6 E4 FF // 40 cells\r
490 // 0 93 E8 FF // 32 cells\r
491\r
492 // Gens (?) v-render\r
493 // start <hblank=84> hint hdisplay <404> |\r
494 // |---------------------|--------------------------|\r
495 // E4 (hc[0x43]==0) 07 B1 // 40\r
496 // E8 (hc[0x45]==0) 05 91 // 32\r
4f672280 497\r
cc68a136 498 // check: Sonic 3D Blast bonus, Cannon Fodder, Chase HQ II, 3 Ninjas kick back, Road Rash 3, Skitchin', Wheel of Fortune\r
499 if ((a&0x1c)==0x08)\r
500 {\r
b6d7ac70 501 unsigned int hc, d;\r
cc68a136 502\r
b6d7ac70 503 if (Pico.m.scanline != -1)\r
504 {\r
cc68a136 505 int lineCycles=(488-SekCyclesLeft)&0x1ff;\r
506 d=Pico.m.scanline; // V-Counter\r
507\r
508 if(Pico.video.reg[12]&1)\r
509 hc=hcounts_40[lineCycles];\r
510 else hc=hcounts_32[lineCycles];\r
511\r
8c1952f0 512 //if(lineCycles > 488-12) d++; // Wheel of Fortune\r
cc68a136 513 } else {\r
514 // get approximate V-Counter\r
515 d=vcounts[SekCyclesDone()>>8];\r
516 hc = Pico.m.rotate&0xff;\r
517 }\r
518\r
519 if(Pico.m.pal) {\r
b6d7ac70 520 if (d >= 0x103) d-=56; // based on Gens\r
cc68a136 521 } else {\r
b6d7ac70 522 if (d >= 0xEB) d-=6;\r
cc68a136 523 }\r
524\r
525 if((Pico.video.reg[12]&6) == 6) {\r
526 // interlace mode 2 (Combat Cars (UE) [!])\r
527 d <<= 1;\r
528 if (d&0xf00) d|= 1;\r
529 }\r
530\r
69996cb7 531 elprintf(EL_HVCNT, "hv: %02x %02x (%i) @ %06x", hc, d, SekCyclesDone(), SekPc);\r
cc68a136 532 d&=0xff; d<<=8;\r
533 d|=hc;\r
b6d7ac70 534 return d;\r
cc68a136 535 }\r
536\r
b6d7ac70 537 return 0;\r
cc68a136 538}\r