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
53 // decided that nobody would ever launch an app from the command line. :-P
54 // [Unfortunately, this doesn't seem to work on Vista/7. :-(]
56 BOOL (WINAPI * AttachConsole)(DWORD dwProcessId);
58 AttachConsole = (BOOL (WINAPI *)(DWORD))
59 GetProcAddress(LoadLibraryA("kernel32.dll"), "AttachConsole");
61 if (AttachConsole != NULL && AttachConsole(((DWORD)-1)))
63 if (_fileno(stdout) == -1)
64 freopen("CONOUT$","wb",stdout);
65 if (_fileno(stderr) == -1)
66 freopen("CONOUT$","wb",stderr);
67 if (_fileno(stdin) == -1)
68 freopen("CONIN$","rb",stdin);
71 std::ios::sync_with_stdio();
75 // Normally, this would be read in from the settings module... :-P
76 vjs.hardwareTypeAlpine = false;
77 // This is stuff we pass into the mainWindow...
78 // noUntunedTankPlease = false;
80 // Check for options that must be in place be constructing the App object
81 if (!ParseCommandLine(argc, argv))
86 Q_INIT_RESOURCE(virtualjaguar); // This must the same name as the exe filename
87 //or is it the .qrc filename???
88 // This is so we can pass this stuff using signal/slot mechanism...
89 //this is left here to remind me not to try doing this again :-P
90 //ick int id = qRegisterMetaType<uint32>();
92 int retVal = -1; // Default is failure
96 bool success = (bool)LogInit("./virtualjaguar.log"); // Init logfile
99 printf("Failed to open virtualjaguar.log for writing!\n");
102 // Set up SDL library
103 if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0)
105 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
109 WriteLog("VJ: SDL (joystick, audio) successfully initialized.\n");
110 App app(argc, argv); // Declare an instance of the application
111 Gamepad::AllocateJoysticks();
112 AutoConnectProfiles();
113 retVal = app.exec(); // And run it!
114 Gamepad::DeallocateJoysticks();
116 // Free SDL components last...!
117 SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO);
126 LogDone(); // Close logfile
131 // Main app constructor--we stick globally accessible stuff here... (?)
133 App::App(int & argc, char * argv[]): QApplication(argc, argv)
135 bool loadAndGo = !filename.isEmpty();
137 mainWindow = new MainWin(loadAndGo);
138 mainWindow->plzDontKillMyComputer = noUntunedTankPlease;
139 ParseOptions(argc, argv); // Override defaults with command line (if any)
140 mainWindow->SyncUI();
143 mainWindow->LoadFile(filename);
150 // Here we parse out stuff that needs to be looked at *before* we construct the
153 bool ParseCommandLine(int argc, char * argv[])
155 for(int i=1; i<argc; i++)
157 if ((strcmp(argv[i], "--help") == 0) || (strcmp(argv[i], "-h") == 0)
158 || (strcmp(argv[i], "-?") == 0))
161 "Virtual Jaguar " VJ_RELEASE_VERSION " (" VJ_RELEASE_SUBVERSION ")\n"
162 "Based upon Virtual Jaguar core v1.0.0 by David Raingeard.\n"
163 "Written by James Hammons (Linux/WIN32), Niels Wagenaar (Linux/WIN32),\n"
164 "Carwin Jones (BeOS), and Adam Green (MacOS)\n"
165 "Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n"
168 " virtualjaguar [<filename>] [switches]\n"
170 " Option Description\n"
171 " ---------------- -----------------------------------\n"
172 " <filename> Name of file to autoload\n"
173 " --alpine -a Put Virtual Jaguar into Alpine mode\n"
174 " --pal -p PAL mode\n"
175 " --ntsc -n NTSC mode\n"
176 " --bios -b Boot using Jagaur BIOS\n"
177 " --no-bios Do not use Jaguar BIOS\n"
178 " --gpu -g Enable GPU\n"
179 " --no-gpu Disable GPU\n"
180 " --dsp -d Enable DSP\n"
181 " --no-dsp Disable DSP\n"
182 " --fullscreen -f Start in full screen mode\n"
183 " --blur -B Enable GL bilinear filter\n"
184 " --no-blur Disable GL bilinear filtering\n"
185 " --log -l Create and use log file\n"
186 " --no-log Do not use log file\n"
187 " --help -h Show this message\n"
188 " --please-dont-kill-my-computer\n"
189 " -z Run Virtual Jaguar without \"snow\"\n"
191 "Invoking Virtual Jagaur with no filename will cause it to boot up\n"
192 "with the VJ GUI. Using Alpine mode will enable log file.\n"
197 if (strcmp(argv[i], "--yarrr") == 0)
200 printf("Shiver me timbers!\n");
205 if ((strcmp(argv[i], "--alpine") == 0) || (strcmp(argv[i], "-a") == 0))
207 printf("Alpine Mode enabled.\n");
208 vjs.hardwareTypeAlpine = true;
209 // We also enable logging as well :-)
213 if ((strcmp(argv[i], "--please-dont-kill-my-computer") == 0) || (strcmp(argv[i], "-z") == 0))
215 noUntunedTankPlease = true;
218 if ((strcmp(argv[i], "--log") == 0) || (strcmp(argv[i], "-l") == 0))
223 if (strcmp(argv[i], "--no-log") == 0)
228 // Check for filename
229 if (argv[i][0] != '-')
241 // This is to override settings loaded from the config file.
242 // Note that settings set here will become the new defaults!
243 // (Not any more: Settings are only saved if the config dialog was OKed, or
244 // the toolbar buttons were pressed.)
246 void ParseOptions(int argc, char * argv[])
248 for(int i=1; i<argc; i++)
250 if ((strcmp(argv[i], "--pal") == 0) || (strcmp(argv[i], "-p") == 0))
252 vjs.hardwareTypeNTSC = false;
255 if ((strcmp(argv[i], "--ntsc") == 0) || (strcmp(argv[i], "-n") == 0))
257 vjs.hardwareTypeNTSC = true;
260 if ((strcmp(argv[i], "--bios") == 0) || (strcmp(argv[i], "-b") == 0))
262 vjs.useJaguarBIOS = true;
265 if (strcmp(argv[i], "--no-bios") == 0)
267 vjs.useJaguarBIOS = false;
270 if ((strcmp(argv[i], "--gpu") == 0) || (strcmp(argv[i], "-g") == 0))
272 vjs.GPUEnabled = true;
275 if (strcmp(argv[i], "--no-gpu") == 0)
277 vjs.GPUEnabled = false;
280 if ((strcmp(argv[i], "--dsp") == 0) || (strcmp(argv[i], "-d") == 0))
282 vjs.DSPEnabled = true;
283 vjs.audioEnabled = true;
286 if (strcmp(argv[i], "--no-dsp") == 0)
288 vjs.DSPEnabled = false;
289 vjs.audioEnabled = false;
292 if ((strcmp(argv[i], "--fullscreen") == 0) || (strcmp(argv[i], "-f") == 0))
294 vjs.fullscreen = true;
297 if ((strcmp(argv[i], "--blur") == 0) || (strcmp(argv[i], "-B") == 0))
302 if (strcmp(argv[i], "--no-blur") == 0)
311 int32 joyport; // Joystick port
312 bool hardwareTypeNTSC; // Set to false for PAL
316 bool usePipelinedDSP;
320 bool hardwareTypeAlpine;
324 bool allowWritesToROM;
326 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
328 uint32 p1KeyBindings[21];
329 uint32 p2KeyBindings[21];
333 char ROMPath[MAX_PATH];
334 char jagBootPath[MAX_PATH];
335 char CDBootPath[MAX_PATH];
336 char EEPROMPath[MAX_PATH];
337 char alpineROMPath[MAX_PATH];
338 char absROMPath[MAX_PATH];