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