gpu_unai: move command handler to main loop
authornotaz <notasas@gmail.com>
Fri, 24 Feb 2012 00:21:08 +0000 (02:21 +0200)
committernotaz <notasas@gmail.com>
Sun, 26 Feb 2012 22:27:46 +0000 (00:27 +0200)
plugins/gpu_unai/gpulib_if.cpp

index 4994ef4..d665895 100644 (file)
@@ -135,10 +135,6 @@ static u32   GPU_GP1;
 // GPU command buffer execution/store
 #include "../gpu_unai/gpu_command.h"
 
-#define unai_do_prim(cmd, list, len) \
-  memcpy(PacketBuffer.U4, list, (len) * 4); \
-  gpuSendPacketFunction(cmd)
-
 /////////////////////////////////////////////////////////////////////////////
 
 int renderer_init(void)
@@ -164,7 +160,7 @@ extern const unsigned char cmd_lengths[256];
 
 int do_cmd_list(unsigned int *list, int list_len, int *last_cmd)
 {
-  unsigned int cmd = 0, len;
+  unsigned int cmd = 0, len, i;
   unsigned int *list_start = list;
   unsigned int *list_end = list + list_len;
 
@@ -182,22 +178,120 @@ int do_cmd_list(unsigned int *list, int list_len, int *last_cmd)
       break;
     }
 
-#ifndef TEST
-    if (cmd == 0xa0 || cmd == 0xc0)
-      break; // image i/o, forward to upper layer
-    else if ((cmd & 0xf8) == 0xe0)
-      gpu.ex_regs[cmd & 7] = list[0];
-#endif
+    #define PRIM cmd
+    PacketBuffer.U4[0] = list[0];
+    for (i = 1; i <= len; i++)
+      PacketBuffer.U4[i] = list[i];
 
