release 1.80beta1 for pandora
[picodrive.git] / platform / uiq3 / engine / vid.cpp
index bd1b3fd..d004bdf 100644 (file)
@@ -5,7 +5,7 @@
 \r
 #include "vid.h"\r
 #include "../Engine.h"\r
-#include <Pico/PicoInt.h>\r
+#include <pico/pico_int.h>\r
 #include "../../common/emu.h"\r
 #include "blit.h"\r
 #include "debug.h"\r
@@ -19,7 +19,7 @@ extern const char *actionNames[];
 static void *screenbuff = 0; // pointer to real device video memory\r
 //static\r
 extern "C" { unsigned char *PicoDraw2FB = 0; }  // temporary buffer\r
-const int framebuffsize  = (8+320)*(8+240+8)*2+8*2; // actual framebuffer size (in bytes+to support new rendering mode)\r
+const int framebuffsize  = (8+320)*(8+240+8)*2+8*2; // PicoDraw2FB size (in bytes+to support new rendering mode)\r
 \r
 // drawer function pointers\r
 static void (*drawTextFps)(const char *text) = 0;\r
@@ -92,7 +92,7 @@ static const unsigned long mask_numbers[] = {
 \r
 static int EmuScanBegin8(unsigned int num)\r
 {\r
-       DrawLineDest = PicoDraw2FB + 328*num + 328*8 + 8;\r
+       DrawLineDest = PicoDraw2FB + 328*num + 8;\r
 \r
        return 0;\r
 }\r
@@ -105,7 +105,7 @@ static int EmuScanEndFit0(unsigned int num)
        static int u = 0, num2 = 0;\r
        if(!num) u = num2 = 0;\r
 \r
-       DrawLineDest = PicoDraw2FB + 328*(++num2) + 328*8 + 8;\r
+       DrawLineDest = PicoDraw2FB + 328*(++num2) + 8;\r
 \r
        u += 6666;\r
 \r
@@ -182,7 +182,7 @@ static void drawTextM2Fat(int x, int y, const char *text)
 static void drawTextFpsCenter0(const char *text)\r
 {\r
        if(!text) return;\r
-       drawTextM2(214, 216, text);\r
+       drawTextM2((Pico.video.reg[12]&1) ? 234 : 214, 216, text);\r
 }\r
 \r
 static void drawTextFpsFit0(const char *text)\r
@@ -206,7 +206,7 @@ static void drawTextFps0(const char *text)
 static void drawTextNoticeCenter0(const char *text)\r
 {\r
        if(!text) return;\r
-       drawTextM2(2, 216, text);\r
+       drawTextM2(42, 216, text);\r
 }\r
 \r
 static void drawTextNoticeFit0(const char *text)\r
@@ -250,12 +250,14 @@ static void fillLocalPal(void)
                memcpy32(localPal+0xc0, localPal+0x40, 0x40);\r
                localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
                localPal[0xf0] = 0x00ee0000;\r
-       } else if (rendstatus & 0x20) { // mid-frame palette changes\r
+       }\r
+       else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes\r
                vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
                vidConvCpyRGB32(localPal+0x40, HighPal, 0x40);\r
                vidConvCpyRGB32(localPal+0x80, HighPal+0x40, 0x40);\r
        } else {\r
                vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
+               memcpy32(localPal+0x80, localPal, 0x40); // for sprite prio mess\r
        }\r
 }\r
 \r
@@ -266,15 +268,13 @@ static void vidBlit_90(int full)
        unsigned char *ps = PicoDraw2FB+328*8;\r
        unsigned long *pd = (unsigned long *) screenbuff;\r
 \r
-       if (Pico.m.dirtyPal) fillLocalPal();\r
-\r
        if(Pico.video.reg[12]&1)\r
                vidConvCpy_90(pd, ps, localPal, 320/8);\r
        else {\r
                if(full) vidClear(pd, 32);\r
-               pd += 256*32;\r
+               pd += (240+VID_BORDER_R)*32;\r
                vidConvCpy_90(pd, ps, localPal, 256/8);\r
-               if(full) vidClear(pd + 256*256, 32);\r
+               if(full) vidClear(pd + (240+VID_BORDER_R)*256, 32);\r
        }\r
 }\r
 \r
