[gens-sdl] Options: Added a '--region' option.
authorDavid Korth <gerbilsoft@gerbilsoft.com>
Sun, 3 Apr 2016 01:50:42 +0000 (21:50 -0400)
committerDavid Korth <gerbilsoft@gerbilsoft.com>
Sun, 3 Apr 2016 01:50:42 +0000 (21:50 -0400)
Currently does not support auto-detection.

EmuLoop.cpp: Use the region specified on the command line.

This allows gens-sdl to run ROMs in PAL.

src/gens-sdl/EmuLoop.cpp
src/gens-sdl/Options.cpp
src/gens-sdl/Options.hpp

index 069fa27..2a68135 100644 (file)
@@ -42,9 +42,11 @@ using GensSdl::VBackend;
 #include "libgens/Rom.hpp"
 #include "libgens/Util/MdFb.hpp"
 #include "libgens/Vdp/Vdp.hpp"
+#include "libgens/EmuContext/SysVersion.hpp"
 using LibGens::Rom;
 using LibGens::MdFb;
 using LibGens::Vdp;
+using LibGens::SysVersion;
 
 // Emulation Context.
 #include "libgens/EmuContext/EmuContext.hpp"
@@ -678,7 +680,7 @@ int EmuLoop::run(const Options *options)
        }
 
        // Create the emulation context.
-       d->emuContext = EmuContextFactory::createContext(d->rom);
+       d->emuContext = EmuContextFactory::createContext(d->rom, options->region());
        if (!d->emuContext || !d->emuContext->isRomOpened()) {
                // Error loading the ROM into EmuMD.
                // TODO: Error code?
@@ -704,8 +706,21 @@ int EmuLoop::run(const Options *options)
        checkForStartupMessages();
 
        // Set frame timing.
-       // TODO: Region code?
-       bool isPal = false;
+       // TODO: SysVersion convenience function to check if a RegionCode_t is PAL.
+       bool isPal;
+       switch (options->region()) {
+               case SysVersion::REGION_US_NTSC:
+               case SysVersion::REGION_JP_NTSC:
+               case SysVersion::REGION_AUTO:   // TODO: Auto-detect.
+               default:
+                       isPal = false;
+                       break;
+
+               case SysVersion::REGION_EU_PAL:
+               case SysVersion::REGION_ASIA_PAL:
+                       isPal = true;
+                       break;
+       }
        d->setFrameTiming(isPal ? 50 : 60);
 
        // Update the window title information.
index df1f924..1a8212a 100644 (file)
@@ -21,9 +21,9 @@
 
 #include "Options.hpp"
 
-// MdFb
-#include "libgens/Util/MdFb.hpp"
+// LibGens
 using LibGens::MdFb;
+using LibGens::SysVersion;
 
 // C includes. (C++ namespace)
 #include <cstring>
@@ -78,6 +78,7 @@ class OptionsPrivate
                // Emulation options.
                int sprite_limits;              // Enable sprite limits?
                int auto_fix_checksum;          // Auto fix checksum?
+               SysVersion::RegionCode_t region;        // Region code.
 
                // UI options.
                int fps_counter;                // Enable FPS counter?
@@ -115,6 +116,7 @@ void OptionsPrivate::reset(void)
        // Emulation options.
        sprite_limits = true;
        auto_fix_checksum = false;
+       region = SysVersion::REGION_US_NTSC;
 
        // UI options.
        fps_counter = true;
@@ -205,6 +207,7 @@ int Options::parse(int argc, const char *argv[])
        struct {
                const char *rom_filename;
                const char *tmss_rom_filename;
+               const char *region;
                int bpp;
        } tmp;
        memset(&tmp, 0, sizeof(tmp));
@@ -242,6 +245,8 @@ int Options::parse(int argc, const char *argv[])
                        "  Automatically fix checksums.", NULL},
                {"no-auto-fix-checksum", '\0', POPT_ARG_VAL, &d->auto_fix_checksum, 0,
                        "* Don't automatically fix checksums.", NULL},
+               {"region", '\0', POPT_ARG_STRING, &tmp.region, 0,
+                       "  Set the region code: J,U,E,Asia (default U)", "REGION"},
                POPT_TABLEEND
        };
 
@@ -374,6 +379,65 @@ int Options::parse(int argc, const char *argv[])
                d->tmss_rom_filename = string(tmp.tmss_rom_filename);
        }
 
+       // Region code.
+       if (tmp.region != nullptr) {
+               // Region code specified.
+               // TODO: Auto-detect; region code order.
+               if (!strcasecmp(tmp.region, "u") ||
+                   !strcasecmp(tmp.region, "usa"))
+               {
+                       d->region = SysVersion::REGION_US_NTSC;
+               }
+               else if (!strcasecmp(tmp.region, "j") ||
+                        !strcasecmp(tmp.region, "jp") ||
+                        !strcasecmp(tmp.region, "ja") ||
+                        !strcasecmp(tmp.region, "jpn") ||
+                        !strcasecmp(tmp.region, "jap") ||
+                        !strcasecmp(tmp.region, "japan") ||
+                        !strcasecmp(tmp.region, "japanese"))
+               {
+                       d->region = SysVersion::REGION_JP_NTSC;
+               }
+               else if (!strcasecmp(tmp.region, "e") ||
+                        !strcasecmp(tmp.region, "eu") ||
+                        !strcasecmp(tmp.region, "eur") ||
+                        !strcasecmp(tmp.region, "euro") ||
+                        !strcasecmp(tmp.region, "europe") ||
+                        !strcasecmp(tmp.region, "pal"))
+               {
+                       d->region = SysVersion::REGION_EU_PAL;
+               }
+               else if (!strcasecmp(tmp.region, "asia"))
+               {
+                       d->region = SysVersion::REGION_ASIA_PAL;
+               }
+               else
+               {
+                       // Invalid region code.
+                       fprintf(stderr, "%s: '--region=%s': invalid region code\n"
+                               "Valid options are J, U, E, Asia.\n"
+                               "Try `%s --help` for more information.\n",
+                               argv[0], tmp.region, argv[0]);
+                       poptFreeContext(optCon);
+                       return -EINVAL;
+               }
+       }
+
+       // Verify certain options.
+       d->bpp = MdFb::bppToColorDepth(tmp.bpp);
+       if (d->bpp < 0 || d->bpp >= MdFb::BPP_MAX) {
+               // Invalid color depth.
+               fprintf(stderr, "%s: '--bpp=%d': invalid color depth\n"
+                       "Valid options are 15, 16, and 32.\n"
+                       "Try `%s --help` for more information.\n",
+                       argv[0], tmp.bpp, argv[0]);
+               poptFreeContext(optCon);
+               return -EINVAL;
+       }
+
+       // Check the ROM filename last so we can verify that the other
+       // arguments are correct.
+
        // Get the ROM filename.
        // ROM filename is *not* required here.
        // If the frontend can't run without a ROM,
@@ -402,18 +466,6 @@ int Options::parse(int argc, const char *argv[])
                return -EINVAL;
        }
 
-       // Verify certain options.
-       d->bpp = MdFb::bppToColorDepth(tmp.bpp);
-       if (d->bpp < 0 || d->bpp >= MdFb::BPP_MAX) {
-               // Invalid color depth.
-               fprintf(stderr, "%s: '--bpp=%d': invalid color depth\n"
-                       "Valid options are 15, 16, and 32.\n"
-                       "Try `%s --help` for more information.\n",
-                       argv[0], tmp.bpp, argv[0]);
-               poptFreeContext(optCon);
-               return -EINVAL;
-       }
-
        // Done parsing arguments.
        poptFreeContext(optCon);
        return 0;
@@ -474,6 +526,7 @@ ACCESSOR_BOOL(stereo)
 /** Emulation options. **/
 ACCESSOR_BOOL(sprite_limits)
 ACCESSOR_BOOL(auto_fix_checksum)
+ACCESSOR(SysVersion::RegionCode_t, region);
 
 /** UI options. **/
 ACCESSOR_BOOL(fps_counter)
index f259814..935d183 100644 (file)
@@ -22,8 +22,9 @@
 #ifndef __GENS_SDL_OPTIONS_HPP__
 #define __GENS_SDL_OPTIONS_HPP__
 
-// MdFb
+// LibGens
 #include "libgens/Util/MdFb.hpp"
+#include "libgens/EmuContext/SysVersion.hpp"
 
 // C++ includes.
 #include <string>
@@ -123,6 +124,12 @@ class Options
                 */
                bool auto_fix_checksum(void) const;
 
+               /**
+                * Region code.
+                * @return Region code.
+                */
+               LibGens::SysVersion::RegionCode_t region(void) const;
+
                /** UI options. **/
 
                /**