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
15 // JLH 03/05/2013 Fixed console redireciton on win32 platform :-P
21 #include <QApplication>
30 // Apparently on win32, SDL is hijacking main from Qt. So let's do this:
33 #include <windows.h> // Ick, but needed for console redirection on win32 :-O
36 // Function prototypes...
37 static bool ParseCommandLine(int argc, char * argv[]);
38 static void ParseOptions(int argc, char * argv[]);
42 // This is stuff we pass into the mainWindow...
43 // Also, these are defaults. :-)
44 bool noUntunedTankPlease = false;
45 bool loadAndGo = false;
46 bool useLogfile = false;
49 // Here's the main application loop--short and simple...
50 int main(int argc, char * argv[])
52 // Win32 console redirection, because MS and their band of super geniuses decided
53 // that nobody would ever launch an app from the command line. :-P
55 BOOL (WINAPI * AttachConsole)(DWORD dwProcessId);
57 AttachConsole = (BOOL (WINAPI *)(DWORD))
58 GetProcAddress(LoadLibraryA("kernel32.dll"), "AttachConsole");
60 if (AttachConsole != NULL && AttachConsole(((DWORD)-1)))
62 if (_fileno(stdout) == -1)
63 freopen("CONOUT$","wb",stdout);
64 if (_fileno(stderr) == -1)
65 freopen("CONOUT$","wb",stderr);
66 if (_fileno(stdin) == -1)
67 freopen("CONIN$","rb",stdin);
70 std::ios::sync_with_stdio();
74 // Normally, this would be read in from the settings module... :-P
75 vjs.hardwareTypeAlpine = false;
76 // This is stuff we pass into the mainWindow...
77 // noUntunedTankPlease = false;
79 // Check for options that must be in place be constructing the App object
80 if (!ParseCommandLine(argc, argv))
85 Q_INIT_RESOURCE(virtualjaguar); // This must the same name as the exe filename
86 //or is it the .qrc filename???
87 // This is so we can pass this stuff using signal/slot mechanism...
88 //this is left here to remind me not to try doing this again :-P
89 //ick int id = qRegisterMetaType<uint32>();
91 int retVal = -1; // Default is failure
95 bool success = (bool)LogInit("./virtualjaguar.log"); // Init logfile
98 printf("Failed to open virtualjaguar.log for writing!\n");
101 // Set up SDL library
102 if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0)
104 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
108 WriteLog("VJ: SDL (joystick, audio) successfully initialized.\n");
109 App app(argc, argv); // Declare an instance of the application
110 Gamepad::AllocateJoysticks();
111 retVal = app.exec(); // And run it!
112 Gamepad::DeallocateJoysticks();
114 // Free SDL components last...!
115 SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO);
124 LogDone(); // Close logfile
129 // Main app constructor--we stick globally accessible stuff here... (?)
131 App::App(int & argc, char * argv[]): QApplication(argc, argv)
133 bool loadAndGo = !filename.isEmpty();
135 mainWindow = new MainWin(loadAndGo);
136 mainWindow->plzDontKillMyComputer = noUntunedTankPlease;
137 ParseOptions(argc, argv); // Override defaults with command line (if any)
138 mainWindow->SyncUI();
141 mainWindow->LoadFile(filename);
148 // Here we parse out stuff that needs to be looked at *before* we construct the
151 bool ParseCommandLine(int argc, char * argv[])
153 for(int i=1; i<argc; i++)
155 if ((strcmp(argv[i], "--help") == 0) || (strcmp(argv[i], "-h") == 0)
156 || (strcmp(argv[i], "-?") == 0))
159 "Virtual Jaguar " VJ_RELEASE_VERSION " (" VJ_RELEASE_SUBVERSION ")\n"
160 "Based upon Virtual Jaguar core v1.0.0 by David Raingeard.\n"
161 "Written by James Hammons (Linux/WIN32), Niels Wagenaar (Linux/WIN32),\n"
162 "Carwin Jones (BeOS), and Adam Green (MacOS)\n"
163 "Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n"
166 " virtualjaguar [<filename>] [switches]\n"
168 " Option Description\n"
169 " ---------------- -----------------------------------\n"
170 " <filename> Name of file to autoload\n"
171 " --alpine -a Put Virtual Jaguar into Alpine mode\n"
172 " --pal -p PAL mode\n"
173 " --ntsc -n NTSC mode\n"
174 " --bios -b Boot using Jagaur BIOS\n"
175 " --no-bios Do not use Jaguar BIOS\n"
176 " --gpu -g Enable GPU\n"
177 " --no-gpu Disable GPU\n"
178 " --dsp -d Enable DSP\n"
179 " --no-dsp Disable DSP\n"
180 " --fullscreen -f Start in full screen mode\n"
181 " --blur -B Enable GL bilinear filter\n"
182 " --no-blur Disable GL bilinear filtering\n"
183 " --log -l Create and use log file\n"
184 " --no-log Do not use log file\n"
185 " --help -h Show this message\n"
186 " --please-dont-kill-my-computer\n"
187 " -z Run Virtual Jaguar without \"snow\"\n"
189 "Invoking Virtual Jagaur with no filename will cause it to boot up\n"
195 if (strcmp(argv[i], "--yarrr") == 0)
198 printf("Shiver me timbers!\n");
203 if ((strcmp(argv[i], "--alpine") == 0) || (strcmp(argv[i], "-a") == 0))
205 printf("Alpine Mode enabled.\n");
206 vjs.hardwareTypeAlpine = true;
209 if ((strcmp(argv[i], "--please-dont-kill-my-computer") == 0) || (strcmp(argv[i], "-z") == 0))
211 noUntunedTankPlease = true;
214 if ((strcmp(argv[i], "--log") == 0) || (strcmp(argv[i], "-l") == 0))
219 if (strcmp(argv[i], "--no-log") == 0)
224 // Check for filename
225 if (argv[i][0] != '-')
237 // This is to override settings loaded from the config file.
238 // Note that settings set here will become the new defaults!
239 // (Not any more: Settings are only saved if the config dialog was OKed, or
240 // the toolbar buttons were pressed.)
242 void ParseOptions(int argc, char * argv[])
244 for(int i=1; i<argc; i++)
246 if ((strcmp(argv[i], "--pal") == 0) || (strcmp(argv[i], "-p") == 0))
248 vjs.hardwareTypeNTSC = false;
251 if ((strcmp(argv[i], "--ntsc") == 0) || (strcmp(argv[i], "-n") == 0))
253 vjs.hardwareTypeNTSC = true;
256 if ((strcmp(argv[i], "--bios") == 0) || (strcmp(argv[i], "-b") == 0))
258 vjs.useJaguarBIOS = true;
261 if (strcmp(argv[i], "--no-bios") == 0)
263 vjs.useJaguarBIOS = false;
266 if ((strcmp(argv[i], "--gpu") == 0) || (strcmp(argv[i], "-g") == 0))
268 vjs.GPUEnabled = true;
271 if (strcmp(argv[i], "--no-gpu") == 0)
273 vjs.GPUEnabled = false;
276 if ((strcmp(argv[i], "--dsp") == 0) || (strcmp(argv[i], "-d") == 0))
278 vjs.DSPEnabled = true;
279 vjs.audioEnabled = true;
282 if (strcmp(argv[i], "--no-dsp") == 0)
284 vjs.DSPEnabled = false;
285 vjs.audioEnabled = false;
288 if ((strcmp(argv[i], "--fullscreen") == 0) || (strcmp(argv[i], "-f") == 0))
290 vjs.fullscreen = true;
293 if ((strcmp(argv[i], "--blur") == 0) || (strcmp(argv[i], "-B") == 0))
298 if (strcmp(argv[i], "--no-blur") == 0)
307 int32 joyport; // Joystick port
308 bool hardwareTypeNTSC; // Set to false for PAL
312 bool usePipelinedDSP;
316 bool hardwareTypeAlpine;
320 bool allowWritesToROM;
322 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
324 uint32 p1KeyBindings[21];
325 uint32 p2KeyBindings[21];
329 char ROMPath[MAX_PATH];
330 char jagBootPath[MAX_PATH];
331 char CDBootPath[MAX_PATH];
332 char EEPROMPath[MAX_PATH];
333 char alpineROMPath[MAX_PATH];
334 char absROMPath[MAX_PATH];