@@ -284,16 +284,14 @@ static void vidBlit_270(int full)
        unsigned char *ps = PicoDraw2FB+328*8;\r
        unsigned long *pd = (unsigned long *) screenbuff;\r
 \r
-       if (Pico.m.dirtyPal) fillLocalPal();\r
-\r
        if(Pico.video.reg[12]&1)\r
                vidConvCpy_270(pd, ps, localPal, 320/8);\r
        else {\r
                if(full) vidClear(pd, 32);\r
-               pd += 256*32;\r
+               pd += (240+VID_BORDER_R)*32;\r
                ps -= 64;     // the blitter starts copying from the right border, so we need to adjust\r
                vidConvCpy_270(pd, ps, localPal, 256/8);\r
-               if(full) vidClear(pd + 256*256, 32);\r
+               if(full) vidClear(pd + (240+VID_BORDER_R)*256, 32);\r
        }\r
 }\r
 \r
@@ -303,11 +301,9 @@ static void vidBlitCenter_0(int full)
        unsigned char *ps = PicoDraw2FB+328*8+8;\r
        unsigned long *pd = (unsigned long *) screenbuff;\r
 \r
-       if (Pico.m.dirtyPal) fillLocalPal();\r
-\r
        if(Pico.video.reg[12]&1) ps += 32;\r
        vidConvCpy_center_0(pd, ps, localPal);\r
-       if(full) vidClear(pd + 224*256, 96);\r
+       if(full) vidClear(pd + (240+VID_BORDER_R)*224, 96);\r
 }\r
 \r
 \r
@@ -316,58 +312,47 @@ static void vidBlitCenter_180(int full)
        unsigned char *ps = PicoDraw2FB+328*8+8;\r
        unsigned long *pd = (unsigned long *) screenbuff;\r
 \r
-       if (Pico.m.dirtyPal) fillLocalPal();\r
-\r
        if(Pico.video.reg[12]&1) ps += 32;\r
        vidConvCpy_center_180(pd, ps, localPal);\r
-       if(full) vidClear(pd + 224*256, 96);\r
+       if(full) vidClear(pd + (240+VID_BORDER_R)*224, 96);\r
 }\r
 \r
 \r
 static void vidBlitFit_0(int full)\r
 {\r
-       if (Pico.m.dirtyPal) fillLocalPal();\r
-\r
        if(Pico.video.reg[12]&1)\r
-                vidConvCpy_center2_40c_0(screenbuff, PicoDraw2FB+328*8, localPal, 168);\r
+            vidConvCpy_center2_40c_0(screenbuff, PicoDraw2FB+328*8, localPal, 168);\r
        else vidConvCpy_center2_32c_0(screenbuff, PicoDraw2FB+328*8, localPal, 168);\r
-       if(full) vidClear((unsigned long *)screenbuff + 168*256, 320-168);\r
+       if(full) vidClear((unsigned long *)screenbuff + (240+VID_BORDER_R)*168, 320-168);\r
 }\r
 \r
 \r
 static void vidBlitFit_180(int full)\r
 {\r
-       if (Pico.m.dirtyPal) fillLocalPal();\r
-\r
        if(Pico.video.reg[12]&1)\r
             vidConvCpy_center2_40c_180(screenbuff, PicoDraw2FB+328*8, localPal, 168);\r
        else vidConvCpy_center2_32c_180(screenbuff, PicoDraw2FB+328*8-64, localPal, 168);\r
-       if(full) vidClear((unsigned long *)screenbuff + 168*256, 320-168);\r
+       if(full) vidClear((unsigned long *)screenbuff + (240+VID_BORDER_R)*168, 320-168);\r
 }\r
 \r
 \r
 static void vidBlitFit2_0(int full)\r
 {\r
-       if (Pico.m.dirtyPal) fillLocalPal();\r
-\r
        if(Pico.video.reg[12]&1)\r
             vidConvCpy_center2_40c_0(screenbuff, PicoDraw2FB+328*8, localPal, 224);\r
        else vidConvCpy_center2_32c_0(screenbuff, PicoDraw2FB+328*8, localPal, 224);\r
-       if(full) vidClear((unsigned long *)screenbuff + 224*256, 96);\r
+       if(full) vidClear((unsigned long *)screenbuff + (240+VID_BORDER_R)*224, 96);\r
 }\r
 \r
 \r
 static void vidBlitFit2_180(int full)\r
 {\r
-       if (Pico.m.dirtyPal) fillLocalPal();\r
-\r
        if(Pico.video.reg[12]&1)\r
             vidConvCpy_center2_40c_180(screenbuff, PicoDraw2FB+328*8, localPal, 224);\r
        else vidConvCpy_center2_32c_180(screenbuff, PicoDraw2FB+328*8-64, localPal, 224);\r
-       if(full) vidClear((unsigned long *)screenbuff + 224*256, 96);\r
+       if(full) vidClear((unsigned long *)screenbuff + (240+VID_BORDER_R)*224, 96);\r
 }\r
 \r
-\r
 static void vidBlitCfg(void)\r
 {\r
        unsigned short *ps = (unsigned short *) PicoDraw2FB;\r
@@ -378,7 +363,7 @@ static void vidBlitCfg(void)
        //for (int i = 1; i < 320; i++, ps += 240, pd += 256)\r
        //      vidConvCpyRGB32(pd, ps, 240);\r
 \r
-       for (i = 0; i < 320; i++, pd += 16)\r
+       for (i = 0; i < 320; i++, pd += VID_BORDER_R)\r
                for (int u = 0; u < 240; u++, ps++, pd++)\r
                        *pd = ((*ps & 0xf) << 20) | ((*ps & 0xf0) << 8) | ((*ps & 0xf00) >> 4);\r
 }\r
@@ -403,6 +388,7 @@ int vidInit(void *vidmem, int reinit)
        // select suitable blitters\r
        vidBlit = vidBlit_270;\r
        PicoScanBegin = EmuScanBegin8;\r
+       PicoScanEnd = NULL;\r
        drawTextFps = drawTextFps0;\r
        drawTextNotice = drawTextNotice0;\r
 \r
@@ -425,6 +411,7 @@ int vidInit(void *vidmem, int reinit)
                        vidBlit = vidBlitFit_0;\r
                        drawTextFps = drawTextFpsFit0;\r
                        drawTextNotice = drawTextNoticeFit0;\r
+                       PicoScanBegin = NULL;\r
                        PicoScanEnd = EmuScanEndFit0;\r
                }\r
        } else if (currentConfig.rotation == TPicoConfig::PRot90) {\r
@@ -446,6 +433,7 @@ int vidInit(void *vidmem, int reinit)
                        vidBlit = vidBlitFit_180;\r
                        drawTextFps = drawTextFpsFit0;\r
                        drawTextNotice = drawTextNoticeFit0;\r
+                       PicoScanBegin = NULL;\r
                        PicoScanEnd = EmuScanEndFit0;\r
                }\r
        }\r
@@ -453,6 +441,7 @@ int vidInit(void *vidmem, int reinit)
                vidBlit = vidBlit_270;\r
        }\r
 \r
+       fillLocalPal();\r
        vidBlit(1);\r
        PicoOpt |= 0x100;\r
        Pico.m.dirtyPal = 1;\r
@@ -475,6 +464,7 @@ void vidDrawFrame(char *noticeStr, char *fpsStr, int num)
                drawTextFps(fpsStr);\r
        drawTextNotice(noticeStr);\r
 \r
+       if (Pico.m.dirtyPal) fillLocalPal();\r
        vidBlit(!num); // copy full frame once a second\r
 }\r
 \r