scroll size improvement
[picodrive.git] / pico / draw.c
CommitLineData
cff531af 1/*\r
2 * line renderer\r
3 * (c) Copyright Dave, 2004\r
4 * (C) notaz, 2006-2010\r
5 *\r
6 * This work is licensed under the terms of MAME license.\r
7 * See COPYING file in the top-level directory.\r
8 */\r
e5fa9817 9/*\r
10 * The renderer has 4 modes now:\r
11 * - normal\r
12 * - shadow/hilight (s/h)\r
40644bfe 13 * - "sonic mode" for midline palette changes (8bit mode only)\r
14 * - accurate sprites (AS) [+ s/h]\r
e5fa9817 15 *\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
40644bfe 19 *\r
bfa12428 20 * since renderer always draws line in 8bit mode, there are 2 spare bits:\r
21 * b \ mode: s/h as sonic\r
a39d8ba5 22 * 00 normal - pal index\r
bfa12428 23 * 01 shadow - pal index\r
24 * 10 hilight+op spr spr pal index\r
25 * 11 shadow +op spr - pal index\r
26 *\r
40644bfe 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
e5fa9817 30 */\r
cc68a136 31\r
efcba75f 32#include "pico_int.h"\r
cc68a136 33\r
602133e1 34int (*PicoScanBegin)(unsigned int num) = NULL;\r
35int (*PicoScanEnd) (unsigned int num) = NULL;\r
cc68a136 36\r
ea8c405f 37static unsigned char DefHighCol[8+320+8];\r
5a681086 38static unsigned char *HighColBase = DefHighCol;\r
39static int HighColIncrement;\r
40\r
87b0845f 41static unsigned int DefOutBuff[320*2/2];\r
5a681086 42void *DrawLineDestBase = DefOutBuff;\r
43int DrawLineDestIncrement;\r
ea8c405f 44\r
cc68a136 45static int HighCacheA[41+1]; // caches for high layers\r
46static int HighCacheB[41+1];\r
99bdfd31 47static int HighPreSpr[80*2+1]; // slightly preprocessed sprites\r
381eea9b 48\r
fbc65db7 49#define SPRL_HAVE_HI 0x80 // have hi priority sprites\r
50#define SPRL_HAVE_LO 0x40 // *lo*\r
51#define SPRL_MAY_HAVE_OP 0x20 // may have operator sprites on the line\r
52#define SPRL_LO_ABOVE_HI 0x10 // low priority sprites may be on top of hi\r
53unsigned char HighLnSpr[240][3 + MAX_LINE_SPRITES]; // sprite_count, ^flags, tile_count, [spritep]...\r
d9fc2fe1 54\r
ea38612f 55int rendstatus_old;\r
ae87bffa 56int rendlines;\r
fbc65db7 57int PicoDrawMask = -1;\r
cc68a136 58\r
602133e1 59static int skip_next_line=0;\r
60\r
cc68a136 61//unsigned short ppt[] = { 0x0f11, 0x0ff1, 0x01f1, 0x011f, 0x01ff, 0x0f1f, 0x0f0e, 0x0e7c };\r
62\r
63struct TileStrip\r
64{\r
65 int nametab; // Position in VRAM of name table (for this tile line)\r
6d7acf9e 66 int line; // Line number in pixels 0x000-0x3ff within the virtual tilemap\r
cc68a136 67 int hscroll; // Horizontal scroll value in pixels for the line\r
68 int xmask; // X-Mask (0x1f - 0x7f) for horizontal wraparound in the tilemap\r
69 int *hc; // cache for high tile codes and their positions\r
70 int cells; // cells (tiles) to draw (32 col mode doesn't need to update whole 320)\r
71};\r
72\r
73// stuff available in asm:\r
74#ifdef _ASM_DRAW_C\r
ea38612f 75void DrawWindow(int tstart, int tend, int prio, int sh,\r
76 struct PicoEState *est);\r
77void DrawAllSprites(unsigned char *sprited, int prio, int sh,\r
78 struct PicoEState *est);\r
79void DrawTilesFromCache(int *hc, int sh, int rlim,\r
80 struct PicoEState *est);\r
81void DrawSpritesSHi(unsigned char *sprited, struct PicoEState *est);\r
82void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells,\r
83 struct PicoEState *est);\r
7b802576 84void *blockcpy(void *dst, const void *src, size_t n);\r
cc68a136 85void blockcpy_or(void *dst, void *src, size_t n, int pat);\r
86#else\r
87// utility\r
88void blockcpy_or(void *dst, void *src, size_t n, int pat)\r
89{\r
90 unsigned char *pd = dst, *ps = src;\r
91 for (; n; n--)\r
92 *pd++ = (unsigned char) (*ps++ | pat);\r
93}\r
7b802576 94#define blockcpy memcpy\r
cc68a136 95#endif\r
96\r
97\r
07abbab1 98#define TileNormMaker(funcname,pix_func) \\r
99static int funcname(int sx,int addr,int pal) \\r
100{ \\r
99bdfd31 101 unsigned char *pd = Pico.est.HighCol+sx; \\r
07abbab1 102 unsigned int pack=0; unsigned int t=0; \\r
103 \\r
104 pack=*(unsigned int *)(Pico.vram+addr); /* Get 8 pixels */ \\r
105 if (pack) \\r
106 { \\r
107 t=(pack&0x0000f000)>>12; pix_func(0); \\r
108 t=(pack&0x00000f00)>> 8; pix_func(1); \\r
109 t=(pack&0x000000f0)>> 4; pix_func(2); \\r
110 t=(pack&0x0000000f) ; pix_func(3); \\r
111 t=(pack&0xf0000000)>>28; pix_func(4); \\r
112 t=(pack&0x0f000000)>>24; pix_func(5); \\r
113 t=(pack&0x00f00000)>>20; pix_func(6); \\r
114 t=(pack&0x000f0000)>>16; pix_func(7); \\r
115 return 0; \\r
116 } \\r
117 \\r
118 return 1; /* Tile blank */ \\r
cc68a136 119}\r
120\r
cc68a136 121\r
07abbab1 122#define TileFlipMaker(funcname,pix_func) \\r
123static int funcname(int sx,int addr,int pal) \\r
124{ \\r
99bdfd31 125 unsigned char *pd = Pico.est.HighCol+sx; \\r
07abbab1 126 unsigned int pack=0; unsigned int t=0; \\r
127 \\r
128 pack=*(unsigned int *)(Pico.vram+addr); /* Get 8 pixels */ \\r
129 if (pack) \\r
130 { \\r
131 t=(pack&0x000f0000)>>16; pix_func(0); \\r
132 t=(pack&0x00f00000)>>20; pix_func(1); \\r
133 t=(pack&0x0f000000)>>24; pix_func(2); \\r
134 t=(pack&0xf0000000)>>28; pix_func(3); \\r
135 t=(pack&0x0000000f) ; pix_func(4); \\r
136 t=(pack&0x000000f0)>> 4; pix_func(5); \\r
137 t=(pack&0x00000f00)>> 8; pix_func(6); \\r
138 t=(pack&0x0000f000)>>12; pix_func(7); \\r
139 return 0; \\r
140 } \\r
141 \\r
142 return 1; /* Tile blank */ \\r
cc68a136 143}\r
cc68a136 144\r
cc68a136 145\r
07abbab1 146#ifdef _ASM_DRAW_C_AMIPS\r
147int TileNorm(int sx,int addr,int pal);\r
148int TileFlip(int sx,int addr,int pal);\r
149#else\r
cc68a136 150\r
07abbab1 151#define pix_just_write(x) \\r
152 if (t) pd[x]=pal|t\r
cc68a136 153\r
07abbab1 154TileNormMaker(TileNorm,pix_just_write)\r
155TileFlipMaker(TileFlip,pix_just_write)\r
cc68a136 156\r
cc68a136 157#endif\r
158\r
e352c3af 159#ifndef _ASM_DRAW_C\r
160\r
07abbab1 161// draw a sprite pixel, process operator colors\r
162#define pix_sh(x) \\r
163 if (!t); \\r
40644bfe 164 else if (t>=0xe) pd[x]=(pd[x]&0x3f)|(t<<6); /* c0 shadow, 80 hilight */ \\r
07abbab1 165 else pd[x]=pal|t\r
e5fa9817 166\r
07abbab1 167TileNormMaker(TileNormSH, pix_sh)\r
168TileFlipMaker(TileFlipSH, pix_sh)\r
cc68a136 169\r
40644bfe 170// draw a sprite pixel, mark operator colors\r
171#define pix_sh_markop(x) \\r
172 if (!t); \\r
173 else if (t>=0xe) pd[x]|=0x80; \\r
174 else pd[x]=pal|t\r
cc68a136 175\r
40644bfe 176TileNormMaker(TileNormSH_markop, pix_sh_markop)\r
177TileFlipMaker(TileFlipSH_markop, pix_sh_markop)\r
6c254710 178\r
40644bfe 179// process operator pixels only, apply only on low pri tiles and other op pixels\r
07abbab1 180#define pix_sh_onlyop(x) \\r
40644bfe 181 if (t>=0xe && (pd[x]&0xc0)) \\r
182 pd[x]=(pd[x]&0x3f)|(t<<6); /* c0 shadow, 80 hilight */ \\r
cc68a136 183\r
07abbab1 184TileNormMaker(TileNormSH_onlyop_lp, pix_sh_onlyop)\r
185TileFlipMaker(TileFlipSH_onlyop_lp, pix_sh_onlyop)\r
cc68a136 186\r
e352c3af 187#endif\r
188\r
07abbab1 189// draw a sprite pixel (AS)\r
190#define pix_as(x) \\r
191 if (t && !(pd[x]&0x80)) pd[x]=pal|t\r
cc68a136 192\r
07abbab1 193TileNormMaker(TileNormAS, pix_as)\r
194TileFlipMaker(TileFlipAS, pix_as)\r
cc68a136 195\r
07abbab1 196// draw a sprite pixel, skip operator colors (AS)\r
197#define pix_sh_as_noop(x) \\r
198 if (t && t < 0xe && !(pd[x]&0x80)) pd[x]=pal|t\r
cc68a136 199\r
07abbab1 200TileNormMaker(TileNormAS_noop, pix_sh_as_noop)\r
201TileFlipMaker(TileFlipAS_noop, pix_sh_as_noop)\r
cc68a136 202\r
07abbab1 203// mark pixel as sprite pixel (AS)\r
204#define pix_sh_as_onlymark(x) \\r
205 if (t) pd[x]|=0x80\r
cc68a136 206\r
07abbab1 207TileNormMaker(TileNormAS_onlymark, pix_sh_as_onlymark)\r
208TileFlipMaker(TileFlipAS_onlymark, pix_sh_as_onlymark)\r
cc68a136 209\r
e5fa9817 210\r
cc68a136 211// --------------------------------------------\r
212\r
213#ifndef _ASM_DRAW_C\r
83c093a4 214static void DrawStrip(struct TileStrip *ts, int plane_sh, int cellskip)\r
cc68a136 215{\r
83c093a4 216 int tilex,dx,ty,code=0,addr=0,cells;\r
cc68a136 217 int oldcode=-1,blank=-1; // The tile we know is blank\r
83c093a4 218 int pal=0,sh;\r
cc68a136 219\r
220 // Draw tiles across screen:\r
83c093a4 221 sh=(plane_sh<<5)&0x40;\r
222 tilex=((-ts->hscroll)>>3)+cellskip;\r
cc68a136 223 ty=(ts->line&7)<<1; // Y-Offset into tile\r
224 dx=((ts->hscroll-1)&7)+1;\r
83c093a4 225 cells = ts->cells - cellskip;\r
cc68a136 226 if(dx != 8) cells++; // have hscroll, need to draw 1 cell more\r
83c093a4 227 dx+=cellskip<<3;\r
cc68a136 228\r
83c093a4 229 for (; cells > 0; dx+=8,tilex++,cells--)\r
cc68a136 230 {\r
231 int zero=0;\r
232\r
233 code=Pico.vram[ts->nametab+(tilex&ts->xmask)];\r
234 if (code==blank) continue;\r
235 if (code>>15) { // high priority tile\r
236 int cval = code | (dx<<16) | (ty<<25);\r
237 if(code&0x1000) cval^=7<<26;\r
238 *ts->hc++ = cval; // cache it\r
239 continue;\r
240 }\r
241\r
242 if (code!=oldcode) {\r
243 oldcode = code;\r
244 // Get tile address/2:\r
245 addr=(code&0x7ff)<<4;\r
246 addr+=ty;\r
247 if (code&0x1000) addr^=0xe; // Y-flip\r
248\r
83c093a4 249 pal=((code>>9)&0x30)|sh;\r
cc68a136 250 }\r
251\r
252 if (code&0x0800) zero=TileFlip(dx,addr,pal);\r
253 else zero=TileNorm(dx,addr,pal);\r
254\r
255 if (zero) blank=code; // We know this tile is blank now\r
256 }\r
257\r
258 // terminate the cache list\r
259 *ts->hc = 0;\r
740da8c6 260 // if oldcode wasn't changed, it means all layer is hi priority\r
ea38612f 261 if (oldcode == -1) Pico.est.rendstatus |= PDRAW_PLANE_HI_PRIO;\r
cc68a136 262}\r
cc68a136 263\r
264// this is messy\r
83c093a4 265void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip)\r
cc68a136 266{\r
83c093a4 267 int tilex,dx,code=0,addr=0,cell=0;\r
cc68a136 268 int oldcode=-1,blank=-1; // The tile we know is blank\r
ea38612f 269 int pal=0,scan=Pico.est.DrawScanline;\r
cc68a136 270\r
271 // Draw tiles across screen:\r
272 tilex=(-ts->hscroll)>>3;\r
273 dx=((ts->hscroll-1)&7)+1;\r
83c093a4 274 if(dx != 8) cell--; // have hscroll, start with negative cell\r
275 cell+=cellskip;\r
276 tilex+=cellskip;\r
277 dx+=cellskip<<3;\r
cc68a136 278\r
279 for (; cell < ts->cells; dx+=8,tilex++,cell++)\r
280 {\r
83c093a4 281 int zero=0,nametabadd,ty;\r
cc68a136 282\r
83c093a4 283 //if((cell&1)==0)\r
284 {\r
cc68a136 285 int line,vscroll;\r
83c093a4 286 vscroll=Pico.vsram[(plane_sh&1)+(cell&~1)];\r
cc68a136 287\r
288 // Find the line in the name table\r
289 line=(vscroll+scan)&ts->line&0xffff; // ts->line is really ymask ..\r
290 nametabadd=(line>>3)<<(ts->line>>24); // .. and shift[width]\r
291 ty=(line&7)<<1; // Y-Offset into tile\r
292 }\r
293\r
294 code=Pico.vram[ts->nametab+nametabadd+(tilex&ts->xmask)];\r
295 if (code==blank) continue;\r
296 if (code>>15) { // high priority tile\r
297 int cval = code | (dx<<16) | (ty<<25);\r
298 if(code&0x1000) cval^=7<<26;\r
299 *ts->hc++ = cval; // cache it\r
300 continue;\r
301 }\r
302\r
303 if (code!=oldcode) {\r
304 oldcode = code;\r
305 // Get tile address/2:\r
306 addr=(code&0x7ff)<<4;\r
307 if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip\r
308\r
83c093a4 309 pal=((code>>9)&0x30)|((plane_sh<<5)&0x40);\r
cc68a136 310 }\r
311\r
312 if (code&0x0800) zero=TileFlip(dx,addr,pal);\r
313 else zero=TileNorm(dx,addr,pal);\r
314\r
315 if (zero) blank=code; // We know this tile is blank now\r
316 }\r
317\r
318 // terminate the cache list\r
319 *ts->hc = 0;\r
ea38612f 320 if (oldcode == -1) Pico.est.rendstatus |= PDRAW_PLANE_HI_PRIO;\r
cc68a136 321}\r
6d7acf9e 322#endif\r
cc68a136 323\r
324#ifndef _ASM_DRAW_C\r
325static\r
326#endif\r
327void DrawStripInterlace(struct TileStrip *ts)\r
328{\r
329 int tilex=0,dx=0,ty=0,code=0,addr=0,cells;\r
330 int oldcode=-1,blank=-1; // The tile we know is blank\r
331 int pal=0;\r
332\r
333 // Draw tiles across screen:\r
334 tilex=(-ts->hscroll)>>3;\r
335 ty=(ts->line&15)<<1; // Y-Offset into tile\r
336 dx=((ts->hscroll-1)&7)+1;\r
337 cells = ts->cells;\r
338 if(dx != 8) cells++; // have hscroll, need to draw 1 cell more\r
339\r
340 for (; cells; dx+=8,tilex++,cells--)\r
341 {\r
342 int zero=0;\r
343\r
344 code=Pico.vram[ts->nametab+(tilex&ts->xmask)];\r
345 if (code==blank) continue;\r
346 if (code>>15) { // high priority tile\r
347 int cval = (code&0xfc00) | (dx<<16) | (ty<<25);\r
348 cval|=(code&0x3ff)<<1;\r
349 if(code&0x1000) cval^=0xf<<26;\r
350 *ts->hc++ = cval; // cache it\r
351 continue;\r
352 }\r
353\r
354 if (code!=oldcode) {\r
355 oldcode = code;\r
356 // Get tile address/2:\r
357 addr=(code&0x7ff)<<5;\r
358 if (code&0x1000) addr+=30-ty; else addr+=ty; // Y-flip\r
359\r
360// pal=Pico.cram+((code>>9)&0x30);\r
361 pal=((code>>9)&0x30);\r
362 }\r
363\r
364 if (code&0x0800) zero=TileFlip(dx,addr,pal);\r
365 else zero=TileNorm(dx,addr,pal);\r
366\r
367 if (zero) blank=code; // We know this tile is blank now\r
368 }\r
369\r
370 // terminate the cache list\r
371 *ts->hc = 0;\r
372}\r
373\r
374// --------------------------------------------\r
375\r
376#ifndef _ASM_DRAW_C\r
ea38612f 377static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells,\r
378 struct PicoEState *est)\r
cc68a136 379{\r
380 struct PicoVideo *pvid=&Pico.video;\r
381 const char shift[4]={5,6,5,7}; // 32,64 or 128 sized tilemaps (2 is invalid)\r
382 struct TileStrip ts;\r
383 int width, height, ymask;\r
384 int vscroll, htab;\r
385\r
386 ts.hc=hcache;\r
387 ts.cells=maxcells;\r
388\r
389 // Work out the TileStrip to draw\r
390\r
391 // Work out the name table size: 32 64 or 128 tiles (0-3)\r
392 width=pvid->reg[16];\r
393 height=(width>>4)&3; width&=3;\r
394\r
395 ts.xmask=(1<<shift[width])-1; // X Mask in tiles (0x1f-0x7f)\r
396 ymask=(height<<8)|0xff; // Y Mask in pixels\r
eced0190 397 switch (width) {\r
398 case 1: ymask &= 0x1ff; break;\r
399 case 2: ymask = 0x007; break;\r
400 case 3: ymask = 0x0ff; break;\r
401 }\r
cc68a136 402\r
403 // Find name table:\r
83c093a4 404 if (plane_sh&1) ts.nametab=(pvid->reg[4]&0x07)<<12; // B\r
405 else ts.nametab=(pvid->reg[2]&0x38)<< 9; // A\r
cc68a136 406\r
407 htab=pvid->reg[13]<<9; // Horizontal scroll table address\r
ea38612f 408 if ( pvid->reg[11]&2) htab+=est->DrawScanline<<1; // Offset by line\r
cc68a136 409 if ((pvid->reg[11]&1)==0) htab&=~0xf; // Offset by tile\r
83c093a4 410 htab+=plane_sh&1; // A or B\r
cc68a136 411\r
412 // Get horizontal scroll value, will be masked later\r
413 ts.hscroll=Pico.vram[htab&0x7fff];\r
414\r
415 if((pvid->reg[12]&6) == 6) {\r
416 // interlace mode 2\r
83c093a4 417 vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value\r
cc68a136 418\r
419 // Find the line in the name table\r
ea38612f 420 ts.line=(vscroll+(est->DrawScanline<<1))&((ymask<<1)|1);\r
cc68a136 421 ts.nametab+=(ts.line>>4)<<shift[width];\r
422\r
423 DrawStripInterlace(&ts);\r
424 } else if( pvid->reg[11]&4) {\r
425 // shit, we have 2-cell column based vscroll\r
426 // luckily this doesn't happen too often\r
427 ts.line=ymask|(shift[width]<<24); // save some stuff instead of line\r
83c093a4 428 DrawStripVSRam(&ts, plane_sh, cellskip);\r
cc68a136 429 } else {\r
83c093a4 430 vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value\r
cc68a136 431\r
432 // Find the line in the name table\r
ea38612f 433 ts.line=(vscroll+est->DrawScanline)&ymask;\r
cc68a136 434 ts.nametab+=(ts.line>>3)<<shift[width];\r
435\r
83c093a4 436 DrawStrip(&ts, plane_sh, cellskip);\r
cc68a136 437 }\r
438}\r
439\r
440\r
441// --------------------------------------------\r
442\r
443// tstart & tend are tile pair numbers\r
ea38612f 444static void DrawWindow(int tstart, int tend, int prio, int sh,\r
445 struct PicoEState *est)\r
cc68a136 446{\r
447 struct PicoVideo *pvid=&Pico.video;\r
07abbab1 448 int tilex,ty,nametab,code=0;\r
cc68a136 449 int blank=-1; // The tile we know is blank\r
450\r
451 // Find name table line:\r
452 if (pvid->reg[12]&1)\r
453 {\r
454 nametab=(pvid->reg[3]&0x3c)<<9; // 40-cell mode\r
ea38612f 455 nametab+=(est->DrawScanline>>3)<<6;\r
cc68a136 456 }\r
457 else\r
458 {\r
459 nametab=(pvid->reg[3]&0x3e)<<9; // 32-cell mode\r
ea38612f 460 nametab+=(est->DrawScanline>>3)<<5;\r
cc68a136 461 }\r
462\r
463 tilex=tstart<<1;\r
cc68a136 464\r
ea38612f 465 if (!(est->rendstatus & PDRAW_WND_DIFF_PRIO)) {\r
cc68a136 466 // check the first tile code\r
467 code=Pico.vram[nametab+tilex];\r
468 // if the whole window uses same priority (what is often the case), we may be able to skip this field\r
602133e1 469 if ((code>>15) != prio) return;\r
cc68a136 470 }\r
471\r
07abbab1 472 tend<<=1;\r
ea38612f 473 ty=(est->DrawScanline&7)<<1; // Y-Offset into tile\r
07abbab1 474\r
cc68a136 475 // Draw tiles across screen:\r
81fda4e8 476 if (!sh)\r
cc68a136 477 {\r
81fda4e8 478 for (; tilex < tend; tilex++)\r
479 {\r
480 int addr=0,zero=0;\r
481 int pal;\r
482\r
483 code=Pico.vram[nametab+tilex];\r
602133e1 484 if (code==blank) continue;\r
485 if ((code>>15) != prio) {\r
ea38612f 486 est->rendstatus |= PDRAW_WND_DIFF_PRIO;\r
81fda4e8 487 continue;\r
488 }\r
cc68a136 489\r
81fda4e8 490 pal=((code>>9)&0x30);\r
491\r
492 // Get tile address/2:\r
493 addr=(code&0x7ff)<<4;\r
494 if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip\r
495\r
496 if (code&0x0800) zero=TileFlip(8+(tilex<<3),addr,pal);\r
497 else zero=TileNorm(8+(tilex<<3),addr,pal);\r
498\r
499 if (zero) blank=code; // We know this tile is blank now\r
cc68a136 500 }\r
81fda4e8 501 }\r
502 else\r
503 {\r
504 for (; tilex < tend; tilex++)\r
505 {\r
506 int addr=0,zero=0;\r
07abbab1 507 int pal;\r
81fda4e8 508\r
509 code=Pico.vram[nametab+tilex];\r
510 if(code==blank) continue;\r
511 if((code>>15) != prio) {\r
ea38612f 512 est->rendstatus |= PDRAW_WND_DIFF_PRIO;\r
81fda4e8 513 continue;\r
514 }\r
cc68a136 515\r
81fda4e8 516 pal=((code>>9)&0x30);\r
cc68a136 517\r
07abbab1 518 if (prio) {\r
99bdfd31 519 int *zb = (int *)(est->HighCol+8+(tilex<<3));\r
bfa12428 520 *zb++ &= 0xbfbfbfbf;\r
521 *zb &= 0xbfbfbfbf;\r
cc68a136 522 } else {\r
523 pal |= 0x40;\r
524 }\r
cc68a136 525\r
81fda4e8 526 // Get tile address/2:\r
527 addr=(code&0x7ff)<<4;\r
528 if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip\r
cc68a136 529\r
81fda4e8 530 if (code&0x0800) zero=TileFlip(8+(tilex<<3),addr,pal);\r
531 else zero=TileNorm(8+(tilex<<3),addr,pal);\r
cc68a136 532\r
81fda4e8 533 if (zero) blank=code; // We know this tile is blank now\r
534 }\r
cc68a136 535 }\r
cc68a136 536}\r
537\r
538// --------------------------------------------\r
539\r
81fda4e8 540static void DrawTilesFromCacheShPrep(void)\r
541{\r
602133e1 542 // as some layer has covered whole line with hi priority tiles,\r
40644bfe 543 // we can process whole line and then act as if sh/hi mode was off,\r
544 // but leave lo pri op sprite markers alone\r
99bdfd31 545 int c = 320/4, *zb = (int *)(Pico.est.HighCol+8);\r
ea38612f 546 Pico.est.rendstatus |= PDRAW_SHHI_DONE;\r
602133e1 547 while (c--)\r
81fda4e8 548 {\r
40644bfe 549 *zb++ &= 0xbfbfbfbf;\r
81fda4e8 550 }\r
551}\r
552\r
ea38612f 553static void DrawTilesFromCache(int *hc, int sh, int rlim, struct PicoEState *est)\r
cc68a136 554{\r
740da8c6 555 int code, addr, dx;\r
cc68a136 556 int pal;\r
cc68a136 557\r
558 // *ts->hc++ = code | (dx<<16) | (ty<<25); // cache it\r
559\r
ea38612f 560 if (sh && (est->rendstatus & (PDRAW_SHHI_DONE|PDRAW_PLANE_HI_PRIO)))\r
740da8c6 561 {\r
ea38612f 562 if (!(est->rendstatus & PDRAW_SHHI_DONE))\r
602133e1 563 DrawTilesFromCacheShPrep();\r
740da8c6 564 sh = 0;\r
565 }\r
cc68a136 566\r
81fda4e8 567 if (!sh)\r
740da8c6 568 {\r
81fda4e8 569 short blank=-1; // The tile we know is blank\r
7a7c6476 570 while ((code=*hc++)) {\r
81fda4e8 571 int zero;\r
572 if((short)code == blank) continue;\r
740da8c6 573 // Get tile address/2:\r
574 addr=(code&0x7ff)<<4;\r
575 addr+=(unsigned int)code>>25; // y offset into tile\r
576 dx=(code>>16)&0x1ff;\r
740da8c6 577\r
578 pal=((code>>9)&0x30);\r
7a7c6476 579 if (rlim-dx < 0) goto last_cut_tile;\r
740da8c6 580\r
81fda4e8 581 if (code&0x0800) zero=TileFlip(dx,addr,pal);\r
582 else zero=TileNorm(dx,addr,pal);\r
583\r
584 if (zero) blank=(short)code;\r
cc68a136 585 }\r
740da8c6 586 }\r
587 else\r
588 {\r
7a7c6476 589 while ((code=*hc++)) {\r
81fda4e8 590 unsigned char *zb;\r
740da8c6 591 // Get tile address/2:\r
592 addr=(code&0x7ff)<<4;\r
593 addr+=(unsigned int)code>>25; // y offset into tile\r
594 dx=(code>>16)&0x1ff;\r
99bdfd31 595 zb = est->HighCol+dx;\r
40644bfe 596 *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf;\r
597 *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf;\r
cc68a136 598\r
740da8c6 599 pal=((code>>9)&0x30);\r
7a7c6476 600 if (rlim-dx < 0) goto last_cut_tile;\r
cc68a136 601\r
81fda4e8 602 if (code&0x0800) TileFlip(dx,addr,pal);\r
603 else TileNorm(dx,addr,pal);\r
7a7c6476 604 }\r
605 }\r
606 return;\r
607\r
608last_cut_tile:\r
609 {\r
610 unsigned int t, pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels\r
99bdfd31 611 unsigned char *pd = est->HighCol+dx;\r
7a7c6476 612 if (!pack) return;\r
613 if (code&0x0800)\r
614 {\r
615 switch (rlim-dx+8)\r
616 {\r
617 case 7: t=pack&0x00000f00; if (t) pd[6]=(unsigned char)(pal|(t>> 8)); // "break" is left out intentionally\r
618 case 6: t=pack&0x000000f0; if (t) pd[5]=(unsigned char)(pal|(t>> 4));\r
619 case 5: t=pack&0x0000000f; if (t) pd[4]=(unsigned char)(pal|(t ));\r
620 case 4: t=pack&0xf0000000; if (t) pd[3]=(unsigned char)(pal|(t>>28));\r
621 case 3: t=pack&0x0f000000; if (t) pd[2]=(unsigned char)(pal|(t>>24));\r
622 case 2: t=pack&0x00f00000; if (t) pd[1]=(unsigned char)(pal|(t>>20));\r
623 case 1: t=pack&0x000f0000; if (t) pd[0]=(unsigned char)(pal|(t>>16));\r
624 default: break;\r
625 }\r
626 }\r
627 else\r
628 {\r
629 switch (rlim-dx+8)\r
630 {\r
631 case 7: t=pack&0x00f00000; if (t) pd[6]=(unsigned char)(pal|(t>>20));\r
947fb5f9 632 case 6: t=pack&0x0f000000; if (t) pd[5]=(unsigned char)(pal|(t>>24));\r
633 case 5: t=pack&0xf0000000; if (t) pd[4]=(unsigned char)(pal|(t>>28));\r
634 case 4: t=pack&0x0000000f; if (t) pd[3]=(unsigned char)(pal|(t ));\r
635 case 3: t=pack&0x000000f0; if (t) pd[2]=(unsigned char)(pal|(t>> 4));\r
636 case 2: t=pack&0x00000f00; if (t) pd[1]=(unsigned char)(pal|(t>> 8));\r
637 case 1: t=pack&0x0000f000; if (t) pd[0]=(unsigned char)(pal|(t>>12));\r
638 default: break;\r
7a7c6476 639 }\r
740da8c6 640 }\r
cc68a136 641 }\r
642}\r
643\r
644// --------------------------------------------\r
645\r
646// Index + 0 : hhhhvvvv ab--hhvv yyyyyyyy yyyyyyyy // a: offscreen h, b: offs. v, h: horiz. size\r
647// Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8\r
648\r
97a7f774 649static void DrawSprite(int *sprite, int sh)\r
cc68a136 650{\r
651 int width=0,height=0;\r
652 int row=0,code=0;\r
653 int pal;\r
654 int tile=0,delta=0;\r
655 int sx, sy;\r
656 int (*fTileFunc)(int sx,int addr,int pal);\r
657\r
658 // parse the sprite data\r
659 sy=sprite[0];\r
660 code=sprite[1];\r
661 sx=code>>16; // X\r
662 width=sy>>28;\r
663 height=(sy>>24)&7; // Width and height in tiles\r
664 sy=(sy<<16)>>16; // Y\r
665\r
ea38612f 666 row=Pico.est.DrawScanline-sy; // Row of the sprite we are on\r
cc68a136 667\r
668 if (code&0x1000) row=(height<<3)-1-row; // Flip Y\r
669\r
07abbab1 670 tile=code + (row>>3); // Tile number increases going down\r
cc68a136 671 delta=height; // Delta to increase tile by going right\r
672 if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X\r
673\r
07abbab1 674 tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address\r
ee4f03ae 675 delta<<=4; // Delta of address\r
07abbab1 676\r
677 pal=(code>>9)&0x30;\r
97a7f774 678 pal|=sh<<6;\r
e5fa9817 679\r
680 if (sh && (code&0x6000) == 0x6000) {\r
40644bfe 681 if(code&0x0800) fTileFunc=TileFlipSH_markop;\r
682 else fTileFunc=TileNormSH_markop;\r
e5fa9817 683 } else {\r
684 if(code&0x0800) fTileFunc=TileFlip;\r
685 else fTileFunc=TileNorm;\r
cc68a136 686 }\r
687\r
688 for (; width; width--,sx+=8,tile+=delta)\r
689 {\r
690 if(sx<=0) continue;\r
691 if(sx>=328) break; // Offscreen\r
692\r
693 tile&=0x7fff; // Clip tile address\r
e5fa9817 694 fTileFunc(sx,tile,pal);\r
cc68a136 695 }\r
696}\r
e5fa9817 697#endif\r
cc68a136 698\r
699static void DrawSpriteInterlace(unsigned int *sprite)\r
700{\r
701 int width=0,height=0;\r
702 int row=0,code=0;\r
703 int pal;\r
704 int tile=0,delta=0;\r
705 int sx, sy;\r
706\r
707 // parse the sprite data\r
708 sy=sprite[0];\r
709 height=sy>>24;\r
710 sy=(sy&0x3ff)-0x100; // Y\r
711 width=(height>>2)&3; height&=3;\r
712 width++; height++; // Width and height in tiles\r
713\r
ea38612f 714 row=(Pico.est.DrawScanline<<1)-sy; // Row of the sprite we are on\r
cc68a136 715\r
716 code=sprite[1];\r
717 sx=((code>>16)&0x1ff)-0x78; // X\r
718\r
719 if (code&0x1000) row^=(16<<height)-1; // Flip Y\r
720\r
721 tile=code&0x3ff; // Tile number\r
722 tile+=row>>4; // Tile number increases going down\r
723 delta=height; // Delta to increase tile by going right\r
724 if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X\r
725\r
726 tile<<=5; tile+=(row&15)<<1; // Tile address\r
727\r
728 delta<<=5; // Delta of address\r
729 pal=((code>>9)&0x30); // Get palette pointer\r
730\r
731 for (; width; width--,sx+=8,tile+=delta)\r
732 {\r
733 if(sx<=0) continue;\r
734 if(sx>=328) break; // Offscreen\r
735\r
736 tile&=0x7fff; // Clip tile address\r
737 if (code&0x0800) TileFlip(sx,tile,pal);\r
738 else TileNorm(sx,tile,pal);\r
739 }\r
740}\r
741\r
742\r
ee4f03ae 743static void DrawAllSpritesInterlace(int pri, int sh)\r
cc68a136 744{\r
745 struct PicoVideo *pvid=&Pico.video;\r
ea38612f 746 int i,u,table,link=0,sline=Pico.est.DrawScanline<<1;\r
cc68a136 747 unsigned int *sprites[80]; // Sprite index\r
748\r
749 table=pvid->reg[5]&0x7f;\r
750 if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode\r
751 table<<=8; // Get sprite table address/2\r
752\r
753 for (i=u=0; u < 80 && i < 21; u++)\r
754 {\r
755 unsigned int *sprite;\r
756 int code, sx, sy, height;\r
757\r
758 sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite\r
759\r
760 // get sprite info\r
761 code = sprite[0];\r
762 sx = sprite[1];\r
763 if(((sx>>15)&1) != pri) goto nextsprite; // wrong priority sprite\r
764\r
765 // check if it is on this line\r
766 sy = (code&0x3ff)-0x100;\r
767 height = (((code>>24)&3)+1)<<4;\r
768 if(sline < sy || sline >= sy+height) goto nextsprite; // no\r
769\r
770 // check if sprite is not hidden offscreen\r
771 sx = (sx>>16)&0x1ff;\r
772 sx -= 0x78; // Get X coordinate + 8\r
947fb5f9 773 if(sx <= -8*3 || sx >= 328) goto nextsprite;\r
cc68a136 774\r
775 // sprite is good, save it's pointer\r
776 sprites[i++]=sprite;\r
777\r
778 nextsprite:\r
779 // Find next sprite\r
780 link=(code>>16)&0x7f;\r
781 if(!link) break; // End of sprites\r
782 }\r
783\r
784 // Go through sprites backwards:\r
785 for (i-- ;i>=0; i--)\r
786 DrawSpriteInterlace(sprites[i]);\r
787}\r
788\r
789\r
790#ifndef _ASM_DRAW_C\r
40644bfe 791/*\r
792 * s/h drawing: lo_layers|40, lo_sprites|40 && mark_op,\r
793 * hi_layers&=~40, hi_sprites\r
794 *\r
795 * Index + 0 : hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: vert./horiz. size\r
796 * Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8\r
797 */\r
ea38612f 798static void DrawSpritesSHi(unsigned char *sprited, const struct PicoEState *est)\r
cc68a136 799{\r
cc68a136 800 int (*fTileFunc)(int sx,int addr,int pal);\r
ee4f03ae 801 unsigned char *p;\r
802 int cnt;\r
803\r
fbc65db7 804 cnt = sprited[0] & 0x7f;\r
ee4f03ae 805 if (cnt == 0) return;\r
cc68a136 806\r
fbc65db7 807 p = &sprited[3];\r
cc68a136 808\r
ee4f03ae 809 // Go through sprites backwards:\r
810 for (cnt--; cnt >= 0; cnt--)\r
07abbab1 811 {\r
ee4f03ae 812 int *sprite, code, pal, tile, sx, sy;\r
813 int offs, delta, width, height, row;\r
814\r
815 offs = (p[cnt] & 0x7f) * 2;\r
99bdfd31 816 sprite = est->HighPreSpr + offs;\r
ee4f03ae 817 code = sprite[1];\r
818 pal = (code>>9)&0x30;\r
cc68a136 819\r
fbc65db7 820 if (pal == 0x30)\r
07abbab1 821 {\r
ee4f03ae 822 if (code & 0x8000) // hi priority\r
07abbab1 823 {\r
ee4f03ae 824 if (code&0x800) fTileFunc=TileFlipSH;\r
825 else fTileFunc=TileNormSH;\r
07abbab1 826 } else {\r
ee4f03ae 827 if (code&0x800) fTileFunc=TileFlipSH_onlyop_lp;\r
828 else fTileFunc=TileNormSH_onlyop_lp;\r
07abbab1 829 }\r
cc68a136 830 } else {\r
ee4f03ae 831 if (!(code & 0x8000)) continue; // non-operator low sprite, already drawn\r
832 if (code&0x800) fTileFunc=TileFlip;\r
833 else fTileFunc=TileNorm;\r
cc68a136 834 }\r
835\r
ee4f03ae 836 // parse remaining sprite data\r
837 sy=sprite[0];\r
838 sx=code>>16; // X\r
839 width=sy>>28;\r
840 height=(sy>>24)&7; // Width and height in tiles\r
841 sy=(sy<<16)>>16; // Y\r
842\r
ea38612f 843 row=est->DrawScanline-sy; // Row of the sprite we are on\r
ee4f03ae 844\r
845 if (code&0x1000) row=(height<<3)-1-row; // Flip Y\r
846\r
847 tile=code + (row>>3); // Tile number increases going down\r
848 delta=height; // Delta to increase tile by going right\r
849 if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X\r
850\r
851 tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address\r
852 delta<<=4; // Delta of address\r
853\r
cc68a136 854 for (; width; width--,sx+=8,tile+=delta)\r
855 {\r
856 if(sx<=0) continue;\r
857 if(sx>=328) break; // Offscreen\r
858\r
859 tile&=0x7fff; // Clip tile address\r
860 fTileFunc(sx,tile,pal);\r
861 }\r
862 }\r
863}\r
f8af9634 864#endif // !_ASM_DRAW_C\r
cc68a136 865\r
fbc65db7 866static void DrawSpritesHiAS(unsigned char *sprited, int sh)\r
e5fa9817 867{\r
e5fa9817 868 int (*fTileFunc)(int sx,int addr,int pal);\r
ee4f03ae 869 unsigned char *p;\r
870 int entry, cnt, sh_cnt = 0;\r
871\r
fbc65db7 872 cnt = sprited[0] & 0x7f;\r
ee4f03ae 873 if (cnt == 0) return;\r
e5fa9817 874\r
ea38612f 875 Pico.est.rendstatus |= PDRAW_SPR_LO_ON_HI;\r
f8af9634 876\r
fbc65db7 877 p = &sprited[3];\r
e5fa9817 878\r
ee4f03ae 879 // Go through sprites:\r
880 for (entry = 0; entry < cnt; entry++)\r
07abbab1 881 {\r
ee4f03ae 882 int *sprite, code, pal, tile, sx, sy;\r
883 int offs, delta, width, height, row;\r
884\r
885 offs = (p[entry] & 0x7f) * 2;\r
886 sprite = HighPreSpr + offs;\r
887 code = sprite[1];\r
888 pal = (code>>9)&0x30;\r
889\r
890 if (code & 0x8000) // hi priority\r
07abbab1 891 {\r
892 if (sh && pal == 0x30)\r
893 {\r
ee4f03ae 894 if (code&0x800) fTileFunc=TileFlipAS_noop;\r
895 else fTileFunc=TileNormAS_noop;\r
07abbab1 896 } else {\r
ee4f03ae 897 if (code&0x800) fTileFunc=TileFlipAS;\r
898 else fTileFunc=TileNormAS;\r
07abbab1 899 }\r
e5fa9817 900 } else {\r
ee4f03ae 901 if (code&0x800) fTileFunc=TileFlipAS_onlymark;\r
902 else fTileFunc=TileNormAS_onlymark;\r
e5fa9817 903 }\r
411cba90 904 if (sh && pal == 0x30)\r
ee4f03ae 905 p[sh_cnt++] = offs / 2; // re-save for sh/hi pass\r
906\r
907 // parse remaining sprite data\r
908 sy=sprite[0];\r
909 sx=code>>16; // X\r
910 width=sy>>28;\r
911 height=(sy>>24)&7; // Width and height in tiles\r
912 sy=(sy<<16)>>16; // Y\r
913\r
ea38612f 914 row=Pico.est.DrawScanline-sy; // Row of the sprite we are on\r
ee4f03ae 915\r
916 if (code&0x1000) row=(height<<3)-1-row; // Flip Y\r
917\r
918 tile=code + (row>>3); // Tile number increases going down\r
919 delta=height; // Delta to increase tile by going right\r
920 if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X\r
921\r
922 tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address\r
923 delta<<=4; // Delta of address\r
e5fa9817 924\r
07abbab1 925 pal |= 0x80;\r
926 for (; width; width--,sx+=8,tile+=delta)\r
927 {\r
928 if(sx<=0) continue;\r
929 if(sx>=328) break; // Offscreen\r
930\r
931 tile&=0x7fff; // Clip tile address\r
932 fTileFunc(sx,tile,pal);\r
933 }\r
934 }\r
935\r
fbc65db7 936 if (!sh || !(sprited[1]&SPRL_MAY_HAVE_OP)) return;\r
07abbab1 937\r
938 /* nasty 1: remove 'sprite' flags */\r
939 {\r
99bdfd31 940 int c = 320/4/4, *zb = (int *)(Pico.est.HighCol+8);\r
07abbab1 941 while (c--)\r
942 {\r
bfa12428 943 *zb++ &= 0x7f7f7f7f; *zb++ &= 0x7f7f7f7f;\r
944 *zb++ &= 0x7f7f7f7f; *zb++ &= 0x7f7f7f7f;\r
07abbab1 945 }\r
946 }\r
947\r
ee4f03ae 948 /* nasty 2: sh operator pass */\r
fbc65db7 949 sprited[0] = sh_cnt;\r
ea38612f 950 DrawSpritesSHi(sprited, &Pico.est);\r
e5fa9817 951}\r
952\r
cc68a136 953\r
954// Index + 0 : ----hhvv -lllllll -------y yyyyyyyy\r
955// Index + 4 : -------x xxxxxxxx pccvhnnn nnnnnnnn\r
956// v\r
d9fc2fe1 957// Index + 0 : hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: vert./horiz. size\r
cc68a136 958// Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8\r
959\r
6d8782a1 960static NOINLINE void PrepareSprites(int full)\r
cc68a136 961{\r
ea38612f 962 const struct PicoVideo *pvid=&Pico.video;\r
963 const struct PicoEState *est=&Pico.est;\r
fbc65db7 964 int u,link=0,sh;\r
cc68a136 965 int table=0;\r
966 int *pd = HighPreSpr;\r
947fb5f9 967 int max_lines = 224, max_sprites = 80, max_width = 328;\r
d9fc2fe1 968 int max_line_sprites = 20; // 20 sprites, 40 tiles\r
969\r
970 if (!(Pico.video.reg[12]&1))\r
947fb5f9 971 max_sprites = 64, max_line_sprites = 16, max_width = 264;\r
d9fc2fe1 972 if (PicoOpt & POPT_DIS_SPRITE_LIM)\r
973 max_line_sprites = MAX_LINE_SPRITES;\r
974\r
975 if (pvid->reg[1]&8) max_lines = 240;\r
fbc65db7 976 sh = Pico.video.reg[0xC]&8; // shadow/hilight?\r
cc68a136 977\r
978 table=pvid->reg[5]&0x7f;\r
979 if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode\r
980 table<<=8; // Get sprite table address/2\r
981\r
982 if (!full)\r
983 {\r
984 int pack;\r
985 // updates: tilecode, sx\r
4c436138 986 for (u=0; u < max_sprites && (pack = *pd); u++, pd+=2)\r
cc68a136 987 {\r
988 unsigned int *sprite;\r
d9fc2fe1 989 int code2, sx, sy, height;\r
cc68a136 990\r
991 sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite\r
992\r
993 // parse sprite info\r
cc68a136 994 code2 = sprite[1];\r
d9fc2fe1 995 sx = (code2>>16)&0x1ff;\r
996 sx -= 0x78; // Get X coordinate + 8\r
997 sy = (pack << 16) >> 16;\r
947fb5f9 998 height = (pack >> 24) & 0xf;\r
cc68a136 999\r
ea38612f 1000 if (sy < max_lines &&\r
1001 sy + (height<<3) > est->DrawScanline && // sprite onscreen (y)?\r
947fb5f9 1002 (sx > -24 || sx < max_width)) // onscreen x\r
d9fc2fe1 1003 {\r
ea38612f 1004 int y = (sy >= est->DrawScanline) ? sy : est->DrawScanline;\r
ee4f03ae 1005 int entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80);\r
d9fc2fe1 1006 for (; y < sy + (height<<3) && y < max_lines; y++)\r
1007 {\r
947fb5f9 1008 int i, cnt;\r
d9fc2fe1 1009 cnt = HighLnSpr[y][0] & 0x7f;\r
1010 if (cnt >= max_line_sprites) continue; // sprite limit?\r
d9fc2fe1 1011\r
1012 for (i = 0; i < cnt; i++)\r
fbc65db7 1013 if (((HighLnSpr[y][3+i] ^ entry) & 0x7f) == 0) goto found;\r
d9fc2fe1 1014\r
1015 // this sprite was previously missing\r
fbc65db7 1016 HighLnSpr[y][3+cnt] = entry;\r
d9fc2fe1 1017 HighLnSpr[y][0] = cnt + 1;\r
1018found:;\r
e352c3af 1019 if (entry & 0x80)\r
fbc65db7 1020 HighLnSpr[y][1] |= SPRL_HAVE_HI;\r
1021 else HighLnSpr[y][1] |= SPRL_HAVE_LO;\r
d9fc2fe1 1022 }\r
cc68a136 1023 }\r
1024\r
d9fc2fe1 1025 code2 &= ~0xfe000000;\r
1026 code2 -= 0x00780000; // Get X coordinate + 8 in upper 16 bits\r
1027 pd[1] = code2;\r
cc68a136 1028\r
1029 // Find next sprite\r
d9fc2fe1 1030 link=(sprite[0]>>16)&0x7f;\r
1031 if (!link) break; // End of sprites\r
cc68a136 1032 }\r
cc68a136 1033 }\r
1034 else\r
1035 {\r
d9fc2fe1 1036 for (u = 0; u < max_lines; u++)\r
1037 *((int *)&HighLnSpr[u][0]) = 0;\r
1038\r
4c436138 1039 for (u = 0; u < max_sprites; u++)\r
cc68a136 1040 {\r
1041 unsigned int *sprite;\r
d9fc2fe1 1042 int code, code2, sx, sy, hv, height, width;\r
cc68a136 1043\r
1044 sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite\r
1045\r
1046 // parse sprite info\r
1047 code = sprite[0];\r
1048 sy = (code&0x1ff)-0x80;\r
1049 hv = (code>>24)&0xf;\r
1050 height = (hv&3)+1;\r
1051\r
cc68a136 1052 width = (hv>>2)+1;\r
1053 code2 = sprite[1];\r
1054 sx = (code2>>16)&0x1ff;\r
1055 sx -= 0x78; // Get X coordinate + 8\r
6d7acf9e 1056\r
ea38612f 1057 if (sy < max_lines && sy + (height<<3) > est->DrawScanline) // sprite onscreen (y)?\r
d9fc2fe1 1058 {\r
fbc65db7 1059 int entry, y, sx_min, onscr_x, maybe_op = 0;\r
1060\r
1061 sx_min = 8-(width<<3);\r
1062 onscr_x = sx_min < sx && sx < max_width;\r
1063 if (sh && (code2 & 0x6000) == 0x6000)\r
1064 maybe_op = SPRL_MAY_HAVE_OP;\r
1065\r
fbc65db7 1066 entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80);\r
ea38612f 1067 y = (sy >= est->DrawScanline) ? sy : est->DrawScanline;\r
d9fc2fe1 1068 for (; y < sy + (height<<3) && y < max_lines; y++)\r
1069 {\r
0fc0e241 1070 unsigned char *p = &HighLnSpr[y][0];\r
1071 int cnt = p[0];\r
d9fc2fe1 1072 if (cnt >= max_line_sprites) continue; // sprite limit?\r
1073\r
0fc0e241 1074 if (p[2] >= max_line_sprites*2) { // tile limit?\r
1075 p[0] |= 0x80;\r
947fb5f9 1076 continue;\r
d9fc2fe1 1077 }\r
0fc0e241 1078 p[2] += width;\r
d9fc2fe1 1079\r
1080 if (sx == -0x78) {\r
1081 if (cnt > 0)\r
0fc0e241 1082 p[0] |= 0x80; // masked, no more sprites for this line\r
947fb5f9 1083 continue;\r
d9fc2fe1 1084 }\r
1085 // must keep the first sprite even if it's offscreen, for masking\r
fbc65db7 1086 if (cnt > 0 && !onscr_x) continue; // offscreen x\r
d9fc2fe1 1087\r
0fc0e241 1088 p[3+cnt] = entry;\r
1089 p[0] = cnt + 1;\r
1090 p[1] |= (entry & 0x80) ? SPRL_HAVE_HI : SPRL_HAVE_LO;\r
1091 p[1] |= maybe_op; // there might be op sprites on this line\r
1092 if (cnt > 0 && (code2 & 0x8000) && !(p[3+cnt-1]&0x80))\r
1093 p[1] |= SPRL_LO_ABOVE_HI;\r
d9fc2fe1 1094 }\r
cc68a136 1095 }\r
6d7acf9e 1096\r
d9fc2fe1 1097 *pd++ = (width<<28)|(height<<24)|(hv<<16)|((unsigned short)sy);\r
cc68a136 1098 *pd++ = (sx<<16)|((unsigned short)code2);\r
6d7acf9e 1099\r
cc68a136 1100 // Find next sprite\r
1101 link=(code>>16)&0x7f;\r
d9fc2fe1 1102 if (!link) break; // End of sprites\r
cc68a136 1103 }\r
d9fc2fe1 1104 *pd = 0;\r
1105\r
1106#if 0\r
1107 for (u = 0; u < max_lines; u++)\r
1108 {\r
1109 int y;\r
fbc65db7 1110 printf("c%03i: %2i, %2i: ", u, HighLnSpr[u][0] & 0x7f, HighLnSpr[u][2]);\r
d9fc2fe1 1111 for (y = 0; y < HighLnSpr[u][0] & 0x7f; y++)\r
fbc65db7 1112 printf(" %i", HighLnSpr[u][y+3]);\r
d9fc2fe1 1113 printf("\n");\r
1114 }\r
1115#endif\r
cc68a136 1116 }\r
1117}\r
1118\r
283fec1b 1119#ifndef _ASM_DRAW_C\r
ea38612f 1120static void DrawAllSprites(unsigned char *sprited, int prio, int sh,\r
1121 struct PicoEState *est)\r
cc68a136 1122{\r
d9fc2fe1 1123 unsigned char *p;\r
97a7f774 1124 int cnt;\r
cc68a136 1125\r
fbc65db7 1126 cnt = sprited[0] & 0x7f;\r
ee4f03ae 1127 if (cnt == 0) return;\r
cc68a136 1128\r
fbc65db7 1129 p = &sprited[3];\r
cc68a136 1130\r
ee4f03ae 1131 // Go through sprites backwards:\r
1132 for (cnt--; cnt >= 0; cnt--)\r
1133 {\r
1134 int offs;\r
97a7f774 1135 if ((p[cnt] >> 7) != prio) continue;\r
ee4f03ae 1136 offs = (p[cnt]&0x7f) * 2;\r
97a7f774 1137 DrawSprite(HighPreSpr + offs, sh);\r
cc68a136 1138 }\r
cc68a136 1139}\r
1140\r
1141\r
1142// --------------------------------------------\r
1143\r
99bdfd31 1144void BackFill(int reg7, int sh, struct PicoEState *est)\r
cc68a136 1145{\r
b542be46 1146 unsigned int back;\r
cc68a136 1147\r
1148 // Start with a blank scanline (background colour):\r
1149 back=reg7&0x3f;\r
1150 back|=sh<<6;\r
1151 back|=back<<8;\r
1152 back|=back<<16;\r
1153\r
99bdfd31 1154 memset32((int *)(est->HighCol+8), back, 320/4);\r
cc68a136 1155}\r
1156#endif\r
1157\r
1158// --------------------------------------------\r
1159\r
b2305d08 1160#ifndef _ASM_DRAW_C\r
ea38612f 1161void PicoDoHighPal555(int sh, int line, struct PicoEState *est)\r
e55f0cbb 1162{\r
19954be1 1163 unsigned int *spal, *dpal;\r
a39d8ba5 1164 unsigned int t, i;\r
e55f0cbb 1165\r
1166 Pico.m.dirtyPal = 0;\r
1167\r
19954be1 1168 spal = (void *)Pico.cram;\r
98a27142 1169 dpal = (void *)est->HighPal;\r
19954be1 1170\r
a39d8ba5 1171 for (i = 0; i < 0x40 / 2; i++) {\r
1172 t = spal[i];\r
e55f0cbb 1173#ifdef USE_BGR555\r
19954be1 1174 t = ((t & 0x000e000e)<< 1) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)<<4);\r
e55f0cbb 1175#else\r
19954be1 1176 t = ((t & 0x000e000e)<<12) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)>>7);\r
e55f0cbb 1177#endif\r
a39d8ba5 1178 // treat it like it was 4-bit per channel, since in s/h mode it somewhat is that.\r
1179 // otherwise intensity difference between this and s/h will be wrong\r
1180 t |= (t >> 4) & 0x08610861; // 0x18e318e3\r
19954be1 1181 dpal[i] = t;\r
e55f0cbb 1182 }\r
1183\r
a39d8ba5 1184 // norm: xxx0, sh: 0xxx, hi: 0xxx + 7\r
e55f0cbb 1185 if (sh)\r
1186 {\r
1187 // shadowed pixels\r
a39d8ba5 1188 for (i = 0; i < 0x40 / 2; i++)\r
1189 dpal[0x40/2 | i] = dpal[0xc0/2 | i] = (dpal[i] >> 1) & 0x738e738e;\r
e55f0cbb 1190 // hilighted pixels\r
a39d8ba5 1191 for (i = 0; i < 0x40 / 2; i++) {\r
1192 t = ((dpal[i] >> 1) & 0x738e738e) + 0x738e738e; // 0x7bef7bef;\r
1193 t |= (t >> 4) & 0x08610861;\r
1194 dpal[0x80/2 | i] = t;\r
e55f0cbb 1195 }\r
1196 }\r
1197}\r
1198\r
99bdfd31 1199void FinalizeLine555(int sh, int line, struct PicoEState *est)\r
cc68a136 1200{\r
99bdfd31 1201 unsigned short *pd=est->DrawLineDest;\r
1202 unsigned char *ps=est->HighCol+8;\r
98a27142 1203 unsigned short *pal=est->HighPal;\r
e55f0cbb 1204 int len;\r
cc68a136 1205\r
e55f0cbb 1206 if (Pico.m.dirtyPal)\r
ea38612f 1207 PicoDoHighPal555(sh, line, est);\r
cc68a136 1208\r
70357ce5 1209 if (Pico.video.reg[12]&1) {\r
1210 len = 320;\r
1211 } else {\r
602133e1 1212 if (!(PicoOpt&POPT_DIS_32C_BORDER)) pd+=32;\r
70357ce5 1213 len = 256;\r
1214 }\r
1215\r
e5fa9817 1216 {\r
70357ce5 1217#ifndef PSP\r
e55f0cbb 1218 int i, mask=0xff;\r
ea38612f 1219 if (!sh && (est->rendstatus & PDRAW_SPR_LO_ON_HI))\r
e5fa9817 1220 mask=0x3f; // accurate sprites, upper bits are priority stuff\r
1221\r
1222 for (i = 0; i < len; i++)\r
1223 pd[i] = pal[ps[i] & mask];\r
70357ce5 1224#else\r
70357ce5 1225 extern void amips_clut(unsigned short *dst, unsigned char *src, unsigned short *pal, int count);\r
e5fa9817 1226 extern void amips_clut_6bit(unsigned short *dst, unsigned char *src, unsigned short *pal, int count);\r
ea38612f 1227 if (!sh && (est->rendstatus & PDRAW_SPR_LO_ON_HI))\r
e5fa9817 1228 amips_clut_6bit(pd, ps, pal, len);\r
1229 else amips_clut(pd, ps, pal, len);\r
70357ce5 1230#endif\r
e5fa9817 1231 }\r
cc68a136 1232}\r
1233#endif\r
1234\r
ea38612f 1235static void FinalizeLine8bit(int sh, int line, struct PicoEState *est)\r
cc68a136 1236{\r
99bdfd31 1237 unsigned char *pd = est->DrawLineDest;\r
ea38612f 1238 int len, rs = est->rendstatus;\r
cc68a136 1239 static int dirty_count;\r
1240\r
87b0845f 1241 if (!sh && Pico.m.dirtyPal == 1)\r
602133e1 1242 {\r
cc68a136 1243 // a hack for mid-frame palette changes\r
602133e1 1244 if (!(rs & PDRAW_SONIC_MODE))\r
cc68a136 1245 dirty_count = 1;\r
1246 else dirty_count++;\r
602133e1 1247 rs |= PDRAW_SONIC_MODE;\r
ea38612f 1248 est->rendstatus = rs;\r
cc68a136 1249 if (dirty_count == 3) {\r
98a27142 1250 blockcpy(est->HighPal, Pico.cram, 0x40*2);\r
cc68a136 1251 } else if (dirty_count == 11) {\r
98a27142 1252 blockcpy(est->HighPal+0x40, Pico.cram, 0x40*2);\r
cc68a136 1253 }\r
1254 }\r
1255\r
1256 if (Pico.video.reg[12]&1) {\r
1257 len = 320;\r
1258 } else {\r
19954be1 1259 if (!(PicoOpt & POPT_DIS_32C_BORDER))\r
1260 pd += 32;\r
cc68a136 1261 len = 256;\r
1262 }\r
1263\r
602133e1 1264 if (!sh && (rs & PDRAW_SONIC_MODE)) {\r
cc68a136 1265 if (dirty_count >= 11) {\r
99bdfd31 1266 blockcpy_or(pd, est->HighCol+8, len, 0x80);\r
cc68a136 1267 } else {\r
99bdfd31 1268 blockcpy_or(pd, est->HighCol+8, len, 0x40);\r
cc68a136 1269 }\r
1270 } else {\r
99bdfd31 1271 blockcpy(pd, est->HighCol+8, len);\r
cc68a136 1272 }\r
1273}\r
1274\r
ea38612f 1275static void (*FinalizeLine)(int sh, int line, struct PicoEState *est);\r
cc68a136 1276\r
b6d7ac70 1277// --------------------------------------------\r
1278\r
0fc0e241 1279static int DrawDisplay(int sh)\r
cc68a136 1280{\r
ea38612f 1281 struct PicoEState *est=&Pico.est;\r
1282 unsigned char *sprited = &HighLnSpr[est->DrawScanline][0];\r
cc68a136 1283 struct PicoVideo *pvid=&Pico.video;\r
1284 int win=0,edge=0,hvwind=0;\r
fbc65db7 1285 int maxw,maxcells;\r
cc68a136 1286\r
6d8782a1 1287 if (est->rendstatus & (PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES)) {\r
1288 // elprintf(EL_STATUS, "PrepareSprites(%i)", (est->rendstatus>>4)&1);\r
1289 PrepareSprites(est->rendstatus & PDRAW_DIRTY_SPRITES);\r
1290 est->rendstatus &= ~(PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES);\r
1291 }\r
1292\r
ea38612f 1293 est->rendstatus &= ~(PDRAW_SHHI_DONE|PDRAW_PLANE_HI_PRIO);\r
740da8c6 1294\r
fbc65db7 1295 if (pvid->reg[12]&1) {\r
cc68a136 1296 maxw = 328; maxcells = 40;\r
1297 } else {\r
1298 maxw = 264; maxcells = 32;\r
1299 }\r
1300\r
1301 // Find out if the window is on this line:\r
1302 win=pvid->reg[0x12];\r
1303 edge=(win&0x1f)<<3;\r
1304\r
ea38612f 1305 if (win&0x80) { if (est->DrawScanline>=edge) hvwind=1; }\r
1306 else { if (est->DrawScanline< edge) hvwind=1; }\r
cc68a136 1307\r
fbc65db7 1308 if (!hvwind) // we might have a vertical window here\r
1309 {\r
cc68a136 1310 win=pvid->reg[0x11];\r
1311 edge=win&0x1f;\r
7a7c6476 1312 if (win&0x80) {\r
1313 if (!edge) hvwind=1;\r
cc68a136 1314 else if(edge < (maxcells>>1)) hvwind=2;\r
1315 } else {\r
7a7c6476 1316 if (!edge);\r
cc68a136 1317 else if(edge < (maxcells>>1)) hvwind=2;\r
1318 else hvwind=1;\r
1319 }\r
1320 }\r
1321\r
fbc65db7 1322 /* - layer B low - */\r
1323 if (PicoDrawMask & PDRAW_LAYERB_ON)\r
ea38612f 1324 DrawLayer(1|(sh<<1), HighCacheB, 0, maxcells, est);\r
fbc65db7 1325 /* - layer A low - */\r
1326 if (!(PicoDrawMask & PDRAW_LAYERA_ON));\r
1327 else if (hvwind == 1)\r
ea38612f 1328 DrawWindow(0, maxcells>>1, 0, sh, est);\r
7a7c6476 1329 else if (hvwind == 2) {\r
ea38612f 1330 DrawLayer(0|(sh<<1), HighCacheA, (win&0x80) ? 0 : edge<<1, (win&0x80) ? edge<<1 : maxcells, est);\r
1331 DrawWindow( (win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 0, sh, est);\r
cc68a136 1332 } else\r
ea38612f 1333 DrawLayer(0|(sh<<1), HighCacheA, 0, maxcells, est);\r
fbc65db7 1334 /* - sprites low - */\r
1335 if (!(PicoDrawMask & PDRAW_SPRITES_LOW_ON));\r
6d8782a1 1336 else if (est->rendstatus & PDRAW_INTERLACE)\r
fbc65db7 1337 DrawAllSpritesInterlace(0, sh);\r
1338 else if (sprited[1] & SPRL_HAVE_LO)\r
ea38612f 1339 DrawAllSprites(sprited, 0, sh, est);\r
fbc65db7 1340\r
1341 /* - layer B hi - */\r
1342 if ((PicoDrawMask & PDRAW_LAYERB_ON) && HighCacheB[0])\r
ea38612f 1343 DrawTilesFromCache(HighCacheB, sh, maxw, est);\r
fbc65db7 1344 /* - layer A hi - */\r
1345 if (!(PicoDrawMask & PDRAW_LAYERA_ON));\r
1346 else if (hvwind == 1)\r
ea38612f 1347 DrawWindow(0, maxcells>>1, 1, sh, est);\r
7a7c6476 1348 else if (hvwind == 2) {\r
ea38612f 1349 if (HighCacheA[0])\r
1350 DrawTilesFromCache(HighCacheA, sh, (win&0x80) ? edge<<4 : maxw, est);\r
1351 DrawWindow((win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 1, sh, est);\r
cc68a136 1352 } else\r
ea38612f 1353 if (HighCacheA[0])\r
1354 DrawTilesFromCache(HighCacheA, sh, maxw, est);\r
fbc65db7 1355 /* - sprites hi - */\r
1356 if (!(PicoDrawMask & PDRAW_SPRITES_HI_ON));\r
6d8782a1 1357 else if (est->rendstatus & PDRAW_INTERLACE)\r
fbc65db7 1358 DrawAllSpritesInterlace(1, sh);\r
f8af9634 1359 // have sprites without layer pri bit ontop of sprites with that bit\r
1360 else if ((sprited[1] & 0xd0) == 0xd0 && (PicoOpt & POPT_ACC_SPRITES))\r
fbc65db7 1361 DrawSpritesHiAS(sprited, sh);\r
1362 else if (sh && (sprited[1] & SPRL_MAY_HAVE_OP))\r
ea38612f 1363 DrawSpritesSHi(sprited, est);\r
fbc65db7 1364 else if (sprited[1] & SPRL_HAVE_HI)\r
ea38612f 1365 DrawAllSprites(sprited, 1, 0, est);\r
cc68a136 1366\r
740da8c6 1367#if 0\r
1368 {\r
1369 int *c, a, b;\r
1370 for (a = 0, c = HighCacheA; *c; c++, a++);\r
1371 for (b = 0, c = HighCacheB; *c; c++, b++);\r
ea38612f 1372 printf("%i:%03i: a=%i, b=%i\n", Pico.m.frame_count,\r
1373 Pico.est.DrawScanline, a, b);\r
740da8c6 1374 }\r
1375#endif\r
1376\r
cc68a136 1377 return 0;\r
1378}\r
1379\r
f8af9634 1380// MUST be called every frame\r
eff55556 1381PICO_INTERNAL void PicoFrameStart(void)\r
cc68a136 1382{\r
5a681086 1383 int offs = 8, lines = 224;\r
ae87bffa 1384\r
cc68a136 1385 // prepare to do this frame\r
ea38612f 1386 Pico.est.rendstatus = 0;\r
ae87bffa 1387 if ((Pico.video.reg[12] & 6) == 6)\r
ea38612f 1388 Pico.est.rendstatus |= PDRAW_INTERLACE; // interlace mode\r
ae87bffa 1389 if (!(Pico.video.reg[12] & 1))\r
ea38612f 1390 Pico.est.rendstatus |= PDRAW_32_COLS;\r
5a681086 1391 if (Pico.video.reg[1] & 8) {\r
1392 offs = 0;\r
ae87bffa 1393 lines = 240;\r
5a681086 1394 }\r
e5fa9817 1395\r
ea38612f 1396 if (Pico.est.rendstatus != rendstatus_old || lines != rendlines) {\r
ae87bffa 1397 rendlines = lines;\r
b60b8745 1398 // mode_change() might reset rendstatus_old by calling SetColorFormat\r
ae87bffa 1399 emu_video_mode_change((lines == 240) ? 0 : 8,\r
1400 lines, (Pico.video.reg[12] & 1) ? 0 : 1);\r
ea38612f 1401 rendstatus_old = Pico.est.rendstatus;\r
19954be1 1402 }\r
1403\r
99bdfd31 1404 Pico.est.HighCol = HighColBase + offs * HighColIncrement;\r
1405 Pico.est.DrawLineDest = (char *)DrawLineDestBase + offs * DrawLineDestIncrement;\r
ea38612f 1406 Pico.est.DrawScanline = 0;\r
b7d64dbd 1407 skip_next_line = 0;\r
1408\r
19954be1 1409 if (PicoOpt & POPT_ALT_RENDERER)\r
1410 return;\r
1411\r
87b0845f 1412 if (Pico.m.dirtyPal)\r
1413 Pico.m.dirtyPal = 2; // reset dirty if needed\r
cc68a136 1414 PrepareSprites(1);\r
cc68a136 1415}\r
1416\r
974fdb5b 1417static void DrawBlankedLine(int line, int offs, int sh, int bgc)\r
87b0845f 1418{\r
87b0845f 1419 if (PicoScanBegin != NULL)\r
1420 PicoScanBegin(line + offs);\r
1421\r
99bdfd31 1422 BackFill(bgc, sh, &Pico.est);\r
87b0845f 1423\r
1424 if (FinalizeLine != NULL)\r
ea38612f 1425 FinalizeLine(sh, line, &Pico.est);\r
87b0845f 1426\r
1427 if (PicoScanEnd != NULL)\r
1428 PicoScanEnd(line + offs);\r
b2670137 1429\r
99bdfd31 1430 Pico.est.HighCol += HighColIncrement;\r
1431 Pico.est.DrawLineDest = (char *)Pico.est.DrawLineDest + DrawLineDestIncrement;\r
87b0845f 1432}\r
1433\r
974fdb5b 1434static void PicoLine(int line, int offs, int sh, int bgc)\r
cc68a136 1435{\r
ae87bffa 1436 int skip = 0;\r
1437\r
87b0845f 1438 if (skip_next_line > 0) {\r
1439 skip_next_line--;\r
1440 return;\r
1441 }\r
cc68a136 1442\r
ea38612f 1443 Pico.est.DrawScanline = line;\r
602133e1 1444 if (PicoScanBegin != NULL)\r
ae87bffa 1445 skip = PicoScanBegin(line + offs);\r
1446\r
1447 if (skip) {\r
1448 skip_next_line = skip - 1;\r
1449 return;\r
1450 }\r
602133e1 1451\r
cc68a136 1452 // Draw screen:\r
99bdfd31 1453 BackFill(bgc, sh, &Pico.est);\r
cc68a136 1454 if (Pico.video.reg[1]&0x40)\r
0fc0e241 1455 DrawDisplay(sh);\r
cc68a136 1456\r
ea8c405f 1457 if (FinalizeLine != NULL)\r
ea38612f 1458 FinalizeLine(sh, line, &Pico.est);\r
cc68a136 1459\r
602133e1 1460 if (PicoScanEnd != NULL)\r
87b0845f 1461 skip_next_line = PicoScanEnd(line + offs);\r
5a681086 1462\r
99bdfd31 1463 Pico.est.HighCol += HighColIncrement;\r
1464 Pico.est.DrawLineDest = (char *)Pico.est.DrawLineDest + DrawLineDestIncrement;\r
cc68a136 1465}\r
1466\r
b6d7ac70 1467void PicoDrawSync(int to, int blank_last_line)\r
1468{\r
87b0845f 1469 int line, offs = 0;\r
974fdb5b 1470 int sh = (Pico.video.reg[0xC] & 8) >> 3; // shadow/hilight?\r
1471 int bgc = Pico.video.reg[7];\r
87b0845f 1472\r
f6c49d38 1473 pprof_start(draw);\r
1474\r
ae87bffa 1475 if (rendlines != 240)\r
87b0845f 1476 offs = 8;\r
1477\r
ea38612f 1478 for (line = Pico.est.DrawScanline; line < to; line++)\r
b6d7ac70 1479 {\r
974fdb5b 1480 PicoLine(line, offs, sh, bgc);\r
b6d7ac70 1481 }\r
1482\r
b6d7ac70 1483 // last line\r
87b0845f 1484 if (line <= to)\r
b6d7ac70 1485 {\r
1486 if (blank_last_line)\r
974fdb5b 1487 DrawBlankedLine(line, offs, sh, bgc);\r
1488 else PicoLine(line, offs, sh, bgc);\r
87b0845f 1489 line++;\r
b6d7ac70 1490 }\r
ea38612f 1491 Pico.est.DrawScanline = line;\r
f6c49d38 1492\r
1493 pprof_end(draw);\r
b6d7ac70 1494}\r
cc68a136 1495\r
5a681086 1496// also works for fast renderer\r
1497void PicoDrawUpdateHighPal(void)\r
1498{\r
98a27142 1499 struct PicoEState *est = &Pico.est;\r
5a681086 1500 int sh = (Pico.video.reg[0xC] & 8) >> 3; // shadow/hilight?\r
1501 if (PicoOpt & POPT_ALT_RENDERER)\r
1502 sh = 0; // no s/h support\r
1503\r
ea38612f 1504 PicoDoHighPal555(sh, 0, &Pico.est);\r
98a27142 1505 if (est->rendstatus & PDRAW_SONIC_MODE) {\r
5a681086 1506 // FIXME?\r
98a27142 1507 memcpy(est->HighPal + 0x40, est->HighPal, 0x40*2);\r
1508 memcpy(est->HighPal + 0x80, est->HighPal, 0x40*2);\r
5a681086 1509 }\r
1510}\r
1511\r
41946d70 1512void PicoDrawSetOutFormat(pdso_t which, int use_32x_line_mode)\r
cc68a136 1513{\r
ea8c405f 1514 switch (which)\r
1515 {\r
5a681086 1516 case PDF_8BIT:\r
1517 FinalizeLine = FinalizeLine8bit;\r
1518 break;\r
1519\r
1520 case PDF_RGB555:\r
41946d70 1521 if ((PicoAHW & PAHW_32X) && use_32x_line_mode)\r
5a681086 1522 FinalizeLine = FinalizeLine32xRGB555;\r
1523 else\r
1524 FinalizeLine = FinalizeLine555;\r
1525 break;\r
1526\r
1527 default:\r
1528 FinalizeLine = NULL;\r
1529 break;\r
ea8c405f 1530 }\r
41946d70 1531 PicoDrawSetOutFormat32x(which, use_32x_line_mode);\r
5a681086 1532 PicoDrawSetOutputMode4(which);\r
205bc456 1533 rendstatus_old = -1;\r
5a681086 1534}\r
1535\r
e51e5983 1536// note: may be called on the middle of frame\r
5a681086 1537void PicoDrawSetOutBuf(void *dest, int increment)\r
1538{\r
1539 DrawLineDestBase = dest;\r
1540 DrawLineDestIncrement = increment;\r
99bdfd31 1541 Pico.est.DrawLineDest = DrawLineDestBase + Pico.est.DrawScanline * increment;\r
5a681086 1542}\r
1543\r
1544void PicoDrawSetInternalBuf(void *dest, int increment)\r
1545{\r
1546 if (dest != NULL) {\r
1547 HighColBase = dest;\r
1548 HighColIncrement = increment;\r
99bdfd31 1549 Pico.est.HighCol = HighColBase + Pico.est.DrawScanline * increment;\r
5a681086 1550 }\r
1551 else {\r
1552 HighColBase = DefHighCol;\r
1553 HighColIncrement = 0;\r
1554 }\r
cc68a136 1555}\r
ea8c405f 1556\r
f4750ee0 1557void PicoDrawSetCallbacks(int (*begin)(unsigned int num), int (*end)(unsigned int num))\r
1558{\r
1559 PicoScanBegin = NULL;\r
1560 PicoScanEnd = NULL;\r
1561 PicoScan32xBegin = NULL;\r
1562 PicoScan32xEnd = NULL;\r
1563\r
1564 if ((PicoAHW & PAHW_32X) && FinalizeLine != FinalizeLine32xRGB555) {\r
1565 PicoScan32xBegin = begin;\r
1566 PicoScan32xEnd = end;\r
1567 }\r
1568 else {\r
1569 PicoScanBegin = begin;\r
1570 PicoScanEnd = end;\r
1571 }\r
1572}\r
ea38612f 1573\r
99bdfd31 1574void PicoDrawInit(void)\r
1575{\r
1576 Pico.est.DrawLineDest = DefOutBuff;\r
1577 Pico.est.HighCol = HighColBase;\r
1578 Pico.est.HighPreSpr = HighPreSpr;\r
1579 rendstatus_old = -1;\r
1580}\r
1581\r
1582// vim:ts=2:sw=2:expandtab\r