From: notaz Date: Mon, 7 Feb 2011 23:21:46 +0000 (+0200) Subject: frontend: support ingame actions (state load and such) X-Git-Tag: r6~5 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f8926485e641efb187ff9ae11cef9d23d1e8982;p=pcsx_rearmed.git frontend: support ingame actions (state load and such) --- diff --git a/frontend/main.c b/frontend/main.c index 3344819c..64a16d37 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -29,6 +29,13 @@ int ready_to_go; unsigned long gpuDisp; char cfgfile_basename[MAXPATHLEN]; static char *(*real_getenv)(const char *name); +int state_slot; +enum sched_action emu_action, emu_action_old; +char hud_msg[64]; +int hud_new_msg; + +// from softgpu plugin +extern int UseFrameSkip; static void make_path(char *buf, size_t size, const char *dir, const char *fname) { @@ -98,6 +105,51 @@ static void set_default_paths(void) snprintf(Config.PatchesDir, sizeof(Config.PatchesDir), "." PATCHES_DIR); } +void do_emu_action(void) +{ + int ret; + + emu_action_old = emu_action; + + switch (emu_action) { + case SACTION_NONE: + return; + case SACTION_ENTER_MENU: + menu_loop(); + return; + case SACTION_LOAD_STATE: + ret = emu_load_state(state_slot); + snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "LOADED" : "FAIL!"); + break; + case SACTION_SAVE_STATE: + ret = emu_save_state(state_slot); + snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "SAVED" : "FAIL!"); + break; + case SACTION_NEXT_SSLOT: + state_slot++; + if (state_slot > 9) + state_slot = 0; + goto do_state_slot; + case SACTION_PREV_SSLOT: + state_slot--; + if (state_slot < 0) + state_slot = 9; + goto do_state_slot; + case SACTION_TOGGLE_FSKIP: + UseFrameSkip ^= 1; + snprintf(hud_msg, sizeof(hud_msg), "FRAMESKIP %s", + UseFrameSkip ? "ON" : "OFF"); + break; + } + hud_new_msg = 3; + return; + +do_state_slot: + snprintf(hud_msg, sizeof(hud_msg), "STATE SLOT %d [%s]", state_slot, + emu_check_state(state_slot) == 0 ? "USED" : "FREE"); + hud_new_msg = 3; +} + int main(int argc, char *argv[]) { void *tmp; @@ -238,11 +290,8 @@ int main(int argc, char *argv[]) // If a state has been specified, then load that if (loadst) { - char state_filename[MAXPATHLEN]; - int ret = get_state_filename(state_filename, sizeof(state_filename), loadst - 1); - if (ret == 0) - ret = LoadState(state_filename); - printf("%s state %s\n", ret ? "failed to load" : "loaded", state_filename); + int ret = emu_load_state(loadst - 1); + printf("%s state %d\n", ret ? "failed to load" : "loaded", loadst); } if (ready_to_go) @@ -255,8 +304,11 @@ int main(int argc, char *argv[]) while (1) { stop = 0; + emu_action = SACTION_NONE; + psxCpu->Execute(); - menu_loop(); + if (emu_action != SACTION_NONE) + do_emu_action(); } return 0; @@ -345,6 +397,42 @@ int get_state_filename(char *buf, int size, int i) { return 0; } +int emu_check_state(int slot) +{ + char fname[MAXPATHLEN]; + int ret; + + ret = get_state_filename(fname, sizeof(fname), slot); + if (ret != 0) + return ret; + + return CheckState(fname); +} + +int emu_save_state(int slot) +{ + char fname[MAXPATHLEN]; + int ret; + + ret = get_state_filename(fname, sizeof(fname), slot); + if (ret != 0) + return ret; + + return SaveState(fname); +} + +int emu_load_state(int slot) +{ + char fname[MAXPATHLEN]; + int ret; + + ret = get_state_filename(fname, sizeof(fname), slot); + if (ret != 0) + return ret; + + return LoadState(fname); +} + void SysPrintf(const char *fmt, ...) { va_list list; char msg[512]; diff --git a/frontend/main.h b/frontend/main.h index 0ebb0fc2..b64bc4cd 100644 --- a/frontend/main.h +++ b/frontend/main.h @@ -34,10 +34,40 @@ extern char cfgfile_basename[MAXPATHLEN]; +extern int state_slot; int get_state_filename(char *buf, int size, int i); +int emu_check_state(int slot); +int emu_save_state(int slot); +int emu_load_state(int slot); + void set_cd_image(const char *fname); extern unsigned long gpuDisp; extern int ready_to_go; +extern char hud_msg[64]; +extern int hud_new_msg; + +enum sched_action { + SACTION_NONE, + SACTION_ENTER_MENU, + SACTION_LOAD_STATE, + SACTION_SAVE_STATE, + SACTION_NEXT_SSLOT, + SACTION_PREV_SSLOT, + SACTION_TOGGLE_FSKIP, +}; + +static inline void emu_set_action(enum sched_action action_) +{ + extern enum sched_action emu_action, emu_action_old; + extern int stop; + + if (action_ == SACTION_NONE) + emu_action_old = 0; + else if (action_ != emu_action_old) + stop = 1; + emu_action = action_; +} + #endif /* __LINUX_H__ */ diff --git a/frontend/menu.c b/frontend/menu.c index e7d20ffe..d5c7d91a 100644 --- a/frontend/menu.c +++ b/frontend/menu.c @@ -60,7 +60,7 @@ enum { }; static int last_psx_w, last_psx_h, last_psx_bpp; -static int scaling, filter, state_slot, cpu_clock, cpu_clock_st; +static int scaling, filter, cpu_clock, cpu_clock_st; static char rom_fname_reload[MAXPATHLEN]; static char last_selected_fname[MAXPATHLEN]; static int region, in_type_sel; @@ -103,28 +103,16 @@ void emu_make_path(char *buff, const char *end, int size) static int emu_check_save_file(int slot) { - char fname[MAXPATHLEN]; - int ret; - - ret = get_state_filename(fname, sizeof(fname), slot); - if (ret != 0) - return 0; - - ret = CheckState(fname); + int ret = emu_check_state(slot); return ret == 0 ? 1 : 0; } -static int emu_save_load_game(int load, int sram) +static int emu_save_load_game(int load, int unused) { - char fname[MAXPATHLEN]; int ret; - ret = get_state_filename(fname, sizeof(fname), state_slot); - if (ret != 0) - return 0; - if (load) { - ret = LoadState(fname); + ret = emu_load_state(state_slot); // reflect hle/bios mode from savestate if (Config.HLE) @@ -134,7 +122,7 @@ static int emu_save_load_game(int load, int sram) bios_sel = 1; } else - ret = SaveState(fname); + ret = emu_save_state(state_slot); return ret; } @@ -663,13 +651,12 @@ me_bind_action me_ctrl_actions[] = me_bind_action emuctrl_actions[] = { -/* - { "Load State ", PEV_STATE_LOAD }, - { "Save State ", PEV_STATE_SAVE }, - { "Prev Save Slot ", PEV_SSLOT_PREV }, - { "Next Save Slot ", PEV_SSLOT_NEXT }, -*/ - { "Enter Menu ", PEV_MENU }, + { "Save State ", 1 << SACTION_SAVE_STATE }, + { "Load State ", 1 << SACTION_LOAD_STATE }, + { "Prev Save Slot ", 1 << SACTION_PREV_SSLOT }, + { "Next Save Slot ", 1 << SACTION_NEXT_SSLOT }, + { "Toggle Frameskip ", 1 << SACTION_TOGGLE_FSKIP }, + { "Enter Menu ", 1 << SACTION_ENTER_MENU }, { NULL, 0 } }; @@ -835,7 +822,7 @@ static void keys_load_all(const char *cfg) bind = parse_bind_val(act, &bindtype); if (bind != -1 && bind != 0) { - printf("bind #%d '%s' %08x (%s)\n", dev_id, key, bind, act); + //printf("bind #%d '%s' %08x (%s)\n", dev_id, key, bind, act); in_config_bind_key(dev_id, key, bind, bindtype); } else @@ -1095,7 +1082,7 @@ static int menu_loop_plugin_options(int id, int keys) // ------------ adv options menu ------------ -static const char h_cfg_cpul[] = "Shows CPU usage in %%"; +static const char h_cfg_cpul[] = "Shows CPU usage in %"; static const char h_cfg_fl[] = "Frame Limiter keeps the game from running too fast"; static const char h_cfg_xa[] = "Disables XA sound, which can sometimes improve performance"; static const char h_cfg_cdda[] = "Disable CD Audio for a performance boost\n" diff --git a/frontend/pandora.c b/frontend/pandora.c index cd50728e..677784e6 100644 --- a/frontend/pandora.c +++ b/frontend/pandora.c @@ -17,6 +17,7 @@ #include "common/input.h" #include "plugin_lib.h" +#include "main.h" static int fdnub[2]; static int analog_init_done; @@ -43,7 +44,6 @@ struct in_default_bind in_evdev_defbinds[] = { { KEY_DOWN, IN_BINDTYPE_PLAYER12, DKEY_DOWN }, { KEY_LEFT, IN_BINDTYPE_PLAYER12, DKEY_LEFT }, { KEY_RIGHT, IN_BINDTYPE_PLAYER12, DKEY_RIGHT }, - { KEY_SPACE, IN_BINDTYPE_EMU, PEVB_MENU }, { KEY_PAGEUP, IN_BINDTYPE_PLAYER12, DKEY_TRIANGLE }, { KEY_PAGEDOWN, IN_BINDTYPE_PLAYER12, DKEY_CROSS }, { KEY_END, IN_BINDTYPE_PLAYER12, DKEY_CIRCLE }, @@ -54,6 +54,12 @@ struct in_default_bind in_evdev_defbinds[] = { { KEY_RIGHTCTRL, IN_BINDTYPE_PLAYER12, DKEY_R1 }, { KEY_Q, IN_BINDTYPE_PLAYER12, DKEY_L2 }, { KEY_P, IN_BINDTYPE_PLAYER12, DKEY_R2 }, + { KEY_SPACE, IN_BINDTYPE_EMU, SACTION_ENTER_MENU }, + { KEY_1, IN_BINDTYPE_EMU, SACTION_SAVE_STATE }, + { KEY_2, IN_BINDTYPE_EMU, SACTION_LOAD_STATE }, + { KEY_3, IN_BINDTYPE_EMU, SACTION_PREV_SSLOT }, + { KEY_4, IN_BINDTYPE_EMU, SACTION_NEXT_SSLOT }, + { KEY_5, IN_BINDTYPE_EMU, SACTION_TOGGLE_FSKIP }, { 0, 0, 0 } }; diff --git a/frontend/plugin_lib.c b/frontend/plugin_lib.c index a2fb4951..975fc0a5 100644 --- a/frontend/plugin_lib.c +++ b/frontend/plugin_lib.c @@ -1,5 +1,5 @@ /* - * (C) notaz, 2010 + * (C) notaz, 2010-2011 * * This work is licensed under the terms of the GNU GPLv2 or later. * See the COPYING file in the top-level directory. @@ -23,6 +23,7 @@ #include "common/input.h" #include "omap.h" #include "menu.h" +#include "main.h" #include "pcnt.h" #include "../libpcsxcore/new_dynarec/new_dynarec.h" #include "../libpcsxcore/psemu_plugin_defs.h" @@ -58,6 +59,12 @@ static int get_cpu_ticks(void) return ret; } +static void print_hud(void) +{ + if (pl_fbdev_bpp == 16) + pl_text_out16(2, pl_fbdev_h - 10, "%s", hud_msg); +} + static void print_fps(void) { if (pl_fbdev_bpp == 16) @@ -98,8 +105,11 @@ void *pl_fbdev_flip(void) flip_cnt++; if (pl_fbdev_buf != NULL) { - if (g_opts & OPT_SHOWFPS) + if (hud_msg[0] != 0) + print_hud(); + else if (g_opts & OPT_SHOWFPS) print_fps(); + if (g_opts & OPT_SHOWCPU) print_cpu_usage(); } @@ -124,12 +134,20 @@ void pl_fbdev_close(void) static void update_input(void) { int actions[IN_BINDTYPE_COUNT] = { 0, }; + unsigned int emu_act; in_update(actions); if (in_type == PSE_PAD_TYPE_ANALOGPAD) in_update_analogs(); - if (actions[IN_BINDTYPE_EMU] & PEV_MENU) - stop = 1; + emu_act = actions[IN_BINDTYPE_EMU]; + if (emu_act) { + int which = 0; + for (; !(emu_act & 1); emu_act >>= 1, which++) + ; + emu_act = which; + } + emu_set_action(emu_act); + in_keystate = actions[IN_BINDTYPE_PLAYER12]; #ifdef X11 @@ -179,6 +197,12 @@ void pl_frame_limit(void) tv_old = now; if (g_opts & OPT_SHOWCPU) tick_per_sec = get_cpu_ticks(); + + if (hud_new_msg > 0) { + hud_new_msg--; + if (hud_new_msg == 0) + hud_msg[0] = 0; + } } #ifdef PCNT static int ya_vsync_count; diff --git a/maemo/hildon.c b/maemo/hildon.c index df42a90a..37e67aff 100644 --- a/maemo/hildon.c +++ b/maemo/hildon.c @@ -5,6 +5,7 @@ #include #include #include "plugin_lib.h" +#include "main.h" #include "../libpcsxcore/psemu_plugin_defs.h" #define X_RES 800 @@ -80,10 +81,12 @@ window_key_proxy(GtkWidget *widget, psxkey2 = DKEY_RIGHT; break; case 19: - //SaveState(cfile); + if (event->type == GDK_KEY_PRESS) + emu_set_action(SACTION_SAVE_STATE); return; case 20: - //LoadState(cfile); + if (event->type == GDK_KEY_PRESS) + emu_set_action(SACTION_LOAD_STATE); return; } @@ -98,6 +101,8 @@ window_key_proxy(GtkWidget *widget, in_keystate &= ~(1 << psxkey1); if (psxkey2 >= 0) in_keystate &= ~(1 << psxkey2); + + emu_set_action(SACTION_NONE); } } @@ -148,6 +153,10 @@ void maemo_init(int *argc, char ***argv) gtk_widget_show_all (GTK_WIDGET (window)); } +void menu_loop(void) +{ +} + void *pl_fbdev_set_mode(int w, int h, int bpp) { if (w <= 0 || h <= 0) diff --git a/maemo/main.c b/maemo/main.c index 80919ace..f797c122 100644 --- a/maemo/main.c +++ b/maemo/main.c @@ -173,11 +173,8 @@ int maemo_main(int argc, char **argv) // If a state has been specified, then load that if (loadst) { - char state_filename[MAXPATHLEN]; - int ret = get_state_filename(state_filename, sizeof(state_filename), loadst - 1); - if (ret == 0) - ret = LoadState(state_filename); - printf("%s state %s\n", ret ? "failed to load" : "loaded", state_filename); + int ret = emu_load_state(loadst - 1); + printf("%s state %d\n", ret ? "failed to load" : "loaded", loadst); } if (ready_to_go)