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