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