3 * (c) Copyright Dave, 2004
\r
4 * (C) notaz, 2006-2010
\r
6 * This work is licensed under the terms of MAME license.
\r
7 * See COPYING file in the top-level directory.
\r
10 * The renderer has 4 modes now:
\r
12 * - shadow/hilight (s/h)
\r
13 * - "sonic mode" for midline palette changes (8bit mode only)
\r
14 * - accurate sprites (AS) [+ s/h]
\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
20 * since renderer always draws line in 8bit mode, there are 2 spare bits:
\r
21 * b \ mode: s/h as sonic
\r
22 * 00 normal - pal index
\r
23 * 01 shadow - pal index
\r
24 * 10 hilight+op spr spr pal index
\r
25 * 11 shadow +op spr - pal index
\r
27 * not handled properly:
\r
28 * - hilight op on shadow tile
\r
29 * - AS + s/h (s/h sprite flag interferes with and cleared by AS code)
\r
32 #include "pico_int.h"
\r
34 int (*PicoScanBegin)(unsigned int num) = NULL;
\r
35 int (*PicoScanEnd) (unsigned int num) = NULL;
\r
37 static unsigned char DefHighCol[8+320+8];
\r
38 static unsigned char *HighColBase = DefHighCol;
\r
39 static int HighColIncrement;
\r
41 static unsigned int DefOutBuff[320*2/2];
\r
42 void *DrawLineDestBase = DefOutBuff;
\r
43 int DrawLineDestIncrement;
\r
45 static int HighCacheA[41+1]; // caches for high layers
\r
46 static int HighCacheB[41+1];
\r
47 static int HighPreSpr[80*2+1]; // slightly preprocessed sprites
\r
49 #define LF_PLANE_1 (1 << 0)
\r
50 #define LF_SH (1 << 1) // must be = 2
\r
51 #define LF_FORCE (1 << 2)
\r
53 #define SPRL_HAVE_HI 0x80 // have hi priority sprites
\r
54 #define SPRL_HAVE_LO 0x40 // *lo*
\r
55 #define SPRL_MAY_HAVE_OP 0x20 // may have operator sprites on the line
\r
56 #define SPRL_LO_ABOVE_HI 0x10 // low priority sprites may be on top of hi
\r
57 unsigned char HighLnSpr[240][3 + MAX_LINE_SPRITES]; // sprite_count, ^flags, tile_count, [spritep]...
\r
62 static int skip_next_line=0;
\r
66 int nametab; // Position in VRAM of name table (for this tile line)
\r
67 int line; // Line number in pixels 0x000-0x3ff within the virtual tilemap
\r
68 int hscroll; // Horizontal scroll value in pixels for the line
\r
69 int xmask; // X-Mask (0x1f - 0x7f) for horizontal wraparound in the tilemap
\r
70 int *hc; // cache for high tile codes and their positions
\r
71 int cells; // cells (tiles) to draw (32 col mode doesn't need to update whole 320)
\r
74 // stuff available in asm:
\r
76 void DrawWindow(int tstart, int tend, int prio, int sh,
\r
77 struct PicoEState *est);
\r
78 void DrawAllSprites(unsigned char *sprited, int prio, int sh,
\r
79 struct PicoEState *est);
\r
80 void DrawTilesFromCache(int *hc, int sh, int rlim,
\r
81 struct PicoEState *est);
\r
82 void DrawSpritesSHi(unsigned char *sprited, struct PicoEState *est);
\r
83 void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells,
\r
84 struct PicoEState *est);
\r
85 void *blockcpy(void *dst, const void *src, size_t n);
\r
86 void blockcpy_or(void *dst, void *src, size_t n, int pat);
\r
89 void blockcpy_or(void *dst, void *src, size_t n, int pat)
\r
91 unsigned char *pd = dst, *ps = src;
\r
93 *pd++ = (unsigned char) (*ps++ | pat);
\r
95 #define blockcpy memcpy
\r
99 #define TileNormMaker(funcname,pix_func) \
\r
100 static void funcname(int sx, unsigned int pack, int pal) \
\r
102 unsigned char *pd = Pico.est.HighCol + sx; \
\r
105 t = (pack&0x0000f000)>>12; pix_func(0); \
\r
106 t = (pack&0x00000f00)>> 8; pix_func(1); \
\r
107 t = (pack&0x000000f0)>> 4; pix_func(2); \
\r
108 t = (pack&0x0000000f) ; pix_func(3); \
\r
109 t = (pack&0xf0000000)>>28; pix_func(4); \
\r
110 t = (pack&0x0f000000)>>24; pix_func(5); \
\r
111 t = (pack&0x00f00000)>>20; pix_func(6); \
\r
112 t = (pack&0x000f0000)>>16; pix_func(7); \
\r
115 #define TileFlipMaker(funcname,pix_func) \
\r
116 static void funcname(int sx, unsigned int pack, int pal) \
\r
118 unsigned char *pd = Pico.est.HighCol + sx; \
\r
121 t = (pack&0x000f0000)>>16; pix_func(0); \
\r
122 t = (pack&0x00f00000)>>20; pix_func(1); \
\r
123 t = (pack&0x0f000000)>>24; pix_func(2); \
\r
124 t = (pack&0xf0000000)>>28; pix_func(3); \
\r
125 t = (pack&0x0000000f) ; pix_func(4); \
\r
126 t = (pack&0x000000f0)>> 4; pix_func(5); \
\r
127 t = (pack&0x00000f00)>> 8; pix_func(6); \
\r
128 t = (pack&0x0000f000)>>12; pix_func(7); \
\r
132 #ifdef _ASM_DRAW_C_AMIPS
\r
133 int TileNorm(int sx, unsigned int pack, int pal);
\r
134 int TileFlip(int sx, unsigned int pack, int pal);
\r
137 #define pix_just_write(x) \
\r
140 TileNormMaker(TileNorm,pix_just_write)
\r
141 TileFlipMaker(TileFlip,pix_just_write)
\r
145 #ifndef _ASM_DRAW_C
\r
147 // draw a sprite pixel, process operator colors
\r
148 #define pix_sh(x) \
\r
150 else if (t>=0xe) pd[x]=(pd[x]&0x3f)|(t<<6); /* c0 shadow, 80 hilight */ \
\r
153 TileNormMaker(TileNormSH, pix_sh)
\r
154 TileFlipMaker(TileFlipSH, pix_sh)
\r
156 // draw a sprite pixel, mark operator colors
\r
157 #define pix_sh_markop(x) \
\r
159 else if (t>=0xe) pd[x]|=0x80; \
\r
162 TileNormMaker(TileNormSH_markop, pix_sh_markop)
\r
163 TileFlipMaker(TileFlipSH_markop, pix_sh_markop)
\r
165 // process operator pixels only, apply only on low pri tiles and other op pixels
\r
166 #define pix_sh_onlyop(x) \
\r
167 if (t>=0xe && (pd[x]&0xc0)) \
\r
168 pd[x]=(pd[x]&0x3f)|(t<<6); /* c0 shadow, 80 hilight */ \
\r
170 TileNormMaker(TileNormSH_onlyop_lp, pix_sh_onlyop)
\r
171 TileFlipMaker(TileFlipSH_onlyop_lp, pix_sh_onlyop)
\r
175 // draw a sprite pixel (AS)
\r
176 #define pix_as(x) \
\r
177 if (t && !(pd[x]&0x80)) pd[x]=pal|t
\r
179 TileNormMaker(TileNormAS, pix_as)
\r
180 TileFlipMaker(TileFlipAS, pix_as)
\r
182 // draw a sprite pixel, skip operator colors (AS)
\r
183 #define pix_sh_as_noop(x) \
\r
184 if (t && t < 0xe && !(pd[x]&0x80)) pd[x]=pal|t
\r
186 TileNormMaker(TileNormAS_noop, pix_sh_as_noop)
\r
187 TileFlipMaker(TileFlipAS_noop, pix_sh_as_noop)
\r
189 // mark pixel as sprite pixel (AS)
\r
190 #define pix_sh_as_onlymark(x) \
\r
193 TileNormMaker(TileNormAS_onlymark, pix_sh_as_onlymark)
\r
194 TileFlipMaker(TileFlipAS_onlymark, pix_sh_as_onlymark)
\r
196 // mark pixel as sprite pixel (AS)
\r
197 #define pix_and(x) \
\r
198 pd[x] = (pd[x] & 0xc0) | (pd[x] & (pal | t))
\r
200 TileNormMaker(TileNorm_and, pix_and)
\r
201 TileFlipMaker(TileFlip_and, pix_and)
\r
203 // --------------------------------------------
\r
205 #ifndef _ASM_DRAW_C
\r
206 static void DrawStrip(struct TileStrip *ts, int lflags, int cellskip)
\r
208 int tilex,dx,ty,code=0,addr=0,cells;
\r
209 int oldcode=-1,blank=-1; // The tile we know is blank
\r
212 // Draw tiles across screen:
\r
213 sh = (lflags & LF_SH) << 5; // 0x40
\r
214 tilex=((-ts->hscroll)>>3)+cellskip;
\r
215 ty=(ts->line&7)<<1; // Y-Offset into tile
\r
216 dx=((ts->hscroll-1)&7)+1;
\r
217 cells = ts->cells - cellskip;
\r
218 if(dx != 8) cells++; // have hscroll, need to draw 1 cell more
\r
221 for (; cells > 0; dx+=8, tilex++, cells--)
\r
225 code = Pico.vram[ts->nametab + (tilex & ts->xmask)];
\r
228 if ((code >> 15) | (lflags & LF_FORCE)) { // high priority tile
\r
229 int cval = code | (dx<<16) | (ty<<25);
\r
230 if(code&0x1000) cval^=7<<26;
\r
231 *ts->hc++ = cval; // cache it
\r
235 if (code!=oldcode) {
\r
237 // Get tile address/2:
\r
238 addr=(code&0x7ff)<<4;
\r
240 if (code&0x1000) addr^=0xe; // Y-flip
\r
242 pal=((code>>9)&0x30)|sh;
\r
245 pack = *(unsigned int *)(Pico.vram + addr);
\r
251 if (code & 0x0800) TileFlip(dx, pack, pal);
\r
252 else TileNorm(dx, pack, pal);
\r
255 // terminate the cache list
\r
257 // if oldcode wasn't changed, it means all layer is hi priority
\r
258 if (oldcode == -1) Pico.est.rendstatus |= PDRAW_PLANE_HI_PRIO;
\r
262 static void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip)
\r
264 int tilex,dx,code=0,addr=0,cell=0;
\r
265 int oldcode=-1,blank=-1; // The tile we know is blank
\r
266 int pal=0,scan=Pico.est.DrawScanline;
\r
268 // Draw tiles across screen:
\r
269 tilex=(-ts->hscroll)>>3;
\r
270 dx=((ts->hscroll-1)&7)+1;
\r
271 if(dx != 8) cell--; // have hscroll, start with negative cell
\r
276 for (; cell < ts->cells; dx+=8,tilex++,cell++)
\r
278 int nametabadd, ty;
\r
284 vscroll=Pico.vsram[(plane_sh&1)+(cell&~1)];
\r
286 // Find the line in the name table
\r
287 line=(vscroll+scan)&ts->line&0xffff; // ts->line is really ymask ..
\r
288 nametabadd=(line>>3)<<(ts->line>>24); // .. and shift[width]
\r
289 ty=(line&7)<<1; // Y-Offset into tile
\r
292 code=Pico.vram[ts->nametab+nametabadd+(tilex&ts->xmask)];
\r
293 if (code==blank) continue;
\r
294 if (code>>15) { // high priority tile
\r
295 int cval = code | (dx<<16) | (ty<<25);
\r
296 if(code&0x1000) cval^=7<<26;
\r
297 *ts->hc++ = cval; // cache it
\r
301 if (code!=oldcode) {
\r
303 // Get tile address/2:
\r
304 addr=(code&0x7ff)<<4;
\r
305 if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip
\r
307 pal=((code>>9)&0x30)|((plane_sh<<5)&0x40);
\r
310 pack = *(unsigned int *)(Pico.vram + addr);
\r
316 if (code & 0x0800) TileFlip(dx, pack, pal);
\r
317 else TileNorm(dx, pack, pal);
\r
320 // terminate the cache list
\r
322 if (oldcode == -1) Pico.est.rendstatus |= PDRAW_PLANE_HI_PRIO;
\r
326 #ifndef _ASM_DRAW_C
\r
329 void DrawStripInterlace(struct TileStrip *ts)
\r
331 int tilex=0,dx=0,ty=0,code=0,addr=0,cells;
\r
332 int oldcode=-1,blank=-1; // The tile we know is blank
\r
335 // Draw tiles across screen:
\r
336 tilex=(-ts->hscroll)>>3;
\r
337 ty=(ts->line&15)<<1; // Y-Offset into tile
\r
338 dx=((ts->hscroll-1)&7)+1;
\r
340 if(dx != 8) cells++; // have hscroll, need to draw 1 cell more
\r
342 for (; cells; dx+=8,tilex++,cells--)
\r
346 code=Pico.vram[ts->nametab+(tilex&ts->xmask)];
\r
347 if (code==blank) continue;
\r
348 if (code>>15) { // high priority tile
\r
349 int cval = (code&0xfc00) | (dx<<16) | (ty<<25);
\r
350 cval|=(code&0x3ff)<<1;
\r
351 if(code&0x1000) cval^=0xf<<26;
\r
352 *ts->hc++ = cval; // cache it
\r
356 if (code!=oldcode) {
\r
358 // Get tile address/2:
\r
359 addr=(code&0x7ff)<<5;
\r
360 if (code&0x1000) addr+=30-ty; else addr+=ty; // Y-flip
\r
362 // pal=Pico.cram+((code>>9)&0x30);
\r
363 pal=((code>>9)&0x30);
\r
366 pack = *(unsigned int *)(Pico.vram + addr);
\r
372 if (code & 0x0800) TileFlip(dx, pack, pal);
\r
373 else TileNorm(dx, pack, pal);
\r
376 // terminate the cache list
\r
380 // --------------------------------------------
\r
382 #ifndef _ASM_DRAW_C
\r
383 static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells,
\r
384 struct PicoEState *est)
\r
386 struct PicoVideo *pvid=&Pico.video;
\r
387 const char shift[4]={5,6,5,7}; // 32,64 or 128 sized tilemaps (2 is invalid)
\r
388 struct TileStrip ts;
\r
389 int width, height, ymask;
\r
395 // Work out the TileStrip to draw
\r
397 // Work out the name table size: 32 64 or 128 tiles (0-3)
\r
398 width=pvid->reg[16];
\r
399 height=(width>>4)&3; width&=3;
\r
401 ts.xmask=(1<<shift[width])-1; // X Mask in tiles (0x1f-0x7f)
\r
402 ymask=(height<<8)|0xff; // Y Mask in pixels
\r
404 case 1: ymask &= 0x1ff; break;
\r
405 case 2: ymask = 0x007; break;
\r
406 case 3: ymask = 0x0ff; break;
\r
409 // Find name table:
\r
410 if (plane_sh&1) ts.nametab=(pvid->reg[4]&0x07)<<12; // B
\r
411 else ts.nametab=(pvid->reg[2]&0x38)<< 9; // A
\r
413 htab=pvid->reg[13]<<9; // Horizontal scroll table address
\r
414 if ( pvid->reg[11]&2) htab+=est->DrawScanline<<1; // Offset by line
\r
415 if ((pvid->reg[11]&1)==0) htab&=~0xf; // Offset by tile
\r
416 htab+=plane_sh&1; // A or B
\r
418 // Get horizontal scroll value, will be masked later
\r
419 ts.hscroll=Pico.vram[htab&0x7fff];
\r
421 if((pvid->reg[12]&6) == 6) {
\r
422 // interlace mode 2
\r
423 vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value
\r
425 // Find the line in the name table
\r
426 ts.line=(vscroll+(est->DrawScanline<<1))&((ymask<<1)|1);
\r
427 ts.nametab+=(ts.line>>4)<<shift[width];
\r
429 DrawStripInterlace(&ts);
\r
430 } else if( pvid->reg[11]&4) {
\r
431 // shit, we have 2-cell column based vscroll
\r
432 // luckily this doesn't happen too often
\r
433 ts.line=ymask|(shift[width]<<24); // save some stuff instead of line
\r
434 DrawStripVSRam(&ts, plane_sh, cellskip);
\r
436 vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value
\r
438 // Find the line in the name table
\r
439 ts.line=(vscroll+est->DrawScanline)&ymask;
\r
440 ts.nametab+=(ts.line>>3)<<shift[width];
\r
442 DrawStrip(&ts, plane_sh, cellskip);
\r
447 // --------------------------------------------
\r
449 // tstart & tend are tile pair numbers
\r
450 static void DrawWindow(int tstart, int tend, int prio, int sh,
\r
451 struct PicoEState *est)
\r
453 struct PicoVideo *pvid=&Pico.video;
\r
454 int tilex,ty,nametab,code=0;
\r
455 int blank=-1; // The tile we know is blank
\r
457 // Find name table line:
\r
458 if (pvid->reg[12]&1)
\r
460 nametab=(pvid->reg[3]&0x3c)<<9; // 40-cell mode
\r
461 nametab+=(est->DrawScanline>>3)<<6;
\r
465 nametab=(pvid->reg[3]&0x3e)<<9; // 32-cell mode
\r
466 nametab+=(est->DrawScanline>>3)<<5;
\r
471 if (!(est->rendstatus & PDRAW_WND_DIFF_PRIO)) {
\r
472 // check the first tile code
\r
473 code=Pico.vram[nametab+tilex];
\r
474 // if the whole window uses same priority (what is often the case), we may be able to skip this field
\r
475 if ((code>>15) != prio) return;
\r
479 ty=(est->DrawScanline&7)<<1; // Y-Offset into tile
\r
481 // Draw tiles across screen:
\r
484 for (; tilex < tend; tilex++)
\r
490 code=Pico.vram[nametab+tilex];
\r
491 if (code==blank) continue;
\r
492 if ((code>>15) != prio) {
\r
493 est->rendstatus |= PDRAW_WND_DIFF_PRIO;
\r
497 // Get tile address/2:
\r
498 addr=(code&0x7ff)<<4;
\r
499 if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip
\r
501 pack = *(unsigned int *)(Pico.vram + addr);
\r
507 pal = ((code >> 9) & 0x30);
\r
508 dx = 8 + (tilex << 3);
\r
510 if (code & 0x0800) TileFlip(dx, pack, pal);
\r
511 else TileNorm(dx, pack, pal);
\r
516 for (; tilex < tend; tilex++)
\r
522 code=Pico.vram[nametab+tilex];
\r
523 if(code==blank) continue;
\r
524 if((code>>15) != prio) {
\r
525 est->rendstatus |= PDRAW_WND_DIFF_PRIO;
\r
529 pal=((code>>9)&0x30);
\r
532 int *zb = (int *)(est->HighCol+8+(tilex<<3));
\r
533 *zb++ &= 0xbfbfbfbf;
\r
539 // Get tile address/2:
\r
540 addr=(code&0x7ff)<<4;
\r
541 if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip
\r
543 pack = *(unsigned int *)(Pico.vram + addr);
\r
549 dx = 8 + (tilex << 3);
\r
551 if (code & 0x0800) TileFlip(dx, pack, pal);
\r
552 else TileNorm(dx, pack, pal);
\r
557 // --------------------------------------------
\r
559 static void DrawTilesFromCacheShPrep(void)
\r
561 // as some layer has covered whole line with hi priority tiles,
\r
562 // we can process whole line and then act as if sh/hi mode was off,
\r
563 // but leave lo pri op sprite markers alone
\r
564 int c = 320/4, *zb = (int *)(Pico.est.HighCol+8);
\r
565 Pico.est.rendstatus |= PDRAW_SHHI_DONE;
\r
568 *zb++ &= 0xbfbfbfbf;
\r
572 static void DrawTilesFromCache(int *hc, int sh, int rlim, struct PicoEState *est)
\r
574 int code, addr, dx;
\r
578 // *ts->hc++ = code | (dx<<16) | (ty<<25); // cache it
\r
580 if (sh && (est->rendstatus & (PDRAW_SHHI_DONE|PDRAW_PLANE_HI_PRIO)))
\r
582 if (!(est->rendstatus & PDRAW_SHHI_DONE))
\r
583 DrawTilesFromCacheShPrep();
\r
589 short blank=-1; // The tile we know is blank
\r
590 while ((code=*hc++)) {
\r
591 if (!(code & 0x8000) || (short)code == blank)
\r
593 // Get tile address/2:
\r
594 addr = (code & 0x7ff) << 4;
\r
595 addr += code >> 25; // y offset into tile
\r
597 pack = *(unsigned int *)(Pico.vram + addr);
\r
599 blank = (short)code;
\r
603 dx = (code >> 16) & 0x1ff;
\r
604 pal = ((code >> 9) & 0x30);
\r
606 goto last_cut_tile;
\r
608 if (code & 0x0800) TileFlip(dx, pack, pal);
\r
609 else TileNorm(dx, pack, pal);
\r
614 while ((code=*hc++)) {
\r
617 // Get tile address/2:
\r
618 addr=(code&0x7ff)<<4;
\r
619 addr+=(unsigned int)code>>25; // y offset into tile
\r
620 dx=(code>>16)&0x1ff;
\r
621 zb = est->HighCol+dx;
\r
622 *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf;
\r
623 *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf;
\r
625 pack = *(unsigned int *)(Pico.vram + addr);
\r
629 pal = ((code >> 9) & 0x30);
\r
631 goto last_cut_tile;
\r
633 if (code & 0x0800) TileFlip(dx, pack, pal);
\r
634 else TileNorm(dx, pack, pal);
\r
640 // for vertical window cutoff
\r
642 unsigned char *pd = est->HighCol + dx;
\r
649 case 7: t=pack&0x00000f00; if (t) pd[6]=(unsigned char)(pal|(t>> 8)); // "break" is left out intentionally
\r
650 case 6: t=pack&0x000000f0; if (t) pd[5]=(unsigned char)(pal|(t>> 4));
\r
651 case 5: t=pack&0x0000000f; if (t) pd[4]=(unsigned char)(pal|(t ));
\r
652 case 4: t=pack&0xf0000000; if (t) pd[3]=(unsigned char)(pal|(t>>28));
\r
653 case 3: t=pack&0x0f000000; if (t) pd[2]=(unsigned char)(pal|(t>>24));
\r
654 case 2: t=pack&0x00f00000; if (t) pd[1]=(unsigned char)(pal|(t>>20));
\r
655 case 1: t=pack&0x000f0000; if (t) pd[0]=(unsigned char)(pal|(t>>16));
\r
663 case 7: t=pack&0x00f00000; if (t) pd[6]=(unsigned char)(pal|(t>>20));
\r
664 case 6: t=pack&0x0f000000; if (t) pd[5]=(unsigned char)(pal|(t>>24));
\r
665 case 5: t=pack&0xf0000000; if (t) pd[4]=(unsigned char)(pal|(t>>28));
\r
666 case 4: t=pack&0x0000000f; if (t) pd[3]=(unsigned char)(pal|(t ));
\r
667 case 3: t=pack&0x000000f0; if (t) pd[2]=(unsigned char)(pal|(t>> 4));
\r
668 case 2: t=pack&0x00000f00; if (t) pd[1]=(unsigned char)(pal|(t>> 8));
\r
669 case 1: t=pack&0x0000f000; if (t) pd[0]=(unsigned char)(pal|(t>>12));
\r
676 // --------------------------------------------
\r
678 // Index + 0 : hhhhvvvv ab--hhvv yyyyyyyy yyyyyyyy // a: offscreen h, b: offs. v, h: horiz. size
\r
679 // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
\r
681 static void DrawSprite(int *sprite, int sh)
\r
683 int width=0,height=0;
\r
686 int tile=0,delta=0;
\r
688 void (*fTileFunc)(int sx, unsigned int pack, int pal);
\r
690 // parse the sprite data
\r
695 height=(sy>>24)&7; // Width and height in tiles
\r
696 sy=(sy<<16)>>16; // Y
\r
698 row=Pico.est.DrawScanline-sy; // Row of the sprite we are on
\r
700 if (code&0x1000) row=(height<<3)-1-row; // Flip Y
\r
702 tile=code + (row>>3); // Tile number increases going down
\r
703 delta=height; // Delta to increase tile by going right
\r
704 if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
\r
706 tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address
\r
707 delta<<=4; // Delta of address
\r
709 pal=(code>>9)&0x30;
\r
712 if (sh && (code&0x6000) == 0x6000) {
\r
713 if(code&0x0800) fTileFunc=TileFlipSH_markop;
\r
714 else fTileFunc=TileNormSH_markop;
\r
716 if(code&0x0800) fTileFunc=TileFlip;
\r
717 else fTileFunc=TileNorm;
\r
720 for (; width; width--,sx+=8,tile+=delta)
\r
724 if(sx<=0) continue;
\r
725 if(sx>=328) break; // Offscreen
\r
727 pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff));
\r
728 fTileFunc(sx, pack, pal);
\r
733 static NOINLINE void DrawTilesFromCacheForced(const int *hc)
\r
735 int code, addr, dx;
\r
739 // *ts->hc++ = code | (dx<<16) | (ty<<25);
\r
740 while ((code = *hc++)) {
\r
741 // Get tile address/2:
\r
742 addr = (code & 0x7ff) << 4;
\r
743 addr += (code >> 25) & 0x0e; // y offset into tile
\r
745 dx = (code >> 16) & 0x1ff;
\r
746 pal = ((code >> 9) & 0x30);
\r
747 pack = *(unsigned int *)(Pico.vram + addr);
\r
749 if (code & 0x0800) TileFlip_and(dx, pack, pal);
\r
750 else TileNorm_and(dx, pack, pal);
\r
754 static void DrawSpriteInterlace(unsigned int *sprite)
\r
756 int width=0,height=0;
\r
759 int tile=0,delta=0;
\r
762 // parse the sprite data
\r
765 sy=(sy&0x3ff)-0x100; // Y
\r
766 width=(height>>2)&3; height&=3;
\r
767 width++; height++; // Width and height in tiles
\r
769 row=(Pico.est.DrawScanline<<1)-sy; // Row of the sprite we are on
\r
772 sx=((code>>16)&0x1ff)-0x78; // X
\r
774 if (code&0x1000) row^=(16<<height)-1; // Flip Y
\r
776 tile=code&0x3ff; // Tile number
\r
777 tile+=row>>4; // Tile number increases going down
\r
778 delta=height; // Delta to increase tile by going right
\r
779 if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
\r
781 tile<<=5; tile+=(row&15)<<1; // Tile address
\r
783 delta<<=5; // Delta of address
\r
784 pal=((code>>9)&0x30); // Get palette pointer
\r
786 for (; width; width--,sx+=8,tile+=delta)
\r
790 if(sx<=0) continue;
\r
791 if(sx>=328) break; // Offscreen
\r
793 pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff));
\r
794 if (code & 0x0800) TileFlip(sx, pack, pal);
\r
795 else TileNorm(sx, pack, pal);
\r
800 static NOINLINE void DrawAllSpritesInterlace(int pri, int sh)
\r
802 struct PicoVideo *pvid=&Pico.video;
\r
803 int i,u,table,link=0,sline=Pico.est.DrawScanline<<1;
\r
804 unsigned int *sprites[80]; // Sprite index
\r
806 table=pvid->reg[5]&0x7f;
\r
807 if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode
\r
808 table<<=8; // Get sprite table address/2
\r
810 for (i=u=0; u < 80 && i < 21; u++)
\r
812 unsigned int *sprite;
\r
813 int code, sx, sy, height;
\r
815 sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite
\r
820 if(((sx>>15)&1) != pri) goto nextsprite; // wrong priority sprite
\r
822 // check if it is on this line
\r
823 sy = (code&0x3ff)-0x100;
\r
824 height = (((code>>24)&3)+1)<<4;
\r
825 if(sline < sy || sline >= sy+height) goto nextsprite; // no
\r
827 // check if sprite is not hidden offscreen
\r
828 sx = (sx>>16)&0x1ff;
\r
829 sx -= 0x78; // Get X coordinate + 8
\r
830 if(sx <= -8*3 || sx >= 328) goto nextsprite;
\r
832 // sprite is good, save it's pointer
\r
833 sprites[i++]=sprite;
\r
836 // Find next sprite
\r
837 link=(code>>16)&0x7f;
\r
838 if(!link) break; // End of sprites
\r
841 // Go through sprites backwards:
\r
842 for (i-- ;i>=0; i--)
\r
843 DrawSpriteInterlace(sprites[i]);
\r
847 #ifndef _ASM_DRAW_C
\r
849 * s/h drawing: lo_layers|40, lo_sprites|40 && mark_op,
\r
850 * hi_layers&=~40, hi_sprites
\r
852 * Index + 0 : hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: vert./horiz. size
\r
853 * Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
\r
855 static void DrawSpritesSHi(unsigned char *sprited, const struct PicoEState *est)
\r
857 void (*fTileFunc)(int sx, unsigned int pack, int pal);
\r
861 cnt = sprited[0] & 0x7f;
\r
862 if (cnt == 0) return;
\r
866 // Go through sprites backwards:
\r
867 for (cnt--; cnt >= 0; cnt--)
\r
869 int *sprite, code, pal, tile, sx, sy;
\r
870 int offs, delta, width, height, row;
\r
872 offs = (p[cnt] & 0x7f) * 2;
\r
873 sprite = est->HighPreSpr + offs;
\r
875 pal = (code>>9)&0x30;
\r
879 if (code & 0x8000) // hi priority
\r
881 if (code&0x800) fTileFunc=TileFlipSH;
\r
882 else fTileFunc=TileNormSH;
\r
884 if (code&0x800) fTileFunc=TileFlipSH_onlyop_lp;
\r
885 else fTileFunc=TileNormSH_onlyop_lp;
\r
888 if (!(code & 0x8000)) continue; // non-operator low sprite, already drawn
\r
889 if (code&0x800) fTileFunc=TileFlip;
\r
890 else fTileFunc=TileNorm;
\r
893 // parse remaining sprite data
\r
897 height=(sy>>24)&7; // Width and height in tiles
\r
898 sy=(sy<<16)>>16; // Y
\r
900 row=est->DrawScanline-sy; // Row of the sprite we are on
\r
902 if (code&0x1000) row=(height<<3)-1-row; // Flip Y
\r
904 tile=code + (row>>3); // Tile number increases going down
\r
905 delta=height; // Delta to increase tile by going right
\r
906 if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
\r
908 tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address
\r
909 delta<<=4; // Delta of address
\r
911 for (; width; width--,sx+=8,tile+=delta)
\r
915 if(sx<=0) continue;
\r
916 if(sx>=328) break; // Offscreen
\r
918 pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff));
\r
919 fTileFunc(sx, pack, pal);
\r
923 #endif // !_ASM_DRAW_C
\r
925 static void DrawSpritesHiAS(unsigned char *sprited, int sh)
\r
927 void (*fTileFunc)(int sx, unsigned int pack, int pal);
\r
929 int entry, cnt, sh_cnt = 0;
\r
931 cnt = sprited[0] & 0x7f;
\r
932 if (cnt == 0) return;
\r
934 Pico.est.rendstatus |= PDRAW_SPR_LO_ON_HI;
\r
938 // Go through sprites:
\r
939 for (entry = 0; entry < cnt; entry++)
\r
941 int *sprite, code, pal, tile, sx, sy;
\r
942 int offs, delta, width, height, row;
\r
944 offs = (p[entry] & 0x7f) * 2;
\r
945 sprite = HighPreSpr + offs;
\r
947 pal = (code>>9)&0x30;
\r
949 if (code & 0x8000) // hi priority
\r
951 if (sh && pal == 0x30)
\r
953 if (code&0x800) fTileFunc=TileFlipAS_noop;
\r
954 else fTileFunc=TileNormAS_noop;
\r
956 if (code&0x800) fTileFunc=TileFlipAS;
\r
957 else fTileFunc=TileNormAS;
\r
960 if (code&0x800) fTileFunc=TileFlipAS_onlymark;
\r
961 else fTileFunc=TileNormAS_onlymark;
\r
963 if (sh && pal == 0x30)
\r
964 p[sh_cnt++] = offs / 2; // re-save for sh/hi pass
\r
966 // parse remaining sprite data
\r
970 height=(sy>>24)&7; // Width and height in tiles
\r
971 sy=(sy<<16)>>16; // Y
\r
973 row=Pico.est.DrawScanline-sy; // Row of the sprite we are on
\r
975 if (code&0x1000) row=(height<<3)-1-row; // Flip Y
\r
977 tile=code + (row>>3); // Tile number increases going down
\r
978 delta=height; // Delta to increase tile by going right
\r
979 if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
\r
981 tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address
\r
982 delta<<=4; // Delta of address
\r
985 for (; width; width--,sx+=8,tile+=delta)
\r
989 if(sx<=0) continue;
\r
990 if(sx>=328) break; // Offscreen
\r
992 pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff));
\r
993 fTileFunc(sx, pack, pal);
\r
997 if (!sh || !(sprited[1]&SPRL_MAY_HAVE_OP)) return;
\r
999 /* nasty 1: remove 'sprite' flags */
\r
1001 int c = 320/4/4, *zb = (int *)(Pico.est.HighCol+8);
\r
1004 *zb++ &= 0x7f7f7f7f; *zb++ &= 0x7f7f7f7f;
\r
1005 *zb++ &= 0x7f7f7f7f; *zb++ &= 0x7f7f7f7f;
\r
1009 /* nasty 2: sh operator pass */
\r
1010 sprited[0] = sh_cnt;
\r
1011 DrawSpritesSHi(sprited, &Pico.est);
\r
1015 // Index + 0 : ----hhvv -lllllll -------y yyyyyyyy
\r
1016 // Index + 4 : -------x xxxxxxxx pccvhnnn nnnnnnnn
\r
1018 // Index + 0 : hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: vert./horiz. size
\r
1019 // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
\r
1021 static NOINLINE void PrepareSprites(int full)
\r
1023 const struct PicoVideo *pvid=&Pico.video;
\r
1024 const struct PicoEState *est=&Pico.est;
\r
1027 int *pd = HighPreSpr;
\r
1028 int max_lines = 224, max_sprites = 80, max_width = 328;
\r
1029 int max_line_sprites = 20; // 20 sprites, 40 tiles
\r
1031 if (!(Pico.video.reg[12]&1))
\r
1032 max_sprites = 64, max_line_sprites = 16, max_width = 264;
\r
1033 if (PicoOpt & POPT_DIS_SPRITE_LIM)
\r
1034 max_line_sprites = MAX_LINE_SPRITES;
\r
1036 if (pvid->reg[1]&8) max_lines = 240;
\r
1037 sh = Pico.video.reg[0xC]&8; // shadow/hilight?
\r
1039 table=pvid->reg[5]&0x7f;
\r
1040 if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode
\r
1041 table<<=8; // Get sprite table address/2
\r
1046 // updates: tilecode, sx
\r
1047 for (u=0; u < max_sprites && (pack = *pd); u++, pd+=2)
\r
1049 unsigned int *sprite;
\r
1050 int code2, sx, sy, height;
\r
1052 sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite
\r
1054 // parse sprite info
\r
1055 code2 = sprite[1];
\r
1056 sx = (code2>>16)&0x1ff;
\r
1057 sx -= 0x78; // Get X coordinate + 8
\r
1058 sy = (pack << 16) >> 16;
\r
1059 height = (pack >> 24) & 0xf;
\r
1061 if (sy < max_lines &&
\r
1062 sy + (height<<3) > est->DrawScanline && // sprite onscreen (y)?
\r
1063 (sx > -24 || sx < max_width)) // onscreen x
\r
1065 int y = (sy >= est->DrawScanline) ? sy : est->DrawScanline;
\r
1066 int entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80);
\r
1067 for (; y < sy + (height<<3) && y < max_lines; y++)
\r
1070 cnt = HighLnSpr[y][0] & 0x7f;
\r
1071 if (cnt >= max_line_sprites) continue; // sprite limit?
\r
1073 for (i = 0; i < cnt; i++)
\r
1074 if (((HighLnSpr[y][3+i] ^ entry) & 0x7f) == 0) goto found;
\r
1076 // this sprite was previously missing
\r
1077 HighLnSpr[y][3+cnt] = entry;
\r
1078 HighLnSpr[y][0] = cnt + 1;
\r
1081 HighLnSpr[y][1] |= SPRL_HAVE_HI;
\r
1082 else HighLnSpr[y][1] |= SPRL_HAVE_LO;
\r
1086 code2 &= ~0xfe000000;
\r
1087 code2 -= 0x00780000; // Get X coordinate + 8 in upper 16 bits
\r
1090 // Find next sprite
\r
1091 link=(sprite[0]>>16)&0x7f;
\r
1092 if (!link) break; // End of sprites
\r
1097 for (u = 0; u < max_lines; u++)
\r
1098 *((int *)&HighLnSpr[u][0]) = 0;
\r
1100 for (u = 0; u < max_sprites; u++)
\r
1102 unsigned int *sprite;
\r
1103 int code, code2, sx, sy, hv, height, width;
\r
1105 sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite
\r
1107 // parse sprite info
\r
1109 sy = (code&0x1ff)-0x80;
\r
1110 hv = (code>>24)&0xf;
\r
1111 height = (hv&3)+1;
\r
1113 width = (hv>>2)+1;
\r
1114 code2 = sprite[1];
\r
1115 sx = (code2>>16)&0x1ff;
\r
1116 sx -= 0x78; // Get X coordinate + 8
\r
1118 if (sy < max_lines && sy + (height<<3) > est->DrawScanline) // sprite onscreen (y)?
\r
1120 int entry, y, sx_min, onscr_x, maybe_op = 0;
\r
1122 sx_min = 8-(width<<3);
\r
1123 onscr_x = sx_min < sx && sx < max_width;
\r
1124 if (sh && (code2 & 0x6000) == 0x6000)
\r
1125 maybe_op = SPRL_MAY_HAVE_OP;
\r
1127 entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80);
\r
1128 y = (sy >= est->DrawScanline) ? sy : est->DrawScanline;
\r
1129 for (; y < sy + (height<<3) && y < max_lines; y++)
\r
1131 unsigned char *p = &HighLnSpr[y][0];
\r
1133 if (cnt >= max_line_sprites) continue; // sprite limit?
\r
1135 if (p[2] >= max_line_sprites*2) { // tile limit?
\r
1141 if (sx == -0x78) {
\r
1143 p[0] |= 0x80; // masked, no more sprites for this line
\r
1146 // must keep the first sprite even if it's offscreen, for masking
\r
1147 if (cnt > 0 && !onscr_x) continue; // offscreen x
\r
1151 p[1] |= (entry & 0x80) ? SPRL_HAVE_HI : SPRL_HAVE_LO;
\r
1152 p[1] |= maybe_op; // there might be op sprites on this line
\r
1153 if (cnt > 0 && (code2 & 0x8000) && !(p[3+cnt-1]&0x80))
\r
1154 p[1] |= SPRL_LO_ABOVE_HI;
\r
1158 *pd++ = (width<<28)|(height<<24)|(hv<<16)|((unsigned short)sy);
\r
1159 *pd++ = (sx<<16)|((unsigned short)code2);
\r
1161 // Find next sprite
\r
1162 link=(code>>16)&0x7f;
\r
1163 if (!link) break; // End of sprites
\r
1168 for (u = 0; u < max_lines; u++)
\r
1171 printf("c%03i: %2i, %2i: ", u, HighLnSpr[u][0] & 0x7f, HighLnSpr[u][2]);
\r
1172 for (y = 0; y < HighLnSpr[u][0] & 0x7f; y++)
\r
1173 printf(" %i", HighLnSpr[u][y+3]);
\r
1180 #ifndef _ASM_DRAW_C
\r
1181 static void DrawAllSprites(unsigned char *sprited, int prio, int sh,
\r
1182 struct PicoEState *est)
\r
1187 cnt = sprited[0] & 0x7f;
\r
1188 if (cnt == 0) return;
\r
1192 // Go through sprites backwards:
\r
1193 for (cnt--; cnt >= 0; cnt--)
\r
1196 if ((p[cnt] >> 7) != prio) continue;
\r
1197 offs = (p[cnt]&0x7f) * 2;
\r
1198 DrawSprite(HighPreSpr + offs, sh);
\r
1203 // --------------------------------------------
\r
1205 void BackFill(int reg7, int sh, struct PicoEState *est)
\r
1207 unsigned int back;
\r
1209 // Start with a blank scanline (background colour):
\r
1215 memset32((int *)(est->HighCol+8), back, 320/4);
\r
1219 // --------------------------------------------
\r
1221 #ifndef _ASM_DRAW_C
\r
1222 void PicoDoHighPal555(int sh, int line, struct PicoEState *est)
\r
1224 unsigned int *spal, *dpal;
\r
1225 unsigned int t, i;
\r
1227 Pico.m.dirtyPal = 0;
\r
1229 spal = (void *)Pico.cram;
\r
1230 dpal = (void *)est->HighPal;
\r
1232 for (i = 0; i < 0x40 / 2; i++) {
\r
1235 t = ((t & 0x000e000e)<< 1) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)<<4);
\r
1237 t = ((t & 0x000e000e)<<12) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)>>7);
\r
1239 // treat it like it was 4-bit per channel, since in s/h mode it somewhat is that.
\r
1240 // otherwise intensity difference between this and s/h will be wrong
\r
1241 t |= (t >> 4) & 0x08610861; // 0x18e318e3
\r
1245 // norm: xxx0, sh: 0xxx, hi: 0xxx + 7
\r
1248 // shadowed pixels
\r
1249 for (i = 0; i < 0x40 / 2; i++)
\r
1250 dpal[0x40/2 | i] = dpal[0xc0/2 | i] = (dpal[i] >> 1) & 0x738e738e;
\r
1251 // hilighted pixels
\r
1252 for (i = 0; i < 0x40 / 2; i++) {
\r
1253 t = ((dpal[i] >> 1) & 0x738e738e) + 0x738e738e; // 0x7bef7bef;
\r
1254 t |= (t >> 4) & 0x08610861;
\r
1255 dpal[0x80/2 | i] = t;
\r
1260 void FinalizeLine555(int sh, int line, struct PicoEState *est)
\r
1262 unsigned short *pd=est->DrawLineDest;
\r
1263 unsigned char *ps=est->HighCol+8;
\r
1264 unsigned short *pal=est->HighPal;
\r
1267 if (Pico.m.dirtyPal)
\r
1268 PicoDoHighPal555(sh, line, est);
\r
1270 if (Pico.video.reg[12]&1) {
\r
1273 if (!(PicoOpt&POPT_DIS_32C_BORDER)) pd+=32;
\r
1280 if (!sh && (est->rendstatus & PDRAW_SPR_LO_ON_HI))
\r
1281 mask=0x3f; // accurate sprites, upper bits are priority stuff
\r
1283 for (i = 0; i < len; i++)
\r
1284 pd[i] = pal[ps[i] & mask];
\r
1286 extern void amips_clut(unsigned short *dst, unsigned char *src, unsigned short *pal, int count);
\r
1287 extern void amips_clut_6bit(unsigned short *dst, unsigned char *src, unsigned short *pal, int count);
\r
1288 if (!sh && (est->rendstatus & PDRAW_SPR_LO_ON_HI))
\r
1289 amips_clut_6bit(pd, ps, pal, len);
\r
1290 else amips_clut(pd, ps, pal, len);
\r
1296 static void FinalizeLine8bit(int sh, int line, struct PicoEState *est)
\r
1298 unsigned char *pd = est->DrawLineDest;
\r
1299 int len, rs = est->rendstatus;
\r
1300 static int dirty_count;
\r
1302 if (!sh && Pico.m.dirtyPal == 1)
\r
1304 // a hack for mid-frame palette changes
\r
1305 if (!(rs & PDRAW_SONIC_MODE))
\r
1307 else dirty_count++;
\r
1308 rs |= PDRAW_SONIC_MODE;
\r
1309 est->rendstatus = rs;
\r
1310 if (dirty_count == 3) {
\r
1311 blockcpy(est->HighPal, Pico.cram, 0x40*2);
\r
1312 } else if (dirty_count == 11) {
\r
1313 blockcpy(est->HighPal+0x40, Pico.cram, 0x40*2);
\r
1317 if (Pico.video.reg[12]&1) {
\r
1320 if (!(PicoOpt & POPT_DIS_32C_BORDER))
\r
1325 if (!sh && (rs & PDRAW_SONIC_MODE)) {
\r
1326 if (dirty_count >= 11) {
\r
1327 blockcpy_or(pd, est->HighCol+8, len, 0x80);
\r
1329 blockcpy_or(pd, est->HighCol+8, len, 0x40);
\r
1332 blockcpy(pd, est->HighCol+8, len);
\r
1336 static void (*FinalizeLine)(int sh, int line, struct PicoEState *est);
\r
1338 // --------------------------------------------
\r
1340 static int DrawDisplay(int sh)
\r
1342 struct PicoEState *est=&Pico.est;
\r
1343 unsigned char *sprited = &HighLnSpr[est->DrawScanline][0];
\r
1344 struct PicoVideo *pvid=&Pico.video;
\r
1345 int win=0, edge=0, hvwind=0, lflags;
\r
1346 int maxw, maxcells;
\r
1348 if (est->rendstatus & (PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES)) {
\r
1349 // elprintf(EL_STATUS, "PrepareSprites(%i)", (est->rendstatus>>4)&1);
\r
1350 PrepareSprites(est->rendstatus & PDRAW_DIRTY_SPRITES);
\r
1351 est->rendstatus &= ~(PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES);
\r
1354 est->rendstatus &= ~(PDRAW_SHHI_DONE|PDRAW_PLANE_HI_PRIO);
\r
1356 if (pvid->reg[12]&1) {
\r
1357 maxw = 328; maxcells = 40;
\r
1359 maxw = 264; maxcells = 32;
\r
1362 // Find out if the window is on this line:
\r
1363 win=pvid->reg[0x12];
\r
1364 edge=(win&0x1f)<<3;
\r
1366 if (win&0x80) { if (est->DrawScanline>=edge) hvwind=1; }
\r
1367 else { if (est->DrawScanline< edge) hvwind=1; }
\r
1369 if (!hvwind) // we might have a vertical window here
\r
1371 win=pvid->reg[0x11];
\r
1374 if (!edge) hvwind=1;
\r
1375 else if(edge < (maxcells>>1)) hvwind=2;
\r
1378 else if(edge < (maxcells>>1)) hvwind=2;
\r
1383 /* - layer B low - */
\r
1384 if (!(pvid->debug_p & PVD_KILL_B)) {
\r
1385 lflags = LF_PLANE_1 | (sh << 1);
\r
1386 if (pvid->debug_p & PVD_FORCE_B)
\r
1387 lflags |= LF_FORCE;
\r
1388 DrawLayer(lflags, HighCacheB, 0, maxcells, est);
\r
1390 /* - layer A low - */
\r
1391 lflags = 0 | (sh << 1);
\r
1392 if (pvid->debug_p & PVD_FORCE_A)
\r
1393 lflags |= LF_FORCE;
\r
1394 if (pvid->debug_p & PVD_KILL_A)
\r
1396 else if (hvwind == 1)
\r
1397 DrawWindow(0, maxcells>>1, 0, sh, est);
\r
1398 else if (hvwind == 2) {
\r
1399 DrawLayer(lflags, HighCacheA, (win&0x80) ? 0 : edge<<1, (win&0x80) ? edge<<1 : maxcells, est);
\r
1400 DrawWindow( (win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 0, sh, est);
\r
1403 DrawLayer(lflags, HighCacheA, 0, maxcells, est);
\r
1404 /* - sprites low - */
\r
1405 if (pvid->debug_p & PVD_KILL_S_LO)
\r
1407 else if (est->rendstatus & PDRAW_INTERLACE)
\r
1408 DrawAllSpritesInterlace(0, sh);
\r
1409 else if (sprited[1] & SPRL_HAVE_LO)
\r
1410 DrawAllSprites(sprited, 0, sh, est);
\r
1412 /* - layer B hi - */
\r
1413 if (!(pvid->debug_p & PVD_KILL_B) && HighCacheB[0])
\r
1414 DrawTilesFromCache(HighCacheB, sh, maxw, est);
\r
1415 /* - layer A hi - */
\r
1416 if (pvid->debug_p & PVD_KILL_A)
\r
1418 else if (hvwind == 1)
\r
1419 DrawWindow(0, maxcells>>1, 1, sh, est);
\r
1420 else if (hvwind == 2) {
\r
1421 if (HighCacheA[0])
\r
1422 DrawTilesFromCache(HighCacheA, sh, (win&0x80) ? edge<<4 : maxw, est);
\r
1423 DrawWindow((win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 1, sh, est);
\r
1425 if (HighCacheA[0])
\r
1426 DrawTilesFromCache(HighCacheA, sh, maxw, est);
\r
1427 /* - sprites hi - */
\r
1428 if (pvid->debug_p & PVD_KILL_S_HI)
\r
1430 else if (est->rendstatus & PDRAW_INTERLACE)
\r
1431 DrawAllSpritesInterlace(1, sh);
\r
1432 // have sprites without layer pri bit ontop of sprites with that bit
\r
1433 else if ((sprited[1] & 0xd0) == 0xd0 && (PicoOpt & POPT_ACC_SPRITES))
\r
1434 DrawSpritesHiAS(sprited, sh);
\r
1435 else if (sh && (sprited[1] & SPRL_MAY_HAVE_OP))
\r
1436 DrawSpritesSHi(sprited, est);
\r
1437 else if (sprited[1] & SPRL_HAVE_HI)
\r
1438 DrawAllSprites(sprited, 1, 0, est);
\r
1440 if (pvid->debug_p & PVD_FORCE_B)
\r
1441 DrawTilesFromCacheForced(HighCacheB);
\r
1442 else if (pvid->debug_p & PVD_FORCE_A)
\r
1443 DrawTilesFromCacheForced(HighCacheA);
\r
1448 for (a = 0, c = HighCacheA; *c; c++, a++);
\r
1449 for (b = 0, c = HighCacheB; *c; c++, b++);
\r
1450 printf("%i:%03i: a=%i, b=%i\n", Pico.m.frame_count,
\r
1451 Pico.est.DrawScanline, a, b);
\r
1458 // MUST be called every frame
\r
1459 PICO_INTERNAL void PicoFrameStart(void)
\r
1461 int offs = 8, lines = 224;
\r
1463 // prepare to do this frame
\r
1464 Pico.est.rendstatus = 0;
\r
1465 if ((Pico.video.reg[12] & 6) == 6)
\r
1466 Pico.est.rendstatus |= PDRAW_INTERLACE; // interlace mode
\r
1467 if (!(Pico.video.reg[12] & 1))
\r
1468 Pico.est.rendstatus |= PDRAW_32_COLS;
\r
1469 if (Pico.video.reg[1] & 8) {
\r
1474 if (Pico.est.rendstatus != rendstatus_old || lines != rendlines) {
\r
1475 rendlines = lines;
\r
1476 // mode_change() might reset rendstatus_old by calling SetColorFormat
\r
1477 emu_video_mode_change((lines == 240) ? 0 : 8,
\r
1478 lines, (Pico.video.reg[12] & 1) ? 0 : 1);
\r
1479 rendstatus_old = Pico.est.rendstatus;
\r
1482 Pico.est.HighCol = HighColBase + offs * HighColIncrement;
\r
1483 Pico.est.DrawLineDest = (char *)DrawLineDestBase + offs * DrawLineDestIncrement;
\r
1484 Pico.est.DrawScanline = 0;
\r
1485 skip_next_line = 0;
\r
1487 if (PicoOpt & POPT_ALT_RENDERER)
\r
1490 if (Pico.m.dirtyPal)
\r
1491 Pico.m.dirtyPal = 2; // reset dirty if needed
\r
1492 PrepareSprites(1);
\r
1495 static void DrawBlankedLine(int line, int offs, int sh, int bgc)
\r
1497 if (PicoScanBegin != NULL)
\r
1498 PicoScanBegin(line + offs);
\r
1500 BackFill(bgc, sh, &Pico.est);
\r
1502 if (FinalizeLine != NULL)
\r
1503 FinalizeLine(sh, line, &Pico.est);
\r
1505 if (PicoScanEnd != NULL)
\r
1506 PicoScanEnd(line + offs);
\r
1508 Pico.est.HighCol += HighColIncrement;
\r
1509 Pico.est.DrawLineDest = (char *)Pico.est.DrawLineDest + DrawLineDestIncrement;
\r
1512 static void PicoLine(int line, int offs, int sh, int bgc)
\r
1516 if (skip_next_line > 0) {
\r
1521 Pico.est.DrawScanline = line;
\r
1522 if (PicoScanBegin != NULL)
\r
1523 skip = PicoScanBegin(line + offs);
\r
1526 skip_next_line = skip - 1;
\r
1530 if (Pico.video.debug_p & (PVD_FORCE_A | PVD_FORCE_B))
\r
1534 BackFill(bgc, sh, &Pico.est);
\r
1535 if (Pico.video.reg[1]&0x40)
\r
1538 if (FinalizeLine != NULL)
\r
1539 FinalizeLine(sh, line, &Pico.est);
\r
1541 if (PicoScanEnd != NULL)
\r
1542 skip_next_line = PicoScanEnd(line + offs);
\r
1544 Pico.est.HighCol += HighColIncrement;
\r
1545 Pico.est.DrawLineDest = (char *)Pico.est.DrawLineDest + DrawLineDestIncrement;
\r
1548 void PicoDrawSync(int to, int blank_last_line)
\r
1550 int line, offs = 0;
\r
1551 int sh = (Pico.video.reg[0xC] & 8) >> 3; // shadow/hilight?
\r
1552 int bgc = Pico.video.reg[7];
\r
1554 pprof_start(draw);
\r
1556 if (rendlines != 240)
\r
1559 for (line = Pico.est.DrawScanline; line < to; line++)
\r
1561 PicoLine(line, offs, sh, bgc);
\r
1567 if (blank_last_line)
\r
1568 DrawBlankedLine(line, offs, sh, bgc);
\r
1569 else PicoLine(line, offs, sh, bgc);
\r
1572 Pico.est.DrawScanline = line;
\r
1577 // also works for fast renderer
\r
1578 void PicoDrawUpdateHighPal(void)
\r
1580 struct PicoEState *est = &Pico.est;
\r
1581 int sh = (Pico.video.reg[0xC] & 8) >> 3; // shadow/hilight?
\r
1582 if (PicoOpt & POPT_ALT_RENDERER)
\r
1583 sh = 0; // no s/h support
\r
1585 PicoDoHighPal555(sh, 0, &Pico.est);
\r
1586 if (est->rendstatus & PDRAW_SONIC_MODE) {
\r
1588 memcpy(est->HighPal + 0x40, est->HighPal, 0x40*2);
\r
1589 memcpy(est->HighPal + 0x80, est->HighPal, 0x40*2);
\r
1593 void PicoDrawSetOutFormat(pdso_t which, int use_32x_line_mode)
\r
1598 FinalizeLine = FinalizeLine8bit;
\r
1602 if ((PicoAHW & PAHW_32X) && use_32x_line_mode)
\r
1603 FinalizeLine = FinalizeLine32xRGB555;
\r
1605 FinalizeLine = FinalizeLine555;
\r
1609 FinalizeLine = NULL;
\r
1612 PicoDrawSetOutFormat32x(which, use_32x_line_mode);
\r
1613 PicoDrawSetOutputMode4(which);
\r
1614 rendstatus_old = -1;
\r
1617 // note: may be called on the middle of frame
\r
1618 void PicoDrawSetOutBuf(void *dest, int increment)
\r
1620 DrawLineDestBase = dest;
\r
1621 DrawLineDestIncrement = increment;
\r
1622 Pico.est.DrawLineDest = DrawLineDestBase + Pico.est.DrawScanline * increment;
\r
1625 void PicoDrawSetInternalBuf(void *dest, int increment)
\r
1627 if (dest != NULL) {
\r
1628 HighColBase = dest;
\r
1629 HighColIncrement = increment;
\r
1630 Pico.est.HighCol = HighColBase + Pico.est.DrawScanline * increment;
\r
1633 HighColBase = DefHighCol;
\r
1634 HighColIncrement = 0;
\r
1638 void PicoDrawSetCallbacks(int (*begin)(unsigned int num), int (*end)(unsigned int num))
\r
1640 PicoScanBegin = NULL;
\r
1641 PicoScanEnd = NULL;
\r
1642 PicoScan32xBegin = NULL;
\r
1643 PicoScan32xEnd = NULL;
\r
1645 if ((PicoAHW & PAHW_32X) && FinalizeLine != FinalizeLine32xRGB555) {
\r
1646 PicoScan32xBegin = begin;
\r
1647 PicoScan32xEnd = end;
\r
1650 PicoScanBegin = begin;
\r
1651 PicoScanEnd = end;
\r
1655 void PicoDrawInit(void)
\r
1657 Pico.est.DrawLineDest = DefOutBuff;
\r
1658 Pico.est.HighCol = HighColBase;
\r
1659 Pico.est.HighPreSpr = HighPreSpr;
\r
1660 rendstatus_old = -1;
\r
1663 // vim:ts=2:sw=2:expandtab
\r