1 // This is part of Pico Library
\r
3 // (c) Copyright 2004 Dave, All rights reserved.
\r
4 // (c) Copyright 2006-2008 notaz, All rights reserved.
\r
5 // Free for non-commercial use.
\r
7 // For commercial use, separate licencing terms must be obtained.
\r
10 * The renderer has 4 modes now:
\r
12 * - shadow/hilight (s/h)
\r
13 * - "sonic mode" for midline palette changes
\r
14 * - accurate sprites (AS)
\r
16 * AS and s/h both use upper bits for both priority and shadow/hilight flags.
\r
17 * "sonic mode" is autodetected, shadow/hilight is enabled by emulated game.
\r
18 * AS is enabled by user and takes priority over "sonic mode".
\r
21 #include "PicoInt.h"
\r
23 int (*PicoScanBegin)(unsigned int num) = NULL;
\r
24 int (*PicoScanEnd) (unsigned int num) = NULL;
\r
26 #if OVERRIDE_HIGHCOL
\r
27 static unsigned char DefHighCol[8+320+8];
\r
28 unsigned char *HighCol=DefHighCol;
\r
30 unsigned char HighCol[8+320+8];
\r
32 unsigned short DefOutBuff[320*2];
\r
33 void *DrawLineDest=DefOutBuff; // pointer to dest buffer where to draw this line to
\r
35 static int HighCacheA[41+1]; // caches for high layers
\r
36 static int HighCacheB[41+1];
\r
37 int HighPreSpr[80*2+1]; // slightly preprocessed sprites
\r
39 #define SPRL_HAVE_HI 0x80 // have hi priority sprites
\r
40 #define SPRL_HAVE_LO 0x40 // *lo*
\r
41 #define SPRL_MAY_HAVE_OP 0x20 // may have operator sprites on the line
\r
42 #define SPRL_LO_ABOVE_HI 0x10 // low priority sprites may be on top of hi
\r
43 unsigned char HighLnSpr[240][3 + MAX_LINE_SPRITES]; // sprite_count, ^flags, tile_count, [spritep]...
\r
46 int DrawScanline = 0;
\r
47 int PicoDrawMask = -1;
\r
49 static int skip_next_line=0;
\r
51 //unsigned short ppt[] = { 0x0f11, 0x0ff1, 0x01f1, 0x011f, 0x01ff, 0x0f1f, 0x0f0e, 0x0e7c };
\r
55 int nametab; // Position in VRAM of name table (for this tile line)
\r
56 int line; // Line number in pixels 0x000-0x3ff within the virtual tilemap
\r
57 int hscroll; // Horizontal scroll value in pixels for the line
\r
58 int xmask; // X-Mask (0x1f - 0x7f) for horizontal wraparound in the tilemap
\r
59 int *hc; // cache for high tile codes and their positions
\r
60 int cells; // cells (tiles) to draw (32 col mode doesn't need to update whole 320)
\r
63 // stuff available in asm:
\r
65 void DrawWindow(int tstart, int tend, int prio, int sh);
\r
66 void BackFill(int reg7, int sh);
\r
67 void DrawAllSprites(unsigned char *sprited, int prio, int sh);
\r
68 void DrawTilesFromCache(int *hc, int sh, int rlim);
\r
69 void DrawSpritesSHi(unsigned char *sprited);
\r
70 void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells);
\r
71 void FinalizeLineBGR444(int sh);
\r
72 void FinalizeLineRGB555(int sh);
\r
73 void *blockcpy(void *dst, const void *src, size_t n);
\r
74 void blockcpy_or(void *dst, void *src, size_t n, int pat);
\r
77 void blockcpy_or(void *dst, void *src, size_t n, int pat)
\r
79 unsigned char *pd = dst, *ps = src;
\r
81 *pd++ = (unsigned char) (*ps++ | pat);
\r
83 #define blockcpy memcpy
\r
87 #define TileNormMaker(funcname,pix_func) \
\r
88 static int funcname(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&0x0000f000)>>12; pix_func(0); \
\r
97 t=(pack&0x00000f00)>> 8; pix_func(1); \
\r
98 t=(pack&0x000000f0)>> 4; pix_func(2); \
\r
99 t=(pack&0x0000000f) ; pix_func(3); \
\r
100 t=(pack&0xf0000000)>>28; pix_func(4); \
\r
101 t=(pack&0x0f000000)>>24; pix_func(5); \
\r
102 t=(pack&0x00f00000)>>20; pix_func(6); \
\r
103 t=(pack&0x000f0000)>>16; pix_func(7); \
\r
107 return 1; /* Tile blank */ \
\r
111 #define TileFlipMaker(funcname,pix_func) \
\r
112 static int funcname(int sx,int addr,int pal) \
\r
114 unsigned char *pd = HighCol+sx; \
\r
115 unsigned int pack=0; unsigned int t=0; \
\r
117 pack=*(unsigned int *)(Pico.vram+addr); /* Get 8 pixels */ \
\r
120 t=(pack&0x000f0000)>>16; pix_func(0); \
\r
121 t=(pack&0x00f00000)>>20; pix_func(1); \
\r
122 t=(pack&0x0f000000)>>24; pix_func(2); \
\r
123 t=(pack&0xf0000000)>>28; pix_func(3); \
\r
124 t=(pack&0x0000000f) ; pix_func(4); \
\r
125 t=(pack&0x000000f0)>> 4; pix_func(5); \
\r
126 t=(pack&0x00000f00)>> 8; pix_func(6); \
\r
127 t=(pack&0x0000f000)>>12; pix_func(7); \
\r
131 return 1; /* Tile blank */ \
\r
135 #ifdef _ASM_DRAW_C_AMIPS
\r
136 int TileNorm(int sx,int addr,int pal);
\r
137 int TileFlip(int sx,int addr,int pal);
\r
140 #define pix_just_write(x) \
\r
143 TileNormMaker(TileNorm,pix_just_write)
\r
144 TileFlipMaker(TileFlip,pix_just_write)
\r
148 #ifndef _ASM_DRAW_C
\r
150 // draw a sprite pixel, process operator colors
\r
151 #define pix_sh(x) \
\r
153 else if (t==0xe) pd[x]=(pd[x]&0x3f)|0x80; /* hilight */ \
\r
154 else if (t==0xf) pd[x]= pd[x] |0xc0; /* shadow */ \
\r
157 TileNormMaker(TileNormSH, pix_sh)
\r
158 TileFlipMaker(TileFlipSH, pix_sh)
\r
160 // draw a sprite pixel ignoring operator colors
\r
161 #define pix_sh_noop(x) \
\r
162 if (t && t < 0xe) \
\r
165 TileNormMaker(TileNormSH_noop, pix_sh_noop)
\r
166 TileFlipMaker(TileFlipSH_noop, pix_sh_noop)
\r
168 // process operator pixels only, apply only on low pri tiles
\r
169 #define pix_sh_onlyop(x) \
\r
170 if (t==0xe && (pd[x]&0x40)) pd[x]=(pd[x]&0x3f)|0x80; /* hilight */ \
\r
171 else if (t==0xf && (pd[x]&0x40)) pd[x]= pd[x] |0xc0; /* shadow */
\r
173 TileNormMaker(TileNormSH_onlyop_lp, pix_sh_onlyop)
\r
174 TileFlipMaker(TileFlipSH_onlyop_lp, pix_sh_onlyop)
\r
178 // draw a sprite pixel (AS)
\r
179 #define pix_as(x) \
\r
180 if (t && !(pd[x]&0x80)) pd[x]=pal|t
\r
182 TileNormMaker(TileNormAS, pix_as)
\r
183 TileFlipMaker(TileFlipAS, pix_as)
\r
185 // draw a sprite pixel, skip operator colors (AS)
\r
186 #define pix_sh_as_noop(x) \
\r
187 if (t && t < 0xe && !(pd[x]&0x80)) pd[x]=pal|t
\r
189 TileNormMaker(TileNormAS_noop, pix_sh_as_noop)
\r
190 TileFlipMaker(TileFlipAS_noop, pix_sh_as_noop)
\r
192 // mark pixel as sprite pixel (AS)
\r
193 #define pix_sh_as_onlymark(x) \
\r
196 TileNormMaker(TileNormAS_onlymark, pix_sh_as_onlymark)
\r
197 TileFlipMaker(TileFlipAS_onlymark, pix_sh_as_onlymark)
\r
200 // --------------------------------------------
\r
202 #ifndef _ASM_DRAW_C
\r
203 static void DrawStrip(struct TileStrip *ts, int plane_sh, int cellskip)
\r
205 int tilex,dx,ty,code=0,addr=0,cells;
\r
206 int oldcode=-1,blank=-1; // The tile we know is blank
\r
209 // Draw tiles across screen:
\r
210 sh=(plane_sh<<5)&0x40;
\r
211 tilex=((-ts->hscroll)>>3)+cellskip;
\r
212 ty=(ts->line&7)<<1; // Y-Offset into tile
\r
213 dx=((ts->hscroll-1)&7)+1;
\r
214 cells = ts->cells - cellskip;
\r
215 if(dx != 8) cells++; // have hscroll, need to draw 1 cell more
\r
218 for (; cells > 0; dx+=8,tilex++,cells--)
\r
222 code=Pico.vram[ts->nametab+(tilex&ts->xmask)];
\r
223 if (code==blank) continue;
\r
224 if (code>>15) { // high priority tile
\r
225 int cval = code | (dx<<16) | (ty<<25);
\r
226 if(code&0x1000) cval^=7<<26;
\r
227 *ts->hc++ = cval; // cache it
\r
231 if (code!=oldcode) {
\r
233 // Get tile address/2:
\r
234 addr=(code&0x7ff)<<4;
\r
236 if (code&0x1000) addr^=0xe; // Y-flip
\r
238 pal=((code>>9)&0x30)|sh;
\r
241 if (code&0x0800) zero=TileFlip(dx,addr,pal);
\r
242 else zero=TileNorm(dx,addr,pal);
\r
244 if (zero) blank=code; // We know this tile is blank now
\r
247 // terminate the cache list
\r
249 // if oldcode wasn't changed, it means all layer is hi priority
\r
250 if (oldcode == -1) rendstatus |= PDRAW_PLANE_HI_PRIO;
\r
254 void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip)
\r
256 int tilex,dx,code=0,addr=0,cell=0;
\r
257 int oldcode=-1,blank=-1; // The tile we know is blank
\r
258 int pal=0,scan=DrawScanline;
\r
260 // Draw tiles across screen:
\r
261 tilex=(-ts->hscroll)>>3;
\r
262 dx=((ts->hscroll-1)&7)+1;
\r
263 if(dx != 8) cell--; // have hscroll, start with negative cell
\r
268 for (; cell < ts->cells; dx+=8,tilex++,cell++)
\r
270 int zero=0,nametabadd,ty;
\r
275 vscroll=Pico.vsram[(plane_sh&1)+(cell&~1)];
\r
277 // Find the line in the name table
\r
278 line=(vscroll+scan)&ts->line&0xffff; // ts->line is really ymask ..
\r
279 nametabadd=(line>>3)<<(ts->line>>24); // .. and shift[width]
\r
280 ty=(line&7)<<1; // Y-Offset into tile
\r
283 code=Pico.vram[ts->nametab+nametabadd+(tilex&ts->xmask)];
\r
284 if (code==blank) continue;
\r
285 if (code>>15) { // high priority tile
\r
286 int cval = code | (dx<<16) | (ty<<25);
\r
287 if(code&0x1000) cval^=7<<26;
\r
288 *ts->hc++ = cval; // cache it
\r
292 if (code!=oldcode) {
\r
294 // Get tile address/2:
\r
295 addr=(code&0x7ff)<<4;
\r
296 if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip
\r
298 pal=((code>>9)&0x30)|((plane_sh<<5)&0x40);
\r
301 if (code&0x0800) zero=TileFlip(dx,addr,pal);
\r
302 else zero=TileNorm(dx,addr,pal);
\r
304 if (zero) blank=code; // We know this tile is blank now
\r
307 // terminate the cache list
\r
309 if (oldcode == -1) rendstatus |= PDRAW_PLANE_HI_PRIO;
\r
313 #ifndef _ASM_DRAW_C
\r
316 void DrawStripInterlace(struct TileStrip *ts)
\r
318 int tilex=0,dx=0,ty=0,code=0,addr=0,cells;
\r
319 int oldcode=-1,blank=-1; // The tile we know is blank
\r
322 // Draw tiles across screen:
\r
323 tilex=(-ts->hscroll)>>3;
\r
324 ty=(ts->line&15)<<1; // Y-Offset into tile
\r
325 dx=((ts->hscroll-1)&7)+1;
\r
327 if(dx != 8) cells++; // have hscroll, need to draw 1 cell more
\r
329 for (; cells; dx+=8,tilex++,cells--)
\r
333 code=Pico.vram[ts->nametab+(tilex&ts->xmask)];
\r
334 if (code==blank) continue;
\r
335 if (code>>15) { // high priority tile
\r
336 int cval = (code&0xfc00) | (dx<<16) | (ty<<25);
\r
337 cval|=(code&0x3ff)<<1;
\r
338 if(code&0x1000) cval^=0xf<<26;
\r
339 *ts->hc++ = cval; // cache it
\r
343 if (code!=oldcode) {
\r
345 // Get tile address/2:
\r
346 addr=(code&0x7ff)<<5;
\r
347 if (code&0x1000) addr+=30-ty; else addr+=ty; // Y-flip
\r
349 // pal=Pico.cram+((code>>9)&0x30);
\r
350 pal=((code>>9)&0x30);
\r
353 if (code&0x0800) zero=TileFlip(dx,addr,pal);
\r
354 else zero=TileNorm(dx,addr,pal);
\r
356 if (zero) blank=code; // We know this tile is blank now
\r
359 // terminate the cache list
\r
363 // --------------------------------------------
\r
365 #ifndef _ASM_DRAW_C
\r
366 static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells)
\r
368 struct PicoVideo *pvid=&Pico.video;
\r
369 const char shift[4]={5,6,5,7}; // 32,64 or 128 sized tilemaps (2 is invalid)
\r
370 struct TileStrip ts;
\r
371 int width, height, ymask;
\r
377 // Work out the TileStrip to draw
\r
379 // Work out the name table size: 32 64 or 128 tiles (0-3)
\r
380 width=pvid->reg[16];
\r
381 height=(width>>4)&3; width&=3;
\r
383 ts.xmask=(1<<shift[width])-1; // X Mask in tiles (0x1f-0x7f)
\r
384 ymask=(height<<8)|0xff; // Y Mask in pixels
\r
385 if(width == 1) ymask&=0x1ff;
\r
386 else if(width>1) ymask =0x0ff;
\r
388 // Find name table:
\r
389 if (plane_sh&1) ts.nametab=(pvid->reg[4]&0x07)<<12; // B
\r
390 else ts.nametab=(pvid->reg[2]&0x38)<< 9; // A
\r
392 htab=pvid->reg[13]<<9; // Horizontal scroll table address
\r
393 if ( pvid->reg[11]&2) htab+=DrawScanline<<1; // Offset by line
\r
394 if ((pvid->reg[11]&1)==0) htab&=~0xf; // Offset by tile
\r
395 htab+=plane_sh&1; // A or B
\r
397 // Get horizontal scroll value, will be masked later
\r
398 ts.hscroll=Pico.vram[htab&0x7fff];
\r
400 if((pvid->reg[12]&6) == 6) {
\r
401 // interlace mode 2
\r
402 vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value
\r
404 // Find the line in the name table
\r
405 ts.line=(vscroll+(DrawScanline<<1))&((ymask<<1)|1);
\r
406 ts.nametab+=(ts.line>>4)<<shift[width];
\r
408 DrawStripInterlace(&ts);
\r
409 } else if( pvid->reg[11]&4) {
\r
410 // shit, we have 2-cell column based vscroll
\r
411 // luckily this doesn't happen too often
\r
412 ts.line=ymask|(shift[width]<<24); // save some stuff instead of line
\r
413 DrawStripVSRam(&ts, plane_sh, cellskip);
\r
415 vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value
\r
417 // Find the line in the name table
\r
418 ts.line=(vscroll+DrawScanline)&ymask;
\r
419 ts.nametab+=(ts.line>>3)<<shift[width];
\r
421 DrawStrip(&ts, plane_sh, cellskip);
\r
426 // --------------------------------------------
\r
428 // tstart & tend are tile pair numbers
\r
429 static void DrawWindow(int tstart, int tend, int prio, int sh) // int *hcache
\r
431 struct PicoVideo *pvid=&Pico.video;
\r
432 int tilex,ty,nametab,code=0;
\r
433 int blank=-1; // The tile we know is blank
\r
435 // Find name table line:
\r
436 if (pvid->reg[12]&1)
\r
438 nametab=(pvid->reg[3]&0x3c)<<9; // 40-cell mode
\r
439 nametab+=(DrawScanline>>3)<<6;
\r
443 nametab=(pvid->reg[3]&0x3e)<<9; // 32-cell mode
\r
444 nametab+=(DrawScanline>>3)<<5;
\r
449 if (!(rendstatus & PDRAW_WND_DIFF_PRIO)) {
\r
450 // check the first tile code
\r
451 code=Pico.vram[nametab+tilex];
\r
452 // if the whole window uses same priority (what is often the case), we may be able to skip this field
\r
453 if ((code>>15) != prio) return;
\r
457 ty=(DrawScanline&7)<<1; // Y-Offset into tile
\r
459 // Draw tiles across screen:
\r
462 for (; tilex < tend; tilex++)
\r
467 code=Pico.vram[nametab+tilex];
\r
468 if (code==blank) continue;
\r
469 if ((code>>15) != prio) {
\r
470 rendstatus |= PDRAW_WND_DIFF_PRIO;
\r
474 pal=((code>>9)&0x30);
\r
476 // Get tile address/2:
\r
477 addr=(code&0x7ff)<<4;
\r
478 if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip
\r
480 if (code&0x0800) zero=TileFlip(8+(tilex<<3),addr,pal);
\r
481 else zero=TileNorm(8+(tilex<<3),addr,pal);
\r
483 if (zero) blank=code; // We know this tile is blank now
\r
488 for (; tilex < tend; tilex++)
\r
493 code=Pico.vram[nametab+tilex];
\r
494 if(code==blank) continue;
\r
495 if((code>>15) != prio) {
\r
496 rendstatus |= PDRAW_WND_DIFF_PRIO;
\r
500 pal=((code>>9)&0x30);
\r
503 int *zb = (int *)(HighCol+8+(tilex<<3));
\r
504 *zb++ &= 0x3f3f3f3f;
\r
510 // Get tile address/2:
\r
511 addr=(code&0x7ff)<<4;
\r
512 if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip
\r
514 if (code&0x0800) zero=TileFlip(8+(tilex<<3),addr,pal);
\r
515 else zero=TileNorm(8+(tilex<<3),addr,pal);
\r
517 if (zero) blank=code; // We know this tile is blank now
\r
522 // --------------------------------------------
\r
524 static void DrawTilesFromCacheShPrep(void)
\r
526 // as some layer has covered whole line with hi priority tiles,
\r
527 // we can process whole line and then act as if sh/hi mode was off.
\r
528 int c = 320/4, *zb = (int *)(HighCol+8);
\r
529 rendstatus |= PDRAW_SHHI_DONE;
\r
532 *zb++ &= 0x3f3f3f3f;
\r
536 static void DrawTilesFromCache(int *hc, int sh, int rlim)
\r
538 int code, addr, dx;
\r
541 // *ts->hc++ = code | (dx<<16) | (ty<<25); // cache it
\r
543 if (sh && (rendstatus & (PDRAW_SHHI_DONE|PDRAW_PLANE_HI_PRIO)))
\r
545 if (!(rendstatus & PDRAW_SHHI_DONE))
\r
546 DrawTilesFromCacheShPrep();
\r
552 short blank=-1; // The tile we know is blank
\r
553 while ((code=*hc++)) {
\r
555 if((short)code == blank) continue;
\r
556 // Get tile address/2:
\r
557 addr=(code&0x7ff)<<4;
\r
558 addr+=(unsigned int)code>>25; // y offset into tile
\r
559 dx=(code>>16)&0x1ff;
\r
561 pal=((code>>9)&0x30);
\r
562 if (rlim-dx < 0) goto last_cut_tile;
\r
564 if (code&0x0800) zero=TileFlip(dx,addr,pal);
\r
565 else zero=TileNorm(dx,addr,pal);
\r
567 if (zero) blank=(short)code;
\r
572 while ((code=*hc++)) {
\r
574 // Get tile address/2:
\r
575 addr=(code&0x7ff)<<4;
\r
576 addr+=(unsigned int)code>>25; // y offset into tile
\r
577 dx=(code>>16)&0x1ff;
\r
579 *zb++ &= 0x3f; *zb++ &= 0x3f; *zb++ &= 0x3f; *zb++ &= 0x3f;
\r
580 *zb++ &= 0x3f; *zb++ &= 0x3f; *zb++ &= 0x3f; *zb++ &= 0x3f;
\r
582 pal=((code>>9)&0x30);
\r
583 if (rlim-dx < 0) goto last_cut_tile;
\r
585 if (code&0x0800) TileFlip(dx,addr,pal);
\r
586 else TileNorm(dx,addr,pal);
\r
593 unsigned int t, pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
\r
594 unsigned char *pd = HighCol+dx;
\r
600 case 7: t=pack&0x00000f00; if (t) pd[6]=(unsigned char)(pal|(t>> 8)); // "break" is left out intentionally
\r
601 case 6: t=pack&0x000000f0; if (t) pd[5]=(unsigned char)(pal|(t>> 4));
\r
602 case 5: t=pack&0x0000000f; if (t) pd[4]=(unsigned char)(pal|(t ));
\r
603 case 4: t=pack&0xf0000000; if (t) pd[3]=(unsigned char)(pal|(t>>28));
\r
604 case 3: t=pack&0x0f000000; if (t) pd[2]=(unsigned char)(pal|(t>>24));
\r
605 case 2: t=pack&0x00f00000; if (t) pd[1]=(unsigned char)(pal|(t>>20));
\r
606 case 1: t=pack&0x000f0000; if (t) pd[0]=(unsigned char)(pal|(t>>16));
\r
614 case 7: t=pack&0x00f00000; if (t) pd[6]=(unsigned char)(pal|(t>>20));
\r
615 case 6: t=pack&0x0f000000; if (t) pd[5]=(unsigned char)(pal|(t>>24));
\r
616 case 5: t=pack&0xf0000000; if (t) pd[4]=(unsigned char)(pal|(t>>28));
\r
617 case 4: t=pack&0x0000000f; if (t) pd[3]=(unsigned char)(pal|(t ));
\r
618 case 3: t=pack&0x000000f0; if (t) pd[2]=(unsigned char)(pal|(t>> 4));
\r
619 case 2: t=pack&0x00000f00; if (t) pd[1]=(unsigned char)(pal|(t>> 8));
\r
620 case 1: t=pack&0x0000f000; if (t) pd[0]=(unsigned char)(pal|(t>>12));
\r
627 // --------------------------------------------
\r
629 // Index + 0 : hhhhvvvv ab--hhvv yyyyyyyy yyyyyyyy // a: offscreen h, b: offs. v, h: horiz. size
\r
630 // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
\r
632 static void DrawSprite(int *sprite, int sh)
\r
634 int width=0,height=0;
\r
637 int tile=0,delta=0;
\r
639 int (*fTileFunc)(int sx,int addr,int pal);
\r
641 // parse the sprite data
\r
646 height=(sy>>24)&7; // Width and height in tiles
\r
647 sy=(sy<<16)>>16; // Y
\r
649 row=DrawScanline-sy; // Row of the sprite we are on
\r
651 if (code&0x1000) row=(height<<3)-1-row; // Flip Y
\r
653 tile=code + (row>>3); // Tile number increases going down
\r
654 delta=height; // Delta to increase tile by going right
\r
655 if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
\r
657 tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address
\r
658 delta<<=4; // Delta of address
\r
660 pal=(code>>9)&0x30;
\r
663 if (sh && (code&0x6000) == 0x6000) {
\r
664 if(code&0x0800) fTileFunc=TileFlipSH_noop;
\r
665 else fTileFunc=TileNormSH_noop;
\r
667 if(code&0x0800) fTileFunc=TileFlip;
\r
668 else fTileFunc=TileNorm;
\r
671 for (; width; width--,sx+=8,tile+=delta)
\r
673 if(sx<=0) continue;
\r
674 if(sx>=328) break; // Offscreen
\r
676 tile&=0x7fff; // Clip tile address
\r
677 fTileFunc(sx,tile,pal);
\r
682 static void DrawSpriteInterlace(unsigned int *sprite)
\r
684 int width=0,height=0;
\r
687 int tile=0,delta=0;
\r
690 // parse the sprite data
\r
693 sy=(sy&0x3ff)-0x100; // Y
\r
694 width=(height>>2)&3; height&=3;
\r
695 width++; height++; // Width and height in tiles
\r
697 row=(DrawScanline<<1)-sy; // Row of the sprite we are on
\r
700 sx=((code>>16)&0x1ff)-0x78; // X
\r
702 if (code&0x1000) row^=(16<<height)-1; // Flip Y
\r
704 tile=code&0x3ff; // Tile number
\r
705 tile+=row>>4; // Tile number increases going down
\r
706 delta=height; // Delta to increase tile by going right
\r
707 if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
\r
709 tile<<=5; tile+=(row&15)<<1; // Tile address
\r
711 delta<<=5; // Delta of address
\r
712 pal=((code>>9)&0x30); // Get palette pointer
\r
714 for (; width; width--,sx+=8,tile+=delta)
\r
716 if(sx<=0) continue;
\r
717 if(sx>=328) break; // Offscreen
\r
719 tile&=0x7fff; // Clip tile address
\r
720 if (code&0x0800) TileFlip(sx,tile,pal);
\r
721 else TileNorm(sx,tile,pal);
\r
726 static void DrawAllSpritesInterlace(int pri, int sh)
\r
728 struct PicoVideo *pvid=&Pico.video;
\r
729 int i,u,table,link=0,sline=DrawScanline<<1;
\r
730 unsigned int *sprites[80]; // Sprite index
\r
732 table=pvid->reg[5]&0x7f;
\r
733 if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode
\r
734 table<<=8; // Get sprite table address/2
\r
736 for (i=u=0; u < 80 && i < 21; u++)
\r
738 unsigned int *sprite;
\r
739 int code, sx, sy, height;
\r
741 sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite
\r
746 if(((sx>>15)&1) != pri) goto nextsprite; // wrong priority sprite
\r
748 // check if it is on this line
\r
749 sy = (code&0x3ff)-0x100;
\r
750 height = (((code>>24)&3)+1)<<4;
\r
751 if(sline < sy || sline >= sy+height) goto nextsprite; // no
\r
753 // check if sprite is not hidden offscreen
\r
754 sx = (sx>>16)&0x1ff;
\r
755 sx -= 0x78; // Get X coordinate + 8
\r
756 if(sx <= -8*3 || sx >= 328) goto nextsprite;
\r
758 // sprite is good, save it's pointer
\r
759 sprites[i++]=sprite;
\r
762 // Find next sprite
\r
763 link=(code>>16)&0x7f;
\r
764 if(!link) break; // End of sprites
\r
767 // Go through sprites backwards:
\r
768 for (i-- ;i>=0; i--)
\r
769 DrawSpriteInterlace(sprites[i]);
\r
773 #ifndef _ASM_DRAW_C
\r
774 // Index + 0 : hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: vert./horiz. size
\r
775 // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
\r
776 static void DrawSpritesSHi(unsigned char *sprited)
\r
778 int (*fTileFunc)(int sx,int addr,int pal);
\r
782 cnt = sprited[0] & 0x7f;
\r
783 if (cnt == 0) return;
\r
787 // Go through sprites backwards:
\r
788 for (cnt--; cnt >= 0; cnt--)
\r
790 int *sprite, code, pal, tile, sx, sy;
\r
791 int offs, delta, width, height, row;
\r
793 offs = (p[cnt] & 0x7f) * 2;
\r
794 sprite = HighPreSpr + offs;
\r
796 pal = (code>>9)&0x30;
\r
800 if (code & 0x8000) // hi priority
\r
802 if (code&0x800) fTileFunc=TileFlipSH;
\r
803 else fTileFunc=TileNormSH;
\r
805 if (code&0x800) fTileFunc=TileFlipSH_onlyop_lp;
\r
806 else fTileFunc=TileNormSH_onlyop_lp;
\r
809 if (!(code & 0x8000)) continue; // non-operator low sprite, already drawn
\r
810 if (code&0x800) fTileFunc=TileFlip;
\r
811 else fTileFunc=TileNorm;
\r
814 // parse remaining sprite data
\r
818 height=(sy>>24)&7; // Width and height in tiles
\r
819 sy=(sy<<16)>>16; // Y
\r
821 row=DrawScanline-sy; // Row of the sprite we are on
\r
823 if (code&0x1000) row=(height<<3)-1-row; // Flip Y
\r
825 tile=code + (row>>3); // Tile number increases going down
\r
826 delta=height; // Delta to increase tile by going right
\r
827 if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
\r
829 tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address
\r
830 delta<<=4; // Delta of address
\r
832 for (; width; width--,sx+=8,tile+=delta)
\r
834 if(sx<=0) continue;
\r
835 if(sx>=328) break; // Offscreen
\r
837 tile&=0x7fff; // Clip tile address
\r
838 fTileFunc(sx,tile,pal);
\r
844 static void DrawSpritesHiAS(unsigned char *sprited, int sh)
\r
846 int (*fTileFunc)(int sx,int addr,int pal);
\r
848 int entry, cnt, sh_cnt = 0;
\r
850 cnt = sprited[0] & 0x7f;
\r
851 if (cnt == 0) return;
\r
855 // Go through sprites:
\r
856 for (entry = 0; entry < cnt; entry++)
\r
858 int *sprite, code, pal, tile, sx, sy;
\r
859 int offs, delta, width, height, row;
\r
861 offs = (p[entry] & 0x7f) * 2;
\r
862 sprite = HighPreSpr + offs;
\r
864 pal = (code>>9)&0x30;
\r
866 if (code & 0x8000) // hi priority
\r
868 if (sh && pal == 0x30)
\r
870 if (code&0x800) fTileFunc=TileFlipAS_noop;
\r
871 else fTileFunc=TileNormAS_noop;
\r
873 if (code&0x800) fTileFunc=TileFlipAS;
\r
874 else fTileFunc=TileNormAS;
\r
877 if (code&0x800) fTileFunc=TileFlipAS_onlymark;
\r
878 else fTileFunc=TileNormAS_onlymark;
\r
880 if (sh && pal == 0x30)
\r
881 p[sh_cnt++] = offs / 2; // re-save for sh/hi pass
\r
883 // parse remaining sprite data
\r
887 height=(sy>>24)&7; // Width and height in tiles
\r
888 sy=(sy<<16)>>16; // Y
\r
890 row=DrawScanline-sy; // Row of the sprite we are on
\r
892 if (code&0x1000) row=(height<<3)-1-row; // Flip Y
\r
894 tile=code + (row>>3); // Tile number increases going down
\r
895 delta=height; // Delta to increase tile by going right
\r
896 if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
\r
898 tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address
\r
899 delta<<=4; // Delta of address
\r
902 for (; width; width--,sx+=8,tile+=delta)
\r
904 if(sx<=0) continue;
\r
905 if(sx>=328) break; // Offscreen
\r
907 tile&=0x7fff; // Clip tile address
\r
908 fTileFunc(sx,tile,pal);
\r
912 if (!sh || !(sprited[1]&SPRL_MAY_HAVE_OP)) return;
\r
914 /* nasty 1: remove 'sprite' flags */
\r
916 int c = 320/4, *zb = (int *)(HighCol+8);
\r
919 *zb++ &= 0x7f7f7f7f;
\r
923 /* nasty 2: sh operator pass */
\r
924 sprited[0] = sh_cnt;
\r
925 DrawSpritesSHi(sprited);
\r
929 // Index + 0 : ----hhvv -lllllll -------y yyyyyyyy
\r
930 // Index + 4 : -------x xxxxxxxx pccvhnnn nnnnnnnn
\r
932 // Index + 0 : hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: vert./horiz. size
\r
933 // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
\r
935 void PrepareSprites(int full)
\r
937 struct PicoVideo *pvid=&Pico.video;
\r
940 int *pd = HighPreSpr;
\r
941 int max_lines = 224, max_sprites = 80, max_width = 328;
\r
942 int max_line_sprites = 20; // 20 sprites, 40 tiles
\r
944 if (!(Pico.video.reg[12]&1))
\r
945 max_sprites = 64, max_line_sprites = 16, max_width = 264;
\r
946 if (PicoOpt & POPT_DIS_SPRITE_LIM)
\r
947 max_line_sprites = MAX_LINE_SPRITES;
\r
949 if (pvid->reg[1]&8) max_lines = 240;
\r
950 sh = Pico.video.reg[0xC]&8; // shadow/hilight?
\r
952 table=pvid->reg[5]&0x7f;
\r
953 if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode
\r
954 table<<=8; // Get sprite table address/2
\r
959 // updates: tilecode, sx
\r
960 for (u=0; u < max_sprites && (pack = *pd); u++, pd+=2)
\r
962 unsigned int *sprite;
\r
963 int code2, sx, sy, height;
\r
965 sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite
\r
967 // parse sprite info
\r
969 sx = (code2>>16)&0x1ff;
\r
970 sx -= 0x78; // Get X coordinate + 8
\r
971 sy = (pack << 16) >> 16;
\r
972 height = (pack >> 24) & 0xf;
\r
974 if (sy < max_lines && sy + (height<<3) > DrawScanline && // sprite onscreen (y)?
\r
975 (sx > -24 || sx < max_width)) // onscreen x
\r
977 int y = (sy >= DrawScanline) ? sy : DrawScanline;
\r
978 int entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80);
\r
979 for (; y < sy + (height<<3) && y < max_lines; y++)
\r
982 cnt = HighLnSpr[y][0] & 0x7f;
\r
983 if (cnt >= max_line_sprites) continue; // sprite limit?
\r
985 for (i = 0; i < cnt; i++)
\r
986 if (((HighLnSpr[y][3+i] ^ entry) & 0x7f) == 0) goto found;
\r
988 // this sprite was previously missing
\r
989 HighLnSpr[y][3+cnt] = entry;
\r
990 HighLnSpr[y][0] = cnt + 1;
\r
993 HighLnSpr[y][1] |= SPRL_HAVE_HI;
\r
994 else HighLnSpr[y][1] |= SPRL_HAVE_LO;
\r
998 code2 &= ~0xfe000000;
\r
999 code2 -= 0x00780000; // Get X coordinate + 8 in upper 16 bits
\r
1002 // Find next sprite
\r
1003 link=(sprite[0]>>16)&0x7f;
\r
1004 if (!link) break; // End of sprites
\r
1009 for (u = 0; u < max_lines; u++)
\r
1010 *((int *)&HighLnSpr[u][0]) = 0;
\r
1012 for (u = 0; u < max_sprites; u++)
\r
1014 unsigned int *sprite;
\r
1015 int code, code2, sx, sy, hv, height, width;
\r
1017 sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite
\r
1019 // parse sprite info
\r
1021 sy = (code&0x1ff)-0x80;
\r
1022 hv = (code>>24)&0xf;
\r
1023 height = (hv&3)+1;
\r
1025 width = (hv>>2)+1;
\r
1026 code2 = sprite[1];
\r
1027 sx = (code2>>16)&0x1ff;
\r
1028 sx -= 0x78; // Get X coordinate + 8
\r
1030 if (sy < max_lines && sy + (height<<3) > DrawScanline) // sprite onscreen (y)?
\r
1032 int entry, y, sx_min, onscr_x, maybe_op = 0;
\r
1034 sx_min = 8-(width<<3);
\r
1035 onscr_x = sx_min < sx && sx < max_width;
\r
1036 if (sh && (code2 & 0x6000) == 0x6000)
\r
1037 maybe_op = SPRL_MAY_HAVE_OP;
\r
1039 entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80);
\r
1040 y = (sy >= DrawScanline) ? sy : DrawScanline;
\r
1041 for (; y < sy + (height<<3) && y < max_lines; y++)
\r
1043 unsigned char *p = &HighLnSpr[y][0];
\r
1045 if (cnt >= max_line_sprites) continue; // sprite limit?
\r
1047 if (p[2] >= max_line_sprites*2) { // tile limit?
\r
1053 if (sx == -0x78) {
\r
1055 p[0] |= 0x80; // masked, no more sprites for this line
\r
1058 // must keep the first sprite even if it's offscreen, for masking
\r
1059 if (cnt > 0 && !onscr_x) continue; // offscreen x
\r
1063 p[1] |= (entry & 0x80) ? SPRL_HAVE_HI : SPRL_HAVE_LO;
\r
1064 p[1] |= maybe_op; // there might be op sprites on this line
\r
1065 if (cnt > 0 && (code2 & 0x8000) && !(p[3+cnt-1]&0x80))
\r
1066 p[1] |= SPRL_LO_ABOVE_HI;
\r
1070 *pd++ = (width<<28)|(height<<24)|(hv<<16)|((unsigned short)sy);
\r
1071 *pd++ = (sx<<16)|((unsigned short)code2);
\r
1073 // Find next sprite
\r
1074 link=(code>>16)&0x7f;
\r
1075 if (!link) break; // End of sprites
\r
1080 for (u = 0; u < max_lines; u++)
\r
1083 printf("c%03i: %2i, %2i: ", u, HighLnSpr[u][0] & 0x7f, HighLnSpr[u][2]);
\r
1084 for (y = 0; y < HighLnSpr[u][0] & 0x7f; y++)
\r
1085 printf(" %i", HighLnSpr[u][y+3]);
\r
1092 #ifndef _ASM_DRAW_C
\r
1093 static void DrawAllSprites(unsigned char *sprited, int prio, int sh)
\r
1095 int rs = rendstatus;
\r
1099 if (rs & (PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES)) {
\r
1100 //elprintf(EL_STATUS, "PrepareSprites(%i)", (rs>>4)&1);
\r
1101 PrepareSprites(rs & PDRAW_DIRTY_SPRITES);
\r
1102 rendstatus = rs & ~(PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES);
\r
1105 cnt = sprited[0] & 0x7f;
\r
1106 if (cnt == 0) return;
\r
1110 // Go through sprites backwards:
\r
1111 for (cnt--; cnt >= 0; cnt--)
\r
1114 if ((p[cnt] >> 7) != prio) continue;
\r
1115 offs = (p[cnt]&0x7f) * 2;
\r
1116 DrawSprite(HighPreSpr + offs, sh);
\r
1121 // --------------------------------------------
\r
1123 static void BackFill(int reg7, int sh)
\r
1125 unsigned int back;
\r
1127 // Start with a blank scanline (background colour):
\r
1133 memset32((int *)(HighCol+8), back, 320/4);
\r
1137 // --------------------------------------------
\r
1139 unsigned short HighPal[0x100];
\r
1141 #ifndef _ASM_DRAW_C
\r
1142 static void FinalizeLineBGR444(int sh)
\r
1144 unsigned short *pd=DrawLineDest;
\r
1145 unsigned char *ps=HighCol+8;
\r
1146 unsigned short *pal=Pico.cram;
\r
1147 int len, i, t, mask=0xff;
\r
1149 if (Pico.video.reg[12]&1) {
\r
1152 if(!(PicoOpt&POPT_DIS_32C_BORDER)) pd+=32;
\r
1158 if(Pico.m.dirtyPal) {
\r
1159 blockcpy(pal, Pico.cram, 0x40*2);
\r
1160 // shadowed pixels
\r
1161 for(i = 0x3f; i >= 0; i--)
\r
1162 pal[0x40|i] = pal[0xc0|i] = (unsigned short)((pal[i]>>1)&0x0777);
\r
1163 // hilighted pixels
\r
1164 for(i = 0x3f; i >= 0; i--) {
\r
1165 t=pal[i]&0xeee;t+=0x444;if(t&0x10)t|=0xe;if(t&0x100)t|=0xe0;if(t&0x1000)t|=0xe00;t&=0xeee;
\r
1166 pal[0x80|i]=(unsigned short)t;
\r
1168 Pico.m.dirtyPal = 0;
\r
1172 if (!sh && (rendstatus & PDRAW_ACC_SPRITES))
\r
1173 mask=0x3f; // accurate sprites
\r
1175 for(i = 0; i < len; i++)
\r
1176 pd[i] = pal[ps[i] & mask];
\r
1180 static void FinalizeLineRGB555(int sh)
\r
1182 unsigned short *pd=DrawLineDest;
\r
1183 unsigned char *ps=HighCol+8;
\r
1184 unsigned short *pal=HighPal;
\r
1185 int len, i, t, dirtyPal = Pico.m.dirtyPal;
\r
1189 unsigned int *spal=(void *)Pico.cram;
\r
1190 unsigned int *dpal=(void *)HighPal;
\r
1191 for (i = 0x3f/2; i >= 0; i--)
\r
1193 dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);
\r
1195 dpal[i] = ((spal[i]&0x000f000f)<<12)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)>>7);
\r
1197 Pico.m.dirtyPal = 0;
\r
1203 // shadowed pixels
\r
1204 for (i = 0x3f; i >= 0; i--)
\r
1205 pal[0x40|i] = pal[0xc0|i] = (unsigned short)((pal[i]>>1)&0x738e);
\r
1206 // hilighted pixels
\r
1207 for (i = 0x3f; i >= 0; i--) {
\r
1208 t=pal[i]&0xe71c;t+=0x4208;if(t&0x20)t|=0x1c;if(t&0x800)t|=0x700;if(t&0x10000)t|=0xe000;t&=0xe71c;
\r
1209 pal[0x80|i]=(unsigned short)t;
\r
1214 if (Pico.video.reg[12]&1) {
\r
1217 if (!(PicoOpt&POPT_DIS_32C_BORDER)) pd+=32;
\r
1224 if (!sh && (rendstatus & PDRAW_ACC_SPRITES))
\r
1225 mask=0x3f; // accurate sprites, upper bits are priority stuff
\r
1227 for (i = 0; i < len; i++)
\r
1228 pd[i] = pal[ps[i] & mask];
\r
1230 extern void amips_clut(unsigned short *dst, unsigned char *src, unsigned short *pal, int count);
\r
1231 extern void amips_clut_6bit(unsigned short *dst, unsigned char *src, unsigned short *pal, int count);
\r
1232 if (!sh && (rendstatus & PDRAW_ACC_SPRITES))
\r
1233 amips_clut_6bit(pd, ps, pal, len);
\r
1234 else amips_clut(pd, ps, pal, len);
\r
1240 static void FinalizeLine8bit(int sh)
\r
1242 unsigned char *pd=DrawLineDest;
\r
1243 int len, rs = rendstatus;
\r
1244 static int dirty_count;
\r
1246 if (!sh && !(rs & PDRAW_ACC_SPRITES) && Pico.m.dirtyPal == 1 && DrawScanline < 222)
\r
1248 // a hack for mid-frame palette changes
\r
1249 if (!(rs & PDRAW_SONIC_MODE))
\r
1251 else dirty_count++;
\r
1252 rs |= PDRAW_SONIC_MODE;
\r
1254 if (dirty_count == 3) {
\r
1255 blockcpy(HighPal, Pico.cram, 0x40*2);
\r
1256 } else if (dirty_count == 11) {
\r
1257 blockcpy(HighPal+0x40, Pico.cram, 0x40*2);
\r
1261 if (Pico.video.reg[12]&1) {
\r
1264 if (!(PicoOpt&POPT_DIS_32C_BORDER)) pd+=32;
\r
1268 if (!sh && (rs & PDRAW_SONIC_MODE)) {
\r
1269 if (dirty_count >= 11) {
\r
1270 blockcpy_or(pd, HighCol+8, len, 0x80);
\r
1272 blockcpy_or(pd, HighCol+8, len, 0x40);
\r
1275 blockcpy(pd, HighCol+8, len);
\r
1279 static void (*FinalizeLine)(int sh) = FinalizeLineBGR444;
\r
1281 // --------------------------------------------
\r
1283 static void DrawBlankedLine(void)
\r
1285 int sh=(Pico.video.reg[0xC]&8)>>3; // shadow/hilight?
\r
1287 if (PicoScanBegin != NULL)
\r
1288 PicoScanBegin(DrawScanline);
\r
1290 BackFill(Pico.video.reg[7], sh);
\r
1292 if (FinalizeLine != NULL)
\r
1295 if (PicoScanEnd != NULL)
\r
1296 PicoScanEnd(DrawScanline);
\r
1299 static int DrawDisplay(int sh)
\r
1301 unsigned char *sprited = &HighLnSpr[DrawScanline][0];
\r
1302 struct PicoVideo *pvid=&Pico.video;
\r
1303 int win=0,edge=0,hvwind=0;
\r
1304 int maxw,maxcells;
\r
1306 rendstatus &= ~(PDRAW_SHHI_DONE|PDRAW_PLANE_HI_PRIO);
\r
1308 if (pvid->reg[12]&1) {
\r
1309 maxw = 328; maxcells = 40;
\r
1311 maxw = 264; maxcells = 32;
\r
1314 // Find out if the window is on this line:
\r
1315 win=pvid->reg[0x12];
\r
1316 edge=(win&0x1f)<<3;
\r
1318 if (win&0x80) { if (DrawScanline>=edge) hvwind=1; }
\r
1319 else { if (DrawScanline< edge) hvwind=1; }
\r
1321 if (!hvwind) // we might have a vertical window here
\r
1323 win=pvid->reg[0x11];
\r
1326 if (!edge) hvwind=1;
\r
1327 else if(edge < (maxcells>>1)) hvwind=2;
\r
1330 else if(edge < (maxcells>>1)) hvwind=2;
\r
1335 /* - layer B low - */
\r
1336 if (PicoDrawMask & PDRAW_LAYERB_ON)
\r
1337 DrawLayer(1|(sh<<1), HighCacheB, 0, maxcells);
\r
1338 /* - layer A low - */
\r
1339 if (!(PicoDrawMask & PDRAW_LAYERA_ON));
\r
1340 else if (hvwind == 1)
\r
1341 DrawWindow(0, maxcells>>1, 0, sh);
\r
1342 else if (hvwind == 2) {
\r
1343 DrawLayer(0|(sh<<1), HighCacheA, (win&0x80) ? 0 : edge<<1, (win&0x80) ? edge<<1 : maxcells);
\r
1344 DrawWindow( (win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 0, sh);
\r
1346 DrawLayer(0|(sh<<1), HighCacheA, 0, maxcells);
\r
1347 /* - sprites low - */
\r
1348 if (!(PicoDrawMask & PDRAW_SPRITES_LOW_ON));
\r
1349 else if (rendstatus & PDRAW_INTERLACE)
\r
1350 DrawAllSpritesInterlace(0, sh);
\r
1351 else if (sprited[1] & SPRL_HAVE_LO)
\r
1352 DrawAllSprites(sprited, 0, sh);
\r
1354 /* - layer B hi - */
\r
1355 if ((PicoDrawMask & PDRAW_LAYERB_ON) && HighCacheB[0])
\r
1356 DrawTilesFromCache(HighCacheB, sh, maxw);
\r
1357 /* - layer A hi - */
\r
1358 if (!(PicoDrawMask & PDRAW_LAYERA_ON));
\r
1359 else if (hvwind == 1)
\r
1360 DrawWindow(0, maxcells>>1, 1, sh);
\r
1361 else if (hvwind == 2) {
\r
1362 if (HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, (win&0x80) ? edge<<4 : maxw);
\r
1363 DrawWindow((win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 1, sh);
\r
1365 if (HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, maxw);
\r
1366 /* - sprites hi - */
\r
1367 if (!(PicoDrawMask & PDRAW_SPRITES_HI_ON));
\r
1368 else if (rendstatus & PDRAW_INTERLACE)
\r
1369 DrawAllSpritesInterlace(1, sh);
\r
1370 // AS on and have both lo/hi sprites and lo before hi sprites?
\r
1371 else if ((sprited[1] & 0xd0) == 0xd0 && (rendstatus & PDRAW_ACC_SPRITES))
\r
1372 DrawSpritesHiAS(sprited, sh);
\r
1373 else if (sh && (sprited[1] & SPRL_MAY_HAVE_OP))
\r
1374 DrawSpritesSHi(sprited);
\r
1375 else if (sprited[1] & SPRL_HAVE_HI)
\r
1376 DrawAllSprites(sprited, 1, 0);
\r
1381 for (a = 0, c = HighCacheA; *c; c++, a++);
\r
1382 for (b = 0, c = HighCacheB; *c; c++, b++);
\r
1383 printf("%i:%03i: a=%i, b=%i\n", Pico.m.frame_count, DrawScanline, a, b);
\r
1391 PICO_INTERNAL void PicoFrameStart(void)
\r
1393 // prepare to do this frame
\r
1395 if (PicoOpt & POPT_ACC_SPRITES)
\r
1396 rendstatus |= PDRAW_ACC_SPRITES;
\r
1397 if ((Pico.video.reg[12]&6) == 6)
\r
1398 rendstatus |= PDRAW_INTERLACE; // interlace mode
\r
1400 if (Pico.m.dirtyPal) Pico.m.dirtyPal = 2; // reset dirty if needed
\r
1403 PrepareSprites(1);
\r
1407 static void PicoLine(void)
\r
1410 if (skip_next_line>0) { skip_next_line--; return; } // skip rendering lines
\r
1412 sh=(Pico.video.reg[0xC]&8)>>3; // shadow/hilight?
\r
1414 if (PicoScanBegin != NULL)
\r
1415 skip_next_line = PicoScanBegin(DrawScanline);
\r
1418 BackFill(Pico.video.reg[7], sh);
\r
1419 if (Pico.video.reg[1]&0x40)
\r
1422 if (FinalizeLine != NULL)
\r
1425 if (PicoScanEnd != NULL)
\r
1426 PicoScanEnd(DrawScanline);
\r
1429 void PicoDrawSync(int to, int blank_last_line)
\r
1431 for (; DrawScanline < to; DrawScanline++)
\r
1433 #if !CAN_HANDLE_240_LINES
\r
1434 if (DrawScanline >= 224) break;
\r
1439 #if !CAN_HANDLE_240_LINES
\r
1440 if (DrawScanline >= 224) DrawScanline = 240, return;
\r
1444 if (DrawScanline <= to)
\r
1446 if (blank_last_line)
\r
1447 DrawBlankedLine();
\r
1453 void PicoDrawSetColorFormat(int which)
\r
1457 case 2: FinalizeLine = FinalizeLine8bit; break;
\r
1458 case 1: FinalizeLine = FinalizeLineRGB555; break;
\r
1459 case 0: FinalizeLine = FinalizeLineBGR444; break;
\r
1460 default:FinalizeLine = NULL; break;
\r
1462 #if OVERRIDE_HIGHCOL
\r
1463 if (which) HighCol=DefHighCol;
\r