psx_gpu: 2x sprite renderer
authorExophase <exophase@gmail.com>
Sat, 13 Oct 2012 19:50:43 +0000 (22:50 +0300)
committernotaz <notasas@gmail.com>
Sat, 13 Oct 2012 19:50:43 +0000 (22:50 +0300)
plugins/gpu_neon/psx_gpu/psx_gpu_4x.c [new file with mode: 0644]
plugins/gpu_neon/psx_gpu/vector_ops.h

diff --git a/plugins/gpu_neon/psx_gpu/psx_gpu_4x.c b/plugins/gpu_neon/psx_gpu/psx_gpu_4x.c
new file mode 100644 (file)
index 0000000..5e87bea
--- /dev/null
@@ -0,0 +1,881 @@
+#define setup_sprite_tiled_initialize_4bpp_4x()                                \\r
+  u16 *clut_ptr = psx_gpu->clut_ptr;                                           \\r
+  vec_8x16u clut_a, clut_b;                                                    \\r
+  vec_16x8u clut_low, clut_high;                                               \\r
+                                                                               \\r
+  load_8x16b(clut_a, clut_ptr);                                                \\r
+  load_8x16b(clut_b, clut_ptr + 8);                                            \\r
+  unzip_16x8b(clut_low, clut_high, clut_a, clut_b)                             \\r
+\r
+\r
+#define setup_sprite_tiled_initialize_8bpp_4x()                                \\r
+\r
+\r
+#define setup_sprite_tile_fetch_texel_block_8bpp_4x(offset)                    \\r
+  texture_block_ptr = psx_gpu->texture_page_ptr +                              \\r
+   ((texture_offset + offset) & texture_mask);                                 \\r
+                                                                               \\r
+  load_64b(texels, texture_block_ptr)                                          \\r
+\r
+\r
+#define setup_sprite_tile_setup_block_yes_4x(side, offset, texture_mode)       \\r
+\r
+#define setup_sprite_tile_setup_block_no_4x(side, offset, texture_mode)        \\r
+\r
+#define setup_sprite_tile_add_blocks_4x(tile_num_blocks)                       \\r
+  num_blocks += tile_num_blocks * 4;                                           \\r
+  sprite_blocks += tile_num_blocks * 4;                                        \\r
+                                                                               \\r
+  if(num_blocks > MAX_BLOCKS)                                                  \\r
+  {                                                                            \\r
+    flush_render_block_buffer(psx_gpu);                                        \\r
+    num_blocks = tile_num_blocks * 4;                                          \\r
+    block = psx_gpu->blocks;                                                   \\r
+  }                                                                            \\r
+\r
+#define setup_sprite_tile_full_4bpp_4x(edge)                                   \\r
+{                                                                              \\r
+  vec_8x8u texels_low, texels_high;                                            \\r
+  vec_8x16u pixels, pixels_wide;                                               \\r
+  setup_sprite_tile_add_blocks_4x(sub_tile_height * 2);                        \\r
+  u32 left_mask_bits_a = left_mask_bits & 0xFF;                                \\r
+  u32 left_mask_bits_b = left_mask_bits >> 8;                                  \\r
+  u32 right_mask_bits_a = right_mask_bits & 0xFF;                              \\r
+  u32 right_mask_bits_b = right_mask_bits >> 8;                                \\r
+                                                                               \\r
+  while(sub_tile_height)                                                       \\r
+  {                                                                            \\r
+    setup_sprite_tile_fetch_texel_block_8bpp_4x(0);                            \\r
+    tbl_16(texels_low, texels, clut_low);                                      \\r
+    tbl_16(texels_high, texels, clut_high);                                    \\r
+    zip_8x16b(pixels, texels_low, texels_high);                                \\r
+                                                                               \\r
+    zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low);             \\r
+    block->texels = pixels_wide;                                               \\r
+    block->draw_mask_bits = left_mask_bits_a;                                  \\r
+    block->fb_ptr = fb_ptr;                                                    \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->texels = pixels_wide;                                               \\r
+    block->draw_mask_bits = left_mask_bits_a;                                  \\r
+    block->fb_ptr = fb_ptr + 1024;                                             \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.high, pixels.high);  \\r
+    block->texels = pixels_wide;                                               \\r
+    block->draw_mask_bits = left_mask_bits_b;                                  \\r
+    block->fb_ptr = fb_ptr + 8;                                                \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->texels = pixels_wide;                                               \\r
+    block->draw_mask_bits = left_mask_bits_b;                                  \\r
+    block->fb_ptr = fb_ptr + 1024 + 8;                                         \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    setup_sprite_tile_fetch_texel_block_8bpp_4x(8);                            \\r
+    tbl_16(texels_low, texels, clut_low);                                      \\r
+    tbl_16(texels_high, texels, clut_high);                                    \\r
+    zip_8x16b(pixels, texels_low, texels_high);                                \\r
+                                                                               \\r
+    zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low);       \\r
+    block->texels = pixels_wide;                                               \\r
+    block->draw_mask_bits = right_mask_bits_a;                                 \\r
+    block->fb_ptr = fb_ptr + 16;                                               \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->texels = pixels_wide;                                               \\r
+    block->draw_mask_bits = right_mask_bits_a;                                 \\r
+    block->fb_ptr = fb_ptr + 1024 + 16;                                        \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.high, pixels.high);  \\r
+    block->texels = pixels_wide;                                               \\r
+    block->draw_mask_bits = right_mask_bits_b;                                 \\r
+    block->fb_ptr = fb_ptr + 24;                                               \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->texels = pixels_wide;                                               \\r
+    block->draw_mask_bits = right_mask_bits_b;                                 \\r
+    block->fb_ptr = fb_ptr + 1024 + 24;                                        \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    fb_ptr += 2048;                                                            \\r
+    texture_offset += 0x10;                                                    \\r
+    sub_tile_height--;                                                         \\r
+  }                                                                            \\r
+  texture_offset += 0xF00;                                                     \\r
+  psx_gpu->num_blocks = num_blocks;                                            \\r
+}                                                                              \\r
+\r
+#define setup_sprite_tile_half_4bpp_4x(edge)                                   \\r
+{                                                                              \\r
+  vec_8x8u texels_low, texels_high;                                            \\r
+  vec_8x16u pixels, pixels_wide;                                               \\r
+  setup_sprite_tile_add_blocks(sub_tile_height);                               \\r
+  u32 edge##_mask_bits_a = edge##_mask_bits & 0xFF;                            \\r
+  u32 edge##_mask_bits_b = edge##_mask_bits >> 8;                              \\r
+                                                                               \\r
+  while(sub_tile_height)                                                       \\r
+  {                                                                            \\r
+    setup_sprite_tile_fetch_texel_block_8bpp_4x(0);                            \\r
+    tbl_16(texels_low, texels, clut_low);                                      \\r
+    tbl_16(texels_high, texels, clut_high);                                    \\r
+    zip_8x16b(pixels, texels_low, texels_high);                                \\r
+                                                                               \\r
+    zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low);             \\r
+    block->texels = pixels_wide;                                               \\r
+    block->draw_mask_bits = edge##_mask_bits_a;                                \\r
+    block->fb_ptr = fb_ptr;                                                    \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->texels = pixels_wide;                                               \\r
+    block->draw_mask_bits = edge##_mask_bits_a;                                \\r
+    block->fb_ptr = fb_ptr + 1024;                                             \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.high, pixels.high);  \\r
+    block->texels = pixels_wide;                                               \\r
+    block->draw_mask_bits = edge##_mask_bits_b;                                \\r
+    block->fb_ptr = fb_ptr + 8;                                                \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->texels = pixels_wide;                                               \\r
+    block->draw_mask_bits = edge##_mask_bits_b;                                \\r
+    block->fb_ptr = fb_ptr + 1024 + 8;                                         \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    fb_ptr += 2048;                                                            \\r
+    texture_offset += 0x10;                                                    \\r
+    sub_tile_height--;                                                         \\r
+  }                                                                            \\r
+  texture_offset += 0xF00;                                                     \\r
+  psx_gpu->num_blocks = num_blocks;                                            \\r
+}                                                                              \\r
+\r
+  \r
+#define setup_sprite_tile_full_8bpp_4x(edge)                                   \\r
+{                                                                              \\r
+  setup_sprite_tile_add_blocks_4x(sub_tile_height * 2);                        \\r
+  vec_16x8u texels_wide;                                                       \\r
+  u32 left_mask_bits_a = left_mask_bits & 0xFF;                                \\r
+  u32 left_mask_bits_b = left_mask_bits >> 8;                                  \\r
+  u32 right_mask_bits_a = right_mask_bits & 0xFF;                              \\r
+  u32 right_mask_bits_b = right_mask_bits >> 8;                                \\r
+                                                                               \\r
+  while(sub_tile_height)                                                       \\r
+  {                                                                            \\r
+    setup_sprite_tile_fetch_texel_block_8bpp_4x(0);                            \\r
+    zip_8x16b(vector_cast(vec_8x16u, texels_wide), texels, texels);            \\r
+    block->r = texels_wide.low;                                                \\r
+    block->draw_mask_bits = left_mask_bits_a;                                  \\r
+    block->fb_ptr = fb_ptr;                                                    \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->r = texels_wide.low;                                                \\r
+    block->draw_mask_bits = left_mask_bits_a;                                  \\r
+    block->fb_ptr = fb_ptr + 1024;                                             \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->r = texels_wide.high;                                               \\r
+    block->draw_mask_bits = left_mask_bits_b;                                  \\r
+    block->fb_ptr = fb_ptr + 8;                                                \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->r = texels_wide.high;                                               \\r
+    block->draw_mask_bits = left_mask_bits_b;                                  \\r
+    block->fb_ptr = fb_ptr + 1024 + 8;                                         \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    setup_sprite_tile_fetch_texel_block_8bpp_4x(8);                            \\r
+    zip_8x16b(vector_cast(vec_8x16u, texels_wide), texels, texels);            \\r
+    block->r = texels_wide.low;                                                \\r
+    block->draw_mask_bits = right_mask_bits_a;                                 \\r
+    block->fb_ptr = fb_ptr + 16;                                               \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->r = texels_wide.low;                                                \\r
+    block->draw_mask_bits = right_mask_bits_a;                                 \\r
+    block->fb_ptr = fb_ptr + 1024;                                             \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->r = texels_wide.high;                                               \\r
+    block->draw_mask_bits = right_mask_bits_b;                                 \\r
+    block->fb_ptr = fb_ptr + 24 + 1024;                                        \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->r = texels_wide.high;                                               \\r
+    block->draw_mask_bits = right_mask_bits_b;                                 \\r
+    block->fb_ptr = fb_ptr + 24 + 1024;                                        \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    fb_ptr += 2048;                                                            \\r
+    texture_offset += 0x10;                                                    \\r
+    sub_tile_height--;                                                         \\r
+  }                                                                            \\r
+  texture_offset += 0xF00;                                                     \\r
+  psx_gpu->num_blocks = num_blocks;                                            \\r
+}                                                                              \\r
+\r
+#define setup_sprite_tile_half_8bpp_4x(edge)                                   \\r
+{                                                                              \\r
+  setup_sprite_tile_add_blocks_4x(sub_tile_height * 2);                        \\r
+  vec_16x8u texels_wide;                                                       \\r
+  u32 edge##_mask_bits_a = edge##_mask_bits & 0xFF;                            \\r
+  u32 edge##_mask_bits_b = edge##_mask_bits >> 8;                              \\r
+                                                                               \\r
+  while(sub_tile_height)                                                       \\r
+  {                                                                            \\r
+    setup_sprite_tile_fetch_texel_block_8bpp_4x(0);                            \\r
+    zip_8x16b(vector_cast(vec_8x16u, texels_wide), texels, texels);            \\r
+    block->r = texels_wide.low;                                                \\r
+    block->draw_mask_bits = edge##_mask_bits_a;                                \\r
+    block->fb_ptr = fb_ptr;                                                    \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->r = texels_wide.low;                                                \\r
+    block->draw_mask_bits = edge##_mask_bits_a;                                \\r
+    block->fb_ptr = fb_ptr + 1024;                                             \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->r = texels_wide.high;                                               \\r
+    block->draw_mask_bits = edge##_mask_bits_b;                                \\r
+    block->fb_ptr = fb_ptr + 8;                                                \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    block->r = texels_wide.high;                                               \\r
+    block->draw_mask_bits = edge##_mask_bits_b;                                \\r
+    block->fb_ptr = fb_ptr + 8 + 1024;                                         \\r
+    block++;                                                                   \\r
+                                                                               \\r
+    fb_ptr += 2048;                                                            \\r
+    texture_offset += 0x10;                                                    \\r
+    sub_tile_height--;                                                         \\r
+  }                                                                            \\r
+  texture_offset += 0xF00;                                                     \\r
+  psx_gpu->num_blocks = num_blocks;                                            \\r
+}                                                                              \\r
+\r
+  \r
+#define setup_sprite_tile_column_edge_pre_adjust_half_right_4x()               \\r
+  texture_offset = texture_offset_base + 8;                                    \\r
+  fb_ptr += 16                                                                 \\r
+\r
+#define setup_sprite_tile_column_edge_pre_adjust_half_left_4x()                \\r
+  texture_offset = texture_offset_base                                         \\r
+\r
+#define setup_sprite_tile_column_edge_pre_adjust_half_4x(edge)                 \\r
+  setup_sprite_tile_column_edge_pre_adjust_half_##edge##_4x()                  \\r
+\r
+#define setup_sprite_tile_column_edge_pre_adjust_full_4x(edge)                 \\r
+  texture_offset = texture_offset_base                                         \\r
+\r
+#define setup_sprite_tile_column_edge_post_adjust_half_right_4x()              \\r
+  fb_ptr -= 16                                                                 \\r
+\r
+#define setup_sprite_tile_column_edge_post_adjust_half_left_4x()               \\r
+\r
+#define setup_sprite_tile_column_edge_post_adjust_half_4x(edge)                \\r
+  setup_sprite_tile_column_edge_post_adjust_half_##edge##_4x()                 \\r
+\r
+#define setup_sprite_tile_column_edge_post_adjust_full_4x(edge)                \\r
+\r
+\r
+#define setup_sprite_tile_column_height_single_4x(edge_mode, edge,             \\r
+ texture_mode)                                                                 \\r
+do                                                                             \\r
+{                                                                              \\r
+  sub_tile_height = column_data;                                               \\r
+  setup_sprite_tile_column_edge_pre_adjust_##edge_mode##_4x(edge);             \\r
+  setup_sprite_tile_##edge_mode##_##texture_mode##_4x(edge);                   \\r
+  setup_sprite_tile_column_edge_post_adjust_##edge_mode##_4x(edge);            \\r
+} while(0)                                                                     \\r
+\r
+#define setup_sprite_tile_column_height_multi_4x(edge_mode, edge,              \\r
+ texture_mode)                                                                 \\r
+do                                                                             \\r
+{                                                                              \\r
+  u32 tiles_remaining = column_data >> 16;                                     \\r
+  sub_tile_height = column_data & 0xFF;                                        \\r
+  setup_sprite_tile_column_edge_pre_adjust_##edge_mode##_4x(edge);             \\r
+  setup_sprite_tile_##edge_mode##_##texture_mode##_4x(edge);                   \\r
+  tiles_remaining -= 1;                                                        \\r
+                                                                               \\r
+  while(tiles_remaining)                                                       \\r
+  {                                                                            \\r
+    sub_tile_height = 16;                                                      \\r
+    setup_sprite_tile_##edge_mode##_##texture_mode##_4x(edge);                 \\r
+    tiles_remaining--;                                                         \\r
+  }                                                                            \\r
+                                                                               \\r
+  sub_tile_height = (column_data >> 8) & 0xFF;                                 \\r
+  setup_sprite_tile_##edge_mode##_##texture_mode##_4x(edge);                   \\r
+  setup_sprite_tile_column_edge_post_adjust_##edge_mode##_4x(edge);            \\r
+} while(0)                                                                     \\r
+\r
+\r
+#define setup_sprite_column_data_single_4x()                                   \\r
+  column_data = height                                                         \\r
+\r
+#define setup_sprite_column_data_multi_4x()                                    \\r
+  column_data = 16 - offset_v;                                                 \\r
+  column_data |= ((height_rounded & 0xF) + 1) << 8;                            \\r
+  column_data |= (tile_height - 1) << 16                                       \\r
+\r
+\r
+#define setup_sprite_tile_column_width_single_4x(texture_mode, multi_height,   \\r
+ edge_mode, edge)                                                              \\r
+{                                                                              \\r
+  setup_sprite_column_data_##multi_height##_4x();                              \\r
+  left_mask_bits = left_block_mask | right_block_mask;                         \\r
+  right_mask_bits = left_mask_bits >> 16;                                      \\r
+                                                                               \\r
+  setup_sprite_tile_column_height_##multi_height##_4x(edge_mode, edge,         \\r
+   texture_mode);                                                              \\r
+}                                                                              \\r
+\r
+#define setup_sprite_tiled_advance_column_4x()                                 \\r
+  texture_offset_base += 0x100;                                                \\r
+  if((texture_offset_base & 0xF00) == 0)                                       \\r
+    texture_offset_base -= (0x100 + 0xF00)                                     \\r
+\r
+#define setup_sprite_tile_column_width_multi_4x(texture_mode, multi_height,    \\r
+ left_mode, right_mode)                                                        \\r
+{                                                                              \\r
+  setup_sprite_column_data_##multi_height##_4x();                              \\r
+  s32 fb_ptr_advance_column = 32 - (2048 * height);                            \\r
+                                                                               \\r
+  tile_width -= 2;                                                             \\r
+  left_mask_bits = left_block_mask;                                            \\r
+  right_mask_bits = left_mask_bits >> 16;                                      \\r
+                                                                               \\r
+  setup_sprite_tile_column_height_##multi_height##_4x(left_mode, right,        \\r
+   texture_mode);                                                              \\r
+  fb_ptr += fb_ptr_advance_column;                                             \\r
+                                                                               \\r
+  left_mask_bits = 0x00;                                                       \\r
+  right_mask_bits = 0x00;                                                      \\r
+                                                                               \\r
+  while(tile_width)                                                            \\r
+  {                                                                            \\r
+    setup_sprite_tiled_advance_column_4x();                                    \\r
+    setup_sprite_tile_column_height_##multi_height##_4x(full, none,            \\r
+     texture_mode);                                                            \\r
+    fb_ptr += fb_ptr_advance_column;                                           \\r
+    tile_width--;                                                              \\r
+  }                                                                            \\r
+                                                                               \\r
+  left_mask_bits = right_block_mask;                                           \\r
+  right_mask_bits = left_mask_bits >> 16;                                      \\r
+                                                                               \\r
+  setup_sprite_tiled_advance_column();                                         \\r
+  setup_sprite_tile_column_height_##multi_height##_4x(right_mode, left,        \\r
+   texture_mode);                                                              \\r
+}                                                                              \\r
+\r
+\r
+#define setup_sprite_tiled_builder_4x(texture_mode)                            \\r
+void setup_sprite_##texture_mode##_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y,   \\r
+ s32 u, s32 v, s32 width, s32 height, u32 color)                               \\r
+{                                                                              \\r
+  s32 offset_u = u & 0xF;                                                      \\r
+  s32 offset_v = v & 0xF;                                                      \\r
+                                                                               \\r
+  s32 width_rounded = offset_u + width + 15;                                   \\r
+  s32 height_rounded = offset_v + height + 15;                                 \\r
+  s32 tile_height = height_rounded / 16;                                       \\r
+  s32 tile_width = width_rounded / 16;                                         \\r
+  u32 offset_u_right = width_rounded & 0xF;                                    \\r
+                                                                               \\r
+  u32 left_block_mask = ~(0xFFFFFFFF << (offset_u * 2));                       \\r
+  u32 right_block_mask = 0xFFFFFFFE << (offset_u_right * 2);                   \\r
+                                                                               \\r
+  u32 left_mask_bits;                                                          \\r
+  u32 right_mask_bits;                                                         \\r
+                                                                               \\r
+  u32 sub_tile_height;                                                         \\r
+  u32 column_data;                                                             \\r
+                                                                               \\r
+  u32 texture_mask = (psx_gpu->texture_mask_width & 0xF) |                     \\r
+   ((psx_gpu->texture_mask_height & 0xF) << 4) |                               \\r
+   ((psx_gpu->texture_mask_width >> 4) << 8) |                                 \\r
+   ((psx_gpu->texture_mask_height >> 4) << 12);                                \\r
+  u32 texture_offset = ((v & 0xF) << 4) | ((u & 0xF0) << 4) |                  \\r
+   ((v & 0xF0) << 8);                                                          \\r
+  u32 texture_offset_base = texture_offset;                                    \\r
+  u32 control_mask;                                                            \\r
+                                                                               \\r
+  u16 *fb_ptr = psx_gpu->vram_ptr + (y * 1024) + (x - offset_u);               \\r
+  u32 num_blocks = psx_gpu->num_blocks;                                        \\r
+  block_struct *block = psx_gpu->blocks + num_blocks;                          \\r
+                                                                               \\r
+  u16 *texture_block_ptr;                                                      \\r
+  vec_8x8u texels;                                                             \\r
+                                                                               \\r
+  setup_sprite_tiled_initialize_##texture_mode##_4x();                         \\r
+                                                                               \\r
+  control_mask = tile_width == 1;                                              \\r
+  control_mask |= (tile_height == 1) << 1;                                     \\r
+  control_mask |= ((left_block_mask & 0xFFFF) == 0xFFFF) << 2;                 \\r
+  control_mask |= (((right_block_mask >> 8) & 0xFFFF) == 0xFFFF) << 3;         \\r
+                                                                               \\r
+  sprites_##texture_mode++;                                                    \\r
+                                                                               \\r
+  switch(control_mask)                                                         \\r
+  {                                                                            \\r
+    default:                                                                   \\r
+    case 0x0:                                                                  \\r
+      setup_sprite_tile_column_width_multi_4x(texture_mode, multi, full,       \\r
+       full);                                                                  \\r
+      break;                                                                   \\r
+                                                                               \\r
+    case 0x1:                                                                  \\r
+      setup_sprite_tile_column_width_single_4x(texture_mode, multi, full,      \\r
+       none);                                                                  \\r
+      break;                                                                   \\r
+                                                                               \\r
+    case 0x2:                                                                  \\r
+      setup_sprite_tile_column_width_multi_4x(texture_mode, single, full,      \\r
+       full);                                                                  \\r
+      break;                                                                   \\r
+                                                                               \\r
+    case 0x3:                                                                  \\r
+      setup_sprite_tile_column_width_single_4x(texture_mode, single, full,     \\r
+       none);                                                                  \\r
+      break;                                                                   \\r
+                                                                               \\r
+    case 0x4:                                                                  \\r
+      setup_sprite_tile_column_width_multi_4x(texture_mode, multi, half,       \\r
+       full);                                                                  \\r
+      break;                                                                   \\r
+                                                                               \\r
+    case 0x5:                                                                  \\r
+      setup_sprite_tile_column_width_single_4x(texture_mode, multi, half,      \\r
+       right);                                                                 \\r
+      break;                                                                   \\r
+                                                                               \\r
+    case 0x6:                                                                  \\r
+      setup_sprite_tile_column_width_multi_4x(texture_mode, single, half,      \\r
+       full);                                                                  \\r
+      break;                                                                   \\r
+                                                                               \\r
+    case 0x7:                                                                  \\r
+      setup_sprite_tile_column_width_single_4x(texture_mode, single, half,     \\r
+       right);                                                                 \\r
+      break;                                                                   \\r
+                                                                               \\r
+    case 0x8:                                                                  \\r
+      setup_sprite_tile_column_width_multi_4x(texture_mode, multi, full,       \\r
+       half);                                                                  \\r
+      break;                                                                   \\r
+                                                                               \\r
+    case 0x9:                                                                  \\r
+      setup_sprite_tile_column_width_single_4x(texture_mode, multi, half,      \\r
+       left);                                                                  \\r
+      break;                                                                   \\r
+                                                                               \\r
+    case 0xA:                                                                  \\r
+      setup_sprite_tile_column_width_multi_4x(texture_mode, single, full,      \\r
+       half);                                                                  \\r
+      break;                                                                   \\r
+                                                                               \\r
+    case 0xB:                                                                  \\r
+      setup_sprite_tile_column_width_single_4x(texture_mode, single, half,     \\r
+       left);                                                                  \\r
+      break;                                                                   \\r
+                                                                               \\r
+    case 0xC:                                                                  \\r
+      setup_sprite_tile_column_width_multi_4x(texture_mode, multi, half,       \\r
+       half);                                                                  \\r
+      break;                                                                   \\r
+                                                                               \\r
+    case 0xE:                                                                  \\r
+      setup_sprite_tile_column_width_multi_4x(texture_mode, single, half,      \\r
+       half);                                                                  \\r
+      break;                                                                   \\r
+  }                                                                            \\r
+}                                                                              \\r
+\r
+\r
+void setup_sprite_4bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u, s32 v,\r
+ s32 width, s32 height, u32 color);\r
+void setup_sprite_8bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u, s32 v,\r
+ s32 width, s32 height, u32 color);\r
+void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u, s32 v,\r
+ s32 width, s32 height, u32 color);\r
+\r
+//#ifndef NEON_BUILD\r
+#if 1\r
+setup_sprite_tiled_builder_4x(4bpp);\r
+setup_sprite_tiled_builder_4x(8bpp);\r
+\r
+void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,\r
+ s32 v, s32 width, s32 height, u32 color)\r
+{\r
+  u32 left_offset = u & 0x7;\r
+  u32 width_rounded = width + left_offset + 7;\r
+\r
+  u16 *fb_ptr = psx_gpu->vram_ptr + (y * 1024) + (s32)(x - left_offset);\r
+  u32 right_width = width_rounded & 0x7;\r
+  u32 block_width = width_rounded / 8;\r
+  u32 fb_ptr_pitch = (1024 + 8) - (block_width * 8);\r
+\r
+  u32 left_mask_bits = ~(0xFFFF << (left_offset * 2));\r
+  u32 right_mask_bits = 0xFE << (right_width * 2);\r
+\r
+  u32 texture_offset_base = u + (v * 1024);\r
+  u32 texture_mask =\r
+   psx_gpu->texture_mask_width | (psx_gpu->texture_mask_height * 1024);\r
+\r
+  u32 blocks_remaining;\r
+  u32 num_blocks = psx_gpu->num_blocks;\r
+  block_struct *block = psx_gpu->blocks + num_blocks;\r
+\r
+  u16 *texture_page_ptr = psx_gpu->texture_page_ptr;\r
+  u16 *texture_block_ptr;\r
+\r
+  texture_offset_base &= ~0x7;\r
+\r
+  sprites_16bpp++;\r
+\r
+  if(block_width == 1)\r
+  {\r
+    u32 mask_bits = left_mask_bits | right_mask_bits;\r
+    u32 mask_bits_a = mask_bits & 0xFF;\r
+    u32 mask_bits_b = mask_bits >> 8;\r
+    \r
+    vec_8x16u texels;\r
+    vec_8x16u texels_wide;\r
+\r
+    while(height)\r
+    {\r
+      num_blocks += 4;\r
+      sprite_blocks += 4;\r
+\r
+      if(num_blocks > MAX_BLOCKS)\r
+      {\r
+        flush_render_block_buffer(psx_gpu);\r
+        num_blocks = 4;\r
+        block = psx_gpu->blocks;\r
+      }\r
+      \r
+      texture_block_ptr =\r
+       texture_page_ptr + (texture_offset_base & texture_mask);\r
+\r
+      load_128b(texels, texture_block_ptr);\r
+      \r
+      zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low);\r
+      block->texels = texels_wide;\r
+      block->draw_mask_bits = mask_bits_a;\r
+      block->fb_ptr = fb_ptr;          \r
+      block++;\r
+      \r
+      block->texels = texels_wide;\r
+      block->draw_mask_bits = mask_bits_a;\r
+      block->fb_ptr = fb_ptr + 1024;          \r
+      block++;\r
+      \r
+      zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high);\r
+      block->texels = texels_wide;\r
+      block->draw_mask_bits = mask_bits_b;\r
+      block->fb_ptr = fb_ptr + 8;\r
+      block++;\r
+      \r
+      block->texels = texels_wide;\r
+      block->draw_mask_bits = mask_bits_b;\r
+      block->fb_ptr = fb_ptr + 8 + 1024;          \r
+      block++;      \r
+\r
+      texture_offset_base += 1024;\r
+      fb_ptr += 2048;\r
+\r
+      height--;\r
+      psx_gpu->num_blocks = num_blocks;\r
+    }\r
+  }\r
+  else\r
+  {\r
+    u32 texture_offset;\r
+    \r
+    u32 left_mask_bits_a = left_mask_bits & 0xFF;\r
+    u32 left_mask_bits_b = left_mask_bits >> 8;\r
+    u32 right_mask_bits_a = right_mask_bits & 0xFF;\r
+    u32 right_mask_bits_b = right_mask_bits >> 8;\r
+    \r
+    vec_8x16u texels;\r
+    vec_8x16u texels_wide;    \r
+\r
+    while(height)\r
+    {\r
+      blocks_remaining = block_width - 2;\r
+      num_blocks += block_width * 4;\r
+      sprite_blocks += block_width * 4;\r
+\r
+      if(num_blocks > MAX_BLOCKS)\r
+      {\r
+        flush_render_block_buffer(psx_gpu);\r
+        num_blocks = block_width;\r
+        block = psx_gpu->blocks;\r
+      }\r
+\r
+      texture_offset = texture_offset_base;\r
+      texture_offset_base += 1024;\r
+\r
+      texture_block_ptr = texture_page_ptr + (texture_offset & texture_mask);\r
+      \r
+      load_128b(texels, texture_block_ptr);\r
+\r
+      zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low);\r
+      block->texels = texels_wide;\r
+      block->draw_mask_bits = left_mask_bits_a;\r
+      block->fb_ptr = fb_ptr;\r
+      block++;\r
+      \r
+      block->texels = texels_wide;\r
+      block->draw_mask_bits = left_mask_bits_a;\r
+      block->fb_ptr = fb_ptr + 1024;\r
+      block++;      \r
+\r
+      zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high);\r
+      block->texels = texels_wide;\r
+      block->draw_mask_bits = left_mask_bits_b;\r
+      block->fb_ptr = fb_ptr + 8;\r
+      block++;  \r
+      \r
+      block->texels = texels_wide;\r
+      block->draw_mask_bits = left_mask_bits_b;\r
+      block->fb_ptr = fb_ptr + 8 + 1024;\r
+      block++;  \r
+      \r
+      texture_offset += 8;\r
+      fb_ptr += 16;\r
+\r
+      while(blocks_remaining)\r
+      {\r
+        texture_block_ptr = texture_page_ptr + (texture_offset & texture_mask);\r
+        load_128b(texels, texture_block_ptr);\r
+\r
+        zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low);\r
+        block->texels = texels_wide;\r
+        block->draw_mask_bits = 0;\r
+        block->fb_ptr = fb_ptr;\r
+        block++;\r
+        \r
+        block->texels = texels_wide;\r
+        block->draw_mask_bits = 0;\r
+        block->fb_ptr = fb_ptr + 1024;\r
+        block++;      \r
+\r
+        zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high);\r
+        block->texels = texels_wide;\r
+        block->draw_mask_bits = 0;\r
+        block->fb_ptr = fb_ptr + 8;\r
+        block++;\r
+        \r
+        block->texels = texels_wide;\r
+        block->draw_mask_bits = 0;\r
+        block->fb_ptr = fb_ptr + 8 + 1024;\r
+        block++;\r
+        \r
+        texture_offset += 8;\r
+        fb_ptr += 8;\r
+\r
+        blocks_remaining--;\r
+      }\r
+\r
+      texture_block_ptr = texture_page_ptr + (texture_offset & texture_mask);\r
+      load_128b(texels, texture_block_ptr);\r
+      \r
+      zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low);\r
+      block->texels = texels_wide;\r
+      block->draw_mask_bits = right_mask_bits_a;\r
+      block->fb_ptr = fb_ptr;\r
+      block++;\r
+      \r
+      block->texels = texels_wide;\r
+      block->draw_mask_bits = right_mask_bits_a;\r
+      block->fb_ptr = fb_ptr + 1024;\r
+      block++;      \r
+\r
+      zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high);\r
+      block->texels = texels_wide;\r
+      block->draw_mask_bits = right_mask_bits_b;\r
+      block->fb_ptr = fb_ptr + 8;\r
+      block++;\r
+\r
+      block->texels = texels_wide;\r
+      block->draw_mask_bits = right_mask_bits_b;\r
+      block->fb_ptr = fb_ptr + 8 + 1024;      \r
+      block++;\r
+\r
+      fb_ptr += fb_ptr_pitch;\r
+\r
+      height--;\r
+      psx_gpu->num_blocks = num_blocks;\r
+    }\r
+  }\r
+}\r
+\r
+#endif\r
+\r
+#define setup_sprite_blocks_switch_textured_4x(texture_mode)                   \\r
+  setup_sprite_##texture_mode##_4x                                             \\r
+\r
+#define setup_sprite_blocks_switch_untextured_4x(texture_mode)                 \\r
+  setup_sprite_untextured                                                      \\r
+\r
+#define setup_sprite_blocks_switch_4x(texturing, texture_mode)                 \\r
+  setup_sprite_blocks_switch_##texturing##_4x(texture_mode)                    \\r
+\r
+  \r
+#define render_sprite_blocks_switch_block_modulation_4x(texture_mode,          \\r
+ blend_mode, mask_evaluate, shading, dithering, texturing, blending,           \\r
+ modulation)                                                                   \\r
+{                                                                              \\r
+  setup_sprite_blocks_switch_4x(texturing, texture_mode),                      \\r
+  texture_sprite_blocks_switch_##texturing(texture_mode),                      \\r
+  shade_blocks_switch(unshaded, texturing, modulation, undithered, blending,   \\r
+   mask_evaluate),                                                             \\r
+  blend_blocks_switch(texturing, blending, blend_mode, mask_evaluate)          \\r
+}                                                                              \\r
+\r
+#define render_sprite_blocks_switch_block_blending_4x(texture_mode,            \\r
+ blend_mode, mask_evaluate, shading, dithering, texturing, blending)           \\r
+  render_sprite_blocks_switch_block_modulation_4x(texture_mode, blend_mode,    \\r
+   mask_evaluate, shading, dithering, texturing, blending, modulated),         \\r
+  render_sprite_blocks_switch_block_modulation_4x(texture_mode, blend_mode,    \\r
+   mask_evaluate, shading, dithering, texturing, blending, unmodulated)        \\r
+\r
+#define render_sprite_blocks_switch_block_texturing_4x(texture_mode,           \\r
+ blend_mode, mask_evaluate, shading, dithering, texturing)                     \\r
+  render_sprite_blocks_switch_block_blending_4x(texture_mode, blend_mode,      \\r
+   mask_evaluate, shading, dithering, texturing, unblended),                   \\r
+  render_sprite_blocks_switch_block_blending_4x(texture_mode, blend_mode,      \\r
+   mask_evaluate, shading, dithering, texturing, blended)                      \\r
+\r
+#define render_sprite_blocks_switch_block_dithering_4x(texture_mode,           \\r
+ blend_mode, mask_evaluate, shading, dithering)                                \\r
+  render_sprite_blocks_switch_block_texturing_4x(texture_mode, blend_mode,     \\r
+   mask_evaluate, shading, dithering, untextured),                             \\r
+  render_sprite_blocks_switch_block_texturing_4x(texture_mode, blend_mode,     \\r
+   mask_evaluate, shading, dithering, textured)                                \\r
+\r
+#define render_sprite_blocks_switch_block_shading_4x(texture_mode, blend_mode, \\r
+ mask_evaluate, shading)                                                       \\r
+  render_sprite_blocks_switch_block_dithering_4x(texture_mode, blend_mode,     \\r
+   mask_evaluate, shading, undithered),                                        \\r
+  render_sprite_blocks_switch_block_dithering_4x(texture_mode, blend_mode,     \\r
+   mask_evaluate, shading, dithered)                                           \\r
+\r
+#define render_sprite_blocks_switch_block_mask_evaluate_4x(texture_mode,       \\r
+ blend_mode, mask_evaluate)                                                    \\r
+  render_sprite_blocks_switch_block_shading_4x(texture_mode, blend_mode,       \\r
+   mask_evaluate, unshaded),                                                   \\r
+  render_sprite_blocks_switch_block_shading_4x(texture_mode, blend_mode,       \\r
+   mask_evaluate, shaded)                                                      \\r
+\r
+#define render_sprite_blocks_switch_block_blend_mode_4x(texture_mode,          \\r
+ blend_mode)                                                                   \\r
+  render_sprite_blocks_switch_block_mask_evaluate_4x(texture_mode, blend_mode, \\r
+   off),                                                                       \\r
+  render_sprite_blocks_switch_block_mask_evaluate_4x(texture_mode, blend_mode, \\r
+   on)                                                                         \\r
+\r
+#define render_sprite_blocks_switch_block_texture_mode_4x(texture_mode)        \\r
+  render_sprite_blocks_switch_block_blend_mode_4x(texture_mode, average),      \\r
+  render_sprite_blocks_switch_block_blend_mode_4x(texture_mode, add),          \\r
+  render_sprite_blocks_switch_block_blend_mode_4x(texture_mode, subtract),     \\r
+  render_sprite_blocks_switch_block_blend_mode_4x(texture_mode, add_fourth)    \\r
+\r
+#define render_sprite_blocks_switch_block_4x()                                 \\r
+  render_sprite_blocks_switch_block_texture_mode_4x(4bpp),                     \\r
+  render_sprite_blocks_switch_block_texture_mode_4x(8bpp),                     \\r
+  render_sprite_blocks_switch_block_texture_mode_4x(16bpp),                    \\r
+  render_sprite_blocks_switch_block_texture_mode_4x(4bpp)                      \\r
+\r
+\r
+render_block_handler_struct render_sprite_block_handlers_4x[] =\r
+{\r
+  render_sprite_blocks_switch_block_4x()\r
+};\r
+\r
+\r
+void render_sprite_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, u32 u, u32 v,\r
+ s32 width, s32 height, u32 flags, u32 color)\r
+{\r
+  x *= 2;\r
+  y *= 2;\r
+\r
+  s32 x_right = x + width - 1;\r
+  s32 y_bottom = y + height - 1;\r
+\r
+#ifdef PROFILE\r
+  sprites++;\r
+#endif\r
+\r
+  if(x < psx_gpu->viewport_start_x)\r
+  {\r
+    u32 clip = psx_gpu->viewport_start_x - x;\r
+    x += clip;\r
+    u += clip;\r
+    width -= clip;\r
+  }\r
+\r
+  if(y < psx_gpu->viewport_start_y)\r
+  {\r
+    s32 clip = psx_gpu->viewport_start_y - y;\r
+    y += clip;\r
+    v += clip;\r
+    height -= clip;\r
+  }\r
+\r
+  if(x_right > psx_gpu->viewport_end_x)\r
+    width -= x_right - psx_gpu->viewport_end_x;\r
+\r
+  if(y_bottom > psx_gpu->viewport_end_y)\r
+    height -= y_bottom - psx_gpu->viewport_end_y;\r
+\r
+  if((width <= 0) || (height <= 0))\r
+    return;\r
+\r
+#ifdef PROFILE\r
+  span_pixels += width * height;\r
+  spans += height;\r
+#endif\r
+\r
+  u32 render_state = flags &\r
+   (RENDER_FLAGS_MODULATE_TEXELS | RENDER_FLAGS_BLEND |\r
+   RENDER_FLAGS_TEXTURE_MAP);\r
+  render_state |=\r
+   (psx_gpu->render_state_base & ~RENDER_STATE_DITHER);\r
+\r
+  if((psx_gpu->render_state != render_state) ||\r
+   (psx_gpu->primitive_type != PRIMITIVE_TYPE_SPRITE))\r
+  {\r
+    psx_gpu->render_state = render_state;\r
+    flush_render_block_buffer(psx_gpu);\r
+#ifdef PROFILE\r
+    state_changes++;\r
+#endif\r
+  }\r
+\r
+  psx_gpu->primitive_type = PRIMITIVE_TYPE_SPRITE;\r
+\r
+  color &= 0xFFFFFF;\r
+\r
+  if(psx_gpu->triangle_color != color)\r
+  {\r
+    flush_render_block_buffer(psx_gpu);\r
+    psx_gpu->triangle_color = color;\r
+  }\r
+\r
+  if(color == 0x808080)\r
+    render_state |= RENDER_FLAGS_MODULATE_TEXELS;\r
+\r
+  render_block_handler_struct *render_block_handler =\r
+   &(render_sprite_block_handlers_4x[render_state]);\r
+  psx_gpu->render_block_handler = render_block_handler;\r
+\r
+  ((setup_sprite_function_type *)render_block_handler->setup_blocks)\r
+   (psx_gpu, x, y, u, v, width, height, color);\r
+}\r
+\r
index c11955d..b58b190 100644 (file)
@@ -394,6 +394,10 @@ build_vector_types(s);
   foreach_element(8, (dest).e[_i] =                                            \
    (u8)(source_a).e[_i] | ((u8)(source_b).e[_i] << 8))                         \
 
+#define zip_4x32b(dest, source_a, source_b)                                    \
+  foreach_element(4, (dest).e[_i] =                                            \
+   (u8)(source_a).e[_i] | ((u8)(source_b).e[_i] << 16))                        \
+
 #define zip_2x64b(dest, source_a, source_b)                                    \
   foreach_element(2, (dest).e[_i] =                                            \
    (u64)(source_a).e[_i] | ((u64)(source_b).e[_i] << 32))                      \