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