psx_gpu: consolidate C code, implement exnhancement asm
[pcsx_rearmed.git] / frontend / plugin_lib.c
index 1a925ec..484d67b 100644 (file)
@@ -21,6 +21,7 @@
 #include "linux/fbdev.h"
 #include "common/fonts.h"
 #include "common/input.h"
+#include "common/plat.h"
 #include "menu.h"
 #include "main.h"
 #include "plat.h"
@@ -132,6 +133,58 @@ void pl_print_hud(int xborder)
                print_cpu_usage(w, h, xborder);
 }
 
+/* update scaler target size according to user settings */
+static void update_layer_size(int w, int h)
+{
+       float mult;
+       int imult;
+
+       switch (g_scaler) {
+       case SCALE_1_1:
+               g_layer_w = w; g_layer_h = h;
+               break;
+
+       case SCALE_4_3v2:
+               if (h > g_menuscreen_h || (240 < h && h <= 360))
+                       goto fractional_4_3;
+
+               // 4:3 that prefers integer scaling
+               imult = g_menuscreen_h / h;
+               g_layer_w = w * imult;
+               g_layer_h = h * imult;
+               mult = (float)g_layer_w / (float)g_layer_h;
+               if (mult < 1.25f || mult > 1.666f)
+                       g_layer_w = 4.0f/3.0f * (float)g_layer_h;
+               printf("  -> %dx%d %.1f\n", g_layer_w, g_layer_h, mult);
+               break;
+
+       fractional_4_3:
+       case SCALE_4_3:
+               mult = 240.0f / (float)h * 4.0f / 3.0f;
+               if (h > 256)
+                       mult *= 2.0f;
+               g_layer_w = mult * (float)g_menuscreen_h;
+               g_layer_h = g_menuscreen_h;
+               printf("  -> %dx%d %.1f\n", g_layer_w, g_layer_h, mult);
+               break;
+
+       case SCALE_FULLSCREEN:
+               g_layer_w = g_menuscreen_w;
+               g_layer_h = g_menuscreen_h;
+               break;
+
+       default:
+               break;
+       }
+
+       g_layer_x = g_menuscreen_w / 2 - g_layer_w / 2;
+       g_layer_y = g_menuscreen_h / 2 - g_layer_h / 2;
+       if (g_layer_x < 0) g_layer_x = 0;
+       if (g_layer_y < 0) g_layer_y = 0;
+       if (g_layer_w > g_menuscreen_w) g_layer_w = g_menuscreen_w;
+       if (g_layer_h > g_menuscreen_h) g_layer_h = g_menuscreen_h;
+}
+
 static void *pl_vout_set_mode(int w, int h, int bpp)
 {
        // special h handling, Wipeout likes to change it by 1-6
@@ -147,6 +200,8 @@ static void *pl_vout_set_mode(int w, int h, int bpp)
        pl_vout_h = psx_h = h;
        pl_vout_bpp = psx_bpp = bpp;
 
+       update_layer_size(pl_vout_w, pl_vout_h);
+
        pl_vout_buf = plat_gvideo_set_mode(&pl_vout_w, &pl_vout_h, &pl_vout_bpp);
        if (pl_vout_buf == NULL && pl_rearmed_cbs.pl_vout_raw_flip == NULL)
                fprintf(stderr, "failed to set mode %dx%d@%d\n",
@@ -430,12 +485,24 @@ static void pl_get_layer_pos(int *x, int *y, int *w, int *h)
        *h = g_layer_h;
 }
 
+static void *pl_mmap(unsigned int size)
+{
+       return plat_mmap(0, size, 0, 0);
+}
+
+static void pl_munmap(void *ptr, unsigned int size)
+{
+       plat_munmap(ptr, size);
+}
+
 struct rearmed_cbs pl_rearmed_cbs = {
        pl_get_layer_pos,
        pl_vout_open,
        pl_vout_set_mode,
        pl_vout_flip,
        pl_vout_close,
+       pl_mmap,
+       pl_munmap,
 };
 
 /* watchdog */