1 // This is part of Pico Library
\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
7 // For commercial use, separate licencing terms must be obtained.
\r
10 #include "PicoInt.h"
\r
12 #pragma warning (disable:4706) // Disable assignment within conditional
\r
15 int (*PicoScan)(unsigned int num, void *data)=NULL;
\r
17 unsigned short DefOutBuff[320*2];
\r
18 unsigned char HighCol[8+320+8];
\r
19 static int HighCacheA[41+1]; // caches for high layers
\r
20 static int HighCacheB[41+1];
\r
21 static int HighCacheS[80+1]; // and sprites
\r
22 static int HighPreSpr[80*2+1]; // slightly preprocessed sprites
\r
23 char HighSprZ[320+8+8]; // Z-buffer for accurate sprites and shadow/hilight mode
\r
24 // (if bit 7 == 0, sh caused by tile; if bit 6 == 0 pixel must be shadowed, else hilighted, if bit5 == 1)
\r
25 // lsb->msb: moved sprites, not all window tiles use same priority, accurate sprites (copied from PicoOpt), interlace
\r
26 // dirty sprites, sonic mode, have layer with all hi prio tiles (mk3), layer sh/hi already processed
\r
28 void *DrawLineDest=DefOutBuff; // pointer to dest buffer where to draw this line to
\r
29 int Scanline=0; // Scanline
\r
31 static int SpriteBlocks;
\r
32 //unsigned short ppt[] = { 0x0f11, 0x0ff1, 0x01f1, 0x011f, 0x01ff, 0x0f1f, 0x0f0e, 0x0e7c };
\r
36 int nametab; // Position in VRAM of name table (for this tile line)
\r
37 int line; // Line number in pixels 0x000-0x3ff within the virtual tilemap
\r
38 int hscroll; // Horizontal scroll value in pixels for the line
\r
39 int xmask; // X-Mask (0x1f - 0x7f) for horizontal wraparound in the tilemap
\r
40 int *hc; // cache for high tile codes and their positions
\r
41 int cells; // cells (tiles) to draw (32 col mode doesn't need to update whole 320)
\r
44 // stuff available in asm:
\r
46 void DrawWindow(int tstart, int tend, int prio, int sh);
\r
47 void BackFill(int reg7, int sh);
\r
48 void DrawSprite(int *sprite, int **hc, int sh);
\r
49 void DrawTilesFromCache(int *hc, int sh, int rlim);
\r
50 void DrawSpritesFromCache(int *hc, int sh);
\r
51 void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells);
\r
52 void FinalizeLineBGR444(int sh);
\r
53 void FinalizeLineRGB555(int sh);
\r
54 void blockcpy_or(void *dst, void *src, size_t n, int pat);
\r
57 void blockcpy_or(void *dst, void *src, size_t n, int pat)
\r
59 unsigned char *pd = dst, *ps = src;
\r
61 *pd++ = (unsigned char) (*ps++ | pat);
\r
66 static int TileNorm(int sx,int addr,int pal)
\r
68 unsigned char *pd = HighCol+sx;
\r
69 unsigned int pack=0; unsigned int t=0;
\r
71 pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
\r
74 t=pack&0x0000f000; if (t) pd[0]=(unsigned char)(pal|(t>>12));
\r
75 t=pack&0x00000f00; if (t) pd[1]=(unsigned char)(pal|(t>> 8));
\r
76 t=pack&0x000000f0; if (t) pd[2]=(unsigned char)(pal|(t>> 4));
\r
77 t=pack&0x0000000f; if (t) pd[3]=(unsigned char)(pal|(t ));
\r
78 t=pack&0xf0000000; if (t) pd[4]=(unsigned char)(pal|(t>>28));
\r
79 t=pack&0x0f000000; if (t) pd[5]=(unsigned char)(pal|(t>>24));
\r
80 t=pack&0x00f00000; if (t) pd[6]=(unsigned char)(pal|(t>>20));
\r
81 t=pack&0x000f0000; if (t) pd[7]=(unsigned char)(pal|(t>>16));
\r
85 return 1; // Tile blank
\r
88 static int TileFlip(int sx,int addr,int pal)
\r
90 unsigned char *pd = HighCol+sx;
\r
91 unsigned int pack=0; unsigned int t=0;
\r
93 pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
\r
96 t=pack&0x000f0000; if (t) pd[0]=(unsigned char)(pal|(t>>16));
\r
97 t=pack&0x00f00000; if (t) pd[1]=(unsigned char)(pal|(t>>20));
\r
98 t=pack&0x0f000000; if (t) pd[2]=(unsigned char)(pal|(t>>24));
\r
99 t=pack&0xf0000000; if (t) pd[3]=(unsigned char)(pal|(t>>28));
\r
100 t=pack&0x0000000f; if (t) pd[4]=(unsigned char)(pal|(t ));
\r
101 t=pack&0x000000f0; if (t) pd[5]=(unsigned char)(pal|(t>> 4));
\r
102 t=pack&0x00000f00; if (t) pd[6]=(unsigned char)(pal|(t>> 8));
\r
103 t=pack&0x0000f000; if (t) pd[7]=(unsigned char)(pal|(t>>12));
\r
106 return 1; // Tile blank
\r
110 // tile renderers for hacky operator sprite support
\r
111 #define sh_pix(x) \
\r
113 else if(t==0xe) pd[x]=(unsigned char)((pd[x]&0x3f)|0x80); /* hilight */ \
\r
114 else if(t==0xf) pd[x]=(unsigned char)((pd[x]&0x3f)|0xc0); /* shadow */ \
\r
115 else pd[x]=(unsigned char)(pal|t)
\r
117 #ifndef _ASM_DRAW_C
\r
118 static int TileNormSH(int sx,int addr,int pal)
\r
120 unsigned int pack=0; unsigned int t=0;
\r
121 unsigned char *pd = HighCol+sx;
\r
123 pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
\r
126 t=(pack&0x0000f000)>>12; sh_pix(0);
\r
127 t=(pack&0x00000f00)>> 8; sh_pix(1);
\r
128 t=(pack&0x000000f0)>> 4; sh_pix(2);
\r
129 t=(pack&0x0000000f) ; sh_pix(3);
\r
130 t=(pack&0xf0000000)>>28; sh_pix(4);
\r
131 t=(pack&0x0f000000)>>24; sh_pix(5);
\r
132 t=(pack&0x00f00000)>>20; sh_pix(6);
\r
133 t=(pack&0x000f0000)>>16; sh_pix(7);
\r
137 return 1; // Tile blank
\r
140 static int TileFlipSH(int sx,int addr,int pal)
\r
142 unsigned int pack=0; unsigned int t=0;
\r
143 unsigned char *pd = HighCol+sx;
\r
145 pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
\r
148 t=(pack&0x000f0000)>>16; sh_pix(0);
\r
149 t=(pack&0x00f00000)>>20; sh_pix(1);
\r
150 t=(pack&0x0f000000)>>24; sh_pix(2);
\r
151 t=(pack&0xf0000000)>>28; sh_pix(3);
\r
152 t=(pack&0x0000000f) ; sh_pix(4);
\r
153 t=(pack&0x000000f0)>> 4; sh_pix(5);
\r
154 t=(pack&0x00000f00)>> 8; sh_pix(6);
\r
155 t=(pack&0x0000f000)>>12; sh_pix(7);
\r
158 return 1; // Tile blank
\r
162 static int TileNormZ(int sx,int addr,int pal,int zval)
\r
164 unsigned int pack=0; unsigned int t=0;
\r
165 unsigned char *pd = HighCol+sx;
\r
166 char *zb = HighSprZ+sx;
\r
167 int collision = 0, zb_s;
\r
169 pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
\r
172 t=pack&0x0000f000; if(t) { zb_s=zb[0]; if(zb_s) collision=1; if(zval>zb_s) { pd[0]=(unsigned char)(pal|(t>>12)); zb[0]=(char)zval; } }
\r
173 t=pack&0x00000f00; if(t) { zb_s=zb[1]; if(zb_s) collision=1; if(zval>zb_s) { pd[1]=(unsigned char)(pal|(t>> 8)); zb[1]=(char)zval; } }
\r
174 t=pack&0x000000f0; if(t) { zb_s=zb[2]; if(zb_s) collision=1; if(zval>zb_s) { pd[2]=(unsigned char)(pal|(t>> 4)); zb[2]=(char)zval; } }
\r
175 t=pack&0x0000000f; if(t) { zb_s=zb[3]; if(zb_s) collision=1; if(zval>zb_s) { pd[3]=(unsigned char)(pal|(t )); zb[3]=(char)zval; } }
\r
176 t=pack&0xf0000000; if(t) { zb_s=zb[4]; if(zb_s) collision=1; if(zval>zb_s) { pd[4]=(unsigned char)(pal|(t>>28)); zb[4]=(char)zval; } }
\r
177 t=pack&0x0f000000; if(t) { zb_s=zb[5]; if(zb_s) collision=1; if(zval>zb_s) { pd[5]=(unsigned char)(pal|(t>>24)); zb[5]=(char)zval; } }
\r
178 t=pack&0x00f00000; if(t) { zb_s=zb[6]; if(zb_s) collision=1; if(zval>zb_s) { pd[6]=(unsigned char)(pal|(t>>20)); zb[6]=(char)zval; } }
\r
179 t=pack&0x000f0000; if(t) { zb_s=zb[7]; if(zb_s) collision=1; if(zval>zb_s) { pd[7]=(unsigned char)(pal|(t>>16)); zb[7]=(char)zval; } }
\r
180 if(collision) Pico.video.status|=0x20;
\r
184 return 1; // Tile blank
\r
187 static int TileFlipZ(int sx,int addr,int pal,int zval)
\r
189 unsigned int pack=0; unsigned int t=0;
\r
190 unsigned char *pd = HighCol+sx;
\r
191 char *zb = HighSprZ+sx;
\r
192 int collision = 0, zb_s;
\r
194 pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
\r
197 t=pack&0x000f0000; if(t) { zb_s=zb[0]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[0]=(unsigned char)(pal|(t>>16)); zb[0]=(char)zval; } }
\r
198 t=pack&0x00f00000; if(t) { zb_s=zb[1]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[1]=(unsigned char)(pal|(t>>20)); zb[1]=(char)zval; } }
\r
199 t=pack&0x0f000000; if(t) { zb_s=zb[2]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[2]=(unsigned char)(pal|(t>>24)); zb[2]=(char)zval; } }
\r
200 t=pack&0xf0000000; if(t) { zb_s=zb[3]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[3]=(unsigned char)(pal|(t>>28)); zb[3]=(char)zval; } }
\r
201 t=pack&0x0000000f; if(t) { zb_s=zb[4]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[4]=(unsigned char)(pal|(t )); zb[4]=(char)zval; } }
\r
202 t=pack&0x000000f0; if(t) { zb_s=zb[5]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[5]=(unsigned char)(pal|(t>> 4)); zb[5]=(char)zval; } }
\r
203 t=pack&0x00000f00; if(t) { zb_s=zb[6]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[6]=(unsigned char)(pal|(t>> 8)); zb[6]=(char)zval; } }
\r
204 t=pack&0x0000f000; if(t) { zb_s=zb[7]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[7]=(unsigned char)(pal|(t>>12)); zb[7]=(char)zval; } }
\r
205 if(collision) Pico.video.status|=0x20;
\r
208 return 1; // Tile blank
\r
212 #define sh_pixZ(x) \
\r
214 if(zb[x]) collision=1; \
\r
216 if (t==0xe) { pd[x]=(unsigned char)((pd[x]&0x3f)|0x80); /* hilight */ } \
\r
217 else if(t==0xf) { pd[x]=(unsigned char)((pd[x]&0x3f)|0xc0); /* shadow */ } \
\r
218 else { zb[x]=(char)zval; pd[x]=(unsigned char)(pal|t); } \
\r
222 static int TileNormZSH(int sx,int addr,int pal,int zval)
\r
224 unsigned int pack=0; unsigned int t=0;
\r
225 unsigned char *pd = HighCol+sx;
\r
226 char *zb = HighSprZ+sx;
\r
229 pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
\r
232 t=(pack&0x0000f000)>>12; sh_pixZ(0);
\r
233 t=(pack&0x00000f00)>> 8; sh_pixZ(1);
\r
234 t=(pack&0x000000f0)>> 4; sh_pixZ(2);
\r
235 t=(pack&0x0000000f) ; sh_pixZ(3);
\r
236 t=(pack&0xf0000000)>>28; sh_pixZ(4);
\r
237 t=(pack&0x0f000000)>>24; sh_pixZ(5);
\r
238 t=(pack&0x00f00000)>>20; sh_pixZ(6);
\r
239 t=(pack&0x000f0000)>>16; sh_pixZ(7);
\r
240 if(collision) Pico.video.status|=0x20;
\r
244 return 1; // Tile blank
\r
247 static int TileFlipZSH(int sx,int addr,int pal,int zval)
\r
249 unsigned int pack=0; unsigned int t=0;
\r
250 unsigned char *pd = HighCol+sx;
\r
251 char *zb = HighSprZ+sx;
\r
254 pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
\r
257 t=(pack&0x000f0000)>>16; sh_pixZ(0);
\r
258 t=(pack&0x00f00000)>>20; sh_pixZ(1);
\r
259 t=(pack&0x0f000000)>>24; sh_pixZ(2);
\r
260 t=(pack&0xf0000000)>>28; sh_pixZ(3);
\r
261 t=(pack&0x0000000f) ; sh_pixZ(4);
\r
262 t=(pack&0x000000f0)>> 4; sh_pixZ(5);
\r
263 t=(pack&0x00000f00)>> 8; sh_pixZ(6);
\r
264 t=(pack&0x0000f000)>>12; sh_pixZ(7);
\r
265 if(collision) Pico.video.status|=0x20;
\r
268 return 1; // Tile blank
\r
271 // --------------------------------------------
\r
273 #ifndef _ASM_DRAW_C
\r
274 static void DrawStrip(struct TileStrip *ts, int plane_sh, int cellskip)
\r
276 int tilex,dx,ty,code=0,addr=0,cells;
\r
277 int oldcode=-1,blank=-1; // The tile we know is blank
\r
280 // Draw tiles across screen:
\r
281 sh=(plane_sh<<5)&0x40;
\r
282 tilex=((-ts->hscroll)>>3)+cellskip;
\r
283 ty=(ts->line&7)<<1; // Y-Offset into tile
\r
284 dx=((ts->hscroll-1)&7)+1;
\r
285 cells = ts->cells - cellskip;
\r
286 if(dx != 8) cells++; // have hscroll, need to draw 1 cell more
\r
289 for (; cells > 0; dx+=8,tilex++,cells--)
\r
293 code=Pico.vram[ts->nametab+(tilex&ts->xmask)];
\r
294 if (code==blank) continue;
\r
295 if (code>>15) { // high priority tile
\r
296 int cval = code | (dx<<16) | (ty<<25);
\r
297 if(code&0x1000) cval^=7<<26;
\r
298 *ts->hc++ = cval; // cache it
\r
302 if (code!=oldcode) {
\r
304 // Get tile address/2:
\r
305 addr=(code&0x7ff)<<4;
\r
307 if (code&0x1000) addr^=0xe; // Y-flip
\r
309 pal=((code>>9)&0x30)|sh;
\r
312 if (code&0x0800) zero=TileFlip(dx,addr,pal);
\r
313 else zero=TileNorm(dx,addr,pal);
\r
315 if (zero) blank=code; // We know this tile is blank now
\r
318 // terminate the cache list
\r
320 // if oldcode wasn't changed, it means all layer is hi priority
\r
321 if (oldcode == -1) rendstatus|=0x40;
\r
325 void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip)
\r
327 int tilex,dx,code=0,addr=0,cell=0;
\r
328 int oldcode=-1,blank=-1; // The tile we know is blank
\r
329 int pal=0,scan=Scanline;
\r
331 // Draw tiles across screen:
\r
332 tilex=(-ts->hscroll)>>3;
\r
333 dx=((ts->hscroll-1)&7)+1;
\r
334 if(dx != 8) cell--; // have hscroll, start with negative cell
\r
339 for (; cell < ts->cells; dx+=8,tilex++,cell++)
\r
341 int zero=0,nametabadd,ty;
\r
346 vscroll=Pico.vsram[(plane_sh&1)+(cell&~1)];
\r
348 // Find the line in the name table
\r
349 line=(vscroll+scan)&ts->line&0xffff; // ts->line is really ymask ..
\r
350 nametabadd=(line>>3)<<(ts->line>>24); // .. and shift[width]
\r
351 ty=(line&7)<<1; // Y-Offset into tile
\r
354 code=Pico.vram[ts->nametab+nametabadd+(tilex&ts->xmask)];
\r
355 if (code==blank) continue;
\r
356 if (code>>15) { // high priority tile
\r
357 int cval = code | (dx<<16) | (ty<<25);
\r
358 if(code&0x1000) cval^=7<<26;
\r
359 *ts->hc++ = cval; // cache it
\r
363 if (code!=oldcode) {
\r
365 // Get tile address/2:
\r
366 addr=(code&0x7ff)<<4;
\r
367 if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip
\r
369 pal=((code>>9)&0x30)|((plane_sh<<5)&0x40);
\r
372 if (code&0x0800) zero=TileFlip(dx,addr,pal);
\r
373 else zero=TileNorm(dx,addr,pal);
\r
375 if (zero) blank=code; // We know this tile is blank now
\r
378 // terminate the cache list
\r
380 if (oldcode == -1) rendstatus|=0x40;
\r
384 #ifndef _ASM_DRAW_C
\r
387 void DrawStripInterlace(struct TileStrip *ts)
\r
389 int tilex=0,dx=0,ty=0,code=0,addr=0,cells;
\r
390 int oldcode=-1,blank=-1; // The tile we know is blank
\r
393 // Draw tiles across screen:
\r
394 tilex=(-ts->hscroll)>>3;
\r
395 ty=(ts->line&15)<<1; // Y-Offset into tile
\r
396 dx=((ts->hscroll-1)&7)+1;
\r
398 if(dx != 8) cells++; // have hscroll, need to draw 1 cell more
\r
400 for (; cells; dx+=8,tilex++,cells--)
\r
404 code=Pico.vram[ts->nametab+(tilex&ts->xmask)];
\r
405 if (code==blank) continue;
\r
406 if (code>>15) { // high priority tile
\r
407 int cval = (code&0xfc00) | (dx<<16) | (ty<<25);
\r
408 cval|=(code&0x3ff)<<1;
\r
409 if(code&0x1000) cval^=0xf<<26;
\r
410 *ts->hc++ = cval; // cache it
\r
414 if (code!=oldcode) {
\r
416 // Get tile address/2:
\r
417 addr=(code&0x7ff)<<5;
\r
418 if (code&0x1000) addr+=30-ty; else addr+=ty; // Y-flip
\r
420 // pal=Pico.cram+((code>>9)&0x30);
\r
421 pal=((code>>9)&0x30);
\r
424 if (code&0x0800) zero=TileFlip(dx,addr,pal);
\r
425 else zero=TileNorm(dx,addr,pal);
\r
427 if (zero) blank=code; // We know this tile is blank now
\r
430 // terminate the cache list
\r
434 // --------------------------------------------
\r
436 #ifndef _ASM_DRAW_C
\r
437 static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells)
\r
439 struct PicoVideo *pvid=&Pico.video;
\r
440 const char shift[4]={5,6,5,7}; // 32,64 or 128 sized tilemaps (2 is invalid)
\r
441 struct TileStrip ts;
\r
442 int width, height, ymask;
\r
448 // Work out the TileStrip to draw
\r
450 // Work out the name table size: 32 64 or 128 tiles (0-3)
\r
451 width=pvid->reg[16];
\r
452 height=(width>>4)&3; width&=3;
\r
454 ts.xmask=(1<<shift[width])-1; // X Mask in tiles (0x1f-0x7f)
\r
455 ymask=(height<<8)|0xff; // Y Mask in pixels
\r
456 if(width == 1) ymask&=0x1ff;
\r
457 else if(width>1) ymask =0x0ff;
\r
459 // Find name table:
\r
460 if (plane_sh&1) ts.nametab=(pvid->reg[4]&0x07)<<12; // B
\r
461 else ts.nametab=(pvid->reg[2]&0x38)<< 9; // A
\r
463 htab=pvid->reg[13]<<9; // Horizontal scroll table address
\r
464 if ( pvid->reg[11]&2) htab+=Scanline<<1; // Offset by line
\r
465 if ((pvid->reg[11]&1)==0) htab&=~0xf; // Offset by tile
\r
466 htab+=plane_sh&1; // A or B
\r
468 // Get horizontal scroll value, will be masked later
\r
469 ts.hscroll=Pico.vram[htab&0x7fff];
\r
471 if((pvid->reg[12]&6) == 6) {
\r
472 // interlace mode 2
\r
473 vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value
\r
475 // Find the line in the name table
\r
476 ts.line=(vscroll+(Scanline<<1))&((ymask<<1)|1);
\r
477 ts.nametab+=(ts.line>>4)<<shift[width];
\r
479 DrawStripInterlace(&ts);
\r
480 } else if( pvid->reg[11]&4) {
\r
481 // shit, we have 2-cell column based vscroll
\r
482 // luckily this doesn't happen too often
\r
483 ts.line=ymask|(shift[width]<<24); // save some stuff instead of line
\r
484 DrawStripVSRam(&ts, plane_sh, cellskip);
\r
486 vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value
\r
488 // Find the line in the name table
\r
489 ts.line=(vscroll+Scanline)&ymask;
\r
490 ts.nametab+=(ts.line>>3)<<shift[width];
\r
492 DrawStrip(&ts, plane_sh, cellskip);
\r
497 // --------------------------------------------
\r
499 // tstart & tend are tile pair numbers
\r
500 static void DrawWindow(int tstart, int tend, int prio, int sh) // int *hcache
\r
502 struct PicoVideo *pvid=&Pico.video;
\r
503 int tilex=0,ty=0,nametab,code=0;
\r
504 int blank=-1; // The tile we know is blank
\r
506 // Find name table line:
\r
507 if (pvid->reg[12]&1)
\r
509 nametab=(pvid->reg[3]&0x3c)<<9; // 40-cell mode
\r
510 nametab+=(Scanline>>3)<<6;
\r
514 nametab=(pvid->reg[3]&0x3e)<<9; // 32-cell mode
\r
515 nametab+=(Scanline>>3)<<5;
\r
521 ty=(Scanline&7)<<1; // Y-Offset into tile
\r
523 if(!(rendstatus&2)) {
\r
524 // check the first tile code
\r
525 code=Pico.vram[nametab+tilex];
\r
526 // if the whole window uses same priority (what is often the case), we may be able to skip this field
\r
527 if((code>>15) != prio) return;
\r
530 // Draw tiles across screen:
\r
531 for (; tilex < tend; tilex++)
\r
536 code=Pico.vram[nametab+tilex];
\r
537 if(code==blank) continue;
\r
538 if((code>>15) != prio) {
\r
543 pal=((code>>9)&0x30);
\r
546 int tmp, *zb = (int *)(HighCol+8+(tilex<<3));
\r
549 if(!(tmp&0x00000080)) tmp&=~0x000000c0; if(!(tmp&0x00008000)) tmp&=~0x0000c000;
\r
550 if(!(tmp&0x00800000)) tmp&=~0x00c00000; if(!(tmp&0x80000000)) tmp&=~0xc0000000;
\r
551 *zb++=tmp; tmp = *zb;
\r
552 if(!(tmp&0x00000080)) tmp&=~0x000000c0; if(!(tmp&0x00008000)) tmp&=~0x0000c000;
\r
553 if(!(tmp&0x00800000)) tmp&=~0x00c00000; if(!(tmp&0x80000000)) tmp&=~0xc0000000;
\r
560 // Get tile address/2:
\r
561 addr=(code&0x7ff)<<4;
\r
562 if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip
\r
564 if (code&0x0800) zero=TileFlip(8+(tilex<<3),addr,pal);
\r
565 else zero=TileNorm(8+(tilex<<3),addr,pal);
\r
567 if (zero) blank=code; // We know this tile is blank now
\r
570 // terminate the cache list
\r
574 // --------------------------------------------
\r
576 static void DrawTilesFromCache(int *hc, int sh, int rlim)
\r
578 int code, addr, dx;
\r
581 // *ts->hc++ = code | (dx<<16) | (ty<<25); // cache it
\r
583 if (sh && (rendstatus&0xc0))
\r
585 if (!(rendstatus&0x80))
\r
587 // as some layer has covered whole line with hi priority tiles,
\r
588 // we can process whole line and then act as if sh/hi mode was off.
\r
590 int c = 320/4, *zb = (int *)(HighCol+8);
\r
594 if (!(tmp & 0x80808080)) *zb=tmp&0x3f3f3f3f;
\r
596 if(!(tmp&0x00000080)) tmp&=~0x000000c0; if(!(tmp&0x00008000)) tmp&=~0x0000c000;
\r
597 if(!(tmp&0x00800000)) tmp&=~0x00c00000; if(!(tmp&0x80000000)) tmp&=~0xc0000000;
\r
608 while ((code=*hc++)) {
\r
610 // Get tile address/2:
\r
611 addr=(code&0x7ff)<<4;
\r
612 addr+=(unsigned int)code>>25; // y offset into tile
\r
613 dx=(code>>16)&0x1ff;
\r
615 if(!(*zb&0x80)) *zb&=0x3f; zb++; if(!(*zb&0x80)) *zb&=0x3f; zb++;
\r
616 if(!(*zb&0x80)) *zb&=0x3f; zb++; if(!(*zb&0x80)) *zb&=0x3f; zb++;
\r
617 if(!(*zb&0x80)) *zb&=0x3f; zb++; if(!(*zb&0x80)) *zb&=0x3f; zb++;
\r
618 if(!(*zb&0x80)) *zb&=0x3f; zb++; if(!(*zb&0x80)) *zb&=0x3f; zb++;
\r
620 pal=((code>>9)&0x30);
\r
621 if (rlim-dx < 0) goto last_cut_tile;
\r
623 if (code&0x0800) TileFlip(dx,addr,pal);
\r
624 else TileNorm(dx,addr,pal);
\r
629 short blank=-1; // The tile we know is blank
\r
630 while ((code=*hc++)) {
\r
632 if((short)code == blank) continue;
\r
633 // Get tile address/2:
\r
634 addr=(code&0x7ff)<<4;
\r
635 addr+=(unsigned int)code>>25; // y offset into tile
\r
636 dx=(code>>16)&0x1ff;
\r
638 pal=((code>>9)&0x30);
\r
639 if (rlim-dx < 0) goto last_cut_tile;
\r
641 if (code&0x0800) zero=TileFlip(dx,addr,pal);
\r
642 else zero=TileNorm(dx,addr,pal);
\r
644 if (zero) blank=(short)code;
\r
651 unsigned int t, pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
\r
652 unsigned char *pd = HighCol+dx;
\r
658 case 7: t=pack&0x00000f00; if (t) pd[6]=(unsigned char)(pal|(t>> 8)); // "break" is left out intentionally
\r
659 case 6: t=pack&0x000000f0; if (t) pd[5]=(unsigned char)(pal|(t>> 4));
\r
660 case 5: t=pack&0x0000000f; if (t) pd[4]=(unsigned char)(pal|(t ));
\r
661 case 4: t=pack&0xf0000000; if (t) pd[3]=(unsigned char)(pal|(t>>28));
\r
662 case 3: t=pack&0x0f000000; if (t) pd[2]=(unsigned char)(pal|(t>>24));
\r
663 case 2: t=pack&0x00f00000; if (t) pd[1]=(unsigned char)(pal|(t>>20));
\r
664 case 1: t=pack&0x000f0000; if (t) pd[0]=(unsigned char)(pal|(t>>16));
\r
672 case 7: t=pack&0x00f00000; if (t) pd[6]=(unsigned char)(pal|(t>>20));
\r
673 case 6: t=pack&0x0f000000; if (t) pd[5]=(unsigned char)(pal|(t>>24));
\r
674 case 5: t=pack&0xf0000000; if (t) pd[4]=(unsigned char)(pal|(t>>28));
\r
675 case 4: t=pack&0x0000000f; if (t) pd[3]=(unsigned char)(pal|(t ));
\r
676 case 3: t=pack&0x000000f0; if (t) pd[2]=(unsigned char)(pal|(t>> 4));
\r
677 case 2: t=pack&0x00000f00; if (t) pd[1]=(unsigned char)(pal|(t>> 8));
\r
678 case 1: t=pack&0x0000f000; if (t) pd[0]=(unsigned char)(pal|(t>>12));
\r
685 // --------------------------------------------
\r
687 // Index + 0 : hhhhvvvv ab--hhvv yyyyyyyy yyyyyyyy // a: offscreen h, b: offs. v, h: horiz. size
\r
688 // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
\r
690 static void DrawSprite(int *sprite, int **hc, int sh)
\r
692 int width=0,height=0;
\r
695 int tile=0,delta=0;
\r
697 int (*fTileFunc)(int sx,int addr,int pal);
\r
699 // parse the sprite data
\r
704 height=(sy>>24)&7; // Width and height in tiles
\r
705 sy=(sy<<16)>>16; // Y
\r
707 row=Scanline-sy; // Row of the sprite we are on
\r
709 if (code&0x1000) row=(height<<3)-1-row; // Flip Y
\r
711 tile=code&0x7ff; // Tile number
\r
712 tile+=row>>3; // Tile number increases going down
\r
713 delta=height; // Delta to increase tile by going right
\r
714 if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
\r
716 tile<<=4; tile+=(row&7)<<1; // Tile address
\r
718 if(code&0x8000) { // high priority - cache it
\r
719 *(*hc)++ = (tile<<16)|((code&0x0800)<<5)|((sx<<6)&0x0000ffc0)|((code>>9)&0x30)|((sprite[0]>>16)&0xf);
\r
721 delta<<=4; // Delta of address
\r
722 pal=((code>>9)&0x30)|(sh<<6);
\r
724 if(sh && (code&0x6000) == 0x6000) {
\r
725 if(code&0x0800) fTileFunc=TileFlipSH;
\r
726 else fTileFunc=TileNormSH;
\r
728 if(code&0x0800) fTileFunc=TileFlip;
\r
729 else fTileFunc=TileNorm;
\r
732 for (; width; width--,sx+=8,tile+=delta)
\r
734 if(sx<=0) continue;
\r
735 if(sx>=328) break; // Offscreen
\r
737 tile&=0x7fff; // Clip tile address
\r
738 fTileFunc(sx,tile,pal);
\r
745 // Index + 0 : hhhhvvvv s---hhvv yyyyyyyy yyyyyyyy // s: skip flag, h: horiz. size
\r
746 // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
\r
748 static void DrawSpriteZ(int pack, int pack2, int shpri, int sprio)
\r
750 int width=0,height=0;
\r
753 int tile=0,delta=0;
\r
755 int (*fTileFunc)(int sx,int addr,int pal,int zval);
\r
757 // parse the sprite data
\r
759 sy=(pack <<16)>>16; // Y
\r
761 height=(pack>>24)&7; // Width and height in tiles
\r
763 row=Scanline-sy; // Row of the sprite we are on
\r
765 if (pack2&0x1000) row=(height<<3)-1-row; // Flip Y
\r
767 tile=pack2&0x7ff; // Tile number
\r
768 tile+=row>>3; // Tile number increases going down
\r
769 delta=height; // Delta to increase tile by going right
\r
770 if (pack2&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
\r
772 tile<<=4; tile+=(row&7)<<1; // Tile address
\r
773 delta<<=4; // Delta of address
\r
774 pal=((pack2>>9)&0x30);
\r
775 if((shpri&1)&&!(shpri&2)) pal|=0x40;
\r
778 if((pack2&0x6000) != 0x6000) shpri = 0;
\r
779 shpri |= (pack2&0x0800)>>10;
\r
782 case 0: fTileFunc=TileNormZ; break;
\r
783 case 1: fTileFunc=TileNormZSH; break;
\r
784 case 2: fTileFunc=TileFlipZ; break;
\r
785 case 3: fTileFunc=TileFlipZSH; break;
\r
788 for (; width; width--,sx+=8,tile+=delta)
\r
790 if(sx<=0) continue;
\r
791 if(sx>=328) break; // Offscreen
\r
793 tile&=0x7fff; // Clip tile address
\r
794 fTileFunc(sx,tile,pal,sprio);
\r
798 static void DrawSpriteInterlace(unsigned int *sprite)
\r
800 int width=0,height=0;
\r
803 int tile=0,delta=0;
\r
806 // parse the sprite data
\r
809 sy=(sy&0x3ff)-0x100; // Y
\r
810 width=(height>>2)&3; height&=3;
\r
811 width++; height++; // Width and height in tiles
\r
813 row=(Scanline<<1)-sy; // Row of the sprite we are on
\r
816 sx=((code>>16)&0x1ff)-0x78; // X
\r
818 if (code&0x1000) row^=(16<<height)-1; // Flip Y
\r
820 tile=code&0x3ff; // Tile number
\r
821 tile+=row>>4; // Tile number increases going down
\r
822 delta=height; // Delta to increase tile by going right
\r
823 if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
\r
825 tile<<=5; tile+=(row&15)<<1; // Tile address
\r
827 delta<<=5; // Delta of address
\r
828 pal=((code>>9)&0x30); // Get palette pointer
\r
830 for (; width; width--,sx+=8,tile+=delta)
\r
832 if(sx<=0) continue;
\r
833 if(sx>=328) break; // Offscreen
\r
835 tile&=0x7fff; // Clip tile address
\r
836 if (code&0x0800) TileFlip(sx,tile,pal);
\r
837 else TileNorm(sx,tile,pal);
\r
842 static void DrawAllSpritesInterlace(int pri, int maxwidth)
\r
844 struct PicoVideo *pvid=&Pico.video;
\r
845 int i,u,table,link=0,sline=Scanline<<1;
\r
846 unsigned int *sprites[80]; // Sprite index
\r
848 table=pvid->reg[5]&0x7f;
\r
849 if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode
\r
850 table<<=8; // Get sprite table address/2
\r
852 for (i=u=0; u < 80 && i < 21; u++)
\r
854 unsigned int *sprite;
\r
855 int code, sx, sy, height;
\r
857 sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite
\r
862 if(((sx>>15)&1) != pri) goto nextsprite; // wrong priority sprite
\r
864 // check if it is on this line
\r
865 sy = (code&0x3ff)-0x100;
\r
866 height = (((code>>24)&3)+1)<<4;
\r
867 if(sline < sy || sline >= sy+height) goto nextsprite; // no
\r
869 // check if sprite is not hidden offscreen
\r
870 sx = (sx>>16)&0x1ff;
\r
871 sx -= 0x78; // Get X coordinate + 8
\r
872 if(sx <= -8*3 || sx >= maxwidth) goto nextsprite;
\r
874 // sprite is good, save it's pointer
\r
875 sprites[i++]=sprite;
\r
878 // Find next sprite
\r
879 link=(code>>16)&0x7f;
\r
880 if(!link) break; // End of sprites
\r
883 // Go through sprites backwards:
\r
884 for (i-- ;i>=0; i--)
\r
885 DrawSpriteInterlace(sprites[i]);
\r
889 #ifndef _ASM_DRAW_C
\r
890 static void DrawSpritesFromCache(int *hc, int sh)
\r
892 int code, tile, sx, delta, width;
\r
894 int (*fTileFunc)(int sx,int addr,int pal);
\r
896 // *(*hc)++ = (tile<<16)|((code&0x0800)<<5)|((sx<<6)&0x0000ffc0)|((code>>9)&0x30)|((sprite[0]>>24)&0xf);
\r
898 while((code=*hc++)) {
\r
901 width=delta>>2; delta&=3;
\r
902 width++; delta++; // Width and height in tiles
\r
903 if (code&0x10000) delta=-delta; // Flip X
\r
905 tile=((unsigned int)code>>17)<<1;
\r
906 sx=(code<<16)>>22; // sx can be negative (start offscreen), so sign extend
\r
908 if(sh && pal == 0x30) { //
\r
909 if(code&0x10000) fTileFunc=TileFlipSH;
\r
910 else fTileFunc=TileNormSH;
\r
912 if(code&0x10000) fTileFunc=TileFlip;
\r
913 else fTileFunc=TileNorm;
\r
916 for (; width; width--,sx+=8,tile+=delta)
\r
918 if(sx<=0) continue;
\r
919 if(sx>=328) break; // Offscreen
\r
921 tile&=0x7fff; // Clip tile address
\r
922 fTileFunc(sx,tile,pal);
\r
929 // Index + 0 : ----hhvv -lllllll -------y yyyyyyyy
\r
930 // Index + 4 : -------x xxxxxxxx pccvhnnn nnnnnnnn
\r
932 // Index + 0 : hhhhvvvv ab--hhvv yyyyyyyy yyyyyyyy // a: offscreen h, b: offs. v, h: horiz. size
\r
933 // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
\r
935 static void PrepareSprites(int full)
\r
937 struct PicoVideo *pvid=&Pico.video;
\r
938 int u=0,link=0,sblocks=0;
\r
940 int *pd = HighPreSpr;
\r
942 table=pvid->reg[5]&0x7f;
\r
943 if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode
\r
944 table<<=8; // Get sprite table address/2
\r
949 // updates: tilecode, sx
\r
950 for (u=0; u < 80 && (pack = *pd); u++, pd+=2)
\r
952 unsigned int *sprite;
\r
953 int code, code2, sx, sy, skip=0;
\r
955 sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite
\r
957 // parse sprite info
\r
960 code2 &= ~0xfe000000;
\r
961 code2 -= 0x00780000; // Get X coordinate + 8 in upper 16 bits
\r
964 if((sx <= 8-((pack>>28)<<3) && sx >= -0x76) || sx >= 328) skip=1<<23;
\r
965 else if ((sy = (pack<<16)>>16) < 240 && sy > -32) {
\r
966 int sbl = (2<<(pack>>28))-1;
\r
967 sblocks |= sbl<<(sy>>3);
\r
970 *pd = (pack&~(1<<23))|skip;
\r
973 // Find next sprite
\r
974 link=(code>>16)&0x7f;
\r
975 if(!link) break; // End of sprites
\r
977 SpriteBlocks |= sblocks;
\r
981 for (; u < 80; u++)
\r
983 unsigned int *sprite;
\r
984 int code, code2, sx, sy, hv, height, width, skip=0, sx_min;
\r
986 sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite
\r
988 // parse sprite info
\r
990 sy = (code&0x1ff)-0x80;
\r
991 hv = (code>>24)&0xf;
\r
994 if(sy > 240 || sy + (height<<3) <= 0) skip|=1<<22;
\r
998 sx = (code2>>16)&0x1ff;
\r
999 sx -= 0x78; // Get X coordinate + 8
\r
1000 sx_min = 8-(width<<3);
\r
1002 if((sx <= sx_min && sx >= -0x76) || sx >= 328) skip|=1<<23;
\r
1003 else if (sx > sx_min && !skip) {
\r
1004 int sbl = (2<<height)-1;
\r
1006 if(shi < 0) shi=0; // negative sy
\r
1007 sblocks |= sbl<<shi;
\r
1010 *pd++ = (width<<28)|(height<<24)|skip|(hv<<16)|((unsigned short)sy);
\r
1011 *pd++ = (sx<<16)|((unsigned short)code2);
\r
1013 // Find next sprite
\r
1014 link=(code>>16)&0x7f;
\r
1015 if(!link) break; // End of sprites
\r
1017 SpriteBlocks = sblocks;
\r
1018 *pd = 0; // terminate
\r
1022 static void DrawAllSprites(int *hcache, int maxwidth, int prio, int sh)
\r
1025 int sx1seen=0; // sprite with x coord 1 or 0 seen
\r
1026 int ntiles = 0; // tile counter for sprite limit emulation
\r
1027 int *sprites[40]; // Sprites to draw in fast mode
\r
1028 int *ps, pack, rs = rendstatus, scan=Scanline;
\r
1031 DrawAllSpritesInterlace(prio, maxwidth);
\r
1035 //dprintf("PrepareSprites(%i) [%i]", (rs>>4)&1, scan);
\r
1036 PrepareSprites(rs&0x10);
\r
1037 rendstatus=rs&~0x11;
\r
1039 if (!(SpriteBlocks & (1<<(scan>>3)))) return;
\r
1041 if(((rs&4)||sh)&&prio==0)
\r
1042 memset(HighSprZ, 0, 328);
\r
1043 if(!(rs&4)&&prio) {
\r
1044 if(hcache[0]) DrawSpritesFromCache(hcache, sh);
\r
1050 // Index + 0 : hhhhvvvv ab--hhvv yyyyyyyy yyyyyyyy // a: offscreen h, b: offs. v, h: horiz. size
\r
1051 // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
\r
1053 for(i=u=n=0; (pack = *ps) && n < 20; ps+=2, u++)
\r
1055 int sx, sy, row, pack2;
\r
1057 if(pack & 0x00400000) continue;
\r
1059 // get sprite info
\r
1062 sy = (pack <<16)>>16;
\r
1065 //dprintf("x: %i y: %i %ix%i", sx, sy, (pack>>28)<<3, (pack>>21)&0x38);
\r
1067 if(sx == -0x77) sx1seen|=1; // for masking mode 2
\r
1069 // check if it is on this line
\r
1070 if(row < 0 || row >= ((pack>>21)&0x38)) continue; // no
\r
1071 n++; // number of sprites on this line (both visible and hidden, max is 20) [broken]
\r
1074 ntiles += pack>>28;
\r
1075 if(ntiles > 40) break;
\r
1077 if(pack & 0x00800000) continue;
\r
1079 // masking sprite?
\r
1081 if(!(sx1seen&1) || sx1seen==3) {
\r
1082 break; // this sprite is not drawn and remaining sprites are masked
\r
1084 if((sx1seen>>8) == 0) sx1seen=(i+1)<<8;
\r
1087 else if(sx == -0x77) {
\r
1088 // masking mode2 (Outrun, Galaxy Force II, Shadow of the beast)
\r
1089 if(sx1seen>>8) { i=(sx1seen>>8)-1; break; } // seen both 0 and 1
\r
1094 // accurate sprites
\r
1095 //dprintf("P:%i",((sx>>15)&1));
\r
1097 // might need to skip this sprite
\r
1098 if((pack2&0x8000) ^ (prio<<15)) continue;
\r
1099 DrawSpriteZ(pack,pack2,sh|(prio<<1),(char)(0x1f-n));
\r
1103 // sprite is good, save it's pointer
\r
1107 // Go through sprites backwards:
\r
1109 for (i--; i>=0; i--)
\r
1110 DrawSprite(sprites[i],&hcache,sh);
\r
1112 // terminate cache list
\r
1118 // --------------------------------------------
\r
1120 #ifndef _ASM_DRAW_C
\r
1121 static void BackFill(int reg7, int sh)
\r
1123 unsigned int back=0;
\r
1124 unsigned int *pd=NULL,*end=NULL;
\r
1126 // Start with a blank scanline (background colour):
\r
1132 pd= (unsigned int *)(HighCol+8);
\r
1133 end=(unsigned int *)(HighCol+8+320);
\r
1135 do { pd[0]=pd[1]=pd[2]=pd[3]=back; pd+=4; } while (pd<end);
\r
1139 // --------------------------------------------
\r
1141 unsigned short HighPal[0x100];
\r
1143 #ifndef _ASM_DRAW_C
\r
1144 static void FinalizeLineBGR444(int sh)
\r
1146 unsigned short *pd=DrawLineDest;
\r
1147 unsigned char *ps=HighCol+8;
\r
1148 unsigned short *pal=Pico.cram;
\r
1151 if (Pico.video.reg[12]&1) {
\r
1154 if(!(PicoOpt&0x100)) pd+=32;
\r
1160 if(Pico.m.dirtyPal) {
\r
1161 blockcpy(pal, Pico.cram, 0x40*2);
\r
1162 // shadowed pixels
\r
1163 for(i = 0x3f; i >= 0; i--)
\r
1164 pal[0x40|i] = pal[0xc0|i] = (unsigned short)((pal[i]>>1)&0x0777);
\r
1165 // hilighted pixels
\r
1166 for(i = 0x3f; i >= 0; i--) {
\r
1167 t=pal[i]&0xeee;t+=0x444;if(t&0x10)t|=0xe;if(t&0x100)t|=0xe0;if(t&0x1000)t|=0xe00;t&=0xeee;
\r
1168 pal[0x80|i]=(unsigned short)t;
\r
1170 Pico.m.dirtyPal = 0;
\r
1174 for(i = 0; i < len; i++)
\r
1175 pd[i] = pal[ps[i]];
\r
1179 static void FinalizeLineRGB555(int sh)
\r
1181 unsigned short *pd=DrawLineDest;
\r
1182 unsigned char *ps=HighCol+8;
\r
1183 unsigned short *pal=HighPal;
\r
1184 int len, i, t, dirtyPal = Pico.m.dirtyPal;
\r
1187 unsigned short *ppal=Pico.cram;
\r
1188 for(i = 0x3f; i >= 0; i--)
\r
1189 pal[i] = (unsigned short) (((ppal[i]&0x00f)<<12)|((ppal[i]&0x0f0)<<3)|((ppal[i]&0xf00)>>7));
\r
1190 Pico.m.dirtyPal = 0;
\r
1193 if (Pico.video.reg[12]&1) {
\r
1196 if(!(PicoOpt&0x100)) pd+=32;
\r
1202 // shadowed pixels
\r
1203 for(i = 0x3f; i >= 0; i--)
\r
1204 pal[0x40|i] = pal[0xc0|i] = (unsigned short)((pal[i]>>1)&0x738e);
\r
1205 // hilighted pixels
\r
1206 for(i = 0x3f; i >= 0; i--) {
\r
1207 t=pal[i]&0xe71c;t+=0x4208;if(t&0x20)t|=0x1c;if(t&0x800)t|=0x700;if(t&0x10000)t|=0xe000;t&=0xe71c;
\r
1208 pal[0x80|i]=(unsigned short)t;
\r
1213 for(i = 0; i < len; i++)
\r
1214 pd[i] = pal[ps[i]];
\r
1218 static void FinalizeLine8bit(int sh)
\r
1220 unsigned char *pd=DrawLineDest;
\r
1221 int len, rs = rendstatus;
\r
1222 static int dirty_count;
\r
1224 if (!sh && Pico.m.dirtyPal == 1 && Scanline < 222) {
\r
1225 // a hack for mid-frame palette changes
\r
1228 else dirty_count++;
\r
1231 if (dirty_count == 3) {
\r
1232 blockcpy(HighPal, Pico.cram, 0x40*2);
\r
1233 } else if (dirty_count == 11) {
\r
1234 blockcpy(HighPal+0x40, Pico.cram, 0x40*2);
\r
1238 if (Pico.video.reg[12]&1) {
\r
1241 if(!(PicoOpt&0x100)) pd+=32;
\r
1245 if (!sh && rs & 0x20) {
\r
1246 if (dirty_count >= 11) {
\r
1247 blockcpy_or(pd, HighCol+8, len, 0x80);
\r
1249 blockcpy_or(pd, HighCol+8, len, 0x40);
\r
1252 blockcpy(pd, HighCol+8, len);
\r
1256 void (*FinalizeLine)(int sh) = FinalizeLineBGR444;
\r
1258 // --------------------------------------------
\r
1260 static int DrawDisplay(int sh)
\r
1262 struct PicoVideo *pvid=&Pico.video;
\r
1263 int win=0,edge=0,hvwind=0;
\r
1264 int maxw, maxcells;
\r
1266 rendstatus&=~0xc0;
\r
1268 if(pvid->reg[12]&1) {
\r
1269 maxw = 328; maxcells = 40;
\r
1271 maxw = 264; maxcells = 32;
\r
1274 // Find out if the window is on this line:
\r
1275 win=pvid->reg[0x12];
\r
1276 edge=(win&0x1f)<<3;
\r
1278 if (win&0x80) { if (Scanline>=edge) hvwind=1; }
\r
1279 else { if (Scanline< edge) hvwind=1; }
\r
1281 if (!hvwind) { // we might have a vertical window here
\r
1282 win=pvid->reg[0x11];
\r
1285 if (!edge) hvwind=1;
\r
1286 else if(edge < (maxcells>>1)) hvwind=2;
\r
1289 else if(edge < (maxcells>>1)) hvwind=2;
\r
1294 DrawLayer(1|(sh<<1), HighCacheB, 0, maxcells);
\r
1296 DrawWindow(0, maxcells>>1, 0, sh);
\r
1297 else if (hvwind == 2) {
\r
1298 // ahh, we have vertical window
\r
1299 DrawLayer(0|(sh<<1), HighCacheA, (win&0x80) ? 0 : edge<<1, (win&0x80) ? edge<<1 : maxcells);
\r
1300 DrawWindow( (win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 0, sh);
\r
1302 DrawLayer(0|(sh<<1), HighCacheA, 0, maxcells);
\r
1303 DrawAllSprites(HighCacheS, maxw, 0, sh);
\r
1305 if (HighCacheB[0]) DrawTilesFromCache(HighCacheB, sh, 328);
\r
1307 DrawWindow(0, maxcells>>1, 1, sh);
\r
1308 else if (hvwind == 2) {
\r
1309 if(HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, (win&0x80) ? edge<<4 : 328);
\r
1310 DrawWindow((win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 1, sh);
\r
1312 if (HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, 328);
\r
1313 DrawAllSprites(HighCacheS, maxw, 1, sh);
\r
1318 for (a = 0, c = HighCacheA; *c; c++, a++);
\r
1319 for (b = 0, c = HighCacheB; *c; c++, b++);
\r
1320 printf("%i:%03i: a=%i, b=%i\n", Pico.m.frame_count, Scanline, a, b);
\r
1328 static int Skip=0;
\r
1330 PICO_INTERNAL void PicoFrameStart(void)
\r
1332 // prepare to do this frame
\r
1333 rendstatus = (PicoOpt&0x80)>>5; // accurate sprites
\r
1335 Pico.video.status &= ~0x0020;
\r
1336 else Pico.video.status |= 0x0020; // sprite collision
\r
1337 if((Pico.video.reg[12]&6) == 6) rendstatus |= 8; // interlace mode
\r
1338 if(Pico.m.dirtyPal) Pico.m.dirtyPal = 2; // reset dirty if needed
\r
1340 PrepareSprites(1);
\r
1344 PICO_INTERNAL int PicoLine(int scan)
\r
1347 if (Skip>0) { Skip--; return 0; } // Skip rendering lines
\r
1350 sh=(Pico.video.reg[0xC]&8)>>3; // shadow/hilight?
\r
1353 BackFill(Pico.video.reg[7], sh);
\r
1354 if (Pico.video.reg[1]&0x40)
\r
1358 //if (SpriteBlocks & (1<<(scan>>3))) for (sh=0; sh < 30; sh++) DrawLineDest[sh] = 0xf;
\r
1360 Skip=PicoScan(Scanline,DrawLineDest);
\r
1366 void PicoDrawSetColorFormat(int which)
\r
1369 FinalizeLine = FinalizeLine8bit;
\r
1370 else if (which == 1)
\r
1371 FinalizeLine = FinalizeLineRGB555;
\r
1372 else FinalizeLine = FinalizeLineBGR444;
\r