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