From 37631374df39c99b934715fa15054839c12de014 Mon Sep 17 00:00:00 2001 From: kub Date: Fri, 5 Mar 2021 20:20:22 +0100 Subject: [PATCH] ui, revised menu and option handling, added sound filter settings --- pico/pico.h | 5 +- pico/sound/sound.c | 3 +- platform/common/config_file.c | 13 ++- platform/common/emu.c | 10 ++- platform/common/emu.h | 1 + platform/common/menu_pico.c | 150 +++++++++++++++++++++++----------- platform/common/menu_pico.h | 5 +- platform/libretro/libretro.c | 17 ++-- platform/psp/emu.c | 4 +- platform/psp/mp3.c | 2 +- 10 files changed, 138 insertions(+), 72 deletions(-) diff --git a/pico/pico.h b/pico/pico.h index 5ec67d40..912d9502 100644 --- a/pico/pico.h +++ b/pico/pico.h @@ -57,7 +57,7 @@ extern void *p32x_bios_g, *p32x_bios_m, *p32x_bios_s; #define POPT_EN_STEREO (1<< 3) #define POPT_ALT_RENDERER (1<< 4) // 00 00x0 #define POPT_EN_YM2413 (1<< 5) -// unused (1<< 6) +#define POPT_EN_SNDFILTER (1<< 6) #define POPT_ACC_SPRITES (1<< 7) #define POPT_DIS_32C_BORDER (1<< 8) // 00 0x00 #define POPT_EXT_FM (1<< 9) @@ -102,8 +102,7 @@ typedef struct unsigned short overclockM68k; // overclock the emulated 68k, in % int sndRate; // rate in Hz - unsigned short sndFilter; // Set low pass sound filter 0: off, 1: on (use integer in case we want to add other filter types later) - int32_t sndFilterRange; // Low pass sound filter range [0, 65536] + int sndFilterAlpha; // Low pass sound filter alpha (Q16) short *sndOut; // PCM output buffer void (*writeSound)(int len); // write .sndOut callback, called once per frame diff --git a/pico/sound/sound.c b/pico/sound/sound.c index 0807c030..806a597b 100644 --- a/pico/sound/sound.c +++ b/pico/sound/sound.c @@ -50,8 +50,6 @@ PICO_INTERNAL void PsndReset(void) // PsndRerate calls YM2612Init, which also resets PsndRerate(0); timers_reset(); - - mix_reset(PicoIn.sndFilter ? PicoIn.sndFilterRange : 0); } @@ -106,6 +104,7 @@ void PsndRerate(int preserve_state) // set mixer PsndMix_32_to_16l = (PicoIn.opt & POPT_EN_STEREO) ? mix_32_to_16l_stereo : mix_32_to_16_mono; + mix_reset(PicoIn.opt & POPT_EN_SNDFILTER ? PicoIn.sndFilterAlpha : 0); if (PicoIn.AHW & PAHW_PICO) PicoReratePico(); diff --git a/platform/common/config_file.c b/platform/common/config_file.c index e5962e22..59bbe122 100644 --- a/platform/common/config_file.c +++ b/platform/common/config_file.c @@ -279,6 +279,11 @@ static int custom_read(menu_entry *me, const char *var, const char *val) return 0; return 1; + case MA_OPT_SOUND_ALPHA: + if (strcasecmp(var, "Filter strength (alpha)") != 0) return 0; + PicoIn.sndFilterAlpha = 0x10000 * atof(val); + return 1; + case MA_OPT_REGION: if (strcasecmp(var, "Region") != 0) return 0; if (strncasecmp(val, "Auto: ", 6) == 0) @@ -349,12 +354,12 @@ static int custom_read(menu_entry *me, const char *var, const char *val) // XXX: use enum if (strcasecmp(var, "Wait for vsync") != 0) return 0; if (strcasecmp(val, "never") == 0) { - currentConfig.EmuOpt &= ~0x12000; + currentConfig.EmuOpt &= ~(EOPT_VSYNC|EOPT_VSYNC_MODE); } else if (strcasecmp(val, "sometimes") == 0) { - currentConfig.EmuOpt |= 0x12000; + currentConfig.EmuOpt |= (EOPT_VSYNC|EOPT_VSYNC_MODE); } else if (strcasecmp(val, "always") == 0) { - currentConfig.EmuOpt &= ~0x12000; - currentConfig.EmuOpt |= 0x02000; + currentConfig.EmuOpt &= ~EOPT_VSYNC_MODE; + currentConfig.EmuOpt |= EOPT_VSYNC; } else return 0; return 1; diff --git a/platform/common/emu.c b/platform/common/emu.c index 151fb531..ecc91726 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -585,8 +585,10 @@ static void make_config_cfg(char *cfg_buff_512) void emu_prep_defconfig(void) { memset(&defaultConfig, 0, sizeof(defaultConfig)); - defaultConfig.EmuOpt = 0x9d | EOPT_EN_CD_LEDS; - defaultConfig.s_PicoOpt = POPT_EN_STEREO|POPT_EN_FM|POPT_EN_PSG|POPT_EN_Z80 | + defaultConfig.EmuOpt = EOPT_EN_SRAM | EOPT_EN_SOUND | EOPT_16BPP | + EOPT_EN_CD_LEDS | EOPT_GZIP_SAVES | 0x10/*?*/; + defaultConfig.s_PicoOpt = POPT_EN_SNDFILTER| + POPT_EN_STEREO|POPT_EN_FM|POPT_EN_PSG|POPT_EN_Z80 | POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_MCD_GFX | POPT_EN_DRC|POPT_ACC_SPRITES | POPT_EN_32X|POPT_EN_PWM; @@ -594,6 +596,7 @@ void emu_prep_defconfig(void) defaultConfig.s_PicoRegion = 0; // auto defaultConfig.s_PicoAutoRgnOrder = 0x184; // US, EU, JP defaultConfig.s_PicoCDBuffers = 0; + defaultConfig.s_PicoSndFilterAlpha = 0x10000 * 60 / 100; defaultConfig.confirm_save = EOPT_CONFIRM_SAVE; defaultConfig.Frameskip = -1; // auto defaultConfig.input_dev0 = PICO_INPUT_PAD_3BTN; @@ -617,6 +620,7 @@ void emu_set_defconfig(void) PicoIn.sndRate = currentConfig.s_PsndRate; PicoIn.regionOverride = currentConfig.s_PicoRegion; PicoIn.autoRgnOrder = currentConfig.s_PicoAutoRgnOrder; + PicoIn.sndFilterAlpha = currentConfig.s_PicoSndFilterAlpha; } int emu_read_config(const char *rom_fname, int no_defaults) @@ -974,7 +978,7 @@ void emu_set_fastforward(int set_on) PicoIn.sndOut = NULL; currentConfig.Frameskip = 8; currentConfig.EmuOpt &= ~4; - currentConfig.EmuOpt |= 0x40000; + currentConfig.EmuOpt |= EOPT_NO_FRMLIMIT; is_on = 1; emu_status_msg("FAST FORWARD"); } diff --git a/platform/common/emu.h b/platform/common/emu.h index 512ed716..a2110026 100644 --- a/platform/common/emu.h +++ b/platform/common/emu.h @@ -55,6 +55,7 @@ typedef struct _currentConfig_t { int s_PicoRegion; int s_PicoAutoRgnOrder; int s_PicoCDBuffers; + int s_PicoSndFilterAlpha; int Frameskip; int input_dev0; int input_dev1; diff --git a/platform/common/menu_pico.c b/platform/common/menu_pico.c index fc238c30..5aa509dc 100644 --- a/platform/common/menu_pico.c +++ b/platform/common/menu_pico.c @@ -530,7 +530,6 @@ static const char h_ovrclk[] = "Will break some games, keep at 0"; static menu_entry e_menu_adv_options[] = { - mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_EN_SRAM), mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoIn.opt, POPT_DIS_SPRITE_LIM), mee_range_h ("Overclock M68k (%)", MA_OPT2_OVERCLOCK_M68K,currentConfig.overclock_68k, 0, 1000, h_ovrclk), mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoIn.opt, POPT_EN_Z80), @@ -538,12 +537,9 @@ static menu_entry e_menu_adv_options[] = mee_onoff ("Disable YM2612 SSG-EG", MA_OPT2_DISABLE_YM_SSG,PicoIn.opt, POPT_DIS_FM_SSGEG), mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoIn.opt, POPT_EN_PSG), mee_onoff ("Emulate YM2413 (FM)", MA_OPT2_ENABLE_YM2413 ,PicoIn.opt, POPT_EN_YM2413), - mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES), - mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG), mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoIn.opt, POPT_DIS_IDLE_DET), mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT), mee_onoff ("Enable dynarecs", MA_OPT2_DYNARECS, PicoIn.opt, POPT_EN_DRC), - mee_onoff ("Status line in main menu", MA_OPT2_STATUS_LINE, currentConfig.EmuOpt, EOPT_SHOW_RTC), mee_range ("Max auto frameskip", MA_OPT2_MAX_FRAMESKIP, currentConfig.max_skip, 1, 10), mee_onoff ("PWM IRQ optimization", MA_OPT2_PWM_IRQ_OPT, PicoIn.opt, POPT_PWM_IRQ_OPT), MENU_OPTIONS_ADV @@ -560,6 +556,85 @@ static int menu_loop_adv_options(int id, int keys) return 0; } +// ------------ sound options menu ------------ + +static int sndrate_prevnext(int rate, int dir) +{ + static const int rates[] = { 8000, 11025, 16000, 22050, 44100 }; + int i; + + for (i = 0; i < 5; i++) + if (rates[i] == rate) break; + + i += dir ? 1 : -1; + if (i > 4) { + if (!(PicoIn.opt & POPT_EN_STEREO)) { + PicoIn.opt |= POPT_EN_STEREO; + return rates[0]; + } + return rates[4]; + } + if (i < 0) { + if (PicoIn.opt & POPT_EN_STEREO) { + PicoIn.opt &= ~POPT_EN_STEREO; + return rates[4]; + } + return rates[0]; + } + return rates[i]; +} + +static int mh_opt_snd(int id, int keys) +{ + PicoIn.sndRate = sndrate_prevnext(PicoIn.sndRate, keys & PBTN_RIGHT); + return 0; +} + +static const char *mgn_opt_sound(int id, int *offs) +{ + const char *str2; + *offs = -8; + str2 = (PicoIn.opt & POPT_EN_STEREO) ? "stereo" : "mono"; + sprintf(static_buff, "%5iHz %s", PicoIn.sndRate, str2); + return static_buff; +} + +static int mh_opt_alpha(int id, int keys) +{ + int val = (PicoIn.sndFilterAlpha * 100 + 0x08000) / 0x10000; + if (keys & PBTN_LEFT) val--; + if (keys & PBTN_RIGHT) val++; + if (val < 1) val = 1; + if (val > 99) val = 99; + PicoIn.sndFilterAlpha = val * 0x10000 / 100; + return 0; +} + +static const char *mgn_opt_alpha(int id, int *offs) +{ + int val = (PicoIn.sndFilterAlpha * 100 + 0x08000) / 0x10000; + sprintf(static_buff, "0.%02d", val); + return static_buff; +} + +static menu_entry e_menu_snd_options[] = +{ + mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND), + mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_snd, mgn_opt_sound), + mee_onoff ("Sound filter (low pass)", MA_OPT_SOUND_FILTER, PicoIn.opt, POPT_EN_SNDFILTER), + mee_cust ("Filter strength (alpha)", MA_OPT_SOUND_ALPHA, mh_opt_alpha, mgn_opt_alpha), + mee_end, +}; + +static int menu_loop_snd_options(int id, int keys) +{ + static int sel = 0; + + me_loop(e_menu_snd_options, &sel); + + return 0; +} + // ------------ gfx options menu ------------ static const char h_gamma[] = "Gamma/brightness adjustment (default 1.00)"; @@ -590,36 +665,32 @@ static int menu_loop_gfx_options(int id, int keys) return 0; } -// ------------ options menu ------------ +// ------------ UI options menu ------------ -static menu_entry e_menu_options[]; +static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL }; +static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n" + "loading state or both"; -static int sndrate_prevnext(int rate, int dir) +static menu_entry e_menu_ui_options[] = { - static const int rates[] = { 8000, 11025, 16000, 22050, 44100 }; - int i; + mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES, currentConfig.confirm_save, men_confirm_save, h_confirm_save), + mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG), + mee_end, +}; - for (i = 0; i < 5; i++) - if (rates[i] == rate) break; +static int menu_loop_ui_options(int id, int keys) +{ + static int sel = 0; - i += dir ? 1 : -1; - if (i > 4) { - if (!(PicoIn.opt & POPT_EN_STEREO)) { - PicoIn.opt |= POPT_EN_STEREO; - return rates[0]; - } - return rates[4]; - } - if (i < 0) { - if (PicoIn.opt & POPT_EN_STEREO) { - PicoIn.opt &= ~POPT_EN_STEREO; - return rates[4]; - } - return rates[0]; - } - return rates[i]; + me_loop(e_menu_ui_options, &sel); + + return 0; } +// ------------ options menu ------------ + +static menu_entry e_menu_options[]; + static void region_prevnext(int right) { // jp_ntsc=1, jp_pal=2, usa=4, eu=8 @@ -651,9 +722,6 @@ static void region_prevnext(int right) static int mh_opt_misc(int id, int keys) { switch (id) { - case MA_OPT_SOUND_QUALITY: - PicoIn.sndRate = sndrate_prevnext(PicoIn.sndRate, keys & PBTN_RIGHT); - break; case MA_OPT_REGION: region_prevnext(keys & PBTN_RIGHT); break; @@ -711,15 +779,6 @@ static const char *mgn_opt_fskip(int id, int *offs) return static_buff; } -static const char *mgn_opt_sound(int id, int *offs) -{ - const char *str2; - *offs = -8; - str2 = (PicoIn.opt & POPT_EN_STEREO) ? "stereo" : "mono"; - sprintf(static_buff, "%5iHz %s", PicoIn.sndRate, str2); - return static_buff; -} - static const char *mgn_opt_region(int id, int *offs) { static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" }; @@ -754,21 +813,16 @@ static const char *mgn_saveloadcfg(int id, int *offs) return static_buff; } -static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL }; -static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n" - "loading state or both"; - static menu_entry e_menu_options[] = { mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9), mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip), mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region), mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS), - mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND), - mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound), - mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save), mee_range ("", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 3200), + mee_handler ("[Interface options]", menu_loop_ui_options), mee_handler ("[Display options]", menu_loop_gfx_options), + mee_handler ("[Sound options]", menu_loop_snd_options), mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options), #ifndef NO_32X mee_handler ("[32X options]", menu_loop_32x_options), @@ -1219,7 +1273,7 @@ void menu_update_msg(const char *msg) /* hidden options for config engine only */ static menu_entry e_menu_hidden[] = { - mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoIn.opt, 0x080), + mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoIn.opt, POPT_ACC_SPRITES), mee_onoff("autoload savestates", MA_OPT_AUTOLOAD_SAVE, g_autostateld_opt, 1), mee_end, }; @@ -1227,6 +1281,8 @@ static menu_entry e_menu_hidden[] = static menu_entry *e_menu_table[] = { e_menu_options, + e_menu_ui_options, + e_menu_snd_options, e_menu_gfx_options, e_menu_adv_options, e_menu_cd_options, diff --git a/platform/common/menu_pico.h b/platform/common/menu_pico.h index 8f72baf7..ee9d2bab 100644 --- a/platform/common/menu_pico.h +++ b/platform/common/menu_pico.h @@ -28,7 +28,6 @@ typedef enum MA_OPT_INPUT_DEV0, MA_OPT_INPUT_DEV1, MA_OPT_REGION, - MA_OPT_SRAM_STATES, MA_OPT_CONFIRM_STATES, MA_OPT_SAVE_SLOT, MA_OPT_CPU_CLOCKS, @@ -42,6 +41,8 @@ typedef enum MA_OPT_TEARING_FIX, /* wiz */ MA_OPT_VOUT_MODE, MA_OPT_AUTOLOAD_SAVE, + MA_OPT_SOUND_FILTER, + MA_OPT_SOUND_ALPHA, MA_OPT2_GAMMA, MA_OPT2_A_SN_GAMMA, MA_OPT2_DBLBUFF, /* giz */ @@ -51,10 +52,8 @@ typedef enum MA_OPT2_DISABLE_YM_SSG, MA_OPT2_ENABLE_SN76496, MA_OPT2_ENABLE_YM2413, - MA_OPT2_GZIP_STATES, MA_OPT2_NO_LAST_ROM, MA_OPT2_RAMTIMINGS, /* gp2x */ - MA_OPT2_STATUS_LINE, /* psp */ MA_OPT2_NO_FRAME_LIMIT, /* psp */ MA_OPT2_DYNARECS, MA_OPT2_NO_SPRITE_LIM, diff --git a/platform/libretro/libretro.c b/platform/libretro/libretro.c index a6fce3e5..a80fd999 100644 --- a/platform/libretro/libretro.c +++ b/platform/libretro/libretro.c @@ -1543,25 +1543,26 @@ static void update_variables(bool first_run) PicoIn.opt &= ~POPT_EN_DRC; #endif - old_snd_filter = PicoIn.sndFilter; + old_snd_filter = PicoIn.opt & POPT_EN_SNDFILTER; var.value = NULL; var.key = "picodrive_audio_filter"; - PicoIn.sndFilter = 0; + PicoIn.opt &= ~POPT_EN_SNDFILTER; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "low-pass") == 0) - PicoIn.sndFilter = 1; + PicoIn.opt |= POPT_EN_SNDFILTER; } - old_snd_filter_range = PicoIn.sndFilterRange; + old_snd_filter_range = PicoIn.sndFilterAlpha; var.value = NULL; var.key = "picodrive_lowpass_range"; - PicoIn.sndFilterRange = (60 * 65536) / 100; + PicoIn.sndFilterAlpha = (60 * 0x10000 / 100); if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - PicoIn.sndFilterRange = (atoi(var.value) * 65536) / 100; + PicoIn.sndFilterAlpha = (atoi(var.value) * 0x10000 / 100); } - if (old_snd_filter != PicoIn.sndFilter || old_snd_filter_range != PicoIn.sndFilterRange) { - mix_reset(PicoIn.sndFilter ? PicoIn.sndFilterRange : 0); + if (((old_snd_filter ^ PicoIn.opt) & POPT_EN_SNDFILTER) || + old_snd_filter_range != PicoIn.sndFilterAlpha) { + mix_reset (PicoIn.opt & POPT_EN_SNDFILTER ? PicoIn.sndFilterAlpha : 0); } old_frameskip_type = frameskip_type; diff --git a/platform/psp/emu.c b/platform/psp/emu.c index 016c44d9..179bf960 100644 --- a/platform/psp/emu.c +++ b/platform/psp/emu.c @@ -477,7 +477,8 @@ void pemu_sound_start(void) } } - if (PicoIn.sndRate != PsndRate_old || (PicoIn.opt&0x0b) != (PicoOpt_old&0x0b) || Pico.m.pal != pal_old) { + ret = POPT_EN_FM|POPT_EN_PSG|POPT_EN_STEREO; + if (PicoIn.sndRate != PsndRate_old || (PicoIn.opt&ret) != (PicoOpt_old&ret) || Pico.m.pal != pal_old) { PsndRerate(Pico.m.frame_count ? 1 : 0); } stereo=(PicoIn.opt&8)>>3; @@ -578,6 +579,7 @@ void pemu_prep_defconfig(void) defaultConfig.scale = 1.20; // fullscreen defaultConfig.hscale40 = 1.25; defaultConfig.hscale32 = 1.56; + defaultConfig.EmuOpt |= EOPT_SHOW_RTC; } /* check configuration for inconsistencies */ diff --git a/platform/psp/mp3.c b/platform/psp/mp3.c index 5ec82066..cc4fc1be 100644 --- a/platform/psp/mp3.c +++ b/platform/psp/mp3.c @@ -457,7 +457,7 @@ int mp3_get_offset(void) // 0-1023 unsigned int offs1024 = 0; int cdda_on; - cdda_on = (PicoIn.AHW & PAHW_MCD) && (PicoIn.opt&0x800) && !(Pico_mcd->s68k_regs[0x36] & 1) && + cdda_on = (PicoIn.AHW & PAHW_MCD) && (PicoIn.opt & POPT_EN_MCD_CDDA) && !(Pico_mcd->s68k_regs[0x36] & 1) && /* TODO (Pico_mcd->scd.Status_CDC & 1) &&*/ mp3_handle >= 0; if (cdda_on) { -- 2.39.5