1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288 |
- // This is part of Pico Library
- // (c) Copyright 2004 Dave, All rights reserved.
- // (c) Copyright 2006 notaz, All rights reserved.
- // Free for non-commercial use.
- // For commercial use, separate licencing terms must be obtained.
- #include "PicoInt.h"
- #ifndef __GNUC__
- #pragma warning (disable:4706) // Disable assignment within conditional
- #endif
- int (*PicoScan)(unsigned int num, void *data)=NULL;
- unsigned short DefOutBuff[320*2];
- unsigned char HighCol[8+320+8];
- static int HighCacheA[41+1]; // caches for high layers
- static int HighCacheB[41+1];
- static int HighCacheS[80+1]; // and sprites
- static int HighPreSpr[80*2+1]; // slightly preprocessed sprites
- char HighSprZ[320+8+8]; // Z-buffer for accurate sprites and shadow/hilight mode
- // (if bit 7 == 0, sh caused by tile; if bit 6 == 0 pixel must be shadowed, else hilighted, if bit5 == 1)
- // lsb->msb: moved sprites, all window tiles don't use same priority, accurate sprites (copied from PicoOpt), interlace
- // dirty sprites, sonic mode
- int rendstatus;
- void *DrawLineDest=DefOutBuff; // pointer to dest buffer where to draw this line to
- int Scanline=0; // Scanline
- static int SpriteBlocks;
- //unsigned short ppt[] = { 0x0f11, 0x0ff1, 0x01f1, 0x011f, 0x01ff, 0x0f1f, 0x0f0e, 0x0e7c };
- struct TileStrip
- {
- int nametab; // Position in VRAM of name table (for this tile line)
- int line; // Line number in pixels 0x000-0x3ff within the virtual tilemap
- int hscroll; // Horizontal scroll value in pixels for the line
- int xmask; // X-Mask (0x1f - 0x7f) for horizontal wraparound in the tilemap
- int *hc; // cache for high tile codes and their positions
- int cells; // cells (tiles) to draw (32 col mode doesn't need to update whole 320)
- };
- // stuff available in asm:
- #ifdef _ASM_DRAW_C
- void DrawWindow(int tstart, int tend, int prio, int sh);
- void BackFill(int reg7, int sh);
- void DrawSprite(int *sprite, int **hc, int sh);
- void DrawTilesFromCache(int *hc, int sh);
- void DrawSpritesFromCache(int *hc, int sh);
- void DrawLayer(int plane, int *hcache, int maxcells, int sh);
- void FinalizeLineBGR444(int sh);
- void FinalizeLineRGB555(int sh);
- void blockcpy_or(void *dst, void *src, size_t n, int pat);
- #else
- // utility
- void blockcpy_or(void *dst, void *src, size_t n, int pat)
- {
- unsigned char *pd = dst, *ps = src;
- for (; n; n--)
- *pd++ = (unsigned char) (*ps++ | pat);
- }
- #endif
- static int TileNorm(int sx,int addr,int pal)
- {
- unsigned char *pd = HighCol+sx;
- unsigned int pack=0; unsigned int t=0;
- pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
- if (pack)
- {
- t=pack&0x0000f000; if (t) pd[0]=(unsigned char)(pal|(t>>12));
- t=pack&0x00000f00; if (t) pd[1]=(unsigned char)(pal|(t>> 8));
- t=pack&0x000000f0; if (t) pd[2]=(unsigned char)(pal|(t>> 4));
- t=pack&0x0000000f; if (t) pd[3]=(unsigned char)(pal|(t ));
- t=pack&0xf0000000; if (t) pd[4]=(unsigned char)(pal|(t>>28));
- t=pack&0x0f000000; if (t) pd[5]=(unsigned char)(pal|(t>>24));
- t=pack&0x00f00000; if (t) pd[6]=(unsigned char)(pal|(t>>20));
- t=pack&0x000f0000; if (t) pd[7]=(unsigned char)(pal|(t>>16));
- return 0;
- }
- return 1; // Tile blank
- }
- static int TileFlip(int sx,int addr,int pal)
- {
- unsigned char *pd = HighCol+sx;
- unsigned int pack=0; unsigned int t=0;
- pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
- if (pack)
- {
- t=pack&0x000f0000; if (t) pd[0]=(unsigned char)(pal|(t>>16));
- t=pack&0x00f00000; if (t) pd[1]=(unsigned char)(pal|(t>>20));
- t=pack&0x0f000000; if (t) pd[2]=(unsigned char)(pal|(t>>24));
- t=pack&0xf0000000; if (t) pd[3]=(unsigned char)(pal|(t>>28));
- t=pack&0x0000000f; if (t) pd[4]=(unsigned char)(pal|(t ));
- t=pack&0x000000f0; if (t) pd[5]=(unsigned char)(pal|(t>> 4));
- t=pack&0x00000f00; if (t) pd[6]=(unsigned char)(pal|(t>> 8));
- t=pack&0x0000f000; if (t) pd[7]=(unsigned char)(pal|(t>>12));
- return 0;
- }
- return 1; // Tile blank
- }
- // tile renderers for hacky operator sprite support
- #define sh_pix(x) \
- if(!t); \
- else if(t==0xe) pd[x]=(unsigned char)((pd[x]&0x3f)|0x80); /* hilight */ \
- else if(t==0xf) pd[x]=(unsigned char)((pd[x]&0x3f)|0xc0); /* shadow */ \
- else pd[x]=(unsigned char)(pal|t)
- #ifndef _ASM_DRAW_C
- static int TileNormSH(int sx,int addr,int pal)
- {
- unsigned int pack=0; unsigned int t=0;
- unsigned char *pd = HighCol+sx;
- pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
- if (pack)
- {
- t=(pack&0x0000f000)>>12; sh_pix(0);
- t=(pack&0x00000f00)>> 8; sh_pix(1);
- t=(pack&0x000000f0)>> 4; sh_pix(2);
- t=(pack&0x0000000f) ; sh_pix(3);
- t=(pack&0xf0000000)>>28; sh_pix(4);
- t=(pack&0x0f000000)>>24; sh_pix(5);
- t=(pack&0x00f00000)>>20; sh_pix(6);
- t=(pack&0x000f0000)>>16; sh_pix(7);
- return 0;
- }
- return 1; // Tile blank
- }
- static int TileFlipSH(int sx,int addr,int pal)
- {
- unsigned int pack=0; unsigned int t=0;
- unsigned char *pd = HighCol+sx;
- pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
- if (pack)
- {
- t=(pack&0x000f0000)>>16; sh_pix(0);
- t=(pack&0x00f00000)>>20; sh_pix(1);
- t=(pack&0x0f000000)>>24; sh_pix(2);
- t=(pack&0xf0000000)>>28; sh_pix(3);
- t=(pack&0x0000000f) ; sh_pix(4);
- t=(pack&0x000000f0)>> 4; sh_pix(5);
- t=(pack&0x00000f00)>> 8; sh_pix(6);
- t=(pack&0x0000f000)>>12; sh_pix(7);
- return 0;
- }
- return 1; // Tile blank
- }
- #endif
- static int TileNormZ(int sx,int addr,int pal,int zval)
- {
- unsigned int pack=0; unsigned int t=0;
- unsigned char *pd = HighCol+sx;
- char *zb = HighSprZ+sx;
- int collision = 0, zb_s;
- pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
- if (pack)
- {
- t=pack&0x0000f000; if(t) { zb_s=zb[0]; if(zb_s) collision=1; if(zval>zb_s) { pd[0]=(unsigned char)(pal|(t>>12)); zb[0]=(char)zval; } }
- t=pack&0x00000f00; if(t) { zb_s=zb[1]; if(zb_s) collision=1; if(zval>zb_s) { pd[1]=(unsigned char)(pal|(t>> 8)); zb[1]=(char)zval; } }
- t=pack&0x000000f0; if(t) { zb_s=zb[2]; if(zb_s) collision=1; if(zval>zb_s) { pd[2]=(unsigned char)(pal|(t>> 4)); zb[2]=(char)zval; } }
- t=pack&0x0000000f; if(t) { zb_s=zb[3]; if(zb_s) collision=1; if(zval>zb_s) { pd[3]=(unsigned char)(pal|(t )); zb[3]=(char)zval; } }
- t=pack&0xf0000000; if(t) { zb_s=zb[4]; if(zb_s) collision=1; if(zval>zb_s) { pd[4]=(unsigned char)(pal|(t>>28)); zb[4]=(char)zval; } }
- t=pack&0x0f000000; if(t) { zb_s=zb[5]; if(zb_s) collision=1; if(zval>zb_s) { pd[5]=(unsigned char)(pal|(t>>24)); zb[5]=(char)zval; } }
- t=pack&0x00f00000; if(t) { zb_s=zb[6]; if(zb_s) collision=1; if(zval>zb_s) { pd[6]=(unsigned char)(pal|(t>>20)); zb[6]=(char)zval; } }
- t=pack&0x000f0000; if(t) { zb_s=zb[7]; if(zb_s) collision=1; if(zval>zb_s) { pd[7]=(unsigned char)(pal|(t>>16)); zb[7]=(char)zval; } }
- if(collision) Pico.video.status|=0x20;
- return 0;
- }
- return 1; // Tile blank
- }
- static int TileFlipZ(int sx,int addr,int pal,int zval)
- {
- unsigned int pack=0; unsigned int t=0;
- unsigned char *pd = HighCol+sx;
- char *zb = HighSprZ+sx;
- int collision = 0, zb_s;
- pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
- if (pack)
- {
- t=pack&0x000f0000; if(t) { zb_s=zb[0]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[0]=(unsigned char)(pal|(t>>16)); zb[0]=(char)zval; } }
- t=pack&0x00f00000; if(t) { zb_s=zb[1]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[1]=(unsigned char)(pal|(t>>20)); zb[1]=(char)zval; } }
- t=pack&0x0f000000; if(t) { zb_s=zb[2]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[2]=(unsigned char)(pal|(t>>24)); zb[2]=(char)zval; } }
- t=pack&0xf0000000; if(t) { zb_s=zb[3]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[3]=(unsigned char)(pal|(t>>28)); zb[3]=(char)zval; } }
- t=pack&0x0000000f; if(t) { zb_s=zb[4]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[4]=(unsigned char)(pal|(t )); zb[4]=(char)zval; } }
- t=pack&0x000000f0; if(t) { zb_s=zb[5]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[5]=(unsigned char)(pal|(t>> 4)); zb[5]=(char)zval; } }
- t=pack&0x00000f00; if(t) { zb_s=zb[6]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[6]=(unsigned char)(pal|(t>> 8)); zb[6]=(char)zval; } }
- t=pack&0x0000f000; if(t) { zb_s=zb[7]&0x1f; if(zb_s) collision=1; if(zval>zb_s) { pd[7]=(unsigned char)(pal|(t>>12)); zb[7]=(char)zval; } }
- if(collision) Pico.video.status|=0x20;
- return 0;
- }
- return 1; // Tile blank
- }
- #define sh_pixZ(x) \
- if(t) { \
- if(zb[x]) collision=1; \
- if(zval>zb[x]) { \
- if (t==0xe) { pd[x]=(unsigned char)((pd[x]&0x3f)|0x80); /* hilight */ } \
- else if(t==0xf) { pd[x]=(unsigned char)((pd[x]&0x3f)|0xc0); /* shadow */ } \
- else { zb[x]=(char)zval; pd[x]=(unsigned char)(pal|t); } \
- } \
- }
- static int TileNormZSH(int sx,int addr,int pal,int zval)
- {
- unsigned int pack=0; unsigned int t=0;
- unsigned char *pd = HighCol+sx;
- char *zb = HighSprZ+sx;
- int collision = 0;
- pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
- if (pack)
- {
- t=(pack&0x0000f000)>>12; sh_pixZ(0);
- t=(pack&0x00000f00)>> 8; sh_pixZ(1);
- t=(pack&0x000000f0)>> 4; sh_pixZ(2);
- t=(pack&0x0000000f) ; sh_pixZ(3);
- t=(pack&0xf0000000)>>28; sh_pixZ(4);
- t=(pack&0x0f000000)>>24; sh_pixZ(5);
- t=(pack&0x00f00000)>>20; sh_pixZ(6);
- t=(pack&0x000f0000)>>16; sh_pixZ(7);
- if(collision) Pico.video.status|=0x20;
- return 0;
- }
- return 1; // Tile blank
- }
- static int TileFlipZSH(int sx,int addr,int pal,int zval)
- {
- unsigned int pack=0; unsigned int t=0;
- unsigned char *pd = HighCol+sx;
- char *zb = HighSprZ+sx;
- int collision = 0;
- pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
- if (pack)
- {
- t=(pack&0x000f0000)>>16; sh_pixZ(0);
- t=(pack&0x00f00000)>>20; sh_pixZ(1);
- t=(pack&0x0f000000)>>24; sh_pixZ(2);
- t=(pack&0xf0000000)>>28; sh_pixZ(3);
- t=(pack&0x0000000f) ; sh_pixZ(4);
- t=(pack&0x000000f0)>> 4; sh_pixZ(5);
- t=(pack&0x00000f00)>> 8; sh_pixZ(6);
- t=(pack&0x0000f000)>>12; sh_pixZ(7);
- if(collision) Pico.video.status|=0x20;
- return 0;
- }
- return 1; // Tile blank
- }
- // --------------------------------------------
- #ifndef _ASM_DRAW_C
- static void DrawStrip(struct TileStrip *ts, int sh)
- {
- int tilex=0,dx=0,ty=0,code=0,addr=0,cells;
- int oldcode=-1,blank=-1; // The tile we know is blank
- int pal=0;
- // Draw tiles across screen:
- tilex=(-ts->hscroll)>>3;
- ty=(ts->line&7)<<1; // Y-Offset into tile
- dx=((ts->hscroll-1)&7)+1;
- cells = ts->cells;
- if(dx != 8) cells++; // have hscroll, need to draw 1 cell more
- for (; cells; dx+=8,tilex++,cells--)
- {
- int zero=0;
- code=Pico.vram[ts->nametab+(tilex&ts->xmask)];
- if (code==blank) continue;
- if (code>>15) { // high priority tile
- int cval = code | (dx<<16) | (ty<<25);
- if(code&0x1000) cval^=7<<26;
- *ts->hc++ = cval; // cache it
- continue;
- }
- if (code!=oldcode) {
- oldcode = code;
- // Get tile address/2:
- addr=(code&0x7ff)<<4;
- addr+=ty;
- if (code&0x1000) addr^=0xe; // Y-flip
- // pal=Pico.cram+((code>>9)&0x30);
- pal=((code>>9)&0x30)|(sh<<6);
- }
- if (code&0x0800) zero=TileFlip(dx,addr,pal);
- else zero=TileNorm(dx,addr,pal);
- if (zero) blank=code; // We know this tile is blank now
- }
- // terminate the cache list
- *ts->hc = 0;
- }
- // this is messy
- void DrawStripVSRam(struct TileStrip *ts, int plane)
- {
- int tilex=0,dx=0,ty=0,code=0,addr=0,cell=0,nametabadd=0;
- int oldcode=-1,blank=-1; // The tile we know is blank
- int pal=0,scan=Scanline;
- // Draw tiles across screen:
- tilex=(-ts->hscroll)>>3;
- dx=((ts->hscroll-1)&7)+1;
- if(dx != 8) {
- int vscroll, line;
- cell--; // have hscroll, start with negative cell
- // also calculate intial VS stuff
- vscroll=Pico.vsram[plane];
- // Find the line in the name table
- line=(vscroll+scan)&ts->line&0xffff; // ts->line is really ymask ..
- nametabadd=(line>>3)<<(ts->line>>24); // .. and shift[width]
- ty=(line&7)<<1; // Y-Offset into tile
- }
- for (; cell < ts->cells; dx+=8,tilex++,cell++)
- {
- int zero=0;
- if((cell&1)==0) {
- int line,vscroll;
- vscroll=Pico.vsram[plane+(cell&~1)];
- // Find the line in the name table
- line=(vscroll+scan)&ts->line&0xffff; // ts->line is really ymask ..
- nametabadd=(line>>3)<<(ts->line>>24); // .. and shift[width]
- ty=(line&7)<<1; // Y-Offset into tile
- }
- code=Pico.vram[ts->nametab+nametabadd+(tilex&ts->xmask)];
- if (code==blank) continue;
- if (code>>15) { // high priority tile
- int cval = code | (dx<<16) | (ty<<25);
- if(code&0x1000) cval^=7<<26;
- *ts->hc++ = cval; // cache it
- continue;
- }
- if (code!=oldcode) {
- oldcode = code;
- // Get tile address/2:
- addr=(code&0x7ff)<<4;
- if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip
- // pal=Pico.cram+((code>>9)&0x30);
- pal=((code>>9)&0x30);
- }
- if (code&0x0800) zero=TileFlip(dx,addr,pal);
- else zero=TileNorm(dx,addr,pal);
- if (zero) blank=code; // We know this tile is blank now
- }
- // terminate the cache list
- *ts->hc = 0;
- }
- #endif
- #ifndef _ASM_DRAW_C
- static
- #endif
- void DrawStripInterlace(struct TileStrip *ts)
- {
- int tilex=0,dx=0,ty=0,code=0,addr=0,cells;
- int oldcode=-1,blank=-1; // The tile we know is blank
- int pal=0;
- // Draw tiles across screen:
- tilex=(-ts->hscroll)>>3;
- ty=(ts->line&15)<<1; // Y-Offset into tile
- dx=((ts->hscroll-1)&7)+1;
- cells = ts->cells;
- if(dx != 8) cells++; // have hscroll, need to draw 1 cell more
- for (; cells; dx+=8,tilex++,cells--)
- {
- int zero=0;
- code=Pico.vram[ts->nametab+(tilex&ts->xmask)];
- if (code==blank) continue;
- if (code>>15) { // high priority tile
- int cval = (code&0xfc00) | (dx<<16) | (ty<<25);
- cval|=(code&0x3ff)<<1;
- if(code&0x1000) cval^=0xf<<26;
- *ts->hc++ = cval; // cache it
- continue;
- }
- if (code!=oldcode) {
- oldcode = code;
- // Get tile address/2:
- addr=(code&0x7ff)<<5;
- if (code&0x1000) addr+=30-ty; else addr+=ty; // Y-flip
- // pal=Pico.cram+((code>>9)&0x30);
- pal=((code>>9)&0x30);
- }
- if (code&0x0800) zero=TileFlip(dx,addr,pal);
- else zero=TileNorm(dx,addr,pal);
- if (zero) blank=code; // We know this tile is blank now
- }
- // terminate the cache list
- *ts->hc = 0;
- }
- // --------------------------------------------
- #ifndef _ASM_DRAW_C
- static void DrawLayer(int plane, int *hcache, int maxcells, int sh)
- {
- struct PicoVideo *pvid=&Pico.video;
- const char shift[4]={5,6,5,7}; // 32,64 or 128 sized tilemaps (2 is invalid)
- struct TileStrip ts;
- int width, height, ymask;
- int vscroll, htab;
- ts.hc=hcache;
- ts.cells=maxcells;
- // Work out the TileStrip to draw
- // Work out the name table size: 32 64 or 128 tiles (0-3)
- width=pvid->reg[16];
- height=(width>>4)&3; width&=3;
- ts.xmask=(1<<shift[width])-1; // X Mask in tiles (0x1f-0x7f)
- ymask=(height<<8)|0xff; // Y Mask in pixels
- if(width == 1) ymask&=0x1ff;
- else if(width>1) ymask =0x0ff;
- // Find name table:
- if (plane==0) ts.nametab=(pvid->reg[2]&0x38)<< 9; // A
- else ts.nametab=(pvid->reg[4]&0x07)<<12; // B
- htab=pvid->reg[13]<<9; // Horizontal scroll table address
- if ( pvid->reg[11]&2) htab+=Scanline<<1; // Offset by line
- if ((pvid->reg[11]&1)==0) htab&=~0xf; // Offset by tile
- htab+=plane; // A or B
- // Get horizontal scroll value, will be masked later
- ts.hscroll=Pico.vram[htab&0x7fff];
- if((pvid->reg[12]&6) == 6) {
- // interlace mode 2
- vscroll=Pico.vsram[plane]; // Get vertical scroll value
- // Find the line in the name table
- ts.line=(vscroll+(Scanline<<1))&((ymask<<1)|1);
- ts.nametab+=(ts.line>>4)<<shift[width];
- DrawStripInterlace(&ts);
- } else if( pvid->reg[11]&4) {
- // shit, we have 2-cell column based vscroll
- // luckily this doesn't happen too often
- ts.line=ymask|(shift[width]<<24); // save some stuff instead of line
- DrawStripVSRam(&ts, plane);
- } else {
- vscroll=Pico.vsram[plane]; // Get vertical scroll value
- // Find the line in the name table
- ts.line=(vscroll+Scanline)&ymask;
- ts.nametab+=(ts.line>>3)<<shift[width];
- DrawStrip(&ts, sh);
- }
- }
- // --------------------------------------------
- // tstart & tend are tile pair numbers
- static void DrawWindow(int tstart, int tend, int prio, int sh) // int *hcache
- {
- struct PicoVideo *pvid=&Pico.video;
- int tilex=0,ty=0,nametab,code=0;
- int blank=-1; // The tile we know is blank
- // Find name table line:
- if (pvid->reg[12]&1)
- {
- nametab=(pvid->reg[3]&0x3c)<<9; // 40-cell mode
- nametab+=(Scanline>>3)<<6;
- }
- else
- {
- nametab=(pvid->reg[3]&0x3e)<<9; // 32-cell mode
- nametab+=(Scanline>>3)<<5;
- }
- tilex=tstart<<1;
- tend<<=1;
- ty=(Scanline&7)<<1; // Y-Offset into tile
- if(!(rendstatus&2)) {
- // check the first tile code
- code=Pico.vram[nametab+tilex];
- // if the whole window uses same priority (what is often the case), we may be able to skip this field
- if((code>>15) != prio) return;
- }
- // Draw tiles across screen:
- for (; tilex < tend; tilex++)
- {
- int addr=0,zero=0;
- int pal;
- code=Pico.vram[nametab+tilex];
- if(code==blank) continue;
- if((code>>15) != prio) {
- rendstatus|=2;
- continue;
- }
- pal=((code>>9)&0x30);
- if(sh) {
- int tmp, *zb = (int *)(HighCol+8+(tilex<<3));
- if(prio) {
- tmp = *zb;
- if(!(tmp&0x00000080)) tmp&=~0x000000c0; if(!(tmp&0x00008000)) tmp&=~0x0000c000;
- if(!(tmp&0x00800000)) tmp&=~0x00c00000; if(!(tmp&0x80000000)) tmp&=~0xc0000000;
- *zb++=tmp; tmp = *zb;
- if(!(tmp&0x00000080)) tmp&=~0x000000c0; if(!(tmp&0x00008000)) tmp&=~0x0000c000;
- if(!(tmp&0x00800000)) tmp&=~0x00c00000; if(!(tmp&0x80000000)) tmp&=~0xc0000000;
- *zb++=tmp;
- } else {
- pal |= 0x40;
- }
- }
- // Get tile address/2:
- addr=(code&0x7ff)<<4;
- if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip
- if (code&0x0800) zero=TileFlip(8+(tilex<<3),addr,pal);
- else zero=TileNorm(8+(tilex<<3),addr,pal);
- if (zero) blank=code; // We know this tile is blank now
- }
- // terminate the cache list
- //*hcache = 0;
- }
- // --------------------------------------------
- static void DrawTilesFromCache(int *hc, int sh)
- {
- int code, addr, zero, dx;
- int pal;
- short blank=-1; // The tile we know is blank
- // *ts->hc++ = code | (dx<<16) | (ty<<25); // cache it
- while((code=*hc++)) {
- if(!sh && (short)code == blank) continue;
- // Get tile address/2:
- addr=(code&0x7ff)<<4;
- addr+=(unsigned int)code>>25; // y offset into tile
- dx=(code>>16)&0x1ff;
- if(sh) {
- unsigned char *zb = HighCol+dx;
- if(!(*zb&0x80)) *zb&=0x3f; zb++; if(!(*zb&0x80)) *zb&=0x3f; zb++;
- if(!(*zb&0x80)) *zb&=0x3f; zb++; if(!(*zb&0x80)) *zb&=0x3f; zb++;
- if(!(*zb&0x80)) *zb&=0x3f; zb++; if(!(*zb&0x80)) *zb&=0x3f; zb++;
- if(!(*zb&0x80)) *zb&=0x3f; zb++; if(!(*zb&0x80)) *zb&=0x3f; zb++;
- }
- pal=((code>>9)&0x30);
- if (code&0x0800) zero=TileFlip(dx,addr,pal);
- else zero=TileNorm(dx,addr,pal);
- if(zero) blank=(short)code;
- }
- }
- // --------------------------------------------
- // Index + 0 : hhhhvvvv ab--hhvv yyyyyyyy yyyyyyyy // a: offscreen h, b: offs. v, h: horiz. size
- // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
- static void DrawSprite(int *sprite, int **hc, int sh)
- {
- int width=0,height=0;
- int row=0,code=0;
- int pal;
- int tile=0,delta=0;
- int sx, sy;
- int (*fTileFunc)(int sx,int addr,int pal);
- // parse the sprite data
- sy=sprite[0];
- code=sprite[1];
- sx=code>>16; // X
- width=sy>>28;
- height=(sy>>24)&7; // Width and height in tiles
- sy=(sy<<16)>>16; // Y
- row=Scanline-sy; // Row of the sprite we are on
- if (code&0x1000) row=(height<<3)-1-row; // Flip Y
- tile=code&0x7ff; // Tile number
- tile+=row>>3; // Tile number increases going down
- delta=height; // Delta to increase tile by going right
- if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
- tile<<=4; tile+=(row&7)<<1; // Tile address
- if(code&0x8000) { // high priority - cache it
- *(*hc)++ = (tile<<16)|((code&0x0800)<<5)|((sx<<6)&0x0000ffc0)|((code>>9)&0x30)|((sprite[0]>>16)&0xf);
- } else {
- delta<<=4; // Delta of address
- pal=((code>>9)&0x30)|(sh<<6);
- if(sh && (code&0x6000) == 0x6000) {
- if(code&0x0800) fTileFunc=TileFlipSH;
- else fTileFunc=TileNormSH;
- } else {
- if(code&0x0800) fTileFunc=TileFlip;
- else fTileFunc=TileNorm;
- }
- for (; width; width--,sx+=8,tile+=delta)
- {
- if(sx<=0) continue;
- if(sx>=328) break; // Offscreen
- tile&=0x7fff; // Clip tile address
- fTileFunc(sx,tile,pal);
- }
- }
- }
- #endif
- // Index + 0 : hhhhvvvv s---hhvv yyyyyyyy yyyyyyyy // s: skip flag, h: horiz. size
- // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
- static void DrawSpriteZ(int pack, int pack2, int shpri, int sprio)
- {
- int width=0,height=0;
- int row=0;
- int pal;
- int tile=0,delta=0;
- int sx, sy;
- int (*fTileFunc)(int sx,int addr,int pal,int zval);
- // parse the sprite data
- sx=pack2>>16; // X
- sy=(pack <<16)>>16; // Y
- width=pack>>28;
- height=(pack>>24)&7; // Width and height in tiles
- row=Scanline-sy; // Row of the sprite we are on
- if (pack2&0x1000) row=(height<<3)-1-row; // Flip Y
- tile=pack2&0x7ff; // Tile number
- tile+=row>>3; // Tile number increases going down
- delta=height; // Delta to increase tile by going right
- if (pack2&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
- tile<<=4; tile+=(row&7)<<1; // Tile address
- delta<<=4; // Delta of address
- pal=((pack2>>9)&0x30);
- if((shpri&1)&&!(shpri&2)) pal|=0x40;
- shpri&=1;
- if((pack2&0x6000) != 0x6000) shpri = 0;
- shpri |= (pack2&0x0800)>>10;
- switch(shpri) {
- default:
- case 0: fTileFunc=TileNormZ; break;
- case 1: fTileFunc=TileNormZSH; break;
- case 2: fTileFunc=TileFlipZ; break;
- case 3: fTileFunc=TileFlipZSH; break;
- }
- for (; width; width--,sx+=8,tile+=delta)
- {
- if(sx<=0) continue;
- if(sx>=328) break; // Offscreen
- tile&=0x7fff; // Clip tile address
- fTileFunc(sx,tile,pal,sprio);
- }
- }
- static void DrawSpriteInterlace(unsigned int *sprite)
- {
- int width=0,height=0;
- int row=0,code=0;
- int pal;
- int tile=0,delta=0;
- int sx, sy;
- // parse the sprite data
- sy=sprite[0];
- height=sy>>24;
- sy=(sy&0x3ff)-0x100; // Y
- width=(height>>2)&3; height&=3;
- width++; height++; // Width and height in tiles
- row=(Scanline<<1)-sy; // Row of the sprite we are on
- code=sprite[1];
- sx=((code>>16)&0x1ff)-0x78; // X
- if (code&0x1000) row^=(16<<height)-1; // Flip Y
- tile=code&0x3ff; // Tile number
- tile+=row>>4; // Tile number increases going down
- delta=height; // Delta to increase tile by going right
- if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
- tile<<=5; tile+=(row&15)<<1; // Tile address
- delta<<=5; // Delta of address
- pal=((code>>9)&0x30); // Get palette pointer
- for (; width; width--,sx+=8,tile+=delta)
- {
- if(sx<=0) continue;
- if(sx>=328) break; // Offscreen
- tile&=0x7fff; // Clip tile address
- if (code&0x0800) TileFlip(sx,tile,pal);
- else TileNorm(sx,tile,pal);
- }
- }
- static void DrawAllSpritesInterlace(int pri, int maxwidth)
- {
- struct PicoVideo *pvid=&Pico.video;
- int i,u,table,link=0,sline=Scanline<<1;
- unsigned int *sprites[80]; // Sprite index
- table=pvid->reg[5]&0x7f;
- if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode
- table<<=8; // Get sprite table address/2
- for (i=u=0; u < 80 && i < 21; u++)
- {
- unsigned int *sprite;
- int code, sx, sy, height;
- sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite
- // get sprite info
- code = sprite[0];
- sx = sprite[1];
- if(((sx>>15)&1) != pri) goto nextsprite; // wrong priority sprite
- // check if it is on this line
- sy = (code&0x3ff)-0x100;
- height = (((code>>24)&3)+1)<<4;
- if(sline < sy || sline >= sy+height) goto nextsprite; // no
- // check if sprite is not hidden offscreen
- sx = (sx>>16)&0x1ff;
- sx -= 0x78; // Get X coordinate + 8
- if(sx <= -8*3 || sx >= maxwidth) goto nextsprite;
- // sprite is good, save it's pointer
- sprites[i++]=sprite;
- nextsprite:
- // Find next sprite
- link=(code>>16)&0x7f;
- if(!link) break; // End of sprites
- }
- // Go through sprites backwards:
- for (i-- ;i>=0; i--)
- DrawSpriteInterlace(sprites[i]);
- }
- #ifndef _ASM_DRAW_C
- static void DrawSpritesFromCache(int *hc, int sh)
- {
- int code, tile, sx, delta, width;
- int pal;
- int (*fTileFunc)(int sx,int addr,int pal);
- // *(*hc)++ = (tile<<16)|((code&0x0800)<<5)|((sx<<6)&0x0000ffc0)|((code>>9)&0x30)|((sprite[0]>>24)&0xf);
- while((code=*hc++)) {
- pal=(code&0x30);
- delta=code&0xf;
- width=delta>>2; delta&=3;
- width++; delta++; // Width and height in tiles
- if (code&0x10000) delta=-delta; // Flip X
- delta<<=4;
- tile=((unsigned int)code>>17)<<1;
- sx=(code<<16)>>22; // sx can be negative (start offscreen), so sign extend
- if(sh && pal == 0x30) { //
- if(code&0x10000) fTileFunc=TileFlipSH;
- else fTileFunc=TileNormSH;
- } else {
- if(code&0x10000) fTileFunc=TileFlip;
- else fTileFunc=TileNorm;
- }
- for (; width; width--,sx+=8,tile+=delta)
- {
- if(sx<=0) continue;
- if(sx>=328) break; // Offscreen
- tile&=0x7fff; // Clip tile address
- fTileFunc(sx,tile,pal);
- }
- }
- }
- #endif
- // Index + 0 : ----hhvv -lllllll -------y yyyyyyyy
- // Index + 4 : -------x xxxxxxxx pccvhnnn nnnnnnnn
- // v
- // Index + 0 : hhhhvvvv ab--hhvv yyyyyyyy yyyyyyyy // a: offscreen h, b: offs. v, h: horiz. size
- // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
- static void PrepareSprites(int full)
- {
- struct PicoVideo *pvid=&Pico.video;
- int u=0,link=0,sblocks=0;
- int table=0;
- int *pd = HighPreSpr;
- table=pvid->reg[5]&0x7f;
- if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode
- table<<=8; // Get sprite table address/2
- if (!full)
- {
- int pack;
- // updates: tilecode, sx
- for (u=0; u < 80 && (pack = *pd); u++, pd+=2)
- {
- unsigned int *sprite;
- int code, code2, sx, sy, skip=0;
- sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite
- // parse sprite info
- code = sprite[0];
- code2 = sprite[1];
- code2 &= ~0xfe000000;
- code2 -= 0x00780000; // Get X coordinate + 8 in upper 16 bits
- sx = code2>>16;
- if((sx <= 8-((pack>>28)<<3) && sx >= -0x76) || sx >= 328) skip=1<<23;
- else if ((sy = (pack<<16)>>16) < 240 && sy > -32) {
- int sbl = (2<<(pack>>28))-1;
- sblocks |= sbl<<(sy>>3);
- }
- *pd = (pack&~(1<<23))|skip;
- *(pd+1) = code2;
- // Find next sprite
- link=(code>>16)&0x7f;
- if(!link) break; // End of sprites
- }
- SpriteBlocks |= sblocks;
- }
- else
- {
- for (; u < 80; u++)
- {
- unsigned int *sprite;
- int code, code2, sx, sy, hv, height, width, skip=0, sx_min;
- sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite
- // parse sprite info
- code = sprite[0];
- sy = (code&0x1ff)-0x80;
- hv = (code>>24)&0xf;
- height = (hv&3)+1;
- if(sy > 240 || sy + (height<<3) <= 0) skip|=1<<22;
- width = (hv>>2)+1;
- code2 = sprite[1];
- sx = (code2>>16)&0x1ff;
- sx -= 0x78; // Get X coordinate + 8
- sx_min = 8-(width<<3);
- if((sx <= sx_min && sx >= -0x76) || sx >= 328) skip|=1<<23;
- else if (sx > sx_min && !skip) {
- int sbl = (2<<height)-1;
- int shi = sy>>3;
- if(shi < 0) shi=0; // negative sy
- sblocks |= sbl<<shi;
- }
- *pd++ = (width<<28)|(height<<24)|skip|(hv<<16)|((unsigned short)sy);
- *pd++ = (sx<<16)|((unsigned short)code2);
- // Find next sprite
- link=(code>>16)&0x7f;
- if(!link) break; // End of sprites
- }
- SpriteBlocks = sblocks;
- *pd = 0; // terminate
- }
- }
- static void DrawAllSprites(int *hcache, int maxwidth, int prio, int sh)
- {
- int i,u,n;
- int sx1seen=0; // sprite with x coord 1 or 0 seen
- int ntiles = 0; // tile counter for sprite limit emulation
- int *sprites[40]; // Sprites to draw in fast mode
- int *ps, pack, rs = rendstatus, scan=Scanline;
- if(rs&8) {
- DrawAllSpritesInterlace(prio, maxwidth);
- return;
- }
- if(rs&0x11) {
- //dprintf("PrepareSprites(%i) [%i]", (rs>>4)&1, scan);
- PrepareSprites(rs&0x10);
- rendstatus=rs&~0x11;
- }
- if (!(SpriteBlocks & (1<<(scan>>3)))) return;
- if(((rs&4)||sh)&&prio==0)
- memset(HighSprZ, 0, 328);
- if(!(rs&4)&&prio) {
- if(hcache[0]) DrawSpritesFromCache(hcache, sh);
- return;
- }
- ps = HighPreSpr;
- // Index + 0 : hhhhvvvv ab--hhvv yyyyyyyy yyyyyyyy // a: offscreen h, b: offs. v, h: horiz. size
- // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
- for(i=u=n=0; (pack = *ps) && n < 20; ps+=2, u++)
- {
- int sx, sy, row, pack2;
- if(pack & 0x00400000) continue;
- // get sprite info
- pack2 = *(ps+1);
- sx = pack2>>16;
- sy = (pack <<16)>>16;
- row = scan-sy;
- //dprintf("x: %i y: %i %ix%i", sx, sy, (pack>>28)<<3, (pack>>21)&0x38);
- if(sx == -0x77) sx1seen|=1; // for masking mode 2
- // check if it is on this line
- if(row < 0 || row >= ((pack>>21)&0x38)) continue; // no
- n++; // number of sprites on this line (both visible and hidden, max is 20) [broken]
- // sprite limit
- ntiles += pack>>28;
- if(ntiles > 40) break;
- if(pack & 0x00800000) continue;
- // masking sprite?
- if(sx == -0x78) {
- if(!(sx1seen&1) || sx1seen==3) {
- break; // this sprite is not drawn and remaining sprites are masked
- }
- if((sx1seen>>8) == 0) sx1seen=(i+1)<<8;
- continue;
- }
- else if(sx == -0x77) {
- // masking mode2 (Outrun, Galaxy Force II, Shadow of the beast)
- if(sx1seen>>8) { i=(sx1seen>>8)-1; break; } // seen both 0 and 1
- sx1seen |= 2;
- continue;
- }
- // accurate sprites
- //dprintf("P:%i",((sx>>15)&1));
- if(rs&4) {
- // might need to skip this sprite
- if((pack2&0x8000) ^ (prio<<15)) continue;
- DrawSpriteZ(pack,pack2,sh|(prio<<1),(char)(0x1f-n));
- continue;
- }
- // sprite is good, save it's pointer
- sprites[i++]=ps;
- }
- // Go through sprites backwards:
- if(!(rs&4)) {
- for (i--; i>=0; i--)
- DrawSprite(sprites[i],&hcache,sh);
- // terminate cache list
- *hcache = 0;
- }
- }
- // --------------------------------------------
- #ifndef _ASM_DRAW_C
- static void BackFill(int reg7, int sh)
- {
- unsigned int back=0;
- unsigned int *pd=NULL,*end=NULL;
- // Start with a blank scanline (background colour):
- back=reg7&0x3f;
- back|=sh<<6;
- back|=back<<8;
- back|=back<<16;
- pd= (unsigned int *)(HighCol+8);
- end=(unsigned int *)(HighCol+8+320);
- do { pd[0]=pd[1]=pd[2]=pd[3]=back; pd+=4; } while (pd<end);
- }
- #endif
- // --------------------------------------------
- unsigned short HighPal[0x100];
- #ifndef _ASM_DRAW_C
- static void FinalizeLineBGR444(int sh)
- {
- unsigned short *pd=DrawLineDest;
- unsigned char *ps=HighCol+8;
- unsigned short *pal=Pico.cram;
- int len, i, t;
- if (Pico.video.reg[12]&1) {
- len = 320;
- } else {
- if(!(PicoOpt&0x100)) pd+=32;
- len = 256;
- }
- if(sh) {
- pal=HighPal;
- if(Pico.m.dirtyPal) {
- blockcpy(pal, Pico.cram, 0x40*2);
- // shadowed pixels
- for(i = 0x3f; i >= 0; i--)
- pal[0x40|i] = pal[0xc0|i] = (unsigned short)((pal[i]>>1)&0x0777);
- // hilighted pixels
- for(i = 0x3f; i >= 0; i--) {
- t=pal[i]&0xeee;t+=0x444;if(t&0x10)t|=0xe;if(t&0x100)t|=0xe0;if(t&0x1000)t|=0xe00;t&=0xeee;
- pal[0x80|i]=(unsigned short)t;
- }
- Pico.m.dirtyPal = 0;
- }
- }
- for(i = 0; i < len; i++)
- pd[i] = pal[ps[i]];
- }
- static void FinalizeLineRGB555(int sh)
- {
- unsigned short *pd=DrawLineDest;
- unsigned char *ps=HighCol+8;
- unsigned short *pal=HighPal;
- int len, i, t, dirtyPal = Pico.m.dirtyPal;
- if(dirtyPal) {
- unsigned short *ppal=Pico.cram;
- for(i = 0x3f; i >= 0; i--)
- pal[i] = (unsigned short) (((ppal[i]&0x00f)<<12)|((ppal[i]&0x0f0)<<3)|((ppal[i]&0xf00)>>7));
- Pico.m.dirtyPal = 0;
- }
- if (Pico.video.reg[12]&1) {
- len = 320;
- } else {
- if(!(PicoOpt&0x100)) pd+=32;
- len = 256;
- }
- if(sh) {
- if(dirtyPal) {
- // shadowed pixels
- for(i = 0x3f; i >= 0; i--)
- pal[0x40|i] = pal[0xc0|i] = (unsigned short)((pal[i]>>1)&0x738e);
- // hilighted pixels
- for(i = 0x3f; i >= 0; i--) {
- t=pal[i]&0xe71c;t+=0x4208;if(t&0x20)t|=0x1c;if(t&0x800)t|=0x700;if(t&0x10000)t|=0xe000;t&=0xe71c;
- pal[0x80|i]=(unsigned short)t;
- }
- }
- }
- for(i = 0; i < len; i++)
- pd[i] = pal[ps[i]];
- }
- #endif
- static void FinalizeLine8bit(int sh)
- {
- unsigned char *pd=DrawLineDest;
- int len, rs = rendstatus;
- static int dirty_count;
- if (!sh && Pico.m.dirtyPal == 1 && Scanline < 222) {
- // a hack for mid-frame palette changes
- if (!(rs & 0x20))
- dirty_count = 1;
- else dirty_count++;
- rs |= 0x20;
- rendstatus = rs;
- if (dirty_count == 3) {
- blockcpy(HighPal, Pico.cram, 0x40*2);
- } else if (dirty_count == 11) {
- blockcpy(HighPal+0x40, Pico.cram, 0x40*2);
- }
- }
- if (Pico.video.reg[12]&1) {
- len = 320;
- } else {
- if(!(PicoOpt&0x100)) pd+=32;
- len = 256;
- }
- if (!sh && rs & 0x20) {
- if (dirty_count >= 11) {
- blockcpy_or(pd, HighCol+8, len, 0x80);
- } else {
- blockcpy_or(pd, HighCol+8, len, 0x40);
- }
- } else {
- blockcpy(pd, HighCol+8, len);
- }
- }
- void (*FinalizeLine)(int sh) = FinalizeLineBGR444;
- // --------------------------------------------
- static int DrawDisplay(int sh)
- {
- struct PicoVideo *pvid=&Pico.video;
- int win=0,edge=0,hvwind=0;
- int maxw, maxcells;
- if(pvid->reg[12]&1) {
- maxw = 328; maxcells = 40;
- } else {
- maxw = 264; maxcells = 32;
- }
- // Find out if the window is on this line:
- win=pvid->reg[0x12];
- edge=(win&0x1f)<<3;
- if (win&0x80) { if (Scanline>=edge) hvwind=1; }
- else { if (Scanline< edge) hvwind=1; }
- if(!hvwind) { // we might have a vertical window here
- win=pvid->reg[0x11];
- edge=win&0x1f;
- if(win&0x80) {
- if(!edge) hvwind=1;
- else if(edge < (maxcells>>1)) hvwind=2;
- } else {
- if(!edge);
- else if(edge < (maxcells>>1)) hvwind=2;
- else hvwind=1;
- }
- }
- DrawLayer(1, HighCacheB, maxcells, sh);
- if(hvwind == 1)
- DrawWindow(0, maxcells>>1, 0, sh); // HighCacheAW
- else if(hvwind == 2) {
- // ahh, we have vertical window
- DrawLayer(0, HighCacheA, (win&0x80) ? edge<<1 : maxcells, sh);
- DrawWindow((win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 0, sh); // HighCacheW
- } else
- DrawLayer(0, HighCacheA, maxcells, sh);
- DrawAllSprites(HighCacheS, maxw, 0, sh);
- if(HighCacheB[0]) DrawTilesFromCache(HighCacheB, sh);
- if(hvwind == 1)
- DrawWindow(0, maxcells>>1, 1, sh);
- else if(hvwind == 2) {
- if(HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh);
- DrawWindow((win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 1, sh);
- } else
- if(HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh);
- DrawAllSprites(HighCacheS, maxw, 1, sh);
- return 0;
- }
- static int Skip=0;
- PICO_INTERNAL void PicoFrameStart(void)
- {
- // prepare to do this frame
- rendstatus = (PicoOpt&0x80)>>5; // accurate sprites
- if(rendstatus)
- Pico.video.status &= ~0x0020;
- else Pico.video.status |= 0x0020; // sprite collision
- if((Pico.video.reg[12]&6) == 6) rendstatus |= 8; // interlace mode
- if(Pico.m.dirtyPal) Pico.m.dirtyPal = 2; // reset dirty if needed
- PrepareSprites(1);
- Skip=0;
- }
- PICO_INTERNAL int PicoLine(int scan)
- {
- int sh;
- if (Skip>0) { Skip--; return 0; } // Skip rendering lines
- Scanline=scan;
- sh=(Pico.video.reg[0xC]&8)>>3; // shadow/hilight?
- // Draw screen:
- BackFill(Pico.video.reg[7], sh);
- if (Pico.video.reg[1]&0x40)
- DrawDisplay(sh);
- FinalizeLine(sh);
- //if (SpriteBlocks & (1<<(scan>>3))) for (sh=0; sh < 30; sh++) DrawLineDest[sh] = 0xf;
- Skip=PicoScan(Scanline,DrawLineDest);
- return 0;
- }
- void PicoDrawSetColorFormat(int which)
- {
- if (which == 2)
- FinalizeLine = FinalizeLine8bit;
- else if (which == 1)
- FinalizeLine = FinalizeLineRGB555;
- else FinalizeLine = FinalizeLineBGR444;
- }
|