gpu_neon: merge cmd size tables
[pcsx_rearmed.git] / plugins / gpu_neon / psx_gpu / psx_gpu_parse.c
index 2099edf..ac35631 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "common.h"
 
+#ifndef command_lengths
 const u8 command_lengths[256] =
 {
        0,  0,  2,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,   // 00
@@ -24,7 +25,7 @@ const u8 command_lengths[256] =
        5,  5,  5,  5,  8,  8,  8,  8,  7,  7,  7,  7,  11, 11, 11, 11,  // 30
        2,  2,  2,  2,  2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,   // 40
        3,  3,  3,  3,  3,  3,  3,  3,  4,  4,  4,  4,  4,  4,  4,  4,   // 50
-       2,  2,  2,  2,  3,  3,  3,  3,  1,  1,  1,  1,  1,  1,  1,  1,   // 60
+       2,  2,  2,  2,  3,  3,  3,  3,  1,  1,  1,  1,  0,  0,  0,  0,   // 60
        1,  1,  1,  1,  2,  2,  2,  2,  1,  1,  1,  1,  2,  2,  2,  2,   // 70
        3,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,   // 80
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,   // 90
@@ -35,6 +36,7 @@ const u8 command_lengths[256] =
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,   // e0
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0    // f0
 };
+#endif
 
 void update_texture_ptr(psx_gpu_struct *psx_gpu)
 {
@@ -210,16 +212,61 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size)
        s16 *list_s16 = (void *)list;
        current_command = *list >> 24;
        command_length = command_lengths[current_command];
-  
+
        switch(current_command)
        {
                case 0x00:
                        break;
   
                case 0x02:
-        render_block_fill(psx_gpu, list[0] & 0xFFFFFF, list_s16[2] & 0x3FF,
-         list_s16[3] & 0x1FF, list_s16[4] & 0x3FF, list_s16[5] & 0x1FF);
+      {
+        u32 x = list_s16[2] & 0x3FF;
+        u32 y = list_s16[3] & 0x1FF;
+        u32 width = list_s16[4] & 0x3FF;
+        u32 height = list_s16[5] & 0x1FF;
+        u32 color = list[0] & 0xFFFFFF;
+
+        x &= ~0xF;
+        width = ((width + 0xF) & ~0xF);
+
+        if((x + width) > 1024)
+        {
+          u32 width_a = 1024 - x;
+          u32 width_b = width - width_a;
+
+          if((y + height) > 512)
+          {
+            u32 height_a = 512 - y;
+            u32 height_b = height - height_a;
+
+            render_block_fill(psx_gpu, color, x, y, width_a, height_a);
+            render_block_fill(psx_gpu, color, 0, y, width_b, height_a);
+            render_block_fill(psx_gpu, color, x, 0, width_a, height_b);
+            render_block_fill(psx_gpu, color, 0, 0, width_b, height_b);
+          }
+          else
+          {
+            render_block_fill(psx_gpu, color, x, y, width_a, height);
+            render_block_fill(psx_gpu, color, 0, y, width_b, height);
+          }
+        }
+        else
+        {
+          if((y + height) > 512)
+          {
+            u32 height_a = 512 - y;
+            u32 height_b = height - height_a;
+
+            render_block_fill(psx_gpu, color, x, y, width, height_a);
+            render_block_fill(psx_gpu, color, x, 0, width, height_b);
+          }
+          else
+          {
+            render_block_fill(psx_gpu, color, x, y, width, height);
+          }
+        }
                        break;
+      }
   
                case 0x20 ... 0x23:
       {
@@ -228,7 +275,7 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size)
         get_vertex_data_xy(0, 2);
         get_vertex_data_xy(1, 4);
         get_vertex_data_xy(2, 6);
-  
+          
         render_triangle(psx_gpu, vertexes, current_command);
                        break;
       }
@@ -359,7 +406,8 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size)
         while(1)
         {
           xy = *list_position;
-          if(xy == 0x55555555)
+
+          if((xy & 0xF000F000) == 0x50005000)
             break;
 
           vertexes[0] = vertexes[1];
@@ -370,6 +418,9 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size)
           list_position++;
           num_vertexes++;
 
+          if(list_position > list_end)
+            break;
+
           render_line(psx_gpu, vertexes, current_command, list[0]);
         }
 
@@ -413,7 +464,7 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size)
         while(1)
         {
           color = list_position[0];
-          if(color == 0x55555555)
+          if((color & 0xF000F000) == 0x50005000)
             break;
 
           xy = list_position[1];
@@ -429,6 +480,9 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size)
           list_position += 2;
           num_vertexes++;
 
+          if(list_position > list_end)
+            break;
+
           render_line(psx_gpu, vertexes, current_command, 0);
         }
 
@@ -546,7 +600,10 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size)
         u32 load_size = load_width * load_height;
   
         command_length += load_size / 2;
-  
+
+        if(load_size & 1)
+          command_length++;
+
         render_block_copy(psx_gpu, (u16 *)&(list_s16[6]), load_x, load_y,
          load_width, load_height, load_width);
                        break;
@@ -557,6 +614,7 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size)
   
                case 0xE1:
         set_texture(psx_gpu, list[0] & 0x1FF);
+
         if(list[0] & (1 << 9))
           psx_gpu->render_state_base |= RENDER_STATE_DITHER;
         else