2 // app.cpp - Qt-based GUI for Virtual Jaguar
5 // (C) 2010 Underground Software
7 // JLH = James Hammons <jlhamm@acm.org>
10 // --- ---------- -------------------------------------------------------------
11 // JLH 12/23/2009 Created this file
12 // JLH 01/21/2011 Added SDL initialization
13 // JLH 06/26/2011 Added fix to keep SDL from hijacking main() on win32
14 // JLH 05/24/2012 Added option switches
20 #include <QApplication>
28 // Apparently on win32, SDL is hijacking main from Qt. So let's do this:
33 // Function prototypes...
34 static bool ParseCommandLine(int argc, char * argv[]);
35 static void ParseOptions(int argc, char * argv[]);
39 // This is stuff we pass into the mainWindow...
40 bool noUntunedTankPlease = false;
41 bool loadAndGo = false;
42 bool useLogfile = true;
45 // Here's the main application loop--short and simple...
46 int main(int argc, char * argv[])
48 // Normally, this would be read in from the settings module... :-P
49 vjs.hardwareTypeAlpine = false;
50 // This is stuff we pass into the mainWindow...
51 // noUntunedTankPlease = false;
53 // Check for options that must be in place be constructing the App object
54 if (!ParseCommandLine(argc, argv))
57 Q_INIT_RESOURCE(virtualjaguar); // This must the same name as the exe filename
58 //or is it the .qrc filename???
59 // This is so we can pass this stuff using signal/slot mechanism...
60 //this is left here to remind me not to try doing this again :-P
61 //ick int id = qRegisterMetaType<uint32>();
63 int retVal = -1; // Default is failure
67 bool success = (bool)LogInit("./virtualjaguar.log"); // Init logfile
70 printf("Failed to open virtualjaguar.log for writing!\n");
74 if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0)
76 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
80 WriteLog("VJ: SDL (joystick, audio) successfully initialized.\n");
81 App app(argc, argv); // Declare an instance of the application
82 retVal = app.exec(); // And run it!
84 // Free SDL components last...!
85 SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO);
89 LogDone(); // Close logfile
94 // Main app constructor--we stick globally accessible stuff here... (?)
96 App::App(int argc, char * argv[]): QApplication(argc, argv)
98 bool loadAndGo = !filename.isEmpty();
100 mainWindow = new MainWin(loadAndGo);
101 mainWindow->plzDontKillMyComputer = noUntunedTankPlease;
102 ParseOptions(argc, argv); // Override defaults with command line (if any)
103 mainWindow->SyncUI();
106 mainWindow->LoadFile(filename);
113 // Here we parse out stuff that needs to be looked at *before* we construct the
116 bool ParseCommandLine(int argc, char * argv[])
118 for(int i=1; i<argc; i++)
120 if ((strcmp(argv[i], "--help") == 0) || (strcmp(argv[i], "-h") == 0)
121 || (strcmp(argv[i], "-?") == 0))
124 "Virtual Jaguar " VJ_RELEASE_VERSION " (" VJ_RELEASE_SUBVERSION ")\n"
125 "Based upon Virtual Jaguar core v1.0.0 by David Raingeard.\n"
126 "Written by Niels Wagenaar (Linux/WIN32), Carwin Jones (BeOS),\n"
127 "James Hammons (Linux/WIN32) and Adam Green (MacOS)\n"
128 "Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n"
131 " virtualjaguar [<filename>] [switches]\n"
133 " Option Description\n"
134 " ---------------- -----------------------------------\n"
135 " <filename> Name of file to autoload\n"
136 " --alpine -a Put Virtual Jaguar into Alpine mode\n"
137 " --pal -p PAL mode\n"
138 " --ntsc -n NTSC mode\n"
139 " --bios -b Boot using Jagaur BIOS\n"
140 " --no-bios Do not use Jaguar BIOS\n"
141 " --gpu -g Enable GPU\n"
142 " --no-gpu Disable GPU\n"
143 " --dsp -d Enable DSP\n"
144 " --no-dsp Disable DSP\n"
145 " --fullscreen -f Start in full screen mode\n"
146 " --blur -B Enable GL bilinear filter\n"
147 " --no-blur Disable GL bilinear filtering\n"
148 " --log -l Create and use log file\n"
149 " --no-log Do not use log file\n"
150 " --help -h Show this message\n"
152 "Invoking Virtual Jagaur with no filename will cause it to boot up\n"
158 if (strcmp(argv[i], "--yarrr") == 0)
161 printf("Shiver me timbers!\n");
166 if ((strcmp(argv[i], "--alpine") == 0) || (strcmp(argv[i], "-a") == 0))
168 printf("Alpine Mode enabled.\n");
169 vjs.hardwareTypeAlpine = true;
172 if (strcmp(argv[i], "--please-dont-kill-my-computer") == 0)
174 noUntunedTankPlease = true;
177 if ((strcmp(argv[i], "--log") == 0) || (strcmp(argv[i], "-l") == 0))
182 if (strcmp(argv[i], "--no-log") == 0)
187 // Check for filename
188 if (argv[i][0] != '-')
200 // This is to override settings loaded from the config file.
201 // Note that settings set here will become the new defaults!
203 void ParseOptions(int argc, char * argv[])
205 for(int i=1; i<argc; i++)
207 if ((strcmp(argv[i], "--pal") == 0) || (strcmp(argv[i], "-p") == 0))
209 vjs.hardwareTypeNTSC = false;
212 if ((strcmp(argv[i], "--ntsc") == 0) || (strcmp(argv[i], "-n") == 0))
214 vjs.hardwareTypeNTSC = true;
217 if ((strcmp(argv[i], "--bios") == 0) || (strcmp(argv[i], "-b") == 0))
219 vjs.useJaguarBIOS = true;
222 if (strcmp(argv[i], "--no-bios") == 0)
224 vjs.useJaguarBIOS = false;
227 if ((strcmp(argv[i], "--gpu") == 0) || (strcmp(argv[i], "-g") == 0))
229 vjs.GPUEnabled = true;
232 if (strcmp(argv[i], "--no-gpu") == 0)
234 vjs.GPUEnabled = false;
237 if ((strcmp(argv[i], "--dsp") == 0) || (strcmp(argv[i], "-d") == 0))
239 vjs.DSPEnabled = true;
240 vjs.audioEnabled = true;
243 if (strcmp(argv[i], "--no-dsp") == 0)
245 vjs.DSPEnabled = false;
246 vjs.audioEnabled = false;
249 if ((strcmp(argv[i], "--fullscreen") == 0) || (strcmp(argv[i], "-f") == 0))
251 vjs.fullscreen = true;
254 if ((strcmp(argv[i], "--blur") == 0) || (strcmp(argv[i], "-B") == 0))
259 if (strcmp(argv[i], "--no-blur") == 0)
268 int32 joyport; // Joystick port
269 bool hardwareTypeNTSC; // Set to false for PAL
273 bool usePipelinedDSP;
277 bool hardwareTypeAlpine;
281 bool allowWritesToROM;
283 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
285 uint32 p1KeyBindings[21];
286 uint32 p2KeyBindings[21];
290 char ROMPath[MAX_PATH];
291 char jagBootPath[MAX_PATH];
292 char CDBootPath[MAX_PATH];
293 char EEPROMPath[MAX_PATH];
294 char alpineROMPath[MAX_PATH];
295 char absROMPath[MAX_PATH];