ABC turbo
[picodrive.git] / Pico / Draw2.c
index 9fc413b..054cee9 100644 (file)
 \r
 #define USE_CACHE\r
 \r
-\r
-int currpri = 0;\r
+// note: this is not implemented in ARM asm\r
+#if defined(DRAW2_OVERRIDE_LINE_WIDTH)\r
+#define LINE_WIDTH DRAW2_OVERRIDE_LINE_WIDTH\r
+#else\r
+#define LINE_WIDTH 328\r
+#endif\r
 \r
 static int HighCache2A[41*(TILE_ROWS+1)+1+1]; // caches for high layers\r
 static int HighCache2B[41*(TILE_ROWS+1)+1+1];\r
@@ -45,7 +49,7 @@ static int TileXnormYnorm(unsigned char *pd,int addr,unsigned char pal)
        unsigned int pack=0; unsigned int t=0, blank = 1;\r
        int i;\r
 \r
-       for(i=8; i; i--, addr+=2, pd += 320+8) {\r
+       for(i=8; i; i--, addr+=2, pd += LINE_WIDTH) {\r
                pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels\r
                if(!pack) continue;\r
 \r
@@ -68,7 +72,7 @@ static int TileXflipYnorm(unsigned char *pd,int addr,unsigned char pal)
        unsigned int pack=0; unsigned int t=0, blank = 1;\r
        int i;\r
 \r
-       for(i=8; i; i--, addr+=2, pd += 320+8) {\r
+       for(i=8; i; i--, addr+=2, pd += LINE_WIDTH) {\r
                pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels\r
                if(!pack) continue;\r
 \r
@@ -91,7 +95,7 @@ static int TileXnormYflip(unsigned char *pd,int addr,unsigned char pal)
        int i;\r
 \r
        addr+=14;\r
-       for(i=8; i; i--, addr-=2, pd += 320+8) {\r
+       for(i=8; i; i--, addr-=2, pd += LINE_WIDTH) {\r
                pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels\r
                if(!pack) continue;\r
 \r
@@ -115,7 +119,7 @@ static int TileXflipYflip(unsigned char *pd,int addr,unsigned char pal)
        int i;\r
 \r
        addr+=14;\r
-       for(i=8; i; i--, addr-=2, pd += 320+8) {\r
+       for(i=8; i; i--, addr-=2, pd += LINE_WIDTH) {\r
                pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels\r
                if(!pack) continue;\r
 \r
@@ -164,8 +168,8 @@ static void DrawWindowFull(int start, int end, int prio)
        code=Pico.vram[nametab+tile_start];\r
        if ((code>>15) != prio) return; // hack: just assume that whole window uses same priority\r
 \r
-       scrpos+=8*328+8;\r
-       scrpos+=8*328*(start-START_ROW);\r
+       scrpos+=8*LINE_WIDTH+8;\r
+       scrpos+=8*LINE_WIDTH*(start-START_ROW);\r
 \r
        // do a window until we reach planestart row\r
        for(trow = start; trow < end; trow++, nametab+=nametab_step) { // current tile row\r
@@ -193,7 +197,7 @@ static void DrawWindowFull(int start, int end, int prio)
                        if(zero) blank=code; // We know this tile is blank now\r
                }\r
 \r
-               scrpos += 328*8;\r
+               scrpos += LINE_WIDTH*8;\r
        }\r
 }\r
 \r
@@ -239,11 +243,11 @@ static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend)
        else          nametab=(pvid->reg[4]&0x07)<<12; // B\r
 \r
        scrpos = PicoDraw2FB;\r
-       scrpos+=8*328*(planestart-START_ROW);\r
+       scrpos+=8*LINE_WIDTH*(planestart-START_ROW);\r
 \r
        // Get vertical scroll value:\r
        vscroll=Pico.vsram[plane]&0x1ff;\r
-       scrpos+=(8-(vscroll&7))*328;\r
+       scrpos+=(8-(vscroll&7))*LINE_WIDTH;\r
        if(vscroll&7) planeend++; // we have vertically clipped tiles due to vscroll, so we need 1 more row\r
 \r
        *hcache++ = 8-(vscroll&7); // push y-offset to tilecache\r
@@ -278,12 +282,8 @@ static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend)
                        code=Pico.vram[nametab_row+(tilex&xmask)];\r
                        if (code==blank) continue;\r
 \r
-#ifdef USE_CACHE\r
                        if (code>>15) { // high priority tile\r
                                *hcache++ = code|(dx<<16)|(trow<<27); // cache it\r
-#else\r
-                       if ((code>>15) != currpri) {\r
-#endif\r
                                continue;\r
                        }\r
 \r
@@ -302,7 +302,7 @@ static void DrawLayerFull(int plane, int *hcache, int planestart, int planeend)
                        if(zero) blank=code; // We know this tile is blank now\r
                }\r
 \r
-               scrpos += 328*8;\r
+               scrpos += LINE_WIDTH*8;\r
        }\r
 \r
        *hcache = 0; // terminate cache\r
@@ -319,7 +319,7 @@ static void DrawTilesFromCacheF(int *hc)
        unsigned char *scrpos = PicoDraw2FB, *pd = 0;\r
 \r
        // *hcache++ = code|(dx<<16)|(trow<<27); // cache it\r
-       scrpos+=(*hc++)*328 - START_ROW*328*8;\r
+       scrpos+=(*hc++)*LINE_WIDTH - START_ROW*LINE_WIDTH*8;\r
 \r
        while((code=*hc++)) {\r
                if((short)code == blank) continue;\r
@@ -327,7 +327,7 @@ static void DrawTilesFromCacheF(int *hc)
                // y pos\r
                if(((unsigned)code>>27) != prevy) {\r
                        prevy = (unsigned)code>>27;\r
-                       pd = scrpos + prevy*328*8;\r
+                       pd = scrpos + prevy*LINE_WIDTH*8;\r
                }\r
 \r
                // Get tile address/2:\r
@@ -380,7 +380,7 @@ static void DrawSpriteFull(unsigned int *sprite)
        while(sy <= START_ROW*8) { sy+=8; tile+=tdeltay; height--; }\r
 \r
        scrpos = PicoDraw2FB;\r
-       scrpos+=(sy-START_ROW*8)*328;\r
+       scrpos+=(sy-START_ROW*8)*LINE_WIDTH;\r
 \r
        for (; height > 0; height--, sy+=8, tile+=tdeltay)\r
        {\r
@@ -402,7 +402,7 @@ static void DrawSpriteFull(unsigned int *sprite)
                        }\r
                }\r
 \r
-               scrpos+=8*328;\r
+               scrpos+=8*LINE_WIDTH;\r
        }\r
 }\r
 #endif\r
@@ -479,8 +479,7 @@ static void DrawAllSpritesFull(int prio, int maxwidth)
 #ifndef _ASM_DRAW_C\r
 static void BackFillFull(int reg7)\r
 {\r
-       unsigned int back, i;\r
-       unsigned int *p=(unsigned int *)PicoDraw2FB;\r
+       unsigned int back;\r
 \r
        // Start with a background color:\r
 //     back=PicoCramHigh[reg7&0x3f];\r
@@ -488,16 +487,11 @@ static void BackFillFull(int reg7)
        back|=back<<8;\r
        back|=back<<16;\r
 \r
-       for(i = (8+320)*(8+(END_ROW-START_ROW)*8)/16; i; i--) {\r
-               *p++ = back; // do 16 pixels per iteration\r
-               *p++ = back;\r
-               *p++ = back;\r
-               *p++ = back;\r
-       }\r
+       memset32((int *)PicoDraw2FB, back, LINE_WIDTH*(8+(END_ROW-START_ROW)*8)/4);\r
 }\r
 #endif\r
 \r
-static void DrawDisplayFull()\r
+static void DrawDisplayFull(void)\r
 {\r
        struct PicoVideo *pvid=&Pico.video;\r
        int win, edge=0, hvwin=0; // LSb->MSb: hwin&plane, vwin&plane, full\r
@@ -512,7 +506,8 @@ static void DrawDisplayFull()
        }\r
 \r
        // horizontal window?\r
-       if((win=pvid->reg[0x12])) {\r
+       if ((win=pvid->reg[0x12]))\r
+       {\r
                hvwin=1; // hwindow shares display with plane A\r
                edge=win&0x1f;\r
                if(win == 0x80) {\r
@@ -531,7 +526,8 @@ static void DrawDisplayFull()
        }\r
 \r
        // check for vertical window, but only if win is not fullscreen\r
-       if(hvwin != 4) {\r
+       if (hvwin != 4)\r
+       {\r
                win=pvid->reg[0x11];\r
                edge=win&0x1f;\r
                if (win&0x80) {\r
@@ -555,15 +551,16 @@ static void DrawDisplayFull()
                }\r
        }\r
 \r
-       if(hvwin==1) { winend|=maxcolc<<16; planeend|=maxcolc<<16; }\r
+       if (hvwin==1) { winend|=maxcolc<<16; planeend|=maxcolc<<16; }\r
 \r
-       currpri = 0;\r
-       DrawLayerFull(1, HighCache2B, START_ROW, (maxcolc<<16)|END_ROW);\r
-       switch(hvwin) {\r
+       HighCache2A[1] = HighCache2B[1] = 0;\r
+       if (PicoDrawMask & PDRAW_LAYERB_ON)\r
+               DrawLayerFull(1, HighCache2B, START_ROW, (maxcolc<<16)|END_ROW);\r
+       if (PicoDrawMask & PDRAW_LAYERA_ON) switch (hvwin)\r
+       {\r
                case 4:\r
                // fullscreen window\r
                DrawWindowFull(START_ROW, (maxcolc<<16)|END_ROW, 0);\r
-               HighCache2A[1] = 0;\r
                break;\r
 \r
                case 3:\r
@@ -585,12 +582,13 @@ static void DrawDisplayFull()
                DrawLayerFull(0, HighCache2A, START_ROW, (maxcolc<<16)|END_ROW);\r
                break;\r
        }\r
-       DrawAllSpritesFull(0, maxw);\r
+       if (PicoDrawMask & PDRAW_SPRITES_LOW_ON)\r
+               DrawAllSpritesFull(0, maxw);\r
 \r
-#ifdef USE_CACHE\r
-       if(HighCache2B[1]) DrawTilesFromCacheF(HighCache2B);\r
-       if(HighCache2A[1]) DrawTilesFromCacheF(HighCache2A);\r
-       switch(hvwin) {\r
+       if (HighCache2B[1]) DrawTilesFromCacheF(HighCache2B);\r
+       if (HighCache2A[1]) DrawTilesFromCacheF(HighCache2A);\r
+       if (PicoDrawMask & PDRAW_LAYERA_ON) switch (hvwin)\r
+       {\r
                case 4:\r
                // fullscreen window\r
                DrawWindowFull(START_ROW, (maxcolc<<16)|END_ROW, 1);\r
@@ -608,18 +606,15 @@ static void DrawDisplayFull()
                DrawWindowFull(winstart, winend, 1);\r
                break;\r
        }\r
-#else\r
-       currpri = 1;\r
-       // TODO\r
-#endif\r
-       DrawAllSpritesFull(1, maxw);\r
+       if (PicoDrawMask & PDRAW_SPRITES_HI_ON)\r
+               DrawAllSpritesFull(1, maxw);\r
 }\r
 \r
 \r
 PICO_INTERNAL void PicoFrameFull()\r
 {\r
        // prepare cram?\r
-       if(PicoPrepareCram) PicoPrepareCram();\r
+       if (PicoPrepareCram) PicoPrepareCram();\r
 \r
        // Draw screen:\r
        BackFillFull(Pico.video.reg[7]);\r