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