From 9ecdd73ae7f2666068d5bd8d6c2abde3040aa998 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 26 Jul 2009 13:13:01 +0000 Subject: [PATCH 1/1] restore defaults function + some refactoring git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@716 be3aeb3a-fb24-0410-a615-afba39da0efa --- common/emu.c | 8 ++++---- common/emu.h | 1 + common/menu.c | 50 +++++++++++++++++++++++++------------------------- common/plat.h | 2 +- gp2x/emu.c | 21 ++++++++++++++++----- 5 files changed, 47 insertions(+), 35 deletions(-) diff --git a/common/emu.c b/common/emu.c index 08efdb2..8548bdc 100644 --- a/common/emu.c +++ b/common/emu.c @@ -557,7 +557,7 @@ static void make_config_cfg(char *cfg_buff_512) cfg_buff_512[511] = 0; } -static void emu_setDefaultConfig(void) +void emu_set_defconfig(void) { memcpy(¤tConfig, &defaultConfig, sizeof(currentConfig)); PicoOpt = currentConfig.s_PicoOpt; @@ -575,7 +575,7 @@ int emu_read_config(int game, int no_defaults) if (!game) { if (!no_defaults) - emu_setDefaultConfig(); + emu_set_defconfig(); make_config_cfg(cfg); ret = config_readsect(cfg, NULL); } @@ -593,7 +593,7 @@ int emu_read_config(int game, int no_defaults) { // read user's config int vol = currentConfig.volume; - emu_setDefaultConfig(); + emu_set_defconfig(); ret = config_readsect(cfg, sect); currentConfig.volume = vol; // make vol global (bah) } @@ -1076,7 +1076,7 @@ static void run_events_ui(unsigned int which) } if (which & PEV_SWITCH_RND) { - plat_video_toggle_renderer(); + plat_video_toggle_renderer(1, 0); } if (which & (PEV_SSLOT_PREV|PEV_SSLOT_NEXT)) { diff --git a/common/emu.h b/common/emu.h index 55e8ae2..a2d5eb6 100644 --- a/common/emu.h +++ b/common/emu.h @@ -103,6 +103,7 @@ int emu_reload_rom(char *rom_fname); int emu_save_load_game(int load, int sram); void emu_reset_game(void); +void emu_set_defconfig(void); int emu_read_config(int game, int no_defaults); int emu_write_config(int game); diff --git a/common/menu.c b/common/menu.c index b32546f..bc22e1e 100644 --- a/common/menu.c +++ b/common/menu.c @@ -1457,6 +1457,23 @@ static int menu_loop_adv_options(menu_id id, int keys) // ------------ gfx options menu ------------ +static int mh_opt_render(menu_id id, int keys) +{ + plat_video_toggle_renderer((keys & PBTN_RIGHT) ? 1 : 0, 1); + return 0; +} + +static const char *mgn_opt_renderer(menu_id id, int *offs) +{ + *offs = -11; + if (PicoOpt & POPT_ALT_RENDERER) + return " 8bit fast"; + else if (currentConfig.EmuOpt & EOPT_16BPP) + return "16bit accurate"; + else + return " 8bit accurate"; +} + static const char *mgn_opt_scaling(menu_id id, int *offs) { *offs = -13; @@ -1476,6 +1493,7 @@ static const char *mgn_aopt_gamma(menu_id id, int *offs) static menu_entry e_menu_gfx_options[] = { + mee_cust ("Renderer", MA_OPT_RENDERER, mh_opt_render, mgn_opt_renderer), mee_range_cust("Scaling", MA_OPT_SCALING, currentConfig.scaling, 0, 3, mgn_opt_scaling), mee_range_cust("Gamma correction", MA_OPT2_GAMMA, currentConfig.gamma, 1, 300, mgn_aopt_gamma), mee_onoff ("A_SN's gamma curve", MA_OPT2_A_SN_GAMMA, currentConfig.EmuOpt, EOPT_A_SN_GAMMA), @@ -1494,20 +1512,6 @@ static int menu_loop_gfx_options(menu_id id, int keys) static menu_entry e_menu_options[]; -/* TODO: move to plat */ -static int mh_opt_render(menu_id id, int keys) -{ - if (keys & PBTN_LEFT) { - if (PicoOpt&0x10) PicoOpt&= ~0x10; - else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80; - } else { - if (PicoOpt&0x10) return 0; - else if (!(currentConfig.EmuOpt &0x80))PicoOpt|= 0x10; - else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80; - } - return 0; -} - static int sndrate_prevnext(int rate, int dir) { static const int rates[] = { 8000, 11025, 16000, 22050, 44100 }; @@ -1620,15 +1624,11 @@ static int mh_saveloadcfg(menu_id id, int keys) return 1; } -static const char *mgn_opt_renderer(menu_id id, int *offs) +static int mh_restore_defaults(menu_id id, int keys) { - *offs = -6; - if (PicoOpt & POPT_ALT_RENDERER) - return " 8bit fast"; - else if (currentConfig.EmuOpt & 0x80) - return "16bit accurate"; - else - return " 8bit accurate"; + emu_set_defconfig(); + me_update_msg("defaults restored"); + return 1; } static const char *mgn_opt_fskip(menu_id id, int *offs) @@ -1703,9 +1703,8 @@ 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_cust ("Renderer", MA_OPT_RENDERER, mh_opt_render, mgn_opt_renderer), - mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, 0x002), - mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, 0x004), + 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_cust ("Confirm savestate", MA_OPT_CONFIRM_STATES,mh_opt_misc, mgn_opt_c_saves), mee_range (cpu_clk_name, MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 900), @@ -1715,6 +1714,7 @@ static menu_entry e_menu_options[] = mee_handler_mkname_id(MA_OPT_SAVECFG, mh_saveloadcfg, mgn_savecfg), mee_handler_id("Save cfg for current game only", MA_OPT_SAVECFG_GAME, mh_saveloadcfg), mee_handler_mkname_id(MA_OPT_LOADCFG, mh_saveloadcfg, mgn_loadcfg), + mee_handler ("Restore defaults", mh_restore_defaults), mee_end, }; diff --git a/common/plat.h b/common/plat.h index e3705a8..ccdfa79 100644 --- a/common/plat.h +++ b/common/plat.h @@ -34,7 +34,7 @@ void plat_video_menu_enter(int is_rom_loaded); void plat_video_menu_begin(void); void plat_video_menu_end(void); -void plat_video_toggle_renderer(void); +void plat_video_toggle_renderer(int is_next, int is_menu); void plat_validate_config(void); void plat_update_volume(int has_changed, int is_up); diff --git a/gp2x/emu.c b/gp2x/emu.c index e7993ec..64b439c 100644 --- a/gp2x/emu.c +++ b/gp2x/emu.c @@ -341,15 +341,26 @@ static void vidResetMode(void) else gp2x_video_RGB_setscaling(0, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 240); } -void plat_video_toggle_renderer(void) +void plat_video_toggle_renderer(int is_next, int is_menu) { + /* alt, 16bpp, 8bpp */ if (PicoOpt & POPT_ALT_RENDERER) { PicoOpt &= ~POPT_ALT_RENDERER; - currentConfig.EmuOpt |= EOPT_16BPP; - } else if (!(currentConfig.EmuOpt & EOPT_16BPP)) - PicoOpt |= POPT_ALT_RENDERER; - else + if (is_next) + currentConfig.EmuOpt |= EOPT_16BPP; + } else if (!(currentConfig.EmuOpt & EOPT_16BPP)) { + if (is_next) + PicoOpt |= POPT_ALT_RENDERER; + else + currentConfig.EmuOpt |= EOPT_16BPP; + } else { currentConfig.EmuOpt &= ~EOPT_16BPP; + if (!is_next) + PicoOpt |= POPT_ALT_RENDERER; + } + + if (is_menu) + return; vidResetMode(); -- 2.39.2