From 0924243a53f39f1e43a0114a9e74be498055977f Mon Sep 17 00:00:00 2001 From: kub Date: Fri, 10 Sep 2021 18:53:31 +0200 Subject: [PATCH] psp, scaling revisited --- configure | 2 +- platform/common/config_file.c | 12 ----- platform/common/emu.h | 11 ++++- platform/common/menu_pico.h | 8 +--- platform/psp/emu.c | 57 ++++++++++++++--------- platform/psp/menu.c | 86 ++++------------------------------- 6 files changed, 57 insertions(+), 119 deletions(-) diff --git a/configure b/configure index 9e65e221..8fee576e 100755 --- a/configure +++ b/configure @@ -128,7 +128,7 @@ set_platform() # use newlib SYSLIBS="-lc -lpspuser -lpspkernel" CFLAGS="$CFLAGS -D__PSP__" - MFLAGS="-march=mips32r2" + MFLAGS="-march=allegrex" ARCH=mipsel ;; *) diff --git a/platform/common/config_file.c b/platform/common/config_file.c index 8c80f7d5..18331d71 100644 --- a/platform/common/config_file.c +++ b/platform/common/config_file.c @@ -338,18 +338,6 @@ static int custom_read(menu_entry *me, const char *var, const char *val) return 1; /* PSP */ - case MA_OPT3_SCALE: - if (strcasecmp(var, "Scale factor") != 0) return 0; - currentConfig.scale = atof(val); - return 1; - case MA_OPT3_HSCALE32: - if (strcasecmp(var, "Hor. scale (for low res. games)") != 0) return 0; - currentConfig.hscale32 = atof(val); - return 1; - case MA_OPT3_HSCALE40: - if (strcasecmp(var, "Hor. scale (for hi res. games)") != 0) return 0; - currentConfig.hscale40 = atof(val); - return 1; case MA_OPT3_VSYNC: // XXX: use enum if (strcasecmp(var, "Wait for vsync") != 0) return 0; diff --git a/platform/common/emu.h b/platform/common/emu.h index 9e47e44a..c7477dcb 100644 --- a/platform/common/emu.h +++ b/platform/common/emu.h @@ -40,10 +40,19 @@ enum { // linux, GP2X: EOPT_SCALE_SW = 1, EOPT_SCALE_HW, + // PSP horiz: + EOPT_SCALE_43 = 1, // DAR 4:3 (12:9) + EOPT_SCALE_WIDE, // DAR 14:9 + EOPT_SCALE_FULL, // DAR 16:9 + // PSP vert: + EOPT_VSCALE_PAL = 1, // always 240 lines + EOPT_VSCALE_FULL, // zoomed to full height }; enum { EOPT_FILTER_NONE = 0, + // PSP texture filtering + EOPT_FILTER_BILINEAR = 1, // software scalers EOPT_FILTER_SMOOTHER = 1, EOPT_FILTER_BILINEAR1, @@ -75,8 +84,6 @@ typedef struct _currentConfig_t { int scaling; // EOPT_SCALE_* int vscaling; int rotation; // for UIQ - float scale; // psp: screen scale - float hscale32, hscale40; // psp: horizontal scale int gamma2; // psp: black level int turbo_rate; int renderer; diff --git a/platform/common/menu_pico.h b/platform/common/menu_pico.h index ee9d2bab..2b699ef2 100644 --- a/platform/common/menu_pico.h +++ b/platform/common/menu_pico.h @@ -62,13 +62,7 @@ typedef enum MA_OPT2_MAX_FRAMESKIP, MA_OPT2_PWM_IRQ_OPT, MA_OPT2_DONE, - MA_OPT3_SCALE, /* psp (all OPT3) */ - MA_OPT3_HSCALE32, - MA_OPT3_HSCALE40, - MA_OPT3_GAMMAA, - MA_OPT3_PRES_NOSCALE, - MA_OPT3_PRES_SCALE43, - MA_OPT3_PRES_FULLSCR, + MA_OPT3_GAMMAA, /* psp (all OPT3) */ MA_OPT3_FILTERING, MA_OPT3_VSYNC, MA_OPT3_BLACKLVL, diff --git a/platform/psp/emu.c b/platform/psp/emu.c index 45f0623a..eac00609 100644 --- a/platform/psp/emu.c +++ b/platform/psp/emu.c @@ -50,9 +50,9 @@ static int need_pal_upload = 0; static u16 __attribute__((aligned(16))) osd_buf[512*8]; // buffer for osd text -static int h32_mode = 0; static int out_x, out_y; static int out_w, out_h; +static float hscale, vscale; static struct in_default_bind in_psp_defbinds[] = { @@ -152,11 +152,8 @@ static void set_scaling_params(void) int fbimg_width, fbimg_height, fbimg_xoffs, fbimg_yoffs, border_hack = 0; g_vertices[0].z = g_vertices[1].z = 0; - fbimg_height = (int)(out_h * currentConfig.scale + 0.5); - if (!h32_mode) - fbimg_width = (int)(out_w * currentConfig.scale * currentConfig.hscale40 + 0.5); - else - fbimg_width = (int)(out_w * currentConfig.scale * currentConfig.hscale32 + 0.5); + fbimg_height = (int)(out_h * vscale + 0.5); + fbimg_width = (int)(out_w * hscale + 0.5); if (fbimg_width & 1) fbimg_width++; // make even if (fbimg_height & 1) fbimg_height++; @@ -370,7 +367,7 @@ static void vidResetMode(void) sceGuClutMode(GU_PSM_5650,0,0xff,0); sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB); - if (currentConfig.scaling) + if (currentConfig.filter) sceGuTexFilter(GU_LINEAR, GU_LINEAR); else sceGuTexFilter(GU_NEAREST, GU_NEAREST); sceGuTexScale(1.0f,1.0f); @@ -575,10 +572,9 @@ void pemu_prep_defconfig(void) defaultConfig.s_PsndRate = 22050; defaultConfig.s_PicoCDBuffers = 64; defaultConfig.CPUclock = 333; - defaultConfig.scaling = 1; // bilinear filtering for psp - defaultConfig.scale = 1.20; // fullscreen - defaultConfig.hscale40 = 1.25; - defaultConfig.hscale32 = 1.56; + defaultConfig.filter = EOPT_FILTER_BILINEAR; // bilinear filtering + defaultConfig.scaling = EOPT_SCALE_43; + defaultConfig.vscaling = EOPT_VSCALE_FULL; defaultConfig.EmuOpt |= EOPT_SHOW_RTC; } @@ -587,12 +583,6 @@ void pemu_validate_config(void) { if (currentConfig.CPUclock < 33 || currentConfig.CPUclock > 333) currentConfig.CPUclock = 333; - if (currentConfig.scaling < 0.01) - currentConfig.scaling = 0.01; - if (currentConfig.hscale40 < 0.01) - currentConfig.hscale40 = 0.01; - if (currentConfig.hscale32 < 0.01) - currentConfig.hscale32 = 0.01; if (currentConfig.gamma < -4 || currentConfig.gamma > 16) currentConfig.gamma = 0; if (currentConfig.gamma2 < 0 || currentConfig.gamma2 > 2) @@ -676,12 +666,37 @@ void plat_update_volume(int has_changed, int is_up) /* prepare for MD screen mode change */ void emu_video_mode_change(int start_line, int line_count, int start_col, int col_count) { - h32_mode = col_count < 320; - out_y = start_line; out_x = (h32_mode ? 32 : 0); - out_h = line_count; out_w = (h32_mode ? 256:320); + out_y = start_line; out_x = start_col; + out_h = line_count; out_w = col_count; + + switch (currentConfig.vscaling) { + case EOPT_VSCALE_PAL: + vscale = (float)270/240; + break; + case EOPT_VSCALE_FULL: + vscale = (float)270/line_count; + break; + default: + vscale = 1; + break; + } + switch (currentConfig.scaling) { + case EOPT_SCALE_43: + hscale = (float)360/col_count; + break; + case EOPT_SCALE_WIDE: + hscale = (float)420/col_count; + break; + case EOPT_SCALE_FULL: + hscale = (float)480/col_count; + break; + default: + hscale = 1; + break; + } vidResetMode(); - if (h32_mode) // clear borders from h40 remnants + if (col_count < 320) // clear borders from h40 remnants clearArea(1); } diff --git a/platform/psp/menu.c b/platform/psp/menu.c index 18197c40..1ca2ede2 100644 --- a/platform/psp/menu.c +++ b/platform/psp/menu.c @@ -1,84 +1,18 @@ -static const char h_scale43[] = "Scales low and high res to 4:3 screen size.\n" - "For 240 line PAL use Scale factor 1.12"; -static const char h_scalefull[] = "Scales low and high res to full screen.\n" - "For 240 line PAL use scaling 1.12, 1.6, 1.28"; +static const char *men_hscaling_opts[] = { "OFF", "4:3", "wide", "fullscreen", NULL }; +static const char *men_vscaling_opts[] = { "OFF", "PAL", "fullscreen", NULL }; +static const char *men_filter_opts[] = { "OFF", "bilinear" }; + #define MENU_OPTIONS_GFX \ - mee_cust("Scale factor", MA_OPT3_SCALE, mh_scale, ms_scale), \ - mee_cust("Hor. scale (for low res. games)", MA_OPT3_HSCALE32, mh_scale, ms_scale), \ - mee_cust("Hor. scale (for hi res. games)", MA_OPT3_HSCALE40, mh_scale, ms_scale), \ - mee_onoff("Bilinear filtering", MA_OPT3_FILTERING, currentConfig.scaling, 1), \ - mee_range("Gamma adjustment", MA_OPT3_GAMMAA, currentConfig.gamma, -4, 16), \ - mee_range("Black level", MA_OPT3_BLACKLVL, currentConfig.gamma2, 0, 2), \ - mee_onoff("wait for vsync", MA_OPT3_VSYNC, currentConfig.EmuOpt, EOPT_VSYNC), \ - mee_cust_nosave("Set to unscaled centered", MA_OPT3_PRES_NOSCALE, mh_preset_scale, NULL), \ - mee_cust_nosave("Set to 4:3 scaled", MA_OPT3_PRES_SCALE43, mh_preset_scale, NULL), \ - mee_cust_nosave("Set to fullscreen", MA_OPT3_PRES_FULLSCR, mh_preset_scale, NULL), \ + mee_enum ("Horizontal scaling", MA_OPT_SCALING, currentConfig.scaling, men_hscaling_opts), \ + mee_enum ("Vertical scaling", MA_OPT_VSCALING, currentConfig.vscaling, men_vscaling_opts), \ + mee_enum_h ("Scaler type", MA_OPT3_FILTERING, currentConfig.filter, men_filter_opts, NULL), \ + mee_range ("Gamma adjustment", MA_OPT3_GAMMAA, currentConfig.gamma, -4, 16), \ + mee_range ("Black level", MA_OPT3_BLACKLVL, currentConfig.gamma2, 0, 2), \ + mee_onoff ("Wait for vsync", MA_OPT3_VSYNC, currentConfig.EmuOpt, EOPT_VSYNC), \ #define MENU_OPTIONS_ADV - -static const char *ms_scale(int id, int *offs) -{ - float val = 0; - switch (id) { - case MA_OPT3_SCALE: val = currentConfig.scale; break; - case MA_OPT3_HSCALE32: val = currentConfig.hscale32; break; - case MA_OPT3_HSCALE40: val = currentConfig.hscale40; break; - } - sprintf(static_buff, "%.2f", val); - return static_buff; -} - -static int mh_scale(int id, int keys) -{ - float *val = NULL; - switch (id) { - case MA_OPT3_SCALE: val = ¤tConfig.scale; break; - case MA_OPT3_HSCALE32: val = ¤tConfig.hscale32; break; - case MA_OPT3_HSCALE40: val = ¤tConfig.hscale40; break; - } - if (keys & PBTN_LEFT) *val += -0.01; - if (keys & PBTN_RIGHT) *val += +0.01; - if (*val < 0.01) *val = +0.01; - return 0; -} - - -static int mh_preset_scale(int id, int keys) -{ - switch (id) { - case MA_OPT3_PRES_NOSCALE: - currentConfig.scale = 1.0; - currentConfig.hscale32 = 1.0; - currentConfig.hscale40 = 1.0; - break; - case MA_OPT3_PRES_SCALE43: - // parameters for 224 lines; for 240 lines scale = 1.125 - // moreover, H32 and H40 had the same width on a TV. - currentConfig.scale = 1.2; - currentConfig.hscale32 = 1.25; - currentConfig.hscale40 = 1.0; - break; - case MA_OPT3_PRES_FULLSCR: - // uses width 460 to avoid some ugly moiree effects - currentConfig.scale = 1.2; - currentConfig.hscale32 = 1.5; - currentConfig.hscale40 = 1.2; - break; - } - return 0; -} - -static menu_entry e_menu_gfx_options[]; - void psp_menu_init(void) { - int i; - for (i = 0; e_menu_gfx_options[i].name; i++) { - switch (e_menu_gfx_options[i].id) { - case MA_OPT3_PRES_SCALE43: e_menu_gfx_options[i].help = h_scale43; break; - case MA_OPT3_PRES_FULLSCR: e_menu_gfx_options[i].help = h_scalefull; break; - } - } } -- 2.39.5