]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/app.cpp
Minor tweaks to Makefiles, added command line switches for most options.
[virtualjaguar] / src / gui / app.cpp
1 //
2 // app.cpp - Qt-based GUI for Virtual Jaguar
3 //
4 // by James Hammons
5 // (C) 2010 Underground Software
6 //
7 // JLH = James Hammons <jlhamm@acm.org>
8 //
9 // Who  When        What
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 //
16
17 #include "app.h"
18
19 #include <SDL.h>
20 #include <QApplication>
21 #include "log.h"
22 #include "mainwin.h"
23 #include "settings.h"
24 #include "types.h"
25 #include "version.h"
26
27
28 // Apparently on win32, SDL is hijacking main from Qt. So let's do this:
29 #ifdef __GCCWIN32__
30 #undef main
31 #endif
32
33 // Function prototypes...
34 static bool ParseCommandLine(int argc, char * argv[]);
35 static void ParseOptions(int argc, char * argv[]);
36
37
38 //hm. :-/
39 // This is stuff we pass into the mainWindow...
40 bool noUntunedTankPlease = false;
41 bool loadAndGo = false;
42 bool useLogfile = true;
43 QString filename;
44
45 // Here's the main application loop--short and simple...
46 int main(int argc, char * argv[])
47 {
48         // Normally, this would be read in from the settings module... :-P
49         vjs.hardwareTypeAlpine = false;
50         // This is stuff we pass into the mainWindow...
51 //      noUntunedTankPlease = false;
52
53         // Check for options that must be in place be constructing the App object
54         if (!ParseCommandLine(argc, argv))
55                 return 0;
56
57         Q_INIT_RESOURCE(virtualjaguar); // This must the same name as the exe filename
58 //or is it the .qrc filename???
59         // This is so we can pass this stuff using signal/slot mechanism...
60 //this is left here to remind me not to try doing this again :-P
61 //ick   int id = qRegisterMetaType<uint32>();
62
63         int retVal = -1;                                                        // Default is failure
64
65         if (useLogfile)
66         {
67                 bool success = (bool)LogInit("./virtualjaguar.log");    // Init logfile
68
69                 if (!success)
70                         printf("Failed to open virtualjaguar.log for writing!\n");
71         }
72
73         // Set up SDL library
74         if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0)
75         {
76                 WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError());
77         }
78         else
79         {
80                 WriteLog("VJ: SDL (joystick, audio) successfully initialized.\n");
81                 App app(argc, argv);                                    // Declare an instance of the application
82                 retVal = app.exec();                                    // And run it!
83
84                 // Free SDL components last...!
85                 SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO);
86                 SDL_Quit();
87         }
88
89         LogDone();                                                                      // Close logfile
90         return retVal;
91 }
92
93 //
94 // Main app constructor--we stick globally accessible stuff here... (?)
95 //
96 App::App(int argc, char * argv[]): QApplication(argc, argv)
97 {
98         bool loadAndGo = !filename.isEmpty();
99
100         mainWindow = new MainWin(loadAndGo);
101         mainWindow->plzDontKillMyComputer = noUntunedTankPlease;
102         ParseOptions(argc, argv);                                       // Override defaults with command line (if any)
103         mainWindow->SyncUI();
104
105         if (loadAndGo)
106                 mainWindow->LoadFile(filename);
107
108         mainWindow->show();
109 }
110
111
112 //
113 // Here we parse out stuff that needs to be looked at *before* we construct the 
114 // App object.
115 //
116 bool ParseCommandLine(int argc, char * argv[])
117 {
118         for(int i=1; i<argc; i++)
119         {
120                 if ((strcmp(argv[i], "--help") == 0) || (strcmp(argv[i], "-h") == 0)
121                         || (strcmp(argv[i], "-?") == 0))
122                 {
123                         printf(
124                                 "Virtual Jaguar " VJ_RELEASE_VERSION " (" VJ_RELEASE_SUBVERSION ")\n"
125                                 "Based upon Virtual Jaguar core v1.0.0 by David Raingeard.\n"
126                                 "Written by Niels Wagenaar (Linux/WIN32), Carwin Jones (BeOS),\n"
127                                 "James Hammons (Linux/WIN32) and Adam Green (MacOS)\n"
128                                 "Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n"
129                                 "\n"
130                                 "Usage:\n"
131                                 "   virtualjaguar [<filename>] [switches]\n"
132                                 "\n"
133                                 "   Option            Description\n"
134                                 "   ----------------  -----------------------------------\n"
135                                 "   <filename>        Name of file to autoload\n"
136                                 "   --alpine      -a  Put Virtual Jaguar into Alpine mode\n"
137                                 "   --pal         -p  PAL mode\n"
138                                 "   --ntsc        -n  NTSC mode\n"
139                                 "   --bios        -b  Boot using Jagaur BIOS\n"
140                                 "   --no-bios         Do not use Jaguar BIOS\n"
141                                 "   --gpu         -g  Enable GPU\n"
142                                 "   --no-gpu          Disable GPU\n"
143                                 "   --dsp         -d  Enable DSP\n"
144                                 "   --no-dsp          Disable DSP\n"
145                                 "   --fullscreen  -f  Start in full screen mode\n"
146                                 "   --blur        -B  Enable GL bilinear filter\n"
147                                 "   --no-blur         Disable GL bilinear filtering\n"
148                                 "   --log         -l  Create and use log file\n"
149                                 "   --no-log          Do not use log file\n"
150                                 "   --help        -h  Show this message\n"
151                                 "\n"
152                                 "Invoking Virtual Jagaur with no filename will cause it to boot up\n"
153                                 "with the VJ GUI.\n"
154                                 "\n");
155                         return false;
156                 }
157
158                 if (strcmp(argv[i], "--yarrr") == 0)
159                 {
160                         printf("\n");
161                         printf("Shiver me timbers!\n");
162                         printf("\n");
163                         return false;
164                 }
165
166                 if ((strcmp(argv[i], "--alpine") == 0) || (strcmp(argv[i], "-a") == 0))
167                 {
168                         printf("Alpine Mode enabled.\n");
169                         vjs.hardwareTypeAlpine = true;
170                 }
171
172                 if (strcmp(argv[i], "--please-dont-kill-my-computer") == 0)
173                 {
174                         noUntunedTankPlease = true;
175                 }
176
177                 if ((strcmp(argv[i], "--log") == 0) || (strcmp(argv[i], "-l") == 0))
178                 {
179                         useLogfile = true;
180                 }
181
182                 if (strcmp(argv[i], "--no-log") == 0)
183                 {
184                         useLogfile = false;
185                 }
186
187                 // Check for filename
188                 if (argv[i][0] != '-')
189                 {
190                         loadAndGo = true;
191                         filename = argv[i];
192                 }
193         }
194
195         return true;
196 }
197
198
199 //
200 // This is to override settings loaded from the config file.
201 // Note that settings set here will become the new defaults!
202 //
203 void ParseOptions(int argc, char * argv[])
204 {
205         for(int i=1; i<argc; i++)
206         {
207                 if ((strcmp(argv[i], "--pal") == 0) || (strcmp(argv[i], "-p") == 0))
208                 {
209                         vjs.hardwareTypeNTSC = false;
210                 }
211
212                 if ((strcmp(argv[i], "--ntsc") == 0) || (strcmp(argv[i], "-n") == 0))
213                 {
214                         vjs.hardwareTypeNTSC = true;
215                 }
216
217                 if ((strcmp(argv[i], "--bios") == 0) || (strcmp(argv[i], "-b") == 0))
218                 {
219                         vjs.useJaguarBIOS = true;
220                 }
221
222                 if (strcmp(argv[i], "--no-bios") == 0)
223                 {
224                         vjs.useJaguarBIOS = false;
225                 }
226
227                 if ((strcmp(argv[i], "--gpu") == 0) || (strcmp(argv[i], "-g") == 0))
228                 {
229                         vjs.GPUEnabled = true;
230                 }
231
232                 if (strcmp(argv[i], "--no-gpu") == 0)
233                 {
234                         vjs.GPUEnabled = false;
235                 }
236
237                 if ((strcmp(argv[i], "--dsp") == 0) || (strcmp(argv[i], "-d") == 0))
238                 {
239                         vjs.DSPEnabled = true;
240                         vjs.audioEnabled = true;
241                 }
242
243                 if (strcmp(argv[i], "--no-dsp") == 0)
244                 {
245                         vjs.DSPEnabled = false;
246                         vjs.audioEnabled = false;
247                 }
248
249                 if ((strcmp(argv[i], "--fullscreen") == 0) || (strcmp(argv[i], "-f") == 0))
250                 {
251                         vjs.fullscreen = true;
252                 }
253
254                 if ((strcmp(argv[i], "--blur") == 0) || (strcmp(argv[i], "-B") == 0))
255                 {
256                         vjs.glFilter = 1;
257                 }
258
259                 if (strcmp(argv[i], "--no-blur") == 0)
260                 {
261                         vjs.glFilter = 0;
262                 }
263         }
264 }
265
266 #if 0
267         bool useJoystick;
268         int32 joyport;                                                          // Joystick port
269         bool hardwareTypeNTSC;                                          // Set to false for PAL
270         bool useJaguarBIOS;
271         bool GPUEnabled;
272         bool DSPEnabled;
273         bool usePipelinedDSP;
274         bool fullscreen;
275         bool useOpenGL;
276         uint32 glFilter;
277         bool hardwareTypeAlpine;
278         bool audioEnabled;
279         uint32 frameSkip;
280         uint32 renderType;
281         bool allowWritesToROM;
282
283         // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
284
285         uint32 p1KeyBindings[21];
286         uint32 p2KeyBindings[21];
287
288         // Paths
289
290         char ROMPath[MAX_PATH];
291         char jagBootPath[MAX_PATH];
292         char CDBootPath[MAX_PATH];
293         char EEPROMPath[MAX_PATH];
294         char alpineROMPath[MAX_PATH];
295         char absROMPath[MAX_PATH];
296 #endif