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