cff531af |
1 | /*\r |
2 | * tile renderer\r |
3 | * (C) notaz, 2006-2008\r |
4 | *\r |
5 | * This work is licensed under the terms of MAME license.\r |
6 | * See COPYING file in the top-level directory.\r |
7 | */\r |
cc68a136 |
8 | \r |
efcba75f |
9 | #include "pico_int.h"\r |
cc68a136 |
10 | \r |
11 | // port_config.h include must define these 2 defines:\r |
12 | // #define START_ROW 1 // which row of tiles to start rendering at?\r |
13 | // #define END_ROW 27 // ..end\r |
14 | // one row means 8 pixels. If above example was used, (27-1)*8=208 lines would be rendered.\r |
15 | \r |
16 | #define TILE_ROWS END_ROW-START_ROW\r |
17 | \r |
18 | #define USE_CACHE\r |
19 | \r |
9112b6ce |
20 | // note: this is not implemented in ARM asm\r |
21 | #if defined(DRAW2_OVERRIDE_LINE_WIDTH)\r |
22 | #define LINE_WIDTH DRAW2_OVERRIDE_LINE_WIDTH\r |
23 | #else\r |
24 | #define LINE_WIDTH 328\r |
25 | #endif\r |
cc68a136 |
26 | \r |
eff55556 |
27 | static int HighCache2A[41*(TILE_ROWS+1)+1+1]; // caches for high layers\r |
28 | static int HighCache2B[41*(TILE_ROWS+1)+1+1];\r |
cc68a136 |
29 | \r |
30 | unsigned short *PicoCramHigh=Pico.cram; // pointer to CRAM buff (0x40 shorts), converted to native device color (works only with 16bit for now)\r |
31 | void (*PicoPrepareCram)()=0; // prepares PicoCramHigh for renderer to use\r |
32 | \r |
33 | \r |
34 | // stuff available in asm:\r |
35 | #ifdef _ASM_DRAW_C\r |
36 | void BackFillFull(int reg7);\r |
37 | void DrawLayerFull(int plane, int *hcache, int planestart, int planeend);\r |
38 | void DrawTilesFromCacheF(int *hc);\r |
39 | void DrawWindowFull(int start, int end, int prio);\r |
40 | void DrawSpriteFull(unsigned int *sprite);\r |
41 | #else\r |
42 | \r |
43 | \r |
44 | static int TileXnormYnorm(unsigned char *pd,int addr,unsigned char pal)\r |
45 | {\r |
46 | unsigned int pack=0; unsigned int t=0, blank = 1;\r |
47 | int i;\r |
48 | \r |
9112b6ce |
49 | for(i=8; i; i--, addr+=2, pd += LINE_WIDTH) {\r |
cc68a136 |
50 | pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels\r |
51 | if(!pack) continue;\r |
52 | \r |
53 | t=pack&0x0000f000; if (t) pd[0]=(unsigned char)((t>>12)|pal);\r |
54 | t=pack&0x00000f00; if (t) pd[1]=(unsigned char)((t>> 8)|pal);\r |
55 | t=pack&0x000000f0; if (t) pd[2]=(unsigned char)((t>> 4)|pal);\r |
56 | t=pack&0x0000000f; if (t) pd[3]=(unsigned char)((t )|pal);\r |
57 | t=pack&0xf0000000; if (t) pd[4]=(unsigned char)((t>>28)|pal);\r |
58 | t=pack&0x0f000000; if (t) pd[5]=(unsigned char)((t>>24)|pal);\r |
59 | t=pack&0x00f00000; if (t) pd[6]=(unsigned char)((t>>20)|pal);\r |
60 | t=pack&0x000f0000; if (t) pd[7]=(unsigned char)((t>>16)|pal);\r |
61 | blank = 0;\r |
62 | }\r |
63 | \r |
64 | return blank; // Tile blank?\r |
65 | }\r |
66 | \r |
67 | static int TileXflipYnorm(unsigned char *pd,int addr,unsigned char pal)\r |
68 | {\r |
69 | unsigned int pack=0; unsigned int t=0, blank = 1;\r |
70 | int i;\r |
71 | \r |
9112b6ce |
72 | for(i=8; i; i--, addr+=2, pd += LINE_WIDTH) {\r |
cc68a136 |
73 | pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels\r |
74 | if(!pack) continue;\r |
75 | \r |
76 | t=pack&0x000f0000; if (t) pd[0]=(unsigned char)((t>>16)|pal);\r |
77 | t=pack&0x00f00000; if (t) pd[1]=(unsigned char)((t>>20)|pal);\r |
78 | t=pack&0x0f000000; if (t) pd[2]=(unsigned char)((t>>24)|pal);\r |
79 | t=pack&0xf0000000; if (t) pd[3]=(unsigned char)((t>>28)|pal);\r |
80 | t=pack&0x0000000f; if (t) pd[4]=(unsigned char)((t )|pal);\r |
81 | t=pack&0x000000f0; if (t) pd[5]=(unsigned char)((t>> 4)|pal);\r |
82 | t=pack&0x00000f00; if (t) pd[6]=(unsigned char)((t>> 8)|pal);\r |
83 | t=pack&0x0000f000; if (t) pd[7]=(unsigned char)((t>>12)|pal);\r |
84 | blank = 0;\r |
85 | }\r |
86 | return blank; // Tile blank?\r |
87 | }\r |
88 | \r |
89 | static int TileXnormYflip(unsigned char *pd,int addr,unsigned char pal)\r |
90 | {\r |
91 | unsigned int pack=0; unsigned int t=0, blank = 1;\r |
92 | int i;\r |
93 | \r |
94 | addr+=14;\r |
9112b6ce |
95 | for(i=8; i; i--, addr-=2, pd += LINE_WIDTH) {\r |
cc68a136 |
96 | pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels\r |
97 | if(!pack) continue;\r |
98 | \r |
99 | t=pack&0x0000f000; if (t) pd[0]=(unsigned char)((t>>12)|pal);\r |
100 | t=pack&0x00000f00; if (t) pd[1]=(unsigned char)((t>> 8)|pal);\r |
101 | t=pack&0x000000f0; if (t) pd[2]=(unsigned char)((t>> 4)|pal);\r |
102 | t=pack&0x0000000f; if (t) pd[3]=(unsigned char)((t )|pal);\r |
103 | t=pack&0xf0000000; if (t) pd[4]=(unsigned char)((t>>28)|pal);\r |
104 | t=pack&0x0f000000; if (t) pd[5]=(unsigned char)((t>>24)|pal);\r |
105 | t=pack&0x00f00000; if (t) pd[6]=(unsigned char)((t>>20)|pal);\r |
106 | t=pack&0x000f0000; if (t) pd[7]=(unsigned char)((t>>16)|pal);\r |
107 | blank = 0;\r |
108 | }\r |
109 | \r |
110 | return blank; // Tile blank?\r |
111 | }\r |
112 | \r |
113 | static int TileXflipYflip(unsigned char *pd,int addr,unsigned char pal)\r |
114 | {\r |
115 | unsigned int pack=0; unsigned int t=0, blank = 1;\r |
116 | int i;\r |
117 | \r |
118 | addr+=14;\r |
9112b6ce |
119 | for(i=8; i; i--, addr-=2, pd += LINE_WIDTH) {\r |
cc68a136 |
120 | pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels\r |
121 | if(!pack) continue;\r |
122 | \r |
123 | t=pack&0x000f0000; if (t) pd[0]=(unsigned char)((t>>16)|pal);\r |
124 | t=pack&0x00f00000; if (t) pd[1]=(unsigned char)((t>>20)|pal);\r |
125 | t=pack&0x0f000000; if (t) pd[2]=(unsigned char)((t>>24)|pal);\r |
126 | t=pack&0xf0000000; if (t) pd[3]=(unsigned char)((t>>28)|pal);\r |
127 | t=pack&0x0000000f; if (t) pd[4]=(unsigned char)((t )|pal);\r |
128 | t=pack&0x000000f0; if (t) pd[5]=(unsigned char)((t>> 4)|pal);\r |
129 | t=pack&0x00000f00; if (t) pd[6]=(unsigned char)((t>> 8)|pal);\r |
130 | t=pack&0x0000f000; if (t) pd[7]=(unsigned char)((t>>12)|pal);\r |
131 | blank = 0;\r |
132 | }\r |
133 | return blank; // Tile blank?\r |
134 | }\r |
135 | \r |
136 | \r |
137 | // start: (tile_start<<16)|row_start, end: [same]\r |
138 | static void DrawWindowFull(int start, int end, int prio)\r |
139 | {\r |
140 | struct PicoVideo *pvid=&Pico.video;\r |
141 | int nametab, nametab_step, trow, tilex, blank=-1, code;\r |
e5f426aa |
142 | unsigned char *scrpos = PicoDraw2FB;\r |
cc68a136 |
143 | int tile_start, tile_end; // in cells\r |
144 | \r |
145 | // parse ranges\r |
146 | tile_start = start>>16;\r |
147 | tile_end = end>>16;\r |
148 | start = start<<16>>16;\r |
149 | end = end<<16>>16;\r |
150 | \r |
151 | // Find name table line:\r |
152 | if (pvid->reg[12]&1)\r |
153 | {\r |
154 | nametab=(pvid->reg[3]&0x3c)<<9; // 40-cell mode\r |
155 | nametab_step = 1<<6;\r |
156 | }\r |
157 | else\r |
158 | {\r |
159 | nametab=(pvid->reg[3]&0x3e)<<9; // 32-cell mode\r |
160 | nametab_step = 1<<5;\r |
161 | }\r |
162 | nametab += nametab_step*start;\r |
163 | \r |
164 | // check priority\r |
165 | code=Pico.vram[nametab+tile_start];\r |
166 | if ((code>>15) != prio) return; // hack: just assume that whole window uses same priority\r |
167 | \r |
9112b6ce |
168 | scrpos+=8*LINE_WIDTH+8;\r |
169 | scrpos+=8*LINE_WIDTH*(start-START_ROW);\r |
cc68a136 |
170 | \r |
171 | // do a window until we reach planestart row\r |
172 | for(trow = start; trow < end; trow++, nametab+=nametab_step) { // current tile row\r |
173 | for (tilex=tile_start; tilex<tile_end; tilex++)\r |
174 | {\r |
175 | int code,addr,zero=0;\r |
176 | // unsigned short *pal=NULL;\r |
177 | unsigned char pal;\r |
178 | \r |
179 | code=Pico.vram[nametab+tilex];\r |
180 | if (code==blank) continue;\r |
181 | \r |
182 | // Get tile address/2:\r |
183 | addr=(code&0x7ff)<<4;\r |
184 | \r |
185 | // pal=PicoCramHigh+((code>>9)&0x30);\r |
186 | pal=(unsigned char)((code>>9)&0x30);\r |
187 | \r |
188 | switch((code>>11)&3) {\r |
189 | case 0: zero=TileXnormYnorm(scrpos+(tilex<<3),addr,pal); break;\r |
190 | case 1: zero=TileXflipYnorm(scrpos+(tilex<<3),addr,pal); break;\r |
191 | case 2: zero=TileXnormYflip(scrpos+(tilex<<3),addr,pal); break;\r |
192 | case 3: zero=TileXflipYflip(scrpos+(tilex<<3),addr,pal); break;\r |
193 | }\r |
194 | if(zero) blank=code; // We know this tile is blank now\r |
195 | }\r |
196 | \r |
9112b6ce |
197 | scrpos += LINE_WIDTH*8;\r |
cc68a136 |
198 | }\r |
199 | }\r |
200 | \r |
201 | \r |
202 | static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend)\r |
203 | {\r |
204 | struct PicoVideo *pvid=&Pico.video;\r |
205 | static char shift[4]={5,6,6,7}; // 32,64 or 128 sized tilemaps\r |
206 | int width, height, ymask, htab;\r |
207 | int nametab, hscroll=0, vscroll, cells;\r |
208 | unsigned char *scrpos;\r |
209 | int blank=-1, xmask, nametab_row, trow;\r |
210 | \r |
211 | // parse ranges\r |
212 | cells = (planeend>>16)-(planestart>>16);\r |
213 | planestart = planestart<<16>>16;\r |
214 | planeend = planeend<<16>>16;\r |
215 | \r |
216 | // Work out the Tiles to draw\r |
217 | \r |
218 | htab=pvid->reg[13]<<9; // Horizontal scroll table address\r |
219 | // if ( pvid->reg[11]&2) htab+=Scanline<<1; // Offset by line\r |
220 | // if ((pvid->reg[11]&1)==0) htab&=~0xf; // Offset by tile\r |
221 | htab+=plane; // A or B\r |
222 | \r |
223 | if(!(pvid->reg[11]&3)) { // full screen scroll\r |
224 | // Get horizontal scroll value\r |
225 | hscroll=Pico.vram[htab&0x7fff];\r |
226 | htab = 0; // this marks that we don't have to update scroll value\r |
227 | }\r |
228 | \r |
229 | // Work out the name table size: 32 64 or 128 tiles (0-3)\r |
230 | width=pvid->reg[16];\r |
231 | height=(width>>4)&3; width&=3;\r |
232 | \r |
233 | xmask=(1<<shift[width ])-1; // X Mask in tiles\r |
eff55556 |
234 | ymask=(height<<5)|0x1f; // Y Mask in tiles\r |
235 | if(width == 1) ymask&=0x3f;\r |
236 | else if(width>1) ymask =0x1f;\r |
cc68a136 |
237 | \r |
238 | // Find name table:\r |
239 | if (plane==0) nametab=(pvid->reg[2]&0x38)<< 9; // A\r |
240 | else nametab=(pvid->reg[4]&0x07)<<12; // B\r |
241 | \r |
e5f426aa |
242 | scrpos = PicoDraw2FB;\r |
9112b6ce |
243 | scrpos+=8*LINE_WIDTH*(planestart-START_ROW);\r |
cc68a136 |
244 | \r |
245 | // Get vertical scroll value:\r |
246 | vscroll=Pico.vsram[plane]&0x1ff;\r |
9112b6ce |
247 | scrpos+=(8-(vscroll&7))*LINE_WIDTH;\r |
cc68a136 |
248 | if(vscroll&7) planeend++; // we have vertically clipped tiles due to vscroll, so we need 1 more row\r |
249 | \r |
250 | *hcache++ = 8-(vscroll&7); // push y-offset to tilecache\r |
251 | \r |
252 | \r |
253 | for(trow = planestart; trow < planeend; trow++) { // current tile row\r |
254 | int cellc=cells,tilex,dx;\r |
255 | \r |
256 | // Find the tile row in the name table\r |
257 | //ts.line=(vscroll+Scanline)&ymask;\r |
258 | //ts.nametab+=(ts.line>>3)<<shift[width];\r |
259 | nametab_row = nametab + (((trow+(vscroll>>3))&ymask)<<shift[width]); // pointer to nametable entries for this row\r |
260 | \r |
261 | // update hscroll if needed\r |
262 | if(htab) {\r |
263 | int htaddr=htab+(trow<<4);\r |
264 | if(trow) htaddr-=(vscroll&7)<<1;\r |
265 | hscroll=Pico.vram[htaddr&0x7fff];\r |
266 | }\r |
267 | \r |
268 | // Draw tiles across screen:\r |
269 | tilex=(-hscroll)>>3;\r |
270 | dx=((hscroll-1)&7)+1;\r |
271 | if(dx != 8) cellc++; // have hscroll, do more cells\r |
272 | \r |
273 | for (; cellc; dx+=8,tilex++,cellc--)\r |
274 | {\r |
275 | int code=0,addr=0,zero=0;\r |
276 | // unsigned short *pal=NULL;\r |
277 | unsigned char pal;\r |
278 | \r |
279 | code=Pico.vram[nametab_row+(tilex&xmask)];\r |
280 | if (code==blank) continue;\r |
281 | \r |
cc68a136 |
282 | if (code>>15) { // high priority tile\r |
283 | *hcache++ = code|(dx<<16)|(trow<<27); // cache it\r |
cc68a136 |
284 | continue;\r |
285 | }\r |
286 | \r |
287 | // Get tile address/2:\r |
288 | addr=(code&0x7ff)<<4;\r |
289 | \r |
290 | // pal=PicoCramHigh+((code>>9)&0x30);\r |
291 | pal=(unsigned char)((code>>9)&0x30);\r |
292 | \r |
293 | switch((code>>11)&3) {\r |
294 | case 0: zero=TileXnormYnorm(scrpos+dx,addr,pal); break;\r |
295 | case 1: zero=TileXflipYnorm(scrpos+dx,addr,pal); break;\r |
296 | case 2: zero=TileXnormYflip(scrpos+dx,addr,pal); break;\r |
297 | case 3: zero=TileXflipYflip(scrpos+dx,addr,pal); break;\r |
298 | }\r |
299 | if(zero) blank=code; // We know this tile is blank now\r |
300 | }\r |
301 | \r |
9112b6ce |
302 | scrpos += LINE_WIDTH*8;\r |
cc68a136 |
303 | }\r |
304 | \r |
305 | *hcache = 0; // terminate cache\r |
306 | }\r |
307 | \r |
308 | \r |
309 | static void DrawTilesFromCacheF(int *hc)\r |
310 | {\r |
311 | int code, addr, zero = 0;\r |
312 | unsigned int prevy=0xFFFFFFFF;\r |
313 | // unsigned short *pal;\r |
314 | unsigned char pal;\r |
315 | short blank=-1; // The tile we know is blank\r |
e5f426aa |
316 | unsigned char *scrpos = PicoDraw2FB, *pd = 0;\r |
cc68a136 |
317 | \r |
318 | // *hcache++ = code|(dx<<16)|(trow<<27); // cache it\r |
9112b6ce |
319 | scrpos+=(*hc++)*LINE_WIDTH - START_ROW*LINE_WIDTH*8;\r |
cc68a136 |
320 | \r |
321 | while((code=*hc++)) {\r |
322 | if((short)code == blank) continue;\r |
323 | \r |
324 | // y pos\r |
325 | if(((unsigned)code>>27) != prevy) {\r |
326 | prevy = (unsigned)code>>27;\r |
9112b6ce |
327 | pd = scrpos + prevy*LINE_WIDTH*8;\r |
cc68a136 |
328 | }\r |
329 | \r |
330 | // Get tile address/2:\r |
331 | addr=(code&0x7ff)<<4;\r |
332 | // pal=PicoCramHigh+((code>>9)&0x30);\r |
333 | pal=(unsigned char)((code>>9)&0x30);\r |
334 | \r |
335 | switch((code>>11)&3) {\r |
336 | case 0: zero=TileXnormYnorm(pd+((code>>16)&0x1ff),addr,pal); break;\r |
337 | case 1: zero=TileXflipYnorm(pd+((code>>16)&0x1ff),addr,pal); break;\r |
338 | case 2: zero=TileXnormYflip(pd+((code>>16)&0x1ff),addr,pal); break;\r |
339 | case 3: zero=TileXflipYflip(pd+((code>>16)&0x1ff),addr,pal); break;\r |
340 | }\r |
341 | \r |
342 | if(zero) blank=(short)code;\r |
343 | }\r |
344 | }\r |
345 | \r |
346 | \r |
347 | // sx and sy are coords of virtual screen with 8pix borders on top and on left\r |
348 | static void DrawSpriteFull(unsigned int *sprite)\r |
349 | {\r |
350 | int width=0,height=0;\r |
351 | // unsigned short *pal=NULL;\r |
352 | unsigned char pal;\r |
353 | int tile,code,tdeltax,tdeltay;\r |
354 | unsigned char *scrpos;\r |
355 | int sx, sy;\r |
356 | \r |
357 | sy=sprite[0];\r |
358 | height=sy>>24;\r |
359 | sy=(sy&0x1ff)-0x78; // Y\r |
360 | width=(height>>2)&3; height&=3;\r |
361 | width++; height++; // Width and height in tiles\r |
362 | \r |
363 | code=sprite[1];\r |
364 | sx=((code>>16)&0x1ff)-0x78; // X\r |
365 | \r |
366 | tile=code&0x7ff; // Tile number\r |
367 | tdeltax=height; // Delta to increase tile by going right\r |
368 | tdeltay=1; // Delta to increase tile by going down\r |
369 | if (code&0x0800) { tdeltax=-tdeltax; tile+=height*(width-1); } // Flip X\r |
370 | if (code&0x1000) { tdeltay=-tdeltay; tile+=height-1; } // Flip Y\r |
371 | \r |
372 | //delta<<=4; // Delta of address\r |
373 | // pal=PicoCramHigh+((code>>9)&0x30); // Get palette pointer\r |
374 | pal=(unsigned char)((code>>9)&0x30);\r |
375 | \r |
376 | // goto first vertically visible tile\r |
377 | while(sy <= START_ROW*8) { sy+=8; tile+=tdeltay; height--; }\r |
378 | \r |
e5f426aa |
379 | scrpos = PicoDraw2FB;\r |
9112b6ce |
380 | scrpos+=(sy-START_ROW*8)*LINE_WIDTH;\r |
cc68a136 |
381 | \r |
382 | for (; height > 0; height--, sy+=8, tile+=tdeltay)\r |
383 | {\r |
384 | int w = width, x=sx, t=tile;\r |
385 | \r |
386 | if(sy >= END_ROW*8+8) return; // offscreen\r |
387 | \r |
388 | for (; w; w--,x+=8,t+=tdeltax)\r |
389 | {\r |
390 | if(x<=0) continue;\r |
391 | if(x>=328) break; // Offscreen\r |
392 | \r |
393 | t&=0x7fff; // Clip tile address\r |
394 | switch((code>>11)&3) {\r |
395 | case 0: TileXnormYnorm(scrpos+x,t<<4,pal); break;\r |
396 | case 1: TileXflipYnorm(scrpos+x,t<<4,pal); break;\r |
397 | case 2: TileXnormYflip(scrpos+x,t<<4,pal); break;\r |
398 | case 3: TileXflipYflip(scrpos+x,t<<4,pal); break;\r |
399 | }\r |
400 | }\r |
401 | \r |
9112b6ce |
402 | scrpos+=8*LINE_WIDTH;\r |
cc68a136 |
403 | }\r |
404 | }\r |
405 | #endif\r |
406 | \r |
407 | \r |
408 | static void DrawAllSpritesFull(int prio, int maxwidth)\r |
409 | {\r |
410 | struct PicoVideo *pvid=&Pico.video;\r |
411 | int table=0,maskrange=0;\r |
412 | int i,u,link=0;\r |
413 | unsigned int *sprites[80]; // Sprites\r |
414 | int y_min=START_ROW*8, y_max=END_ROW*8; // for a simple sprite masking\r |
415 | \r |
416 | table=pvid->reg[5]&0x7f;\r |
417 | if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode\r |
418 | table<<=8; // Get sprite table address/2\r |
419 | \r |
420 | for (i=u=0; u < 80; u++)\r |
421 | {\r |
422 | unsigned int *sprite=NULL;\r |
423 | int code, code2, sx, sy, height;\r |
424 | \r |
425 | sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite\r |
426 | \r |
427 | // get sprite info\r |
428 | code = sprite[0];\r |
429 | \r |
430 | // check if it is not hidden vertically\r |
431 | sy = (code&0x1ff)-0x80;\r |
432 | height = (((code>>24)&3)+1)<<3;\r |
433 | if(sy+height <= y_min || sy > y_max) goto nextsprite;\r |
434 | \r |
435 | // masking sprite?\r |
436 | code2=sprite[1];\r |
437 | sx = (code2>>16)&0x1ff;\r |
438 | if(!sx) {\r |
439 | int to = sy+height; // sy ~ from\r |
440 | if(maskrange) {\r |
441 | // try to merge with previous range\r |
442 | if((maskrange>>16)+1 >= sy && (maskrange>>16) <= to && (maskrange&0xffff) < sy) sy = (maskrange&0xffff);\r |
443 | else if((maskrange&0xffff)-1 <= to && (maskrange&0xffff) >= sy && (maskrange>>16) > to) to = (maskrange>>16);\r |
444 | }\r |
445 | // support only very simple masking (top and bottom of screen)\r |
446 | if(sy <= y_min && to+1 > y_min) y_min = to+1;\r |
447 | else if(to >= y_max && sy-1 < y_max) y_max = sy-1;\r |
448 | else maskrange=sy|(to<<16);\r |
449 | \r |
450 | goto nextsprite;\r |
451 | }\r |
452 | \r |
453 | // priority\r |
454 | if(((code2>>15)&1) != prio) goto nextsprite; // wrong priority\r |
455 | \r |
456 | // check if sprite is not hidden horizontally\r |
457 | sx -= 0x78; // Get X coordinate + 8\r |
458 | if(sx <= -8*3 || sx >= maxwidth) goto nextsprite;\r |
459 | \r |
460 | // sprite is good, save it's index\r |
461 | sprites[i++]=sprite;\r |
462 | \r |
463 | nextsprite:\r |
464 | // Find next sprite\r |
465 | link=(code>>16)&0x7f;\r |
466 | if(!link) break; // End of sprites\r |
467 | }\r |
468 | \r |
469 | // Go through sprites backwards:\r |
470 | for (i-- ;i>=0; i--)\r |
471 | {\r |
472 | DrawSpriteFull(sprites[i]);\r |
473 | }\r |
474 | }\r |
475 | \r |
476 | #ifndef _ASM_DRAW_C\r |
477 | static void BackFillFull(int reg7)\r |
478 | {\r |
b542be46 |
479 | unsigned int back;\r |
cc68a136 |
480 | \r |
481 | // Start with a background color:\r |
482 | // back=PicoCramHigh[reg7&0x3f];\r |
483 | back=reg7&0x3f;\r |
484 | back|=back<<8;\r |
485 | back|=back<<16;\r |
486 | \r |
b542be46 |
487 | memset32((int *)PicoDraw2FB, back, LINE_WIDTH*(8+(END_ROW-START_ROW)*8)/4);\r |
cc68a136 |
488 | }\r |
489 | #endif\r |
490 | \r |
f579f7b8 |
491 | static void DrawDisplayFull(void)\r |
cc68a136 |
492 | {\r |
493 | struct PicoVideo *pvid=&Pico.video;\r |
494 | int win, edge=0, hvwin=0; // LSb->MSb: hwin&plane, vwin&plane, full\r |
495 | int planestart=START_ROW, planeend=END_ROW; // plane A start/end when window shares display with plane A (in tile rows or columns)\r |
496 | int winstart=START_ROW, winend=END_ROW; // same for window\r |
497 | int maxw, maxcolc; // max width and col cells\r |
498 | \r |
499 | if(pvid->reg[12]&1) {\r |
500 | maxw = 328; maxcolc = 40;\r |
501 | } else {\r |
502 | maxw = 264; maxcolc = 32;\r |
503 | }\r |
504 | \r |
505 | // horizontal window?\r |
f579f7b8 |
506 | if ((win=pvid->reg[0x12]))\r |
507 | {\r |
cc68a136 |
508 | hvwin=1; // hwindow shares display with plane A\r |
509 | edge=win&0x1f;\r |
510 | if(win == 0x80) {\r |
511 | // fullscreen window\r |
512 | hvwin=4;\r |
513 | } else if(win < 0x80) {\r |
514 | // window on the top\r |
515 | if(edge <= START_ROW) hvwin=0; // window not visible in our drawing region\r |
516 | else if(edge >= END_ROW) hvwin=4;\r |
517 | else planestart = winend = edge;\r |
518 | } else if(win > 0x80) {\r |
519 | // window at the bottom\r |
520 | if(edge >= END_ROW) hvwin=0;\r |
521 | else planeend = winstart = edge;\r |
522 | }\r |
523 | }\r |
524 | \r |
525 | // check for vertical window, but only if win is not fullscreen\r |
f579f7b8 |
526 | if (hvwin != 4)\r |
527 | {\r |
cc68a136 |
528 | win=pvid->reg[0x11];\r |
529 | edge=win&0x1f;\r |
530 | if (win&0x80) {\r |
531 | if(!edge) hvwin=4;\r |
532 | else if(edge < (maxcolc>>1)) {\r |
533 | // window is on the right\r |
534 | hvwin|=2;\r |
535 | planeend|=edge<<17;\r |
536 | winstart|=edge<<17;\r |
537 | winend|=maxcolc<<16;\r |
538 | }\r |
539 | } else {\r |
540 | if(edge >= (maxcolc>>1)) hvwin=4;\r |
541 | else if(edge) {\r |
542 | // window is on the left\r |
543 | hvwin|=2;\r |
544 | winend|=edge<<17;\r |
545 | planestart|=edge<<17;\r |
546 | planeend|=maxcolc<<16;\r |
547 | }\r |
548 | }\r |
549 | }\r |
550 | \r |
f579f7b8 |
551 | if (hvwin==1) { winend|=maxcolc<<16; planeend|=maxcolc<<16; }\r |
cc68a136 |
552 | \r |
f579f7b8 |
553 | HighCache2A[1] = HighCache2B[1] = 0;\r |
554 | if (PicoDrawMask & PDRAW_LAYERB_ON)\r |
555 | DrawLayerFull(1, HighCache2B, START_ROW, (maxcolc<<16)|END_ROW);\r |
556 | if (PicoDrawMask & PDRAW_LAYERA_ON) switch (hvwin)\r |
557 | {\r |
cc68a136 |
558 | case 4:\r |
559 | // fullscreen window\r |
560 | DrawWindowFull(START_ROW, (maxcolc<<16)|END_ROW, 0);\r |
cc68a136 |
561 | break;\r |
562 | \r |
563 | case 3:\r |
564 | // we have plane A and both v and h windows\r |
eff55556 |
565 | DrawLayerFull(0, HighCache2A, planestart, planeend);\r |
cc68a136 |
566 | DrawWindowFull( winstart&~0xff0000, (winend&~0xff0000)|(maxcolc<<16), 0); // h\r |
567 | DrawWindowFull((winstart&~0xff)|START_ROW, (winend&~0xff)|END_ROW, 0); // v\r |
568 | break;\r |
569 | \r |
570 | case 2:\r |
571 | case 1:\r |
572 | // both window and plane A visible, window is vertical XOR horizontal\r |
eff55556 |
573 | DrawLayerFull(0, HighCache2A, planestart, planeend);\r |
cc68a136 |
574 | DrawWindowFull(winstart, winend, 0);\r |
575 | break;\r |
576 | \r |
577 | default:\r |
578 | // fullscreen plane A\r |
eff55556 |
579 | DrawLayerFull(0, HighCache2A, START_ROW, (maxcolc<<16)|END_ROW);\r |
cc68a136 |
580 | break;\r |
581 | }\r |
f579f7b8 |
582 | if (PicoDrawMask & PDRAW_SPRITES_LOW_ON)\r |
583 | DrawAllSpritesFull(0, maxw);\r |
cc68a136 |
584 | \r |
f579f7b8 |
585 | if (HighCache2B[1]) DrawTilesFromCacheF(HighCache2B);\r |
586 | if (HighCache2A[1]) DrawTilesFromCacheF(HighCache2A);\r |
8cf22667 |
587 | if (PicoDrawMask & PDRAW_LAYERA_ON) switch (hvwin)\r |
f579f7b8 |
588 | {\r |
cc68a136 |
589 | case 4:\r |
590 | // fullscreen window\r |
591 | DrawWindowFull(START_ROW, (maxcolc<<16)|END_ROW, 1);\r |
592 | break;\r |
593 | \r |
594 | case 3:\r |
595 | // we have plane A and both v and h windows\r |
596 | DrawWindowFull( winstart&~0xff0000, (winend&~0xff0000)|(maxcolc<<16), 1); // h\r |
597 | DrawWindowFull((winstart&~0xff)|START_ROW, (winend&~0xff)|END_ROW, 1); // v\r |
598 | break;\r |
599 | \r |
600 | case 2:\r |
601 | case 1:\r |
602 | // both window and plane A visible, window is vertical XOR horizontal\r |
603 | DrawWindowFull(winstart, winend, 1);\r |
604 | break;\r |
605 | }\r |
f579f7b8 |
606 | if (PicoDrawMask & PDRAW_SPRITES_HI_ON)\r |
607 | DrawAllSpritesFull(1, maxw);\r |
cc68a136 |
608 | }\r |
609 | \r |
610 | \r |
eff55556 |
611 | PICO_INTERNAL void PicoFrameFull()\r |
cc68a136 |
612 | {\r |
25eb407c |
613 | pprof_start(draw);\r |
614 | \r |
cc68a136 |
615 | // prepare cram?\r |
f579f7b8 |
616 | if (PicoPrepareCram) PicoPrepareCram();\r |
cc68a136 |
617 | \r |
618 | // Draw screen:\r |
619 | BackFillFull(Pico.video.reg[7]);\r |
25eb407c |
620 | if (Pico.video.reg[1] & 0x40)\r |
621 | DrawDisplayFull();\r |
622 | \r |
623 | pprof_end(draw);\r |
cc68a136 |
624 | }\r |
625 | \r |