frontend: support ingame actions (state load and such)
authornotaz <notasas@gmail.com>
Mon, 7 Feb 2011 23:21:46 +0000 (01:21 +0200)
committernotaz <notasas@gmail.com>
Thu, 10 Feb 2011 00:07:54 +0000 (02:07 +0200)
frontend/main.c
frontend/main.h
frontend/menu.c
frontend/pandora.c
frontend/plugin_lib.c
maemo/hildon.c
maemo/main.c

index 3344819..64a16d3 100644 (file)
@@ -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];
index 0ebb0fc..b64bc4c 100644 (file)
 
 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__ */
index e7d20ff..d5c7d91 100644 (file)
@@ -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"
index cd50728..677784e 100644 (file)
@@ -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 }
 };
 
index a2fb495..975fc0a 100644 (file)
@@ -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;
index df42a90..37e67af 100644 (file)
@@ -5,6 +5,7 @@
 #include <unistd.h>
 #include <hildon/hildon.h>
 #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)
index 80919ac..f797c12 100644 (file)
@@ -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)