psx_gpu: switch enhancement to 2048 width
authornotaz <notasas@gmail.com>
Sun, 12 Aug 2012 23:53:21 +0000 (02:53 +0300)
committernotaz <notasas@gmail.com>
Thu, 11 Oct 2012 21:05:07 +0000 (00:05 +0300)
otherwise games that position framebuffers horizontally corrupt the
display.

plugins/gpu_neon/psx_gpu/psx_gpu.c
plugins/gpu_neon/psx_gpu/psx_gpu.h
plugins/gpu_neon/psx_gpu/psx_gpu_offsets.h
plugins/gpu_neon/psx_gpu/psx_gpu_offsets_update.c
plugins/gpu_neon/psx_gpu/psx_gpu_parse.c
plugins/gpu_neon/psx_gpu_if.c
plugins/gpulib/vout_pl.c

index 0c1c78d..1385e2e 100644 (file)
@@ -454,7 +454,7 @@ void setup_blocks_shaded_untextured_undithered_unswizzled_indirect(
 
 void flush_render_block_buffer(psx_gpu_struct *psx_gpu)
 {
-  if((psx_gpu->interlace_mode & RENDER_INTERLACE_ENABLED) &&
+  if((psx_gpu->render_mode & RENDER_INTERLACE_ENABLED) &&
    (psx_gpu->primitive_type == PRIMITIVE_TYPE_SPRITE))
   {
     u32 num_blocks_dest = 0;
@@ -464,7 +464,7 @@ void flush_render_block_buffer(psx_gpu_struct *psx_gpu)
     u16 *vram_ptr = psx_gpu->vram_ptr;
     u32 i;
 
-    if(psx_gpu->interlace_mode & RENDER_INTERLACE_ODD)
+    if(psx_gpu->render_mode & RENDER_INTERLACE_ODD)
     {
       for(i = 0; i < psx_gpu->num_blocks; i++)
       {
@@ -3097,11 +3097,11 @@ static void render_triangle_p(psx_gpu_struct *psx_gpu,
   spans += psx_gpu->num_spans;
 #endif
 
-  if(psx_gpu->interlace_mode & RENDER_INTERLACE_ENABLED)
+  if(unlikely(psx_gpu->render_mode & RENDER_INTERLACE_ENABLED))
   {
     u32 i;
 
-    if(psx_gpu->interlace_mode & RENDER_INTERLACE_ODD)
+    if(psx_gpu->render_mode & RENDER_INTERLACE_ODD)
     {
       for(i = 0; i < psx_gpu->num_spans; i++)
       {
@@ -3118,6 +3118,14 @@ static void render_triangle_p(psx_gpu_struct *psx_gpu,
       }
     }
   }
+  if(psx_gpu->render_mode & RENDER_DOUBLE_MODE)
+  {
+    u32 i;
+    for(i = 0; i < psx_gpu->num_spans; i++)
+    {
+      psx_gpu->span_edge_data[i].y *= 2;
+    }
+  }
 
   u32 render_state = flags &
    (RENDER_FLAGS_MODULATE_TEXELS | RENDER_FLAGS_BLEND | 
@@ -4473,12 +4481,12 @@ void render_block_fill(psx_gpu_struct *psx_gpu, u32 color, u32 x, u32 y,
   u32 pitch = 512 - (width / 2);
   u32 num_width;
 
-  if(psx_gpu->interlace_mode & RENDER_INTERLACE_ENABLED)
+  if(psx_gpu->render_mode & RENDER_INTERLACE_ENABLED)
   {
     pitch += 512;
     height /= 2;
 
-    if(psx_gpu->interlace_mode & RENDER_INTERLACE_ODD)
+    if(psx_gpu->render_mode & RENDER_INTERLACE_ODD)
       vram_ptr += 512; 
   }
 
@@ -4505,6 +4513,47 @@ void render_block_fill(psx_gpu_struct *psx_gpu, u32 color, u32 x, u32 y,
   }
 }
 
+void render_block_fill_enh(psx_gpu_struct *psx_gpu, u32 color, u32 x, u32 y,
+ u32 width, u32 height)
+{
+  if((width == 0) || (height == 0))
+    return;
+
+  u32 r = color & 0xFF;
+  u32 g = (color >> 8) & 0xFF;
+  u32 b = (color >> 16) & 0xFF;
+  u32 color_16bpp = (r >> 3) | ((g >> 3) << 5) | ((b >> 3) << 10) |
+   psx_gpu->mask_msb;
+  u32 color_32bpp = color_16bpp | (color_16bpp << 16);
+
+  u32 *vram_ptr = (u32 *)(psx_gpu->vram_out_ptr + x + (y * 2048));
+
+  u32 pitch = 2048 / 2 - (width / 2);
+  u32 num_width;
+
+  while(height)
+  {
+    num_width = width;
+    while(num_width)
+    {
+      vram_ptr[0] = color_32bpp;
+      vram_ptr[1] = color_32bpp;
+      vram_ptr[2] = color_32bpp;
+      vram_ptr[3] = color_32bpp;
+      vram_ptr[4] = color_32bpp;
+      vram_ptr[5] = color_32bpp;
+      vram_ptr[6] = color_32bpp;
+      vram_ptr[7] = color_32bpp;
+
+      vram_ptr += 8;
+      num_width -= 16;
+    }
+
+    vram_ptr += pitch;
+    height--;
+  }
+}
+
 void render_block_copy(psx_gpu_struct *psx_gpu, u16 *source, u32 x, u32 y,
  u32 width, u32 height, u32 pitch)
 {
@@ -4598,7 +4647,7 @@ void initialize_psx_gpu(psx_gpu_struct *psx_gpu, u16 *vram)
   psx_gpu->texture_mask_width = 0xFF;
   psx_gpu->texture_mask_height = 0xFF;
 
-  psx_gpu->interlace_mode = 0;
+  psx_gpu->render_mode = 0;
 
   memset(psx_gpu->vram_ptr, 0, sizeof(u16) * 1024 * 512);
 
index 7ed5622..71b99cd 100644 (file)
@@ -56,8 +56,9 @@ typedef enum
 typedef enum
 {
   RENDER_INTERLACE_ENABLED     = 0x1,
-  RENDER_INTERLACE_ODD         = 0x2
-} render_interlace_enum;
+  RENDER_INTERLACE_ODD         = 0x2,
+  RENDER_DOUBLE_MODE           = 0x4,
+} render_mode_enum;
 
 typedef struct
 {
@@ -179,7 +180,7 @@ typedef struct
   u8 texture_window_y;
 
   u8 primitive_type;
-  u8 interlace_mode;
+  u8 render_mode;
 
   // enhancement stuff
   u16 *enhancement_buf_ptr;
index 2e18174..7ebf7db 100644 (file)
@@ -46,7 +46,7 @@
 #define psx_gpu_texture_window_x_offset                   0x100
 #define psx_gpu_texture_window_y_offset                   0x101
 #define psx_gpu_primitive_type_offset                     0x102
-#define psx_gpu_interlace_mode_offset                     0x103
+#define psx_gpu_render_mode_offset                        0x103
 #define psx_gpu_blocks_offset                             0x200
 #define psx_gpu_span_uvrg_offset_offset                   0x2200
 #define psx_gpu_span_edge_data_offset                     0x4200
index d81f8aa..ff74f34 100644 (file)
@@ -71,7 +71,7 @@ int main()
        WRITE_OFFSET(f, texture_window_x);
        WRITE_OFFSET(f, texture_window_y);
        WRITE_OFFSET(f, primitive_type);
-       WRITE_OFFSET(f, interlace_mode);
+       WRITE_OFFSET(f, render_mode);
        WRITE_OFFSET(f, blocks);
        WRITE_OFFSET(f, span_uvrg_offset);
        WRITE_OFFSET(f, span_edge_data);
index 26715c6..d3616bd 100644 (file)
@@ -755,6 +755,7 @@ breakloop:
   psx_gpu->viewport_start_y = psx_gpu->saved_viewport_start_y; \
   psx_gpu->viewport_end_x = psx_gpu->saved_viewport_end_x; \
   psx_gpu->viewport_end_y = psx_gpu->saved_viewport_end_y; \
+  psx_gpu->render_mode &= ~RENDER_DOUBLE_MODE; \
 }
 
 #define enhancement_enable() { \
@@ -763,6 +764,7 @@ breakloop:
   psx_gpu->viewport_start_y = psx_gpu->saved_viewport_start_y * 2; \
   psx_gpu->viewport_end_x = psx_gpu->saved_viewport_end_x * 2; \
   psx_gpu->viewport_end_y = psx_gpu->saved_viewport_end_y * 2; \
+  psx_gpu->render_mode |= RENDER_DOUBLE_MODE; \
 }
 
 #define shift_vertices3(v) { \
@@ -869,6 +871,9 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size, u32 *last_c
         u32 height = list_s16[5] & 0x1FF;
         u32 color = list[0] & 0xFFFFFF;
 
+        x &= ~0xF;
+        width = ((width + 0xF) & ~0xF);
+
         do_fill(psx_gpu, x, y, width, height, color);
 
         psx_gpu->vram_out_ptr = psx_gpu->enhancement_buf_ptr;
@@ -876,9 +881,7 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size, u32 *last_c
         y *= 2;
         width *= 2;
         height *= 2;
-        if (width > 1024)
-          width = 1024;
-        render_block_fill(psx_gpu, color, x, y, width, height);
+        render_block_fill_enh(psx_gpu, color, x, y, width, height);
         break;
       }
   
index 8610c83..d42f83a 100644 (file)
@@ -64,11 +64,11 @@ void renderer_flush_queues(void)
 
 void renderer_set_interlace(int enable, int is_odd)
 {
-  egpu.interlace_mode &= ~(RENDER_INTERLACE_ENABLED|RENDER_INTERLACE_ODD);
+  egpu.render_mode &= ~(RENDER_INTERLACE_ENABLED|RENDER_INTERLACE_ODD);
   if (enable)
-    egpu.interlace_mode |= RENDER_INTERLACE_ENABLED;
+    egpu.render_mode |= RENDER_INTERLACE_ENABLED;
   if (is_odd)
-    egpu.interlace_mode |= RENDER_INTERLACE_ODD;
+    egpu.render_mode |= RENDER_INTERLACE_ODD;
 }
 
 #include "../../frontend/plugin_lib.h"
index 47c28f3..5131034 100644 (file)
@@ -78,7 +78,8 @@ static void blit(void)
     w *= 2;
     h *= 2;
     stride *= 2;
-    vram_mask = 1024 * 1024 - 1;
+    vram_stride = 2048;
+    vram_mask = 2048 * 1024 - 1;
   }
   fb_offs = y * vram_stride + x;