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>
29 // Apparently on win32, SDL is hijacking main from Qt. So let's do this:
34 // Function prototypes...
35 static bool ParseCommandLine(int argc, char * argv[]);
36 static void ParseOptions(int argc, char * argv[]);
40 // This is stuff we pass into the mainWindow...
41 bool noUntunedTankPlease = false;
42 bool loadAndGo = false;
43 bool useLogfile = true;
46 // Here's the main application loop--short and simple...
47 int main(int argc, char * argv[])
49 // Win32 console redirection, because MS and their band of super geniuses decided
50 // that nobody would ever launch an app from the command line. :-P
51 // And, of course, this doesn't work, but causes weird problems. Yay Microsoft. :-/
54 FILE * ctt = fopen("CON", "w");
55 freopen("CON", "w", stdout);
56 freopen("CON", "w", stderr);
60 // Normally, this would be read in from the settings module... :-P
61 vjs.hardwareTypeAlpine = false;
62 // This is stuff we pass into the mainWindow...
63 // noUntunedTankPlease = false;
65 // Check for options that must be in place be constructing the App object
66 if (!ParseCommandLine(argc, argv))
76 Q_INIT_RESOURCE(virtualjaguar); // This must the same name as the exe filename
77 //or is it the .qrc filename???
78 // This is so we can pass this stuff using signal/slot mechanism...
79 //this is left here to remind me not to try doing this again :-P
80 //ick int id = qRegisterMetaType<uint32>();
82 int retVal = -1; // Default is failure
86 bool success = (bool)LogInit("./virtualjaguar.log"); // Init logfile
89 printf("Failed to open virtualjaguar.log for writing!\n");
93 if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0)
95 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
99 WriteLog("VJ: SDL (joystick, audio) successfully initialized.\n");
100 App app(argc, argv); // Declare an instance of the application
101 Gamepad::AllocateJoysticks();
102 retVal = app.exec(); // And run it!
103 Gamepad::DeallocateJoysticks();
105 // Free SDL components last...!
106 SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO);
115 LogDone(); // Close logfile
120 // Main app constructor--we stick globally accessible stuff here... (?)
122 App::App(int & argc, char * argv[]): QApplication(argc, argv)
124 bool loadAndGo = !filename.isEmpty();
126 mainWindow = new MainWin(loadAndGo);
127 mainWindow->plzDontKillMyComputer = noUntunedTankPlease;
128 ParseOptions(argc, argv); // Override defaults with command line (if any)
129 mainWindow->SyncUI();
132 mainWindow->LoadFile(filename);
139 // Here we parse out stuff that needs to be looked at *before* we construct the
142 bool ParseCommandLine(int argc, char * argv[])
144 for(int i=1; i<argc; i++)
146 if ((strcmp(argv[i], "--help") == 0) || (strcmp(argv[i], "-h") == 0)
147 || (strcmp(argv[i], "-?") == 0))
150 "Virtual Jaguar " VJ_RELEASE_VERSION " (" VJ_RELEASE_SUBVERSION ")\n"
151 "Based upon Virtual Jaguar core v1.0.0 by David Raingeard.\n"
152 "Written by James Hammons (Linux/WIN32), Niels Wagenaar (Linux/WIN32),\n"
153 "Carwin Jones (BeOS), and Adam Green (MacOS)\n"
154 "Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n"
157 " virtualjaguar [<filename>] [switches]\n"
159 " Option Description\n"
160 " ---------------- -----------------------------------\n"
161 " <filename> Name of file to autoload\n"
162 " --alpine -a Put Virtual Jaguar into Alpine mode\n"
163 " --pal -p PAL mode\n"
164 " --ntsc -n NTSC mode\n"
165 " --bios -b Boot using Jagaur BIOS\n"
166 " --no-bios Do not use Jaguar BIOS\n"
167 " --gpu -g Enable GPU\n"
168 " --no-gpu Disable GPU\n"
169 " --dsp -d Enable DSP\n"
170 " --no-dsp Disable DSP\n"
171 " --fullscreen -f Start in full screen mode\n"
172 " --blur -B Enable GL bilinear filter\n"
173 " --no-blur Disable GL bilinear filtering\n"
174 " --log -l Create and use log file\n"
175 " --no-log Do not use log file\n"
176 " --help -h Show this message\n"
178 "Invoking Virtual Jagaur with no filename will cause it to boot up\n"
184 if (strcmp(argv[i], "--yarrr") == 0)
187 printf("Shiver me timbers!\n");
192 if ((strcmp(argv[i], "--alpine") == 0) || (strcmp(argv[i], "-a") == 0))
194 printf("Alpine Mode enabled.\n");
195 vjs.hardwareTypeAlpine = true;
198 if ((strcmp(argv[i], "--please-dont-kill-my-computer") == 0) || (strcmp(argv[i], "-z") == 0))
200 noUntunedTankPlease = true;
203 if ((strcmp(argv[i], "--log") == 0) || (strcmp(argv[i], "-l") == 0))
208 if (strcmp(argv[i], "--no-log") == 0)
213 // Check for filename
214 if (argv[i][0] != '-')
226 // This is to override settings loaded from the config file.
227 // Note that settings set here will become the new defaults!
228 // (Not any more: Settings are only saved if the config dialog was OKed, or
229 // the toolbar buttons were pressed.)
231 void ParseOptions(int argc, char * argv[])
233 for(int i=1; i<argc; i++)
235 if ((strcmp(argv[i], "--pal") == 0) || (strcmp(argv[i], "-p") == 0))
237 vjs.hardwareTypeNTSC = false;
240 if ((strcmp(argv[i], "--ntsc") == 0) || (strcmp(argv[i], "-n") == 0))
242 vjs.hardwareTypeNTSC = true;
245 if ((strcmp(argv[i], "--bios") == 0) || (strcmp(argv[i], "-b") == 0))
247 vjs.useJaguarBIOS = true;
250 if (strcmp(argv[i], "--no-bios") == 0)
252 vjs.useJaguarBIOS = false;
255 if ((strcmp(argv[i], "--gpu") == 0) || (strcmp(argv[i], "-g") == 0))
257 vjs.GPUEnabled = true;
260 if (strcmp(argv[i], "--no-gpu") == 0)
262 vjs.GPUEnabled = false;
265 if ((strcmp(argv[i], "--dsp") == 0) || (strcmp(argv[i], "-d") == 0))
267 vjs.DSPEnabled = true;
268 vjs.audioEnabled = true;
271 if (strcmp(argv[i], "--no-dsp") == 0)
273 vjs.DSPEnabled = false;
274 vjs.audioEnabled = false;
277 if ((strcmp(argv[i], "--fullscreen") == 0) || (strcmp(argv[i], "-f") == 0))
279 vjs.fullscreen = true;
282 if ((strcmp(argv[i], "--blur") == 0) || (strcmp(argv[i], "-B") == 0))
287 if (strcmp(argv[i], "--no-blur") == 0)
296 int32 joyport; // Joystick port
297 bool hardwareTypeNTSC; // Set to false for PAL
301 bool usePipelinedDSP;
305 bool hardwareTypeAlpine;
309 bool allowWritesToROM;
311 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
313 uint32 p1KeyBindings[21];
314 uint32 p2KeyBindings[21];
318 char ROMPath[MAX_PATH];
319 char jagBootPath[MAX_PATH];
320 char CDBootPath[MAX_PATH];
321 char EEPROMPath[MAX_PATH];
322 char alpineROMPath[MAX_PATH];
323 char absROMPath[MAX_PATH];