adding actual player 2 support
[drnoksnes] / platform / config.cpp
index 151feee..869dc7d 100644 (file)
@@ -7,7 +7,10 @@
 #include "port.h"
 #include "snes9x.h"
 #include "display.h"
-#include "hgw.h"
+
+#if CONF_GUI
+#include "osso.h"
+#endif
 
 #define DIE(format, ...) do { \
                fprintf(stderr, "Died at %s:%d: ", __FILE__, __LINE__ ); \
@@ -35,8 +38,8 @@ static struct poptOption commonOptionsTable[] = {
        "start in fullscreen mode", 0 },
        { "transparency", 'y', POPT_ARG_NONE, 0, 5,
        "enable transparency effects (slower)", 0 },
-       { "hacks", 'h', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, 6,
-       "enable hacks (yes, speed-only, no)", "option" },
+       { "scaler", 'S', POPT_ARG_STRING, 0, 6,
+       "select scaler to use", 0 },
        { "pal", 'p', POPT_ARG_NONE, 0, 7,
        "run in PAL mode", 0 },
        { "ntsc", 'n', POPT_ARG_NONE, 0, 8,
@@ -57,6 +60,14 @@ static struct poptOption commonOptionsTable[] = {
        "audio output buffer size", "SAMPLES" },
        { "touchscreen", 'd', POPT_ARG_NONE, 0, 16,
        "enable touchscreen controls", 0 },
+       { "touchscreen-grid", 'D', POPT_ARG_NONE, 0, 17,
+       "enable touchscreen controls and show grid", 0 },
+       { "hacks", 'h', POPT_ARG_NONE, 0, 18,
+       "enable safe subset of speedhacks", 0 },
+       { "all-hacks", 'H', POPT_ARG_NONE, 0, 19,
+       "enable all speedhacks (may break sound)", 0 },
+       { "saver", 'R', POPT_ARG_NONE, 0, 20,
+       "save&exit when the emulator window is unfocused", 0 },
        POPT_TABLEEND
 };
 
@@ -65,7 +76,9 @@ static struct poptOption configOptionsTable[] = {
        "scancode to map", "CODE" },
        { "button", '\0', POPT_ARG_STRING, 0, 101,
        "SNES Button to press (A, B, X, Y, L, R, Up, Down, Left, Right)", "name" },
-       { "action", '\0', POPT_ARG_STRING, 0, 102,
+       { "button2", '\0', POPT_ARG_STRING, 0, 102,
+       "SNES Button to press for joypad 2", "name" },
+       { "action", '\0', POPT_ARG_STRING, 0, 110,
        "emulator action to do (fullscreen, quit, ...)", "action" },
        { "hacks-file", '\0', POPT_ARG_STRING, 0, 200,
        "path to snesadvance.dat file", "FILE" },
@@ -116,6 +129,14 @@ static unsigned char actionNameToBit(const char *s) {
                return kActionQuit;
        } else if (strcasecmp(s, "fullscreen") == 0) {
                return kActionToggleFullscreen;
+       } else if (strcasecmp(s, "quickload1") == 0) {
+               return kActionQuickLoad1;
+       } else if (strcasecmp(s, "quicksave1") == 0) {
+               return kActionQuickSave1;
+       } else if (strcasecmp(s, "quickload2") == 0) {
+               return kActionQuickLoad2;
+       } else if (strcasecmp(s, "quicksave2") == 0) {
+               return kActionQuickSave2;
        } else {
                DIE("Bad action name: %s\n", s);
        }
@@ -123,7 +144,7 @@ static unsigned char actionNameToBit(const char *s) {
 
 const char * S9xGetFilename(FileTypes file)
 {
-       static char filename [PATH_MAX + 1];
+       static char filename[PATH_MAX + 1];
        const char * ext;
        switch (file) {
                case FILE_ROM:
@@ -155,6 +176,13 @@ const char * S9xGetFilename(FileTypes file)
        return filename;
 }
 
+const char * S9xGetQuickSaveFilename(unsigned int slot)
+{
+       static char filename[PATH_MAX + 1];
+       snprintf(filename, PATH_MAX, "%s.frz.%u.gz", basePath, slot);
+       return filename;
+}
+
 static void loadDefaults()
 {
        ZeroMemory(&Settings, sizeof(Settings));
@@ -164,11 +192,15 @@ static void loadDefaults()
        basePath = 0;
 
        Config.quitting = false;
+       Config.saver = false;
        Config.enableAudio = true;
        Config.fullscreen = false;
-       Config.xsp = false;
+       Config.scaler = 0;
        Config.hacksFile = 0;
+       Config.joypad1Enabled = false;
+       Config.joypad2Enabled = false;
        Config.touchscreenInput = false;
+       Config.touchscreenShow = false;
 
        Settings.JoystickEnabled = FALSE;
        Settings.SoundPlaybackRate = 22050;
@@ -244,31 +276,6 @@ static bool gotRomFile()
        return romFile ? true : false;
 }
 
-static void setHacks(const char * value)
-{
-       // Unconditionally enable hacks even if no argument passed
-       Settings.HacksEnabled = TRUE;
-
-       if (!value) return;
-
-       if (strcasecmp(value, "speed-only") == 0 ||
-               strcasecmp(value, "speed") == 0 ||
-               strcasecmp(value, "s") == 0) {
-                       Settings.HacksFilter = TRUE;
-       } else if (strcasecmp(value, "yes") == 0 ||
-               strcasecmp(value, "y") == 0) {
-                       // Do nothing
-       } else if (strcasecmp(value, "no") == 0 ||
-               strcasecmp(value, "n") == 0) {
-                       Settings.HacksEnabled = FALSE;
-       } else {
-               // Hack: the user probably wants to enable hacks
-               // and use this argument as the ROM file.
-               // Wonder why popt does not support this or if there's a better way.
-               S9xSetRomFile(value);
-       }
-}
-
 static void loadConfig(poptContext optCon, const char * file)
 {
        char * out;
@@ -320,8 +327,8 @@ static void parseArgs(poptContext optCon)
                                Settings.Transparency = TRUE;
                                break;
                        case 6:
-                               Settings.HacksEnabled = TRUE;
-                               setHacks(poptGetOptArg(optCon));
+                               free(Config.scaler);
+                               Config.scaler = strdup(poptGetOptArg(optCon));
                                break;
                        case 7:
                                Settings.ForcePAL = TRUE;
@@ -363,14 +370,35 @@ static void parseArgs(poptContext optCon)
                        case 16:
                                Config.touchscreenInput = true;
                                break;
+                       case 17:
+                               Config.touchscreenInput = true;
+                               Config.touchscreenShow = true;
+                               break;
+                       case 18:
+                               Settings.HacksEnabled = TRUE;
+                               Settings.HacksFilter = TRUE;
+                               break;
+                       case 19:
+                               Settings.HacksEnabled = TRUE;
+                               Settings.HacksFilter = FALSE;
+                               break;
+                       case 20:
+                               Config.saver = true;
+                               break;
                        case 100:
                                scancode = atoi(poptGetOptArg(optCon));
                                break;
                        case 101:
-                               Config.joypad1Mapping[scancode] |= 
+                               Config.joypad1Mapping[scancode] |=
                                        buttonNameToBit(poptGetOptArg(optCon));
+                               Config.joypad1Enabled = true;
                                break;
                        case 102:
+                               Config.joypad2Mapping[scancode] |=
+                                       buttonNameToBit(poptGetOptArg(optCon));
+                               Config.joypad2Enabled = true;
+                               break;
+                       case 110:
                                Config.action[scancode] |= 
                                        actionNameToBit(poptGetOptArg(optCon));
                                break;
@@ -398,30 +426,34 @@ static void parseArgs(poptContext optCon)
                S9xSetRomFile(extra_arg);
 }
 
-void S9xLoadConfig(int argc, const char ** argv)
+void S9xLoadConfig(int argc, char ** argv)
 {
-       poptContext optCon =
-               poptGetContext("drnoksnes", argc, argv, optionsTable, 0);
+       poptContext optCon = poptGetContext("drnoksnes",
+               argc, const_cast<const char **>(argv), optionsTable, 0);
        poptSetOtherOptionHelp(optCon, "<rom>");
 
        // Builtin defaults
        loadDefaults();
 
-       // Read config file ~/apps/DrNokSnes.txt
+       // Read config file ~/.config/drnoksnes.conf
        char defConfFile[PATH_MAX];
-       sprintf(defConfFile, "%s/%s", getenv("HOME"), "apps/DrNokSnes.txt");
+       sprintf(defConfFile, "%s/%s", getenv("HOME"), ".config/drnoksnes.conf");
        loadConfig(optCon, defConfFile);
 
        // Command line parameters (including --conf args)
        parseArgs(optCon);
 
-       if (!gotRomFile() && !hgwLaunched) {
-               // User did not specify a ROM file, 
-               // and we're not being launched from D-Bus.
-               fprintf(stderr, "You need to specify a ROM, like this:\n");
-               poptPrintUsage(optCon, stdout, 0);
-               poptFreeContext(optCon); 
-               exit(2);
+#if CONF_GUI
+       if (!OssoOk())
+#endif
+       {
+               if (!gotRomFile()) {
+                       // User did not specify a ROM file in the command line
+                       fprintf(stderr, "You need to specify a ROM, like this:\n");
+                       poptPrintUsage(optCon, stdout, 0);
+                       poptFreeContext(optCon);
+                       exit(2);
+               }
        }
 
        poptFreeContext(optCon);