UIQ3 update, some makefile unification, rm old configs, stuff
[picodrive.git] / platform / uiq3 / engine / vid.cpp
index 308b10b..bd1b3fd 100644 (file)
@@ -5,20 +5,20 @@
 \r
 #include "vid.h"\r
 #include "../Engine.h"\r
-#include "../../../pico/picoInt.h"\r
+#include <Pico/PicoInt.h>\r
+#include "../../common/emu.h"\r
 #include "blit.h"\r
 #include "debug.h"\r
 \r
 \r
 // global stuff\r
-extern TPicoConfig *currentConfig;\r
 extern TPicoAreaConfigEntry areaConfig[];\r
 extern const char *actionNames[];\r
 \r
 // main framebuffer\r
 static void *screenbuff = 0; // pointer to real device video memory\r
 //static\r
-extern "C" { unsigned char *framebuff = 0; }  // temporary buffer\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
 \r
 // drawer function pointers\r
@@ -87,35 +87,25 @@ static const unsigned long mask_numbers[] = {
 };\r
 \r
 \r
-////////////////////////////////\r
-// Cram functions\r
-\r
-static int EmuCramNull(int cram)\r
-{\r
-       User::Panic(_L("Cram called!!"), 0);\r
-       return cram;\r
-}\r
-\r
-\r
 ////////////////////////////////\r
 // PicoScan functions\r
 \r
-static int EmuScan8(unsigned int num, void *sdata)\r
+static int EmuScanBegin8(unsigned int num)\r
 {\r
-       DrawLineDest = framebuff + 328*(num+1) + 328*8 + 8;\r
+       DrawLineDest = PicoDraw2FB + 328*num + 328*8 + 8;\r
 \r
        return 0;\r
 }\r
 \r
 \r
-static int EmuScanFit0(unsigned int num, void *sdata)\r
+static int EmuScanEndFit0(unsigned int num)\r
 {\r
        // 0.75, 168 lines\r
 \r
        static int u = 0, num2 = 0;\r
        if(!num) u = num2 = 0;\r
 \r
-       DrawLineDest = framebuff + 328*(++num2) + 328*8 + 8;\r
+       DrawLineDest = PicoDraw2FB + 328*(++num2) + 328*8 + 8;\r
 \r
        u += 6666;\r
 \r
@@ -136,7 +126,7 @@ static int EmuScanFit0(unsigned int num, void *sdata)
 \r
 static void drawTextM2(int x, int y, const char *text)\r
 {\r
-       unsigned char *vidmem = framebuff + 328*8 + 8;\r
+       unsigned char *vidmem = PicoDraw2FB + 328*8 + 8;\r
        int charmask, i, cx = x, cy;\r
        unsigned char *l, *le;\r
 \r
@@ -164,7 +154,7 @@ static void drawTextM2(int x, int y, const char *text)
 \r
 static void drawTextM2Fat(int x, int y, const char *text)\r
 {\r
-       unsigned char *vidmem = framebuff + 328*8 + 8;\r
+       unsigned char *vidmem = PicoDraw2FB + 328*8 + 8;\r
        int charmask, i, cx = x&~1, cy;\r
        unsigned short *l, *le;\r
 \r
@@ -257,7 +247,7 @@ static void fillLocalPal(void)
                vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
                vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40);\r
                vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40);\r
-               blockcpy(localPal+0xc0, localPal+0x40, 0x40*4);\r
+               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
@@ -273,7 +263,7 @@ static void fillLocalPal(void)
 // note: the internal 8 pixel border is taken care by asm code\r
 static void vidBlit_90(int full)\r
 {\r
-       unsigned char *ps = framebuff+328*8;\r
+       unsigned char *ps = PicoDraw2FB+328*8;\r
        unsigned long *pd = (unsigned long *) screenbuff;\r
 \r
        if (Pico.m.dirtyPal) fillLocalPal();\r
@@ -291,7 +281,7 @@ static void vidBlit_90(int full)
 \r
 static void vidBlit_270(int full)\r
 {\r
-       unsigned char *ps = framebuff+328*8;\r
+       unsigned char *ps = PicoDraw2FB+328*8;\r
        unsigned long *pd = (unsigned long *) screenbuff;\r
 \r
        if (Pico.m.dirtyPal) fillLocalPal();\r
@@ -310,7 +300,7 @@ static void vidBlit_270(int full)
 \r
 static void vidBlitCenter_0(int full)\r
 {\r
-       unsigned char *ps = framebuff+328*8+8;\r
+       unsigned char *ps = PicoDraw2FB+328*8+8;\r
        unsigned long *pd = (unsigned long *) screenbuff;\r
 \r
        if (Pico.m.dirtyPal) fillLocalPal();\r
@@ -323,7 +313,7 @@ static void vidBlitCenter_0(int full)
 \r
 static void vidBlitCenter_180(int full)\r
 {\r
-       unsigned char *ps = framebuff+328*8+8;\r
+       unsigned char *ps = PicoDraw2FB+328*8+8;\r
        unsigned long *pd = (unsigned long *) screenbuff;\r
 \r
        if (Pico.m.dirtyPal) fillLocalPal();\r
@@ -339,8 +329,8 @@ static void vidBlitFit_0(int full)
        if (Pico.m.dirtyPal) fillLocalPal();\r
 \r
        if(Pico.video.reg[12]&1)\r
-                vidConvCpy_center2_40c_0(screenbuff, framebuff+328*8, localPal, 168);\r
-       else vidConvCpy_center2_32c_0(screenbuff, framebuff+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
 }\r
 \r
@@ -350,8 +340,8 @@ static void vidBlitFit_180(int full)
        if (Pico.m.dirtyPal) fillLocalPal();\r
 \r
        if(Pico.video.reg[12]&1)\r
-            vidConvCpy_center2_40c_180(screenbuff, framebuff+328*8, localPal, 168);\r
-       else vidConvCpy_center2_32c_180(screenbuff, framebuff+328*8-64, localPal, 168);\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
 }\r
 \r
@@ -361,8 +351,8 @@ static void vidBlitFit2_0(int full)
        if (Pico.m.dirtyPal) fillLocalPal();\r
 \r
        if(Pico.video.reg[12]&1)\r
-            vidConvCpy_center2_40c_0(screenbuff, framebuff+328*8, localPal, 224);\r
-       else vidConvCpy_center2_32c_0(screenbuff, framebuff+328*8, localPal, 224);\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
 }\r
 \r
@@ -372,15 +362,15 @@ static void vidBlitFit2_180(int full)
        if (Pico.m.dirtyPal) fillLocalPal();\r
 \r
        if(Pico.video.reg[12]&1)\r
-            vidConvCpy_center2_40c_180(screenbuff, framebuff+328*8, localPal, 224);\r
-       else vidConvCpy_center2_32c_180(screenbuff, framebuff+328*8-64, localPal, 224);\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
 }\r
 \r
 \r
 static void vidBlitCfg(void)\r
 {\r
-       unsigned short *ps = (unsigned short *) framebuff;\r
+       unsigned short *ps = (unsigned short *) PicoDraw2FB;\r
        unsigned long *pd = (unsigned long *) screenbuff;\r
        int i;\r
 \r
@@ -402,20 +392,17 @@ int vidInit(void *vidmem, int reinit)
        if(!reinit) {\r
                // prepare framebuffer\r
                screenbuff = vidmem;\r
-               framebuff = (unsigned char *) malloc(framebuffsize);\r
+               PicoDraw2FB = (unsigned char *) malloc(framebuffsize);\r
 \r
                if(!screenbuff) return KErrNotSupported;\r
-               if(!framebuff)  return KErrNoMemory;\r
-\r
-               memset(framebuff, 0, framebuffsize);\r
+               if(!PicoDraw2FB)  return KErrNoMemory;\r
 \r
-               // Cram function: go and hack Pico so it never gets called\r
-               PicoCram = EmuCramNull;\r
+               memset(PicoDraw2FB, 0, framebuffsize);\r
        }\r
 \r
        // select suitable blitters\r
        vidBlit = vidBlit_270;\r
-       PicoScan = EmuScan8;\r
+       PicoScanBegin = EmuScanBegin8;\r
        drawTextFps = drawTextFps0;\r
        drawTextNotice = drawTextNotice0;\r
 \r
@@ -424,12 +411,13 @@ int vidInit(void *vidmem, int reinit)
        localPal[0xf0] = 0x00ee0000;\r
 \r
        // setup all orientation related stuff\r
-       if(currentConfig->iScreenRotation == TPicoConfig::PRot0) {\r
-               if(currentConfig->iScreenMode == TPicoConfig::PMCenter) {\r
+       if (currentConfig.rotation == TPicoConfig::PRot0)\r
+       {\r
+               if (currentConfig.scaling == TPicoConfig::PMCenter) {\r
                        vidBlit = vidBlitCenter_0;\r
                        drawTextFps = drawTextFpsCenter0;\r
                        drawTextNotice = drawTextNoticeCenter0;\r
-               } else if(currentConfig->iScreenMode == TPicoConfig::PMFit2) {\r
+               } else if (currentConfig.scaling == TPicoConfig::PMFit2) {\r
                        vidBlit = vidBlitFit2_0;\r
                        drawTextFps = drawTextFpsFit2_0;\r
                        drawTextNotice = drawTextNoticeFit2_0;\r
@@ -437,16 +425,20 @@ int vidInit(void *vidmem, int reinit)
                        vidBlit = vidBlitFit_0;\r
                        drawTextFps = drawTextFpsFit0;\r
                        drawTextNotice = drawTextNoticeFit0;\r
-                       PicoScan = EmuScanFit0;\r
+                       PicoScanEnd = EmuScanEndFit0;\r
                }\r
-       } else if(currentConfig->iScreenRotation == TPicoConfig::PRot90) {\r
+       } else if (currentConfig.rotation == TPicoConfig::PRot90) {\r
                vidBlit = vidBlit_90;\r
-       } else if(currentConfig->iScreenRotation == TPicoConfig::PRot180) {\r
-               if(currentConfig->iScreenMode == TPicoConfig::PMCenter) {\r
+       }\r
+       else if (currentConfig.rotation == TPicoConfig::PRot180)\r
+       {\r
+               if (currentConfig.scaling == TPicoConfig::PMCenter)\r
+               {\r
                        vidBlit = vidBlitCenter_180;\r
                        drawTextFps = drawTextFpsCenter0;\r
                        drawTextNotice = drawTextNoticeCenter0;\r
-               } else if(currentConfig->iScreenMode == TPicoConfig::PMFit2) {\r
+               }\r
+               else if (currentConfig.scaling == TPicoConfig::PMFit2) {\r
                        vidBlit = vidBlitFit2_180;\r
                        drawTextFps = drawTextFpsFit2_0;\r
                        drawTextNotice = drawTextNoticeFit2_0;\r
@@ -454,9 +446,10 @@ int vidInit(void *vidmem, int reinit)
                        vidBlit = vidBlitFit_180;\r
                        drawTextFps = drawTextFpsFit0;\r
                        drawTextNotice = drawTextNoticeFit0;\r
-                       PicoScan = EmuScanFit0;\r
+                       PicoScanEnd = EmuScanEndFit0;\r
                }\r
-       } else if(currentConfig->iScreenRotation == TPicoConfig::PRot270) {\r
+       }\r
+       else if (currentConfig.rotation == TPicoConfig::PRot270) {\r
                vidBlit = vidBlit_270;\r
        }\r
 \r
@@ -469,16 +462,16 @@ int vidInit(void *vidmem, int reinit)
 \r
 void vidFree()\r
 {\r
-       free(framebuff);\r
-       framebuff = 0;\r
+       free(PicoDraw2FB);\r
+       PicoDraw2FB = 0;\r
 }\r
 \r
 void vidDrawFrame(char *noticeStr, char *fpsStr, int num)\r
 {\r
-       DrawLineDest = framebuff + 328*8 + 8;\r
+       DrawLineDest = PicoDraw2FB + 328*8 + 8;\r
 \r
 //     PicoFrame(); // moved to main loop\r
-       if(currentConfig->iFlags & 2)\r
+       if (currentConfig.EmuOpt & EOPT_SHOW_FPS)\r
                drawTextFps(fpsStr);\r
        drawTextNotice(noticeStr);\r
 \r
@@ -489,7 +482,7 @@ void vidDrawFrame(char *noticeStr, char *fpsStr, int num)
 \r
 static void drawText0(int x, int y, const char *text, long color)\r
 {\r
-       unsigned short *vidmem=(unsigned short *)framebuff;\r
+       unsigned short *vidmem=(unsigned short *)PicoDraw2FB;\r
        int charmask, i, cx = x, cy;\r
        unsigned short *l, *le, dmask=0x0333;\r
 \r
@@ -519,7 +512,7 @@ static void drawText0(int x, int y, const char *text, long color)
 // draws rect with width - 1 and height - 1\r
 static void drawRect(const TRect &rc, unsigned short color)\r
 {\r
-       unsigned short *vidmem=(unsigned short *)framebuff;\r
+       unsigned short *vidmem=(unsigned short *)PicoDraw2FB;\r
 \r
        if(rc.iTl.iX - rc.iBr.iX && rc.iTl.iY - rc.iBr.iY) {\r
                int stepX = rc.iTl.iX < rc.iBr.iX ? 1 : -1;\r
@@ -540,7 +533,7 @@ static void drawRect(const TRect &rc, unsigned short color)
 // draws fullsize filled rect\r
 static void drawRectFilled(const TRect rc, unsigned short color)\r
 {\r
-       unsigned short *vidmem=(unsigned short *)framebuff;\r
+       unsigned short *vidmem=(unsigned short *)PicoDraw2FB;\r
 \r
        if(rc.iTl.iX - rc.iBr.iX && rc.iTl.iY - rc.iBr.iY) {\r
                int stepX = rc.iTl.iX < rc.iBr.iX ? 1 : -1;\r
@@ -559,7 +552,7 @@ static void drawRectFilled(const TRect rc, unsigned short color)
 // direction: -1 left, 1 right\r
 static void drawArrow0(TPoint p, int direction, unsigned short color)\r
 {\r
-       unsigned short *vidmem=(unsigned short *)framebuff;\r
+       unsigned short *vidmem=(unsigned short *)PicoDraw2FB;\r
        int width = 15;\r
        int x = p.iX;\r
        int y = p.iY;\r
@@ -603,7 +596,7 @@ void vidKeyConfigFrame(const TUint whichAction)
        int i;\r
        char buttonNames[128];\r
        buttonNames[0] = 0;\r
-       memset(framebuff, 0, framebuffsize);\r
+       memset(PicoDraw2FB, 0, framebuffsize);\r
 \r
        unsigned long currentActCode = 1 << whichAction;\r
 \r
@@ -611,7 +604,7 @@ void vidKeyConfigFrame(const TUint whichAction)
        const TPicoAreaConfigEntry *e = areaConfig + 1; i = 0;\r
        while(e->rect != TRect(0,0,0,0)) { e++; i++; }\r
        for(e--, i--; e->rect != TRect(0,0,0,0); e--, i--)\r
-               drawRect(e->rect, (currentConfig->iAreaBinds[i] & currentActCode) ? color_red : color_red_dim);\r
+               drawRect(e->rect, (currentConfig.KeyBinds[i+256] & currentActCode) ? color_red : color_red_dim);\r
 \r
        // action name control\r
        drawRectFilled(TRect(72, 2, 168, 20), color_grey); // 96x14\r
@@ -621,14 +614,14 @@ void vidKeyConfigFrame(const TUint whichAction)
        drawText0(86, 9, actionNames[whichAction], color_red);\r
 \r
        // draw active button names if there are any\r
-       for(i = 0; i < 256; i++) {\r
-               if(currentConfig->iKeyBinds[i] & currentActCode) {\r
+       for (i = 0; i < 256; i++) {\r
+               if (currentConfig.KeyBinds[i] & currentActCode) {\r
                        if(buttonNames[0]) strcat(buttonNames, ";@");\r
                        strcat(buttonNames, vidGetScanName(i));\r
                }\r
        }\r
 \r
-       if(buttonNames[0]) {\r
+       if (buttonNames[0]) {\r
                buttonNames[61] = 0; // only 60 chars fit\r
                drawText0(6, 48, buttonNames, color_blue);\r
        }\r
@@ -638,7 +631,7 @@ void vidKeyConfigFrame(const TUint whichAction)
 \r
 void vidDrawNotice(const char *txt)\r
 {\r
-       if(framebuff) {\r
+       if(PicoDraw2FB) {\r
                drawTextNotice(txt);\r
                vidBlit(1);\r
        }\r