2 // app.cpp - Qt-based GUI for Virtual Jaguar
5 // (C) 2010 Underground Software
7 // JLH = James Hammons <jlhamm@acm.org>
8 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 12/23/2009 Created this file
13 // JLH 01/21/2011 Added SDL initialization
14 // JLH 06/26/2011 Added fix to keep SDL from hijacking main() on win32
15 // JLH 05/24/2012 Added option switches
16 // JLH 03/05/2013 Fixed console redireciton on win32 platform :-P
17 // JPM 06/06/2016 Visual Studio support
18 // JPM 06/19/2016 Soft debugger support (--debugger)
19 // JPM 09/ /2017 Added option (--dram-max) to support 8MB ram (which doesn't exist)
20 // JPM 09/06/2017 Added the 'Rx' word to the emulator name and updated the credits line
21 // JPM 09/08/2017 Added option (--es-all, --es-ui, --es-alpine & --es-debugger) to support the erase settings
27 #include <QApplication>
34 #include "debugger/DBGManager.h"
36 // Apparently on win32, SDL is hijacking main from Qt. So let's do this:
37 #if defined (__GCCWIN32__) || defined (_MSC_VER)
39 #include <windows.h> // Ick, but needed for console redirection on win32 :-O
42 // Function prototypes...
43 static bool ParseCommandLine(int argc
, char * argv
[]);
44 static void ParseOptions(int argc
, char * argv
[]);
48 // This is stuff we pass into the mainWindow...
49 // Also, these are defaults. :-)
50 bool noUntunedTankPlease
= false;
51 bool loadAndGo
= false;
52 bool useLogfile
= false;
55 // Here's the main application loop--short and simple...
56 int main(int argc
, char * argv
[])
58 // Win32 console redirection, because MS and their band of super geniuses
59 // decided that nobody would ever launch an app from the command line. :-P
60 // [Unfortunately, this doesn't seem to work on Vista/7. :-(]
61 #if defined (__GCCWIN32__) || defined (_MSC_VER)
62 BOOL(WINAPI
* AttachConsole
)(DWORD dwProcessId
);
64 AttachConsole
= (BOOL (WINAPI
*)(DWORD
))GetProcAddress(LoadLibraryA("kernel32.dll"), "AttachConsole");
66 if (AttachConsole
!= NULL
&& AttachConsole(((DWORD
)-1)))
68 if (_fileno(stdout
) == -1)
69 freopen("CONOUT$", "wb", stdout
);
70 if (_fileno(stderr
) == -1)
71 freopen("CONOUT$", "wb", stderr
);
72 if (_fileno(stdin
) == -1)
73 freopen("CONIN$", "rb", stdin
);
76 std::ios::sync_with_stdio();
80 // Normally, this would be read in from the settings module... :-P
81 vjs
.hardwareTypeAlpine
= false;
82 vjs
.softTypeDebugger
= false;
83 vjs
.DRAM_size
= 0x200000;
84 // This is stuff we pass into the mainWindow...
85 // noUntunedTankPlease = false;
87 // Check for options that must be in place be constructing the App object
88 if (!ParseCommandLine(argc
, argv
))
93 Q_INIT_RESOURCE(virtualjaguar
); // This must the same name as the exe filename
94 //or is it the .qrc filename???
95 // This is so we can pass this stuff using signal/slot mechanism...
96 //this is left here to remind me not to try doing this again :-P
97 //ick int id = qRegisterMetaType<uint32>();
99 int retVal
= -1; // Default is failure
103 bool success
= (bool)LogInit("./virtualjaguar.log"); // Init logfile
106 printf("Failed to open virtualjaguar.log for writing!\n");
109 // Set up SDL library
110 if (SDL_Init(SDL_INIT_JOYSTICK
| SDL_INIT_AUDIO
) < 0)
112 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
116 WriteLog("VJ: SDL (joystick, audio) successfully initialized.\n");
118 App
app(argc
, argv
); // Declare an instance of the application
119 Gamepad::AllocateJoysticks();
120 AutoConnectProfiles();
121 retVal
= app
.exec(); // And run it!
123 Gamepad::DeallocateJoysticks();
125 // Free SDL components last...!
126 SDL_QuitSubSystem(SDL_INIT_JOYSTICK
| SDL_INIT_AUDIO
);
130 #if defined (__GCCWIN32__) || defined (_MSC_VER)
142 // Main app constructor--we stick globally accessible stuff here... (?)
144 App::App(int & argc
, char * argv
[]): QApplication(argc
, argv
)
146 bool loadAndGo
= !filename
.isEmpty();
148 mainWindow
= new MainWin(loadAndGo
);
149 mainWindow
->plzDontKillMyComputer
= noUntunedTankPlease
;
150 // Override defaults with command line (if any)
151 ParseOptions(argc
, argv
);
152 mainWindow
->SyncUI();
156 mainWindow
->LoadFile(filename
);
158 if (!mainWindow
->cartridgeLoaded
)
159 printf("Could not load file \"%s\"!\n", filename
.toUtf8().data());
167 // Here we parse out stuff that needs to be looked at *before* we construct the
170 bool ParseCommandLine(int argc
, char * argv
[])
172 for(int i
=1; i
<argc
; i
++)
174 if ((strcmp(argv
[i
], "--help") == 0) || (strcmp(argv
[i
], "-h") == 0) || (strcmp(argv
[i
], "-?") == 0))
177 "Virtual Jaguar " VJ_RELEASE_VERSION
" (" VJ_RELEASE_SUBVERSION
") Rx\n"
178 "Based upon Virtual Jaguar core v1.0.0 by David Raingeard.\n"
179 "Based upon the work by James Hammons (Linux/WIN32), Niels Wagenaar (Linux/WIN32),\n"
180 "Carwin Jones (BeOS), and Adam Green (MacOS)\n"
181 "Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n"
184 " virtualjaguar [<filename>] [switches]\n"
186 " Option Description\n"
187 " ---------------- -----------------------------------\n"
188 " <filename> Name of file to autoload\n"
189 " --alpine -a Put Virtual Jaguar into Alpine mode\n"
190 " --debugger -d Put Virtual Jaguar into Debugger mode\n"
191 " --pal -p PAL mode\n"
192 " --ntsc -n NTSC mode\n"
193 " --dram-max Set DRAM size to 8MB\n"
194 " --bios -b Boot using Jagaur BIOS\n"
195 " --no-bios Do not use Jaguar BIOS\n"
196 " --gpu -g Enable GPU\n"
197 " --no-gpu Disable GPU\n"
198 " --dsp -d Enable DSP\n"
199 " --no-dsp Disable DSP\n"
200 " --fullscreen -f Start in full screen mode\n"
201 " --blur -B Enable GL bilinear filter\n"
202 " --no-blur Disable GL bilinear filtering\n"
203 " --log -l Create and use log file\n"
204 " --no-log Do not use log file (default)\n"
205 " --help -h Show this message\n"
206 " -? Show this message\n"
207 " --es-all Erase all settings\n"
208 " --es-ui Erase UI settings only\n"
209 " --es-alpine Erase alpine mode settings only\n"
210 " --es-debugger Erase debugger mode settings only\n"
211 " --please-dont-kill-my-computer\n"
212 " -z Run Virtual Jaguar without \"snow\"\n"
214 "Invoking Virtual Jaguar with no filename will cause it to boot up\n"
215 "with the VJ GUI. Using Alpine mode will enable log file.\n"
221 if (strcmp(argv
[i
], "--yarrr") == 0)
224 printf("Shiver me timbers!\n");
230 if (strstr(argv
[i
], "--es-"))
233 if (EraseSettings(&argv
[i
][5]))
235 printf("Settings have been erased");
239 printf("No requested settings have been found");
246 if ((strcmp(argv
[i
], "--alpine") == 0) || (strcmp(argv
[i
], "-a") == 0))
248 printf("Alpine Mode enabled.\n");
249 vjs
.hardwareTypeAlpine
= true;
250 // We also enable logging as well :-)
255 if ((strcmp(argv
[i
], "--debugger") == 0) || (strcmp(argv
[i
], "-d") == 0))
257 printf("Debugger mode enabled.\n");
258 vjs
.softTypeDebugger
= true;
262 if ((strcmp(argv
[i
], "--please-dont-kill-my-computer") == 0) || (strcmp(argv
[i
], "-z") == 0))
264 noUntunedTankPlease
= true;
268 if ((strcmp(argv
[i
], "--log") == 0) || (strcmp(argv
[i
], "-l") == 0))
270 printf("Log file enabled.\n");
275 if (strcmp(argv
[i
], "--no-log") == 0)
277 printf("Log file disabled.\n");
282 if (strcmp(argv
[i
], "--dram-max") == 0)
284 printf("DRAM size set at 8 Mbytes.\n");
285 vjs
.DRAM_size
= 0x800000;
288 // Check for filename
289 if (argv
[i
][0] != '-')
301 // This is to override settings loaded from the config file.
302 // Note that settings set here will become the new defaults!
303 // (Not any more: Settings are only saved if the config dialog was OKed, or the toolbar buttons were pressed.)
305 void ParseOptions(int argc
, char * argv
[])
307 for(int i
=1; i
<argc
; i
++)
310 if ((strcmp(argv
[i
], "--pal") == 0) || (strcmp(argv
[i
], "-p") == 0))
312 vjs
.hardwareTypeNTSC
= false;
316 if ((strcmp(argv
[i
], "--ntsc") == 0) || (strcmp(argv
[i
], "-n") == 0))
318 vjs
.hardwareTypeNTSC
= true;
322 if ((strcmp(argv
[i
], "--bios") == 0) || (strcmp(argv
[i
], "-b") == 0))
324 vjs
.useJaguarBIOS
= true;
328 if (strcmp(argv
[i
], "--no-bios") == 0)
330 vjs
.useJaguarBIOS
= false;
334 if ((strcmp(argv
[i
], "--gpu") == 0) || (strcmp(argv
[i
], "-g") == 0))
336 vjs
.GPUEnabled
= true;
340 if (strcmp(argv
[i
], "--no-gpu") == 0)
342 vjs
.GPUEnabled
= false;
346 if ((strcmp(argv
[i
], "--dsp") == 0) || (strcmp(argv
[i
], "-d") == 0))
348 vjs
.DSPEnabled
= true;
349 vjs
.audioEnabled
= true;
353 if (strcmp(argv
[i
], "--no-dsp") == 0)
355 vjs
.DSPEnabled
= false;
356 vjs
.audioEnabled
= false;
360 if ((strcmp(argv
[i
], "--fullscreen") == 0) || (strcmp(argv
[i
], "-f") == 0))
362 vjs
.fullscreen
= true;
365 // Enable GL bilinear filter
366 if ((strcmp(argv
[i
], "--blur") == 0) || (strcmp(argv
[i
], "-B") == 0))
371 // Disable GL bilinear filter
372 if (strcmp(argv
[i
], "--no-blur") == 0)
381 int32 joyport
; // Joystick port
382 bool hardwareTypeNTSC
; // Set to false for PAL
386 bool usePipelinedDSP
;
390 bool hardwareTypeAlpine
;
391 bool softTypeDebugger
;
395 bool allowWritesToROM
;
397 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
399 uint32 p1KeyBindings
[21];
400 uint32 p2KeyBindings
[21];
404 char ROMPath
[MAX_PATH
];
405 char jagBootPath
[MAX_PATH
];
406 char CDBootPath
[MAX_PATH
];
407 char EEPROMPath
[MAX_PATH
];
408 char alpineROMPath
[MAX_PATH
];
409 char absROMPath
[MAX_PATH
];