-    switch(cmd)
+    switch (cmd)
     {
+      case 0x02:
+        gpuClearImage();
+        break;
+
+      case 0x20:
+      case 0x21:
+      case 0x22:
+      case 0x23:
+        gpuDrawF3(gpuPolySpanDrivers [Blending_Mode | Masking | Blending | PixelMSB]);
+        break;
+
+      case 0x24:
+      case 0x25:
+      case 0x26:
+      case 0x27:
+        gpuSetCLUT   (PacketBuffer.U4[2] >> 16);
+        gpuSetTexture(PacketBuffer.U4[4] >> 16);
+        if ((PacketBuffer.U1[0]>0x5F) && (PacketBuffer.U1[1]>0x5F) && (PacketBuffer.U1[2]>0x5F))
+          gpuDrawFT3(gpuPolySpanDrivers [Blending_Mode | TEXT_MODE | Masking | Blending | PixelMSB]);
+        else
+          gpuDrawFT3(gpuPolySpanDrivers [Blending_Mode | TEXT_MODE | Masking | Blending | Lighting | PixelMSB]);
+        break;
+
+      case 0x28:
+      case 0x29:
+      case 0x2A:
+      case 0x2B: {
+        const PP gpuPolySpanDriver = gpuPolySpanDrivers [Blending_Mode | Masking | Blending | PixelMSB];
+        gpuDrawF3(gpuPolySpanDriver);
+        PacketBuffer.U4[1] = PacketBuffer.U4[4];
+        gpuDrawF3(gpuPolySpanDriver);
+        break;
+      }
+
+      case 0x2C:
+      case 0x2D:
+      case 0x2E:
+      case 0x2F: {
+        gpuSetCLUT   (PacketBuffer.U4[2] >> 16);
+        gpuSetTexture(PacketBuffer.U4[4] >> 16);
+        PP gpuPolySpanDriver;
+        if ((PacketBuffer.U1[0]>0x5F) && (PacketBuffer.U1[1]>0x5F) && (PacketBuffer.U1[2]>0x5F))
+          gpuPolySpanDriver = gpuPolySpanDrivers [Blending_Mode | TEXT_MODE | Masking | Blending | PixelMSB];
+        else
+          gpuPolySpanDriver = gpuPolySpanDrivers [Blending_Mode | TEXT_MODE | Masking | Blending | Lighting | PixelMSB];
+        gpuDrawFT3(gpuPolySpanDriver);
+        PacketBuffer.U4[1] = PacketBuffer.U4[7];
+        PacketBuffer.U4[2] = PacketBuffer.U4[8];
+        gpuDrawFT3(gpuPolySpanDriver);
+        break;
+      }
+
+      case 0x30:
+      case 0x31:
+      case 0x32:
+      case 0x33:
+        gpuDrawG3(gpuPolySpanDrivers [Blending_Mode | Masking | Blending | 129 | PixelMSB]);
+        break;
+
+      case 0x34:
+      case 0x35:
+      case 0x36:
+      case 0x37:
+        gpuSetCLUT    (PacketBuffer.U4[2] >> 16);
+        gpuSetTexture (PacketBuffer.U4[5] >> 16);
+        gpuDrawGT3(gpuPolySpanDrivers [Blending_Mode | TEXT_MODE | Masking | Blending | ((Lighting)?129:0) | PixelMSB]);
+        break;
+
+      case 0x38:
+      case 0x39:
+      case 0x3A:
+      case 0x3B: {
+        const PP gpuPolySpanDriver  = gpuPolySpanDrivers [Blending_Mode | Masking | Blending | 129 | PixelMSB];
+        gpuDrawG3(gpuPolySpanDriver);
+        PacketBuffer.U4[0] = PacketBuffer.U4[6];
+        PacketBuffer.U4[1] = PacketBuffer.U4[7];
+        gpuDrawG3(gpuPolySpanDriver);
+        break;
+      }
+
+      case 0x3C:
+      case 0x3D:
+      case 0x3E:
+      case 0x3F: {
+        gpuSetCLUT    (PacketBuffer.U4[2] >> 16);
+        gpuSetTexture (PacketBuffer.U4[5] >> 16);
+        const PP gpuPolySpanDriver  = gpuPolySpanDrivers [Blending_Mode | TEXT_MODE | Masking | Blending | ((Lighting)?129:0) | PixelMSB];
+        gpuDrawGT3(gpuPolySpanDriver);
+        PacketBuffer.U4[0] = PacketBuffer.U4[9];
+        PacketBuffer.U4[1] = PacketBuffer.U4[10];
+        PacketBuffer.U4[2] = PacketBuffer.U4[11];
+        gpuDrawGT3(gpuPolySpanDriver);
+        break;
+      }
+
+      case 0x40:
+      case 0x41:
+      case 0x42:
+      case 0x43:
+        gpuDrawLF(gpuPixelDrivers [ (Blending_Mode | Masking | Blending | (PixelMSB>>3)) >> 1]);
+        break;
+
       case 0x48 ... 0x4F:
       {
         u32 num_vertexes = 1;
         u32 *list_position = &(list[2]);
-        u32 PRIM = cmd;
 
-        memcpy(&PacketBuffer.U4[0], list, 4 * 3);
         gpuDrawLF(gpuPixelDrivers [ (Blending_Mode | Masking | Blending | (PixelMSB>>3)) >> 1]);
 
         while(1)
@@ -215,13 +309,18 @@ int do_cmd_list(unsigned int *list, int list_len, int *last_cmd)
         break;
       }
 
+      case 0x50:
+      case 0x51:
+      case 0x52:
+      case 0x53:
+        gpuDrawLG(gpuPixelDrivers [ (Blending_Mode | Masking | Blending | (PixelMSB>>3)) >> 1]);
+        break;
+
       case 0x58 ... 0x5F:
       {
         u32 num_vertexes = 1;
         u32 *list_position = &(list[2]);
-        u32 PRIM = cmd;
 
-        memcpy(&PacketBuffer.U4[0], list, 4 * 4);
         gpuDrawLG(gpuPixelDrivers [ (Blending_Mode | Masking | Blending | (PixelMSB>>3)) >> 1]);
 
         while(1)
@@ -241,6 +340,88 @@ int do_cmd_list(unsigned int *list, int list_len, int *last_cmd)
         break;
       }
 
+      case 0x60:
+      case 0x61:
+      case 0x62:
+      case 0x63:
+        gpuDrawT(gpuTileSpanDrivers [Blending_Mode | Masking | Blending | (PixelMSB>>3)]);
+        break;
+
+      case 0x64:
+      case 0x65:
+      case 0x66:
+      case 0x67:
+        gpuSetCLUT    (PacketBuffer.U4[2] >> 16);
+        gpuSetTexture (GPU_GP1);
+        if ((PacketBuffer.U1[0]>0x5F) && (PacketBuffer.U1[1]>0x5F) && (PacketBuffer.U1[2]>0x5F))
+          gpuDrawS(gpuSpriteSpanDrivers [Blending_Mode | TEXT_MODE | Masking | Blending | (enableAbbeyHack<<7)  | PixelMSB]);
+        else
+          gpuDrawS(gpuSpriteSpanDrivers [Blending_Mode | TEXT_MODE | Masking | Blending | Lighting | (enableAbbeyHack<<7)  | PixelMSB]);
+        break;
+
+      case 0x68:
+      case 0x69:
+      case 0x6A:
+      case 0x6B:
+        PacketBuffer.U4[2] = 0x00010001;
+        gpuDrawT(gpuTileSpanDrivers [Blending_Mode | Masking | Blending | (PixelMSB>>3)]);
+        break;
+
+      case 0x70:
+      case 0x71:
+      case 0x72:
+      case 0x73:
+        PacketBuffer.U4[2] = 0x00080008;
+        gpuDrawT(gpuTileSpanDrivers [Blending_Mode | Masking | Blending | (PixelMSB>>3)]);
+        break;
+
+      case 0x74:
+      case 0x75:
+      case 0x76:
+      case 0x77:
+        PacketBuffer.U4[3] = 0x00080008;
+        gpuSetCLUT    (PacketBuffer.U4[2] >> 16);
+        gpuSetTexture (GPU_GP1);
+        if ((PacketBuffer.U1[0]>0x5F) && (PacketBuffer.U1[1]>0x5F) && (PacketBuffer.U1[2]>0x5F))
+          gpuDrawS(gpuSpriteSpanDrivers [Blending_Mode | TEXT_MODE | Masking | Blending | (enableAbbeyHack<<7)  | PixelMSB]);
+        else
+          gpuDrawS(gpuSpriteSpanDrivers [Blending_Mode | TEXT_MODE | Masking | Blending | Lighting | (enableAbbeyHack<<7)  | PixelMSB]);
+        break;
+
+      case 0x78:
+      case 0x79:
+      case 0x7A:
+      case 0x7B:
+        PacketBuffer.U4[2] = 0x00100010;
+        gpuDrawT(gpuTileSpanDrivers [Blending_Mode | Masking | Blending | (PixelMSB>>3)]);
+        break;
+
+      case 0x7C:
+      case 0x7D:
+#ifdef __arm__
+        if ((GPU_GP1 & 0x180) == 0 && (Masking | PixelMSB) == 0)
+        {
+          gpuSetCLUT    (PacketBuffer.U4[2] >> 16);
+          gpuSetTexture (GPU_GP1);
+          gpuDrawS16();
+          break;
+        }
+        // fallthrough
+#endif
+      case 0x7E:
+      case 0x7F:
+        PacketBuffer.U4[3] = 0x00100010;
+        gpuSetCLUT    (PacketBuffer.U4[2] >> 16);
+        gpuSetTexture (GPU_GP1);
+        if ((PacketBuffer.U1[0]>0x5F) && (PacketBuffer.U1[1]>0x5F) && (PacketBuffer.U1[2]>0x5F))
+          gpuDrawS(gpuSpriteSpanDrivers [Blending_Mode | TEXT_MODE | Masking | Blending | (enableAbbeyHack<<7)  | PixelMSB]);
+        else
+          gpuDrawS(gpuSpriteSpanDrivers [Blending_Mode | TEXT_MODE | Masking | Blending | Lighting | (enableAbbeyHack<<7)  | PixelMSB]);
+        break;
+
+      case 0x80:          //  vid -> vid
+        gpuMoveImage();   //  prim handles updateLace && skip
+        break;
 #ifdef TEST
       case 0xA0:          //  sys -> vid
       {
@@ -251,14 +432,66 @@ int do_cmd_list(unsigned int *list, int list_len, int *last_cmd)
         len += load_size / 2;
         break;
       }
+      case 0xC0:
+        break;
+#else
+      case 0xA0:          //  sys ->vid
+      case 0xC0:          //  vid -> sys
+        goto breakloop;
 #endif
-
-      default:
-        unai_do_prim(cmd, list, len + 1);
+      case 0xE1: {
+        const u32 temp = PacketBuffer.U4[0];
+        GPU_GP1 = (GPU_GP1 & ~0x000007FF) | (temp & 0x000007FF);
+        gpuSetTexture(temp);
+        gpu.ex_regs[1] = temp;
+        break;
+      }
+      case 0xE2: {
+        static const u8  TextureMask[32] = {
+          255, 7, 15, 7, 31, 7, 15, 7, 63, 7, 15, 7, 31, 7, 15, 7,
+          127, 7, 15, 7, 31, 7, 15, 7, 63, 7, 15, 7, 31, 7, 15, 7
+        };
+        const u32 temp = PacketBuffer.U4[0];
+        TextureWindow[0] = ((temp >> 10) & 0x1F) << 3;
+        TextureWindow[1] = ((temp >> 15) & 0x1F) << 3;
+        TextureWindow[2] = TextureMask[(temp >> 0) & 0x1F];
+        TextureWindow[3] = TextureMask[(temp >> 5) & 0x1F];
+        gpuSetTexture(GPU_GP1);
+        gpu.ex_regs[2] = temp;
+        break;
+      }
+      case 0xE3: {
+        const u32 temp = PacketBuffer.U4[0];
+        DrawingArea[0] = temp         & 0x3FF;
+        DrawingArea[1] = (temp >> 10) & 0x3FF;
+        gpu.ex_regs[3] = temp;
         break;
+      }
+      case 0xE4: {
+        const u32 temp = PacketBuffer.U4[0];
+        DrawingArea[2] = (temp         & 0x3FF) + 1;
+        DrawingArea[3] = ((temp >> 10) & 0x3FF) + 1;
+        gpu.ex_regs[4] = temp;
+        break;
+      }
+      case 0xE5: {
+        const u32 temp = PacketBuffer.U4[0];
+        DrawingOffset[0] = ((long)temp<<(32-11))>>(32-11);
+        DrawingOffset[1] = ((long)temp<<(32-22))>>(32-11);
+        gpu.ex_regs[5] = temp;
+        break;
+      }
+      case 0xE6: {
+        const u32 temp = PacketBuffer.U4[0];
+        Masking = (temp & 0x2) <<  1;
+        PixelMSB =(temp & 0x1) <<  8;
+        gpu.ex_regs[6] = temp;
+        break;
+      }
     }
   }
 
+breakloop:
   gpu.ex_regs[1] &= ~0x1ff;
   gpu.ex_regs[1] |= GPU_GP1 & 0x1ff;
 
@@ -268,12 +501,8 @@ int do_cmd_list(unsigned int *list, int list_len, int *last_cmd)
 
 void renderer_sync_ecmds(uint32_t *ecmds)
 {
-  unai_do_prim(0xe1, &ecmds[1], 1);
-  unai_do_prim(0xe2, &ecmds[2], 1);
-  unai_do_prim(0xe3, &ecmds[3], 1);
-  unai_do_prim(0xe4, &ecmds[4], 1);
-  unai_do_prim(0xe5, &ecmds[5], 1);
-  unai_do_prim(0xe6, &ecmds[6], 1);
+  int dummy;
+  do_cmd_list(&ecmds[1], 6, &dummy);
 }
 
 void renderer_update_caches(int x, int y, int w, int h)
@@ -301,3 +530,5 @@ void renderer_set_config(const struct rearmed_cbs *cbs)
 }
 
 #endif
+
+// vim:shiftwidth=2:expandtab