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