draw2.c 19 KB

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