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