]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/mainwin.cpp
Added appropriate audio thread pausing to the GUI layer.
[virtualjaguar] / src / gui / mainwin.cpp
1 //
2 // mainwin.cpp - Qt-based GUI for Virtual Jaguar: Main Application Window
3 // by James Hammons
4 // (C) 2009 Underground Software
5 //
6 // JLH = James Hammons <jlhamm@acm.org>
7 //
8 // Who  When        What
9 // ---  ----------  -------------------------------------------------------------
10 // JLH  12/23/2009  Created this file
11 // JLH  12/20/2010  Added settings, menus & toolbars
12 // JLH  07/05/2011  Added CD BIOS functionality to GUI
13 //
14
15 // FIXED:
16 //
17 // - Add dbl click/enter to select in cart list, ESC to dimiss [DONE]
18 // - Autoscan/autoload all available BIOS from 'software' folder [DONE]
19 // - Add 1 key jumping in cartridge list (press 'R', jumps to carts starting with 'R', etc) [DONE]
20 // - Controller configuration [DONE]
21 //
22 // STILL TO BE DONE:
23 //
24 // - Remove SDL dependencies (sound, mainly) from Jaguar core lib
25 // - Fix inconsistency with trailing slashes in paths (eeproms needs one, software doesn't)
26 //
27 // SFDX CODE: 9XF9TUHFM2359
28
29 // Uncomment this for debugging...
30 //#define DEBUG
31 //#define DEBUGFOO                      // Various tool debugging...
32 //#define DEBUGTP                               // Toolpalette debugging...
33
34 #include "mainwin.h"
35
36 #include "SDL.h"
37 #include "app.h"
38 #include "about.h"
39 #include "configdialog.h"
40 #include "filepicker.h"
41 #include "gamepad.h"
42 #include "generaltab.h"
43 #include "glwidget.h"
44 #include "help.h"
45 #include "settings.h"
46 #include "version.h"
47 #include "debug/cpubrowser.h"
48 #include "debug/m68kdasmbrowser.h"
49 #include "debug/memorybrowser.h"
50 #include "debug/opbrowser.h"
51 #include "debug/riscdasmbrowser.h"
52
53 #include "dac.h"
54 #include "jaguar.h"
55 #include "tom.h"
56 #include "log.h"
57 #include "file.h"
58 #include "jagbios.h"
59 #include "jagcdbios.h"
60 #include "jagstub2bios.h"
61 #include "joystick.h"
62
63 // According to SebRmv, this header isn't seen on Arch Linux either... :-/
64 //#ifdef __GCCWIN32__
65 // Apparently on win32, usleep() is not pulled in by the usual suspects.
66 #include <unistd.h>
67 //#endif
68
69 // The way BSNES controls things is by setting a timer with a zero
70 // timeout, sleeping if not emulating anything. Seems there has to be a
71 // better way.
72
73 // It has a novel approach to plugging-in/using different video/audio/input
74 // methods, can we do something similar or should we just use the built-in
75 // QOpenGL?
76
77 // We're going to try to use the built-in OpenGL support and see how it goes.
78 // We'll make the VJ core modular so that it doesn't matter what GUI is in
79 // use, we can drop it in anywhere and use it as-is.
80
81 //MainWin::MainWin(QString filenameToRun): running(true), powerButtonOn(false),
82 MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
83         showUntunedTankCircuit(true), cartridgeLoaded(false), CDActive(false),
84         //, alpineLoadSuccessful(false),
85 //      pauseForFileSelector(false), loadAndGo(false), plzDontKillMyComputer(false)
86         pauseForFileSelector(false), loadAndGo(autoRun), plzDontKillMyComputer(false)
87 {
88         for(int i=0; i<8; i++)
89                 keyHeld[i] = false;
90
91         videoWidget = new GLWidget(this);
92         setCentralWidget(videoWidget);
93         setWindowIcon(QIcon(":/res/vj-icon.png"));
94
95         QString title = QString(tr("Virtual Jaguar " VJ_RELEASE_VERSION ));
96
97         if (vjs.hardwareTypeAlpine)
98                 title += QString(tr(" - Alpine Mode"));
99
100         setWindowTitle(title);
101
102         aboutWin = new AboutWindow(this);
103         helpWin = new HelpWindow(this);
104         filePickWin = new FilePickerWindow(this);
105         memBrowseWin = new MemoryBrowserWindow(this);
106         cpuBrowseWin = new CPUBrowserWindow(this);
107         opBrowseWin = new OPBrowserWindow(this);
108         m68kDasmBrowseWin = new M68KDasmBrowserWindow(this);
109         riscDasmBrowseWin = new RISCDasmBrowserWindow(this);
110
111         videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
112         setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
113
114         setUnifiedTitleAndToolBarOnMac(true);
115
116         // Create actions
117
118         quitAppAct = new QAction(tr("E&xit"), this);
119 //      quitAppAct->setShortcuts(QKeySequence::Quit);
120 //      quitAppAct->setShortcut(QKeySequence(tr("Alt+x")));
121         quitAppAct->setShortcut(QKeySequence(tr("Ctrl+q")));
122         quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
123         connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
124
125         powerGreen.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
126         powerGreen.addFile(":/res/power-on-green.png", QSize(), QIcon::Normal, QIcon::On);
127         powerRed.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
128         powerRed.addFile(":/res/power-on-red.png", QSize(), QIcon::Normal, QIcon::On);
129
130 //      powerAct = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
131         powerAct = new QAction(powerGreen, tr("&Power"), this);
132         powerAct->setStatusTip(tr("Powers Jaguar on/off"));
133         powerAct->setCheckable(true);
134         powerAct->setChecked(false);
135 //      powerAct->setDisabled(true);
136         connect(powerAct, SIGNAL(triggered()), this, SLOT(TogglePowerState()));
137
138         QIcon pauseIcon;
139         pauseIcon.addFile(":/res/pause-off", QSize(), QIcon::Normal, QIcon::Off);
140         pauseIcon.addFile(":/res/pause-on", QSize(), QIcon::Normal, QIcon::On);
141 //      pauseAct = new QAction(QIcon(":/res/pause.png"), tr("Pause"), this);
142         pauseAct = new QAction(pauseIcon, tr("Pause"), this);
143         pauseAct->setStatusTip(tr("Toggles the running state"));
144         pauseAct->setCheckable(true);
145         pauseAct->setDisabled(true);
146         pauseAct->setShortcut(QKeySequence(tr("Esc")));
147         connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
148
149         zoomActs = new QActionGroup(this);
150
151         x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
152         x1Act->setStatusTip(tr("Set window zoom to 100%"));
153         x1Act->setCheckable(true);
154         connect(x1Act, SIGNAL(triggered()), this, SLOT(SetZoom100()));
155
156         x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
157         x2Act->setStatusTip(tr("Set window zoom to 200%"));
158         x2Act->setCheckable(true);
159         connect(x2Act, SIGNAL(triggered()), this, SLOT(SetZoom200()));
160
161         x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
162         x3Act->setStatusTip(tr("Set window zoom to 300%"));
163         x3Act->setCheckable(true);
164         connect(x3Act, SIGNAL(triggered()), this, SLOT(SetZoom300()));
165
166         tvTypeActs = new QActionGroup(this);
167
168         ntscAct = new QAction(QIcon(":/res/ntsc.png"), tr("NTSC"), tvTypeActs);
169         ntscAct->setStatusTip(tr("Sets Jaguar to NTSC mode"));
170         ntscAct->setCheckable(true);
171         connect(ntscAct, SIGNAL(triggered()), this, SLOT(SetNTSC()));
172
173         palAct = new QAction(QIcon(":/res/pal.png"), tr("PAL"), tvTypeActs);
174         palAct->setStatusTip(tr("Sets Jaguar to PAL mode"));
175         palAct->setCheckable(true);
176         connect(palAct, SIGNAL(triggered()), this, SLOT(SetPAL()));
177
178         blurAct = new QAction(QIcon(":/res/generic.png"), tr("Blur"), this);
179         blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
180         blurAct->setCheckable(true);
181         connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
182
183         aboutAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&About..."), this);
184         aboutAct->setStatusTip(tr("Blatant self-promotion"));
185         connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
186
187         helpAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&Contents..."), this);
188         helpAct->setStatusTip(tr("Help is available, if you should need it"));
189         connect(helpAct, SIGNAL(triggered()), this, SLOT(ShowHelpWin()));
190
191         filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this);
192         filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar"));
193         filePickAct->setShortcut(QKeySequence(tr("Ctrl+i")));
194         connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart()));
195
196         configAct = new QAction(QIcon(":/res/wrench.png"), tr("&Configure"), this);
197         configAct->setStatusTip(tr("Configure options for Virtual Jaguar"));
198         configAct->setShortcut(QKeySequence(tr("Ctrl+c")));
199         connect(configAct, SIGNAL(triggered()), this, SLOT(Configure()));
200
201         useCDAct = new QAction(QIcon(":/res/compact-disc.png"), tr("&Use CD Unit"), this);
202         useCDAct->setStatusTip(tr("Use Jaguar Virtual CD unit"));
203 //      useCDAct->setShortcut(QKeySequence(tr("Ctrl+c")));
204         useCDAct->setCheckable(true);
205         connect(useCDAct, SIGNAL(triggered()), this, SLOT(ToggleCDUsage()));
206
207         frameAdvanceAct = new QAction(QIcon(":/res/frame-advance.png"), tr("&Frame Advance"), this);
208         frameAdvanceAct->setShortcut(QKeySequence(tr("F7")));
209         connect(frameAdvanceAct, SIGNAL(triggered()), this, SLOT(FrameAdvance()));
210
211         fullScreenAct = new QAction(QIcon(":/res/generic.png"), tr("F&ull Screen"), this);
212         fullScreenAct->setShortcut(QKeySequence(tr("F9")));
213         connect(fullScreenAct, SIGNAL(triggered()), this, SLOT(ToggleFullScreen()));
214
215         // Debugger Actions
216         memBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("Memory Browser"), this);
217         memBrowseAct->setStatusTip(tr("Shows the Jaguar memory browser window"));
218 //      memBrowseAct->setCheckable(true);
219         connect(memBrowseAct, SIGNAL(triggered()), this, SLOT(ShowMemoryBrowserWin()));
220
221         cpuBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("CPU Browser"), this);
222         cpuBrowseAct->setStatusTip(tr("Shows the Jaguar CPU browser window"));
223 //      memBrowseAct->setCheckable(true);
224         connect(cpuBrowseAct, SIGNAL(triggered()), this, SLOT(ShowCPUBrowserWin()));
225
226         opBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("OP Browser"), this);
227         opBrowseAct->setStatusTip(tr("Shows the Jaguar OP browser window"));
228 //      memBrowseAct->setCheckable(true);
229         connect(opBrowseAct, SIGNAL(triggered()), this, SLOT(ShowOPBrowserWin()));
230
231         m68kDasmBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("68K Listing Browser"), this);
232         m68kDasmBrowseAct->setStatusTip(tr("Shows the 68K disassembly browser window"));
233 //      memBrowseAct->setCheckable(true);
234         connect(m68kDasmBrowseAct, SIGNAL(triggered()), this, SLOT(ShowM68KDasmBrowserWin()));
235
236         riscDasmBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("RISC Listing Browser"), this);
237         riscDasmBrowseAct->setStatusTip(tr("Shows the RISC disassembly browser window"));
238 //      memBrowseAct->setCheckable(true);
239         connect(riscDasmBrowseAct, SIGNAL(triggered()), this, SLOT(ShowRISCDasmBrowserWin()));
240
241         // Misc. connections...
242         connect(filePickWin, SIGNAL(RequestLoad(QString)), this, SLOT(LoadSoftware(QString)));
243         connect(filePickWin, SIGNAL(FilePickerHiding()), this, SLOT(Unpause()));
244
245         // Create menus & toolbars
246
247         fileMenu = menuBar()->addMenu(tr("&Jaguar"));
248         fileMenu->addAction(powerAct);
249         fileMenu->addAction(pauseAct);
250         fileMenu->addAction(frameAdvanceAct);
251         fileMenu->addAction(filePickAct);
252         fileMenu->addAction(useCDAct);
253         fileMenu->addAction(configAct);
254         fileMenu->addAction(quitAppAct);
255
256         if (vjs.hardwareTypeAlpine)
257         {
258                 debugMenu = menuBar()->addMenu(tr("&Debug"));
259                 debugMenu->addAction(memBrowseAct);
260                 debugMenu->addAction(cpuBrowseAct);
261                 debugMenu->addAction(opBrowseAct);
262                 debugMenu->addAction(m68kDasmBrowseAct);
263                 debugMenu->addAction(riscDasmBrowseAct);
264         }
265
266         helpMenu = menuBar()->addMenu(tr("&Help"));
267         helpMenu->addAction(helpAct);
268         helpMenu->addAction(aboutAct);
269
270         toolbar = addToolBar(tr("Stuff"));
271         toolbar->addAction(powerAct);
272         toolbar->addAction(pauseAct);
273         toolbar->addAction(filePickAct);
274         toolbar->addAction(useCDAct);
275         toolbar->addSeparator();
276         toolbar->addAction(x1Act);
277         toolbar->addAction(x2Act);
278         toolbar->addAction(x3Act);
279         toolbar->addSeparator();
280         toolbar->addAction(ntscAct);
281         toolbar->addAction(palAct);
282         toolbar->addSeparator();
283         toolbar->addAction(blurAct);
284         toolbar->addAction(fullScreenAct);
285
286         if (vjs.hardwareTypeAlpine)
287         {
288                 debugbar = addToolBar(tr("&Debug"));
289                 debugbar->addAction(memBrowseAct);
290                 debugbar->addAction(cpuBrowseAct);
291                 debugbar->addAction(opBrowseAct);
292                 debugbar->addAction(m68kDasmBrowseAct);
293                 debugbar->addAction(riscDasmBrowseAct);
294         }
295
296         //      Create status bar
297         statusBar()->showMessage(tr("Ready"));
298
299         ReadSettings();
300
301         // Do this in case original size isn't correct (mostly for the first-run case)
302         ResizeMainWindow();
303
304         // Set up timer based loop for animation...
305         timer = new QTimer(this);
306         connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
307
308         // This isn't very accurate for NTSC: This is early by 40 msec per frame.
309         // This is because it's discarding the 0.6666... on the end of the fraction.
310         // Alas, 6 doesn't divide cleanly into 10. :-P
311 //Should we defer this until SyncUI? Probably.
312 //No, it doesn't work, because it uses setInterval() instead of start()...
313 //      timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
314
315         // We set this initially, to make VJ behave somewhat as it would if no
316         // cart were inserted and the BIOS was set as active...
317         jaguarCartInserted = true;
318         WriteLog("Virtual Jaguar %s (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
319         WriteLog("VJ: Initializing jaguar subsystem...\n");
320         JaguarInit();
321         memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
322
323         // Check for filename passed in on the command line...
324 //      if (!filenameToRun.isEmpty())
325         if (autoRun)
326         {
327 //              loadAndGo = true;
328                 // Attempt to load/run the file the user passed in...
329 //              LoadSoftware(filenameToRun);
330 ////            memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
331                 // Prevent the file scanner from running...
332                 return;
333         }
334
335         // Load up the default ROM if in Alpine mode:
336         if (vjs.hardwareTypeAlpine)
337         {
338                 bool romLoaded = JaguarLoadFile(vjs.alpineROMPath);
339
340                 // If regular load failed, try just a straight file load
341                 // (Dev only! I don't want people to start getting lazy with their releases again! :-P)
342                 if (!romLoaded)
343                         romLoaded = AlpineLoadFile(vjs.alpineROMPath);
344
345                 if (romLoaded)
346                         WriteLog("Alpine Mode: Successfully loaded file \"%s\".\n", vjs.alpineROMPath);
347                 else
348                         WriteLog("Alpine Mode: Unable to load file \"%s\"!\n", vjs.alpineROMPath);
349
350                 // Attempt to load/run the ABS file...
351                 LoadSoftware(vjs.absROMPath);
352                 memcpy(jagMemSpace + 0xE00000, jaguarDevBootROM2, 0x20000);     // Use the stub BIOS
353                 // Prevent the scanner from running...
354                 return;
355         }
356 //      else
357 //              memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Otherwise, use the stock BIOS
358
359         // Run the scanner if nothing passed in and *not* Alpine mode...
360         // NB: Really need to look into caching the info scanned in here...
361         filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
362 }
363
364
365 void MainWin::LoadFile(QString file)
366 {
367         LoadSoftware(file);
368 }
369
370
371 void MainWin::SyncUI(void)
372 {
373         // Set toolbar buttons/menus based on settings read in (sync the UI)...
374         // (Really, this is to sync command line options passed in)
375         blurAct->setChecked(vjs.glFilter);
376         x1Act->setChecked(zoomLevel == 1);
377         x2Act->setChecked(zoomLevel == 2);
378         x3Act->setChecked(zoomLevel == 3);
379 //      running = powerAct->isChecked();
380         ntscAct->setChecked(vjs.hardwareTypeNTSC);
381         palAct->setChecked(!vjs.hardwareTypeNTSC);
382         powerAct->setIcon(vjs.hardwareTypeNTSC ? powerRed : powerGreen);
383
384         fullScreen = vjs.fullscreen;
385         SetFullScreen(fullScreen);
386
387         // Reset the timer to be what was set in the command line (if any):
388 //      timer->setInterval(vjs.hardwareTypeNTSC ? 16 : 20);
389         timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
390 }
391
392
393 void MainWin::closeEvent(QCloseEvent * event)
394 {
395         JaguarDone();
396 // This should only be done by the config dialog
397 //      WriteSettings();
398         WriteUISettings();
399         event->accept(); // ignore() if can't close for some reason
400 }
401
402
403 void MainWin::keyPressEvent(QKeyEvent * e)
404 {
405         // We ignore the Alt key for now, since it causes problems with the GUI
406         if (e->key() == Qt::Key_Alt)
407         {
408                 e->accept();
409                 return;
410         }
411 /*
412         if (e->key() == Qt::Key_F9)
413         {
414                 ToggleFullScreen();
415                 return;
416         }
417 */
418         HandleKeys(e, true);
419 }
420
421
422 void MainWin::keyReleaseEvent(QKeyEvent * e)
423 {
424         // We ignore the Alt key for now, since it causes problems with the GUI
425         if (e->key() == Qt::Key_Alt)
426         {
427                 e->accept();
428                 return;
429         }
430
431         HandleKeys(e, false);
432 }
433
434
435 void MainWin::HandleKeys(QKeyEvent * e, bool state)
436 {
437         enum { P1LEFT = 0, P1RIGHT, P1UP, P1DOWN, P2LEFT, P2RIGHT, P2UP, P2DOWN };
438         // We kill bad key combos here, before they can get to the emulator...
439         // This also kills the illegal instruction problem that cropped up in Rayman!
440         // May want to do this by killing the old one instead of ignoring the new one...
441         // Seems to work better that way...
442
443 // The problem with this approach is that it causes bad results because it doesn't do
444 // any checking of previous states. Need to come up with something better because this
445 // causes problems where the keyboard acts as if it were unresponsive. :-P
446 #if 0
447         if ((e->key() == vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
448                 || (e->key() == vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
449                 || (e->key() == vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
450                 || (e->key() == vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U]))
451                 return;
452 #else
453 #if 0
454         if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
455                 joypad_0_buttons[BUTTON_R] = 0;
456         if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
457                 joypad_0_buttons[BUTTON_L] = 0;
458         if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
459                 joypad_0_buttons[BUTTON_D] = 0;
460         if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U])
461                 joypad_0_buttons[BUTTON_U] = 0;
462
463         if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L] && joypad_1_buttons[BUTTON_R])
464                 joypad_1_buttons[BUTTON_R] = 0;
465         if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R] && joypad_1_buttons[BUTTON_L])
466                 joypad_1_buttons[BUTTON_L] = 0;
467         if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U] && joypad_1_buttons[BUTTON_D])
468                 joypad_1_buttons[BUTTON_D] = 0;
469         if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D] && joypad_1_buttons[BUTTON_U])
470                 joypad_1_buttons[BUTTON_U] = 0;
471 #else
472 //hrm, this still has sticky state problems... Ugh!
473         // First, settle key states...
474         if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L])
475                 keyHeld[P1LEFT] = state;
476         else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R])
477                 keyHeld[P1RIGHT] = state;
478         else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U])
479                 keyHeld[P1UP] = state;
480         else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D])
481                 keyHeld[P1DOWN] = state;
482         else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L])
483                 keyHeld[P2LEFT] = state;
484         else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R])
485                 keyHeld[P2RIGHT] = state;
486         else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U])
487                 keyHeld[P2UP] = state;
488         else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D])
489                 keyHeld[P2DOWN] = state;
490
491         // Next, check for conflicts and bail out if there are any...
492         if ((keyHeld[P1LEFT] && keyHeld[P1RIGHT])
493                 || (keyHeld[P1UP] && keyHeld[P1DOWN])
494                 || (keyHeld[P2LEFT] && keyHeld[P2RIGHT])
495                 || (keyHeld[P2UP] && keyHeld[P2DOWN]))
496                 return;
497 #endif
498 #endif
499
500         // No bad combos exist, let's stuff the emulator key buffers...!
501         for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
502         {
503                 if (e->key() == (int)vjs.p1KeyBindings[i])
504 //                      joypad_0_buttons[i] = (uint8)state;
505                         joypad_0_buttons[i] = (state ? 0x01 : 0x00);
506
507 // Pad #2 is screwing up pad #1. Prolly a problem in joystick.cpp...
508 // So let's try to fix it there. :-P [DONE]
509                 if (e->key() == (int)vjs.p2KeyBindings[i])
510 //                      joypad_1_buttons[i] = (uint8)state;
511                         joypad_1_buttons[i] = (state ? 0x01 : 0x00);
512         }
513 }
514
515
516 void MainWin::HandleGamepads(void)
517 {
518         Gamepad::Update();
519
520         for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
521         {
522                 if (vjs.p1KeyBindings[i] & (JOY_BUTTON | JOY_HAT))
523                         joypad_0_buttons[i] = (Gamepad::GetState(0, vjs.p1KeyBindings[i]) ? 0x01 : 0x00);
524
525                 if (vjs.p2KeyBindings[i] & (JOY_BUTTON | JOY_HAT))
526                         joypad_1_buttons[i] = (Gamepad::GetState(1, vjs.p2KeyBindings[i]) ? 0x01 : 0x00);
527         }
528 }
529
530
531 void MainWin::Open(void)
532 {
533 }
534
535
536 void MainWin::Configure(void)
537 {
538         // Call the configuration dialog and update settings
539         ConfigDialog dlg(this);
540         //ick.
541         dlg.generalTab->useUnknownSoftware->setChecked(allowUnknownSoftware);
542
543         if (dlg.exec() == false)
544                 return;
545
546         QString before = vjs.ROMPath;
547         QString alpineBefore = vjs.alpineROMPath;
548         QString absBefore = vjs.absROMPath;
549 //      bool audioBefore = vjs.audioEnabled;
550         bool audioBefore = vjs.DSPEnabled;
551         dlg.UpdateVJSettings();
552         QString after = vjs.ROMPath;
553         QString alpineAfter = vjs.alpineROMPath;
554         QString absAfter = vjs.absROMPath;
555 //      bool audioAfter = vjs.audioEnabled;
556         bool audioAfter = vjs.DSPEnabled;
557
558         bool allowOld = allowUnknownSoftware;
559         //ick.
560         allowUnknownSoftware = dlg.generalTab->useUnknownSoftware->isChecked();
561
562         // We rescan the "software" folder if the user either changed the path or
563         // checked/unchecked the "Allow unknown files" option in the config dialog.
564         if ((before != after) || (allowOld != allowUnknownSoftware))
565                 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
566
567         // If the "Alpine" ROM is changed, then let's load it...
568         if (alpineBefore != alpineAfter)
569         {
570                 if (!JaguarLoadFile(vjs.alpineROMPath) && !AlpineLoadFile(vjs.alpineROMPath))
571                 {
572                         // Oh crap, we couldn't get the file! Alert the media!
573                         QMessageBox msg;
574                         msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.alpineROMPath));
575                         msg.setIcon(QMessageBox::Warning);
576                         msg.exec();
577                 }
578         }
579
580         // If the "ABS" ROM is changed, then let's load it...
581         if (absBefore != absAfter)
582         {
583                 if (!JaguarLoadFile(vjs.absROMPath))
584                 {
585                         // Oh crap, we couldn't get the file! Alert the media!
586                         QMessageBox msg;
587                         msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.absROMPath));
588                         msg.setIcon(QMessageBox::Warning);
589                         msg.exec();
590                 }
591         }
592
593         // If the "Enable DSP" checkbox changed, then we have to re-init the DAC,
594         // since it's running in the host audio IRQ...
595         if (audioBefore != audioAfter)
596         {
597                 DACDone();
598                 DACInit();
599         }
600
601         // Just in case we crash before a clean exit...
602         WriteSettings();
603 }
604
605
606 //
607 // Here's the main emulator loop
608 //
609 void MainWin::Timer(void)
610 {
611         if (!running)
612                 return;
613
614         if (showUntunedTankCircuit)
615         {
616                 // Some machines can't handle this, so we give them the option to disable it. :-)
617                 if (!plzDontKillMyComputer)
618                 {
619                         // Random hash & trash
620                         // We try to simulate an untuned tank circuit here... :-)
621                         for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
622                         {
623                                 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
624                                 {
625                                         videoWidget->buffer[(y * videoWidget->textureWidth) + x]
626                                                 = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;
627                                 }
628                         }
629                 }
630         }
631         else
632         {
633                 // Otherwise, run the Jaguar simulation
634                 HandleGamepads();
635                 JaguarExecuteNew();
636         }
637
638         videoWidget->updateGL();
639 }
640
641
642 void MainWin::TogglePowerState(void)
643 {
644         powerButtonOn = !powerButtonOn;
645         running = true;
646
647         // With the power off, we simulate white noise on the screen. :-)
648         if (!powerButtonOn)
649         {
650                 useCDAct->setDisabled(false);
651                 palAct->setDisabled(false);
652                 ntscAct->setDisabled(false);
653                 pauseAct->setChecked(false);
654                 pauseAct->setDisabled(true);
655                 showUntunedTankCircuit = true;
656                 // This is just in case the ROM we were playing was in a narrow or wide field mode,
657                 // so the untuned tank sim doesn't look wrong. :-)
658                 DACPauseAudioThread();
659                 TOMReset();
660         }
661         else
662         {
663                 useCDAct->setDisabled(true);
664                 palAct->setDisabled(true);
665                 ntscAct->setDisabled(true);
666                 pauseAct->setChecked(false);
667                 pauseAct->setDisabled(false);
668                 showUntunedTankCircuit = false;
669
670                 // Otherwise, we prepare for running regular software...
671                 if (CDActive)
672                 {
673 // Should check for cartridgeLoaded here as well...!
674 // We can clear it when toggling CDActive on, so that when we power cycle it does the
675 // expected thing. Otherwise, if we use the file picker to insert a cart, we expect
676 // to run the cart! Maybe have a RemoveCart function that only works if the CD unit
677 // is active?
678                         setWindowTitle(QString("Virtual Jaguar " VJ_RELEASE_VERSION
679                                 " - Now playing: Jaguar CD"));
680                 }
681
682                 WriteLog("GUI: Resetting Jaguar...\n");
683                 JaguarReset();
684                 DACPauseAudioThread(false);
685         }
686 }
687
688
689 void MainWin::ToggleRunState(void)
690 {
691         running = !running;
692
693         if (!running)
694         {
695                 for(uint32_t i=0; i<(uint32_t)(videoWidget->textureWidth * 256); i++)
696                 {
697                         uint32_t pixel = videoWidget->buffer[i];
698                         uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
699                         pixel = ((r + g + b) / 3) & 0x00FF;
700                         videoWidget->buffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
701                 }
702
703                 videoWidget->updateGL();
704         }
705
706         // Pause/unpause any running/non-running threads...
707         DACPauseAudioThread(!running);
708 }
709
710
711 void MainWin::SetZoom100(void)
712 {
713         zoomLevel = 1;
714         ResizeMainWindow();
715 }
716
717
718 void MainWin::SetZoom200(void)
719 {
720         zoomLevel = 2;
721         ResizeMainWindow();
722 }
723
724
725 void MainWin::SetZoom300(void)
726 {
727         zoomLevel = 3;
728         ResizeMainWindow();
729 }
730
731
732 void MainWin::SetNTSC(void)
733 {
734         powerAct->setIcon(powerRed);
735         timer->setInterval(16);
736         vjs.hardwareTypeNTSC = true;
737         ResizeMainWindow();
738         WriteSettings();
739 }
740
741
742 void MainWin::SetPAL(void)
743 {
744         powerAct->setIcon(powerGreen);
745         timer->setInterval(20);
746         vjs.hardwareTypeNTSC = false;
747         ResizeMainWindow();
748         WriteSettings();
749 }
750
751
752 void MainWin::ToggleBlur(void)
753 {
754         vjs.glFilter = !vjs.glFilter;
755         WriteSettings();
756 }
757
758
759 void MainWin::ShowAboutWin(void)
760 {
761         aboutWin->show();
762 }
763
764
765 void MainWin::ShowHelpWin(void)
766 {
767         helpWin->show();
768 }
769
770
771 void MainWin::InsertCart(void)
772 {
773         // If the emulator is running, we pause it here and unpause it later
774         // if we dismiss the file selector without choosing anything
775         if (running && powerButtonOn)
776         {
777                 ToggleRunState();
778                 pauseForFileSelector = true;
779         }
780
781         filePickWin->show();
782 }
783
784
785 void MainWin::Unpause(void)
786 {
787         // Here we unpause the emulator if it was paused when we went into the file selector
788         if (pauseForFileSelector)
789         {
790                 pauseForFileSelector = false;
791
792                 // Some nutter might have unpaused while in the file selector, so check for that
793                 if (!running)
794                         ToggleRunState();
795         }
796 }
797
798
799 void MainWin::LoadSoftware(QString file)
800 {
801         running = false;                                                        // Prevent bad things(TM) from happening...
802         pauseForFileSelector = false;                           // Reset the file selector pause flag
803         SET32(jaguarMainRAM, 0, 0x00200000);            // Set top of stack...
804         cartridgeLoaded = JaguarLoadFile(file.toAscii().data());
805
806         char * biosPointer = jaguarBootROM;
807
808         if (vjs.hardwareTypeAlpine)
809                 biosPointer = jaguarDevBootROM2;
810
811         memcpy(jagMemSpace + 0xE00000, biosPointer, 0x20000);
812
813         powerAct->setDisabled(false);
814         powerAct->setChecked(true);
815         powerButtonOn = false;
816         TogglePowerState();
817
818         if (!vjs.hardwareTypeAlpine && !loadAndGo)
819         {
820                 QString newTitle = QString("Virtual Jaguar " VJ_RELEASE_VERSION " - Now playing: %1")
821                         .arg(filePickWin->GetSelectedPrettyName());
822                 setWindowTitle(newTitle);
823         }
824 }
825
826
827 void MainWin::ToggleCDUsage(void)
828 {
829         CDActive = !CDActive;
830
831 #if 0
832         if (CDActive)
833         {
834                 powerAct->setDisabled(false);
835         }
836         else
837         {
838                 powerAct->setDisabled(true);
839         }
840 #else
841         // Set up the Jaguar CD for execution, otherwise, clear memory
842         if (CDActive)
843                 memcpy(jagMemSpace + 0x800000, jaguarCDBootROM, 0x40000);
844         else
845                 memset(jagMemSpace + 0x800000, 0xFF, 0x40000);
846 #endif
847 }
848
849
850 void MainWin::FrameAdvance(void)
851 {
852 //printf("Frame Advance...\n");
853         // Execute 1 frame, then exit (only useful in Pause mode)
854         JaguarExecuteNew();
855         videoWidget->updateGL();
856 }
857
858
859 void MainWin::SetFullScreen(bool state/*= true*/)
860 {
861         if (state)
862         {
863                 mainWinPosition = pos();
864 //              mainWinSize = size();
865                 menuBar()->hide();
866                 statusBar()->hide();
867                 showFullScreen();
868                 QRect r = QApplication::desktop()->availableGeometry();
869 //              double targetWidth = 320.0, targetHeight = (vjs.hardwareTypeNTSC ? 240.0 : 256.0);
870                 double targetWidth = (double)VIRTUAL_SCREEN_WIDTH,
871                         targetHeight = (double)(vjs.hardwareTypeNTSC ? VIRTUAL_SCREEN_HEIGHT_NTSC : VIRTUAL_SCREEN_HEIGHT_PAL);
872                 double aspectRatio = targetWidth / targetHeight;
873                 // NOTE: Really should check here to see which dimension constrains the other.
874                 //       Right now, we assume that height is the constraint.
875                 int newWidth = (int)(aspectRatio * (double)r.height());
876
877                 videoWidget->setFixedSize(newWidth, r.height());
878                 showFullScreen();
879         }
880         else
881         {
882                 menuBar()->show();
883                 statusBar()->show();
884                 showNormal();
885                 ResizeMainWindow();
886                 move(mainWinPosition);
887         }
888
889         // For some reason, this doesn't work: If the emu is paused, toggling from
890         // fullscreen to windowed (& vice versa) shows a white screen.
891 //      videoWidget->updateGL();
892 }
893
894
895 void MainWin::ToggleFullScreen(void)
896 {
897         fullScreen = !fullScreen;
898         SetFullScreen(fullScreen);
899 }
900
901
902 void MainWin::ShowMemoryBrowserWin(void)
903 {
904         memBrowseWin->show();
905         memBrowseWin->RefreshContents();
906 }
907
908
909 void MainWin::ShowCPUBrowserWin(void)
910 {
911         cpuBrowseWin->show();
912         cpuBrowseWin->RefreshContents();
913 }
914
915
916 void MainWin::ShowOPBrowserWin(void)
917 {
918         opBrowseWin->show();
919         opBrowseWin->RefreshContents();
920 }
921
922
923 void MainWin::ShowM68KDasmBrowserWin(void)
924 {
925         m68kDasmBrowseWin->show();
926         m68kDasmBrowseWin->RefreshContents();
927 }
928
929
930 void MainWin::ShowRISCDasmBrowserWin(void)
931 {
932         riscDasmBrowseWin->show();
933         riscDasmBrowseWin->RefreshContents();
934 }
935
936
937 void MainWin::ResizeMainWindow(void)
938 {
939 //      videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
940         videoWidget->setFixedSize(zoomLevel * VIRTUAL_SCREEN_WIDTH,
941                 zoomLevel * (vjs.hardwareTypeNTSC ? VIRTUAL_SCREEN_HEIGHT_NTSC : VIRTUAL_SCREEN_HEIGHT_PAL));
942         show();
943
944         for(int i=0; i<2; i++)
945         {
946                 resize(0, 0);
947                 usleep(2000);
948                 QApplication::processEvents();
949         }
950 }
951
952
953 #warning "!!! Need to check the window geometry to see if the positions are legal !!!"
954 // i.e., someone could drag it to another screen, close it, then disconnect that screen
955 void MainWin::ReadSettings(void)
956 {
957         QSettings settings("Underground Software", "Virtual Jaguar");
958         mainWinPosition = settings.value("pos", QPoint(200, 200)).toPoint();
959         QSize size = settings.value("size", QSize(400, 400)).toSize();
960         resize(size);
961         move(mainWinPosition);
962         QPoint pos = settings.value("cartLoadPos", QPoint(200, 200)).toPoint();
963         filePickWin->move(pos);
964
965         zoomLevel = settings.value("zoom", 2).toInt();
966         allowUnknownSoftware = settings.value("showUnknownSoftware", false).toBool();
967
968         vjs.useJoystick      = settings.value("useJoystick", false).toBool();
969         vjs.joyport          = settings.value("joyport", 0).toInt();
970         vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
971         vjs.frameSkip        = settings.value("frameSkip", 0).toInt();
972         vjs.useJaguarBIOS    = settings.value("useJaguarBIOS", false).toBool();
973         vjs.GPUEnabled       = settings.value("GPUEnabled", true).toBool();
974         vjs.DSPEnabled       = settings.value("DSPEnabled", false).toBool();
975         vjs.audioEnabled     = settings.value("audioEnabled", true).toBool();
976         vjs.usePipelinedDSP  = settings.value("usePipelinedDSP", false).toBool();
977         vjs.fullscreen       = settings.value("fullscreen", false).toBool();
978         vjs.useOpenGL        = settings.value("useOpenGL", true).toBool();
979         vjs.glFilter         = settings.value("glFilterType", 1).toInt();
980         vjs.renderType       = settings.value("renderType", 0).toInt();
981         vjs.allowWritesToROM = settings.value("writeROM", false).toBool();
982 //      strcpy(vjs.jagBootPath, settings.value("JagBootROM", "./bios/[BIOS] Atari Jaguar (USA, Europe).zip").toString().toAscii().data());
983 //      strcpy(vjs.CDBootPath, settings.value("CDBootROM", "./bios/jagcd.rom").toString().toAscii().data());
984         strcpy(vjs.EEPROMPath, settings.value("EEPROMs", "./eeproms/").toString().toAscii().data());
985         strcpy(vjs.ROMPath, settings.value("ROMs", "./software/").toString().toAscii().data());
986         strcpy(vjs.alpineROMPath, settings.value("DefaultROM", "").toString().toAscii().data());
987         strcpy(vjs.absROMPath, settings.value("DefaultABS", "").toString().toAscii().data());
988 WriteLog("MainWin: Paths\n");
989 //WriteLog("    jagBootPath = \"%s\"\n", vjs.jagBootPath);
990 //WriteLog("    CDBootPath  = \"%s\"\n", vjs.CDBootPath);
991 WriteLog("   EEPROMPath = \"%s\"\n", vjs.EEPROMPath);
992 WriteLog("      ROMPath = \"%s\"\n", vjs.ROMPath);
993 WriteLog("AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);
994 WriteLog("   absROMPath = \"%s\"\n", vjs.absROMPath);
995 WriteLog("Pipelined DSP = %s\n", (vjs.usePipelinedDSP ? "ON" : "off"));
996
997         // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
998         vjs.p1KeyBindings[BUTTON_U] = settings.value("p1k_up", Qt::Key_S).toInt();
999         vjs.p1KeyBindings[BUTTON_D] = settings.value("p1k_down", Qt::Key_X).toInt();
1000         vjs.p1KeyBindings[BUTTON_L] = settings.value("p1k_left", Qt::Key_A).toInt();
1001         vjs.p1KeyBindings[BUTTON_R] = settings.value("p1k_right", Qt::Key_D).toInt();
1002         vjs.p1KeyBindings[BUTTON_C] = settings.value("p1k_c", Qt::Key_J).toInt();
1003         vjs.p1KeyBindings[BUTTON_B] = settings.value("p1k_b", Qt::Key_K).toInt();
1004         vjs.p1KeyBindings[BUTTON_A] = settings.value("p1k_a", Qt::Key_L).toInt();
1005         vjs.p1KeyBindings[BUTTON_OPTION] = settings.value("p1k_option", Qt::Key_O).toInt();
1006         vjs.p1KeyBindings[BUTTON_PAUSE] = settings.value("p1k_pause", Qt::Key_P).toInt();
1007         vjs.p1KeyBindings[BUTTON_0] = settings.value("p1k_0", Qt::Key_0).toInt();
1008         vjs.p1KeyBindings[BUTTON_1] = settings.value("p1k_1", Qt::Key_1).toInt();
1009         vjs.p1KeyBindings[BUTTON_2] = settings.value("p1k_2", Qt::Key_2).toInt();
1010         vjs.p1KeyBindings[BUTTON_3] = settings.value("p1k_3", Qt::Key_3).toInt();
1011         vjs.p1KeyBindings[BUTTON_4] = settings.value("p1k_4", Qt::Key_4).toInt();
1012         vjs.p1KeyBindings[BUTTON_5] = settings.value("p1k_5", Qt::Key_5).toInt();
1013         vjs.p1KeyBindings[BUTTON_6] = settings.value("p1k_6", Qt::Key_6).toInt();
1014         vjs.p1KeyBindings[BUTTON_7] = settings.value("p1k_7", Qt::Key_7).toInt();
1015         vjs.p1KeyBindings[BUTTON_8] = settings.value("p1k_8", Qt::Key_8).toInt();
1016         vjs.p1KeyBindings[BUTTON_9] = settings.value("p1k_9", Qt::Key_9).toInt();
1017         vjs.p1KeyBindings[BUTTON_d] = settings.value("p1k_pound", Qt::Key_Minus).toInt();
1018         vjs.p1KeyBindings[BUTTON_s] = settings.value("p1k_star", Qt::Key_Equal).toInt();
1019
1020         vjs.p2KeyBindings[BUTTON_U] = settings.value("p2k_up", Qt::Key_Up).toInt();
1021         vjs.p2KeyBindings[BUTTON_D] = settings.value("p2k_down", Qt::Key_Down).toInt();
1022         vjs.p2KeyBindings[BUTTON_L] = settings.value("p2k_left", Qt::Key_Left).toInt();
1023         vjs.p2KeyBindings[BUTTON_R] = settings.value("p2k_right", Qt::Key_Right).toInt();
1024         vjs.p2KeyBindings[BUTTON_C] = settings.value("p2k_c", Qt::Key_Z).toInt();
1025         vjs.p2KeyBindings[BUTTON_B] = settings.value("p2k_b", Qt::Key_X).toInt();
1026         vjs.p2KeyBindings[BUTTON_A] = settings.value("p2k_a", Qt::Key_C).toInt();
1027         vjs.p2KeyBindings[BUTTON_OPTION] = settings.value("p2k_option", Qt::Key_Apostrophe).toInt();
1028         vjs.p2KeyBindings[BUTTON_PAUSE] = settings.value("p2k_pause", Qt::Key_Return).toInt();
1029         vjs.p2KeyBindings[BUTTON_0] = settings.value("p2k_0", Qt::Key_0).toInt();
1030         vjs.p2KeyBindings[BUTTON_1] = settings.value("p2k_1", Qt::Key_1).toInt();
1031         vjs.p2KeyBindings[BUTTON_2] = settings.value("p2k_2", Qt::Key_2).toInt();
1032         vjs.p2KeyBindings[BUTTON_3] = settings.value("p2k_3", Qt::Key_3).toInt();
1033         vjs.p2KeyBindings[BUTTON_4] = settings.value("p2k_4", Qt::Key_4).toInt();
1034         vjs.p2KeyBindings[BUTTON_5] = settings.value("p2k_5", Qt::Key_5).toInt();
1035         vjs.p2KeyBindings[BUTTON_6] = settings.value("p2k_6", Qt::Key_6).toInt();
1036         vjs.p2KeyBindings[BUTTON_7] = settings.value("p2k_7", Qt::Key_7).toInt();
1037         vjs.p2KeyBindings[BUTTON_8] = settings.value("p2k_8", Qt::Key_8).toInt();
1038         vjs.p2KeyBindings[BUTTON_9] = settings.value("p2k_9", Qt::Key_9).toInt();
1039         vjs.p2KeyBindings[BUTTON_d] = settings.value("p2k_pound", Qt::Key_Slash).toInt();
1040         vjs.p2KeyBindings[BUTTON_s] = settings.value("p2k_star", Qt::Key_Asterisk).toInt();
1041 }
1042
1043
1044 void MainWin::WriteSettings(void)
1045 {
1046         QSettings settings("Underground Software", "Virtual Jaguar");
1047         settings.setValue("pos", pos());
1048         settings.setValue("size", size());
1049         settings.setValue("cartLoadPos", filePickWin->pos());
1050
1051         settings.setValue("zoom", zoomLevel);
1052         settings.setValue("showUnknownSoftware", allowUnknownSoftware);
1053
1054         settings.setValue("useJoystick", vjs.useJoystick);
1055         settings.setValue("joyport", vjs.joyport);
1056         settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
1057         settings.setValue("frameSkip", vjs.frameSkip);
1058         settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
1059         settings.setValue("GPUEnabled", vjs.GPUEnabled);
1060         settings.setValue("DSPEnabled", vjs.DSPEnabled);
1061         settings.setValue("audioEnabled", vjs.audioEnabled);
1062         settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
1063         settings.setValue("fullscreen", vjs.fullscreen);
1064         settings.setValue("useOpenGL", vjs.useOpenGL);
1065         settings.setValue("glFilterType", vjs.glFilter);
1066         settings.setValue("renderType", vjs.renderType);
1067         settings.setValue("writeROM", vjs.allowWritesToROM);
1068         settings.setValue("JagBootROM", vjs.jagBootPath);
1069         settings.setValue("CDBootROM", vjs.CDBootPath);
1070         settings.setValue("EEPROMs", vjs.EEPROMPath);
1071         settings.setValue("ROMs", vjs.ROMPath);
1072         settings.setValue("DefaultROM", vjs.alpineROMPath);
1073         settings.setValue("DefaultABS", vjs.absROMPath);
1074
1075         settings.setValue("p1k_up", vjs.p1KeyBindings[BUTTON_U]);
1076         settings.setValue("p1k_down", vjs.p1KeyBindings[BUTTON_D]);
1077         settings.setValue("p1k_left", vjs.p1KeyBindings[BUTTON_L]);
1078         settings.setValue("p1k_right", vjs.p1KeyBindings[BUTTON_R]);
1079         settings.setValue("p1k_c", vjs.p1KeyBindings[BUTTON_C]);
1080         settings.setValue("p1k_b", vjs.p1KeyBindings[BUTTON_B]);
1081         settings.setValue("p1k_a", vjs.p1KeyBindings[BUTTON_A]);
1082         settings.setValue("p1k_option", vjs.p1KeyBindings[BUTTON_OPTION]);
1083         settings.setValue("p1k_pause", vjs.p1KeyBindings[BUTTON_PAUSE]);
1084         settings.setValue("p1k_0", vjs.p1KeyBindings[BUTTON_0]);
1085         settings.setValue("p1k_1", vjs.p1KeyBindings[BUTTON_1]);
1086         settings.setValue("p1k_2", vjs.p1KeyBindings[BUTTON_2]);
1087         settings.setValue("p1k_3", vjs.p1KeyBindings[BUTTON_3]);
1088         settings.setValue("p1k_4", vjs.p1KeyBindings[BUTTON_4]);
1089         settings.setValue("p1k_5", vjs.p1KeyBindings[BUTTON_5]);
1090         settings.setValue("p1k_6", vjs.p1KeyBindings[BUTTON_6]);
1091         settings.setValue("p1k_7", vjs.p1KeyBindings[BUTTON_7]);
1092         settings.setValue("p1k_8", vjs.p1KeyBindings[BUTTON_8]);
1093         settings.setValue("p1k_9", vjs.p1KeyBindings[BUTTON_9]);
1094         settings.setValue("p1k_pound", vjs.p1KeyBindings[BUTTON_d]);
1095         settings.setValue("p1k_star", vjs.p1KeyBindings[BUTTON_s]);
1096
1097         settings.setValue("p2k_up", vjs.p2KeyBindings[BUTTON_U]);
1098         settings.setValue("p2k_down", vjs.p2KeyBindings[BUTTON_D]);
1099         settings.setValue("p2k_left", vjs.p2KeyBindings[BUTTON_L]);
1100         settings.setValue("p2k_right", vjs.p2KeyBindings[BUTTON_R]);
1101         settings.setValue("p2k_c", vjs.p2KeyBindings[BUTTON_C]);
1102         settings.setValue("p2k_b", vjs.p2KeyBindings[BUTTON_B]);
1103         settings.setValue("p2k_a", vjs.p2KeyBindings[BUTTON_A]);
1104         settings.setValue("p2k_option", vjs.p2KeyBindings[BUTTON_OPTION]);
1105         settings.setValue("p2k_pause", vjs.p2KeyBindings[BUTTON_PAUSE]);
1106         settings.setValue("p2k_0", vjs.p2KeyBindings[BUTTON_0]);
1107         settings.setValue("p2k_1", vjs.p2KeyBindings[BUTTON_1]);
1108         settings.setValue("p2k_2", vjs.p2KeyBindings[BUTTON_2]);
1109         settings.setValue("p2k_3", vjs.p2KeyBindings[BUTTON_3]);
1110         settings.setValue("p2k_4", vjs.p2KeyBindings[BUTTON_4]);
1111         settings.setValue("p2k_5", vjs.p2KeyBindings[BUTTON_5]);
1112         settings.setValue("p2k_6", vjs.p2KeyBindings[BUTTON_6]);
1113         settings.setValue("p2k_7", vjs.p2KeyBindings[BUTTON_7]);
1114         settings.setValue("p2k_8", vjs.p2KeyBindings[BUTTON_8]);
1115         settings.setValue("p2k_9", vjs.p2KeyBindings[BUTTON_9]);
1116         settings.setValue("p2k_pound", vjs.p2KeyBindings[BUTTON_d]);
1117         settings.setValue("p2k_star", vjs.p2KeyBindings[BUTTON_s]);
1118 }
1119
1120
1121 void MainWin::WriteUISettings(void)
1122 {
1123         QSettings settings("Underground Software", "Virtual Jaguar");
1124         settings.setValue("pos", pos());
1125         settings.setValue("size", size());
1126         settings.setValue("cartLoadPos", filePickWin->pos());
1127
1128         settings.setValue("zoom", zoomLevel);
1129 }