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 // Win32 console redirection, because MS and their band of super geniuses decided
49 // that nobody would ever launch an app from the command line. :-P
50 // And, of course, this doesn't work, but causes weird problems. Yay Microsoft. :-/
53 FILE * ctt = fopen("CON", "w");
54 freopen("CON", "w", stdout);
55 freopen("CON", "w", stderr);
59 // Normally, this would be read in from the settings module... :-P
60 vjs.hardwareTypeAlpine = false;
61 // This is stuff we pass into the mainWindow...
62 // noUntunedTankPlease = false;
64 // Check for options that must be in place be constructing the App object
65 if (!ParseCommandLine(argc, argv))
75 Q_INIT_RESOURCE(virtualjaguar); // This must the same name as the exe filename
76 //or is it the .qrc filename???
77 // This is so we can pass this stuff using signal/slot mechanism...
78 //this is left here to remind me not to try doing this again :-P
79 //ick int id = qRegisterMetaType<uint32>();
81 int retVal = -1; // Default is failure
85 bool success = (bool)LogInit("./virtualjaguar.log"); // Init logfile
88 printf("Failed to open virtualjaguar.log for writing!\n");
92 if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0)
94 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
98 WriteLog("VJ: SDL (joystick, audio) successfully initialized.\n");
99 App app(argc, argv); // Declare an instance of the application
100 retVal = app.exec(); // And run it!
102 // Free SDL components last...!
103 SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO);
112 LogDone(); // Close logfile
117 // Main app constructor--we stick globally accessible stuff here... (?)
119 App::App(int argc, char * argv[]): QApplication(argc, argv)
121 bool loadAndGo = !filename.isEmpty();
123 mainWindow = new MainWin(loadAndGo);
124 mainWindow->plzDontKillMyComputer = noUntunedTankPlease;
125 ParseOptions(argc, argv); // Override defaults with command line (if any)
126 mainWindow->SyncUI();
129 mainWindow->LoadFile(filename);
136 // Here we parse out stuff that needs to be looked at *before* we construct the
139 bool ParseCommandLine(int argc, char * argv[])
141 for(int i=1; i<argc; i++)
143 if ((strcmp(argv[i], "--help") == 0) || (strcmp(argv[i], "-h") == 0)
144 || (strcmp(argv[i], "-?") == 0))
147 "Virtual Jaguar " VJ_RELEASE_VERSION " (" VJ_RELEASE_SUBVERSION ")\n"
148 "Based upon Virtual Jaguar core v1.0.0 by David Raingeard.\n"
149 "Written by James Hammons (Linux/WIN32), Niels Wagenaar (Linux/WIN32),\n"
150 "Carwin Jones (BeOS), and Adam Green (MacOS)\n"
151 "Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n"
154 " virtualjaguar [<filename>] [switches]\n"
156 " Option Description\n"
157 " ---------------- -----------------------------------\n"
158 " <filename> Name of file to autoload\n"
159 " --alpine -a Put Virtual Jaguar into Alpine mode\n"
160 " --pal -p PAL mode\n"
161 " --ntsc -n NTSC mode\n"
162 " --bios -b Boot using Jagaur BIOS\n"
163 " --no-bios Do not use Jaguar BIOS\n"
164 " --gpu -g Enable GPU\n"
165 " --no-gpu Disable GPU\n"
166 " --dsp -d Enable DSP\n"
167 " --no-dsp Disable DSP\n"
168 " --fullscreen -f Start in full screen mode\n"
169 " --blur -B Enable GL bilinear filter\n"
170 " --no-blur Disable GL bilinear filtering\n"
171 " --log -l Create and use log file\n"
172 " --no-log Do not use log file\n"
173 " --help -h Show this message\n"
175 "Invoking Virtual Jagaur with no filename will cause it to boot up\n"
181 if (strcmp(argv[i], "--yarrr") == 0)
184 printf("Shiver me timbers!\n");
189 if ((strcmp(argv[i], "--alpine") == 0) || (strcmp(argv[i], "-a") == 0))
191 printf("Alpine Mode enabled.\n");
192 vjs.hardwareTypeAlpine = true;
195 if ((strcmp(argv[i], "--please-dont-kill-my-computer") == 0) || (strcmp(argv[i], "-z") == 0))
197 noUntunedTankPlease = true;
200 if ((strcmp(argv[i], "--log") == 0) || (strcmp(argv[i], "-l") == 0))
205 if (strcmp(argv[i], "--no-log") == 0)
210 // Check for filename
211 if (argv[i][0] != '-')
223 // This is to override settings loaded from the config file.
224 // Note that settings set here will become the new defaults!
225 // (Not any more: Settings are only saved if the config dialog was OKed, or
226 // the toolbar buttons were pressed.)
228 void ParseOptions(int argc, char * argv[])
230 for(int i=1; i<argc; i++)
232 if ((strcmp(argv[i], "--pal") == 0) || (strcmp(argv[i], "-p") == 0))
234 vjs.hardwareTypeNTSC = false;
237 if ((strcmp(argv[i], "--ntsc") == 0) || (strcmp(argv[i], "-n") == 0))
239 vjs.hardwareTypeNTSC = true;
242 if ((strcmp(argv[i], "--bios") == 0) || (strcmp(argv[i], "-b") == 0))
244 vjs.useJaguarBIOS = true;
247 if (strcmp(argv[i], "--no-bios") == 0)
249 vjs.useJaguarBIOS = false;
252 if ((strcmp(argv[i], "--gpu") == 0) || (strcmp(argv[i], "-g") == 0))
254 vjs.GPUEnabled = true;
257 if (strcmp(argv[i], "--no-gpu") == 0)
259 vjs.GPUEnabled = false;
262 if ((strcmp(argv[i], "--dsp") == 0) || (strcmp(argv[i], "-d") == 0))
264 vjs.DSPEnabled = true;
265 vjs.audioEnabled = true;
268 if (strcmp(argv[i], "--no-dsp") == 0)
270 vjs.DSPEnabled = false;
271 vjs.audioEnabled = false;
274 if ((strcmp(argv[i], "--fullscreen") == 0) || (strcmp(argv[i], "-f") == 0))
276 vjs.fullscreen = true;
279 if ((strcmp(argv[i], "--blur") == 0) || (strcmp(argv[i], "-B") == 0))
284 if (strcmp(argv[i], "--no-blur") == 0)
293 int32 joyport; // Joystick port
294 bool hardwareTypeNTSC; // Set to false for PAL
298 bool usePipelinedDSP;
302 bool hardwareTypeAlpine;
306 bool allowWritesToROM;
308 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
310 uint32 p1KeyBindings[21];
311 uint32 p2KeyBindings[21];
315 char ROMPath[MAX_PATH];
316 char jagBootPath[MAX_PATH];
317 char CDBootPath[MAX_PATH];
318 char EEPROMPath[MAX_PATH];
319 char alpineROMPath[MAX_PATH];
320 char absROMPath[MAX_PATH];