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