]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/mainwin.cpp
56c57473b51b8d8b1685a0913aee38a8088b05d4
[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 //This is only correct for PAL. !!! FIX !!! [DONE]
280 //Use timer->setInterval( int msec ) to fix this on the fly
281 //      timer->start(20);
282         // This isn't very accurate for NTSC: This is early by 40 msec per frame.
283         // This is because it's discarding the 0.6666... on the end of the fraction.
284         // Alas, 6 doesn't divide cleanly into 10. :-P
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
360
361 void MainWin::closeEvent(QCloseEvent * event)
362 {
363         JaguarDone();
364 // This should only be done by the config dialog
365 //      WriteSettings();
366         WriteUISettings();
367         event->accept(); // ignore() if can't close for some reason
368 }
369
370
371 void MainWin::keyPressEvent(QKeyEvent * e)
372 {
373         // We ignore the Alt key for now, since it causes problems with the GUI
374         if (e->key() == Qt::Key_Alt)
375         {
376                 e->accept();
377                 return;
378         }
379 /*
380         if (e->key() == Qt::Key_F9)
381         {
382                 ToggleFullScreen();
383                 return;
384         }
385 */
386         HandleKeys(e, true);
387 }
388
389
390 void MainWin::keyReleaseEvent(QKeyEvent * e)
391 {
392         // We ignore the Alt key for now, since it causes problems with the GUI
393         if (e->key() == Qt::Key_Alt)
394         {
395                 e->accept();
396                 return;
397         }
398
399         HandleKeys(e, false);
400 }
401
402
403 void MainWin::HandleKeys(QKeyEvent * e, bool state)
404 {
405         enum { P1LEFT = 0, P1RIGHT, P1UP, P1DOWN, P2LEFT, P2RIGHT, P2UP, P2DOWN };
406         // We kill bad key combos here, before they can get to the emulator...
407         // This also kills the illegal instruction problem that cropped up in Rayman!
408         // May want to do this by killing the old one instead of ignoring the new one...
409         // Seems to work better that way...
410
411 // The problem with this approach is that it causes bad results because it doesn't do
412 // any checking of previous states. Need to come up with something better because this
413 // causes problems where the keyboard acts as if it were unresponsive. :-P
414 #if 0
415         if ((e->key() == vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
416                 || (e->key() == vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
417                 || (e->key() == vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
418                 || (e->key() == vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U]))
419                 return;
420 #else
421 #if 0
422         if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
423                 joypad_0_buttons[BUTTON_R] = 0;
424         if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
425                 joypad_0_buttons[BUTTON_L] = 0;
426         if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
427                 joypad_0_buttons[BUTTON_D] = 0;
428         if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U])
429                 joypad_0_buttons[BUTTON_U] = 0;
430
431         if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L] && joypad_1_buttons[BUTTON_R])
432                 joypad_1_buttons[BUTTON_R] = 0;
433         if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R] && joypad_1_buttons[BUTTON_L])
434                 joypad_1_buttons[BUTTON_L] = 0;
435         if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U] && joypad_1_buttons[BUTTON_D])
436                 joypad_1_buttons[BUTTON_D] = 0;
437         if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D] && joypad_1_buttons[BUTTON_U])
438                 joypad_1_buttons[BUTTON_U] = 0;
439 #else
440 //hrm, this still has sticky state problems... Ugh!
441         // First, settle key states...
442         if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L])
443                 keyHeld[P1LEFT] = state;
444         else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R])
445                 keyHeld[P1RIGHT] = state;
446         else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U])
447                 keyHeld[P1UP] = state;
448         else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D])
449                 keyHeld[P1DOWN] = state;
450         else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L])
451                 keyHeld[P2LEFT] = state;
452         else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R])
453                 keyHeld[P2RIGHT] = state;
454         else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U])
455                 keyHeld[P2UP] = state;
456         else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D])
457                 keyHeld[P2DOWN] = state;
458
459         // Next, check for conflicts and bail out if there are any...
460         if ((keyHeld[P1LEFT] && keyHeld[P1RIGHT])
461                 || (keyHeld[P1UP] && keyHeld[P1DOWN])
462                 || (keyHeld[P2LEFT] && keyHeld[P2RIGHT])
463                 || (keyHeld[P2UP] && keyHeld[P2DOWN]))
464                 return;
465 #endif
466 #endif
467
468         // No bad combos exist, let's stuff the emulator key buffers...!
469         for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
470         {
471                 if (e->key() == (int)vjs.p1KeyBindings[i])
472 //                      joypad_0_buttons[i] = (uint8)state;
473                         joypad_0_buttons[i] = (state ? 0x01 : 0x00);
474
475 // Pad #2 is screwing up pad #1. Prolly a problem in joystick.cpp...
476 // So let's try to fix it there. :-P [DONE]
477                 if (e->key() == (int)vjs.p2KeyBindings[i])
478 //                      joypad_1_buttons[i] = (uint8)state;
479                         joypad_1_buttons[i] = (state ? 0x01 : 0x00);
480         }
481 }
482
483
484 void MainWin::Open(void)
485 {
486 }
487
488
489 void MainWin::Configure(void)
490 {
491         // Call the configuration dialog and update settings
492         ConfigDialog dlg(this);
493         //ick.
494         dlg.generalTab->useUnknownSoftware->setChecked(allowUnknownSoftware);
495
496         if (dlg.exec() == false)
497                 return;
498
499         QString before = vjs.ROMPath;
500         QString alpineBefore = vjs.alpineROMPath;
501         QString absBefore = vjs.absROMPath;
502 //      bool audioBefore = vjs.audioEnabled;
503         bool audioBefore = vjs.DSPEnabled;
504         dlg.UpdateVJSettings();
505         QString after = vjs.ROMPath;
506         QString alpineAfter = vjs.alpineROMPath;
507         QString absAfter = vjs.absROMPath;
508 //      bool audioAfter = vjs.audioEnabled;
509         bool audioAfter = vjs.DSPEnabled;
510
511         bool allowOld = allowUnknownSoftware;
512         //ick.
513         allowUnknownSoftware = dlg.generalTab->useUnknownSoftware->isChecked();
514
515         // We rescan the "software" folder if the user either changed the path or
516         // checked/unchecked the "Allow unknown files" option in the config dialog.
517         if ((before != after) || (allowOld != allowUnknownSoftware))
518                 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
519
520         // If the "Alpine" ROM is changed, then let's load it...
521         if (alpineBefore != alpineAfter)
522         {
523                 if (!JaguarLoadFile(vjs.alpineROMPath) && !AlpineLoadFile(vjs.alpineROMPath))
524                 {
525                         // Oh crap, we couldn't get the file! Alert the media!
526                         QMessageBox msg;
527                         msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.alpineROMPath));
528                         msg.setIcon(QMessageBox::Warning);
529                         msg.exec();
530                 }
531         }
532
533         // If the "ABS" ROM is changed, then let's load it...
534         if (absBefore != absAfter)
535         {
536                 if (!JaguarLoadFile(vjs.absROMPath))
537                 {
538                         // Oh crap, we couldn't get the file! Alert the media!
539                         QMessageBox msg;
540                         msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.absROMPath));
541                         msg.setIcon(QMessageBox::Warning);
542                         msg.exec();
543                 }
544         }
545
546         // If the "Enable DSP" checkbox changed, then we have to re-init the DAC,
547         // since it's running in the host audio IRQ...
548         if (audioBefore != audioAfter)
549         {
550                 DACDone();
551                 DACInit();
552         }
553
554         // Just in case we crash before a clean exit...
555         WriteSettings();
556 }
557
558
559 //
560 // Here's the main emulator loop
561 //
562 void MainWin::Timer(void)
563 {
564         if (!running)
565                 return;
566
567         if (showUntunedTankCircuit)
568         {
569                 // Some machines can't handle this, so we give them the option to disable it. :-)
570                 if (!plzDontKillMyComputer)
571                 {
572                 // Random hash & trash
573                 // We try to simulate an untuned tank circuit here... :-)
574                 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
575                 {
576                         for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
577                         {
578                                 videoWidget->buffer[(y * videoWidget->textureWidth) + x]
579                                         = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;
580                         }
581                 }
582                 }
583         }
584         else
585         {
586                 // Otherwise, run the Jaguar simulation
587                 JaguarExecuteNew();
588         }
589
590         videoWidget->updateGL();
591 }
592
593
594 void MainWin::TogglePowerState(void)
595 {
596         powerButtonOn = !powerButtonOn;
597         running = true;
598
599         // With the power off, we simulate white noise on the screen. :-)
600         if (!powerButtonOn)
601         {
602                 useCDAct->setDisabled(false);
603                 palAct->setDisabled(false);
604                 ntscAct->setDisabled(false);
605                 pauseAct->setChecked(false);
606                 pauseAct->setDisabled(true);
607                 showUntunedTankCircuit = true;
608                 // This is just in case the ROM we were playing was in a narrow or wide field mode,
609                 // so the untuned tank sim doesn't look wrong. :-)
610                 TOMReset();
611         }
612         else
613         {
614                 useCDAct->setDisabled(true);
615                 palAct->setDisabled(true);
616                 ntscAct->setDisabled(true);
617                 pauseAct->setChecked(false);
618                 pauseAct->setDisabled(false);
619                 showUntunedTankCircuit = false;
620
621                 // Otherwise, we prepare for running regular software...
622                 if (CDActive)
623                 {
624 // Should check for cartridgeLoaded here as well...!
625 // We can clear it when toggling CDActive on, so that when we power cycle it does the
626 // expected thing. Otherwise, if we use the file picker to insert a cart, we expect
627 // to run the cart! Maybe have a RemoveCart function that only works if the CD unit
628 // is active?
629                         setWindowTitle(QString("Virtual Jaguar " VJ_RELEASE_VERSION
630                                 " - Now playing: Jaguar CD"));
631                 }
632
633                 WriteLog("GUI: Resetting Jaguar...\n");
634                 JaguarReset();
635         }
636 }
637
638
639 void MainWin::ToggleRunState(void)
640 {
641         running = !running;
642
643         if (!running)
644         {
645                 for(uint32_t i=0; i<(uint32_t)(videoWidget->textureWidth * 256); i++)
646                 {
647                         uint32_t pixel = videoWidget->buffer[i];
648                         uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
649                         pixel = ((r + g + b) / 3) & 0x00FF;
650                         videoWidget->buffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
651                 }
652
653                 videoWidget->updateGL();
654         }
655 }
656
657
658 void MainWin::SetZoom100(void)
659 {
660         zoomLevel = 1;
661         ResizeMainWindow();
662 }
663
664
665 void MainWin::SetZoom200(void)
666 {
667         zoomLevel = 2;
668         ResizeMainWindow();
669 }
670
671
672 void MainWin::SetZoom300(void)
673 {
674         zoomLevel = 3;
675         ResizeMainWindow();
676 }
677
678
679 void MainWin::SetNTSC(void)
680 {
681         powerAct->setIcon(powerRed);
682         timer->setInterval(16);
683         vjs.hardwareTypeNTSC = true;
684         ResizeMainWindow();
685         WriteSettings();
686 }
687
688
689 void MainWin::SetPAL(void)
690 {
691         powerAct->setIcon(powerGreen);
692         timer->setInterval(20);
693         vjs.hardwareTypeNTSC = false;
694         ResizeMainWindow();
695         WriteSettings();
696 }
697
698
699 void MainWin::ToggleBlur(void)
700 {
701         vjs.glFilter = !vjs.glFilter;
702         WriteSettings();
703 }
704
705
706 void MainWin::ShowAboutWin(void)
707 {
708         aboutWin->show();
709 }
710
711
712 void MainWin::ShowHelpWin(void)
713 {
714         helpWin->show();
715 }
716
717
718 void MainWin::InsertCart(void)
719 {
720         // If the emulator is running, we pause it here and unpause it later
721         // if we dismiss the file selector without choosing anything
722         if (running && powerButtonOn)
723         {
724                 ToggleRunState();
725                 pauseForFileSelector = true;
726         }
727
728         filePickWin->show();
729 }
730
731
732 void MainWin::Unpause(void)
733 {
734         // Here we unpause the emulator if it was paused when we went into the file selector
735         if (pauseForFileSelector)
736         {
737                 pauseForFileSelector = false;
738
739                 // Some nutter might have unpaused while in the file selector, so check for that
740                 if (!running)
741                         ToggleRunState();
742         }
743 }
744
745
746 void MainWin::LoadSoftware(QString file)
747 {
748         running = false;                                                        // Prevent bad things(TM) from happening...
749         pauseForFileSelector = false;                           // Reset the file selector pause flag
750         SET32(jaguarMainRAM, 0, 0x00200000);            // Set top of stack...
751         cartridgeLoaded = JaguarLoadFile(file.toAscii().data());
752
753         char * biosPointer = jaguarBootROM;
754
755         if (vjs.hardwareTypeAlpine)
756                 biosPointer = jaguarDevBootROM2;
757
758         memcpy(jagMemSpace + 0xE00000, biosPointer, 0x20000);
759
760         powerAct->setDisabled(false);
761         powerAct->setChecked(true);
762         powerButtonOn = false;
763         TogglePowerState();
764
765         if (!vjs.hardwareTypeAlpine && !loadAndGo)
766         {
767                 QString newTitle = QString("Virtual Jaguar " VJ_RELEASE_VERSION " - Now playing: %1")
768                         .arg(filePickWin->GetSelectedPrettyName());
769                 setWindowTitle(newTitle);
770         }
771 }
772
773
774 void MainWin::ToggleCDUsage(void)
775 {
776         CDActive = !CDActive;
777
778 #if 0
779         if (CDActive)
780         {
781                 powerAct->setDisabled(false);
782         }
783         else
784         {
785                 powerAct->setDisabled(true);
786         }
787 #else
788         // Set up the Jaguar CD for execution, otherwise, clear memory
789         if (CDActive)
790                 memcpy(jagMemSpace + 0x800000, jaguarCDBootROM, 0x40000);
791         else
792                 memset(jagMemSpace + 0x800000, 0xFF, 0x40000);
793 #endif
794 }
795
796
797 void MainWin::FrameAdvance(void)
798 {
799 //printf("Frame Advance...\n");
800         // Execute 1 frame, then exit (only useful in Pause mode)
801         JaguarExecuteNew();
802         videoWidget->updateGL();
803 }
804
805
806 void MainWin::SetFullScreen(bool state/*= true*/)
807 {
808         if (state)
809         {
810                 menuBar()->hide();
811                 statusBar()->hide();
812                 showFullScreen();
813                 QRect r = QApplication::desktop()->availableGeometry();
814                 double targetWidth = 320.0, targetHeight = (vjs.hardwareTypeNTSC ? 240.0 : 256.0);
815                 double aspectRatio = targetWidth / targetHeight;
816                 // NOTE: Really should check here to see which dimension constrains the other.
817                 //       Right now, we assume that height is the constraint.
818                 int newWidth = (int)(aspectRatio * (double)r.height());
819
820                 videoWidget->setFixedSize(newWidth, r.height());
821                 showFullScreen();
822         }
823         else
824         {
825                 menuBar()->show();
826                 statusBar()->show();
827                 showNormal();
828                 ResizeMainWindow();
829         }
830
831         // For some reason, this doesn't work: If the emu is paused, toggling from
832         // fullscreen to windowed (& vice versa) shows a white screen.
833 //      videoWidget->updateGL();
834 }
835
836
837 void MainWin::ToggleFullScreen(void)
838 {
839         fullScreen = !fullScreen;
840         SetFullScreen(fullScreen);
841 }
842
843
844 void MainWin::ShowMemoryBrowserWin(void)
845 {
846         memBrowseWin->show();
847         memBrowseWin->RefreshContents();
848 }
849
850
851 void MainWin::ShowCPUBrowserWin(void)
852 {
853         cpuBrowseWin->show();
854         cpuBrowseWin->RefreshContents();
855 }
856
857
858 void MainWin::ResizeMainWindow(void)
859 {
860         videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
861         show();
862
863         for(int i=0; i<2; i++)
864         {
865                 resize(0, 0);
866                 usleep(2000);
867                 QApplication::processEvents();
868         }
869 }
870
871
872 #warning "!!! Need to check the window geometry to see if the positions are legal !!!"
873 // i.e., someone could drag it to another screen, close it, then disconnect that screen
874 void MainWin::ReadSettings(void)
875 {
876         QSettings settings("Underground Software", "Virtual Jaguar");
877         QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
878         QSize size = settings.value("size", QSize(400, 400)).toSize();
879         resize(size);
880         move(pos);
881         pos = settings.value("cartLoadPos", QPoint(200, 200)).toPoint();
882         filePickWin->move(pos);
883
884         zoomLevel = settings.value("zoom", 2).toInt();
885         allowUnknownSoftware = settings.value("showUnknownSoftware", false).toBool();
886
887         vjs.useJoystick      = settings.value("useJoystick", false).toBool();
888         vjs.joyport          = settings.value("joyport", 0).toInt();
889         vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
890         vjs.frameSkip        = settings.value("frameSkip", 0).toInt();
891         vjs.useJaguarBIOS    = settings.value("useJaguarBIOS", false).toBool();
892         vjs.GPUEnabled       = settings.value("GPUEnabled", true).toBool();
893         vjs.DSPEnabled       = settings.value("DSPEnabled", false).toBool();
894         vjs.audioEnabled     = settings.value("audioEnabled", true).toBool();
895         vjs.usePipelinedDSP  = settings.value("usePipelinedDSP", false).toBool();
896         vjs.fullscreen       = settings.value("fullscreen", false).toBool();
897         vjs.useOpenGL        = settings.value("useOpenGL", true).toBool();
898         vjs.glFilter         = settings.value("glFilterType", 1).toInt();
899         vjs.renderType       = settings.value("renderType", 0).toInt();
900         vjs.allowWritesToROM = settings.value("writeROM", false).toBool();
901 //      strcpy(vjs.jagBootPath, settings.value("JagBootROM", "./bios/[BIOS] Atari Jaguar (USA, Europe).zip").toString().toAscii().data());
902 //      strcpy(vjs.CDBootPath, settings.value("CDBootROM", "./bios/jagcd.rom").toString().toAscii().data());
903         strcpy(vjs.EEPROMPath, settings.value("EEPROMs", "./eeproms/").toString().toAscii().data());
904         strcpy(vjs.ROMPath, settings.value("ROMs", "./software/").toString().toAscii().data());
905         strcpy(vjs.alpineROMPath, settings.value("DefaultROM", "").toString().toAscii().data());
906         strcpy(vjs.absROMPath, settings.value("DefaultABS", "").toString().toAscii().data());
907 WriteLog("MainWin: Paths\n");
908 //WriteLog("    jagBootPath = \"%s\"\n", vjs.jagBootPath);
909 //WriteLog("    CDBootPath  = \"%s\"\n", vjs.CDBootPath);
910 WriteLog("   EEPROMPath = \"%s\"\n", vjs.EEPROMPath);
911 WriteLog("      ROMPath = \"%s\"\n", vjs.ROMPath);
912 WriteLog("AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);
913 WriteLog("   absROMPath = \"%s\"\n", vjs.absROMPath);
914 WriteLog("Pipelined DSP = %s\n", (vjs.usePipelinedDSP ? "ON" : "off"));
915
916         // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
917         vjs.p1KeyBindings[BUTTON_U] = settings.value("p1k_up", Qt::Key_S).toInt();
918         vjs.p1KeyBindings[BUTTON_D] = settings.value("p1k_down", Qt::Key_X).toInt();
919         vjs.p1KeyBindings[BUTTON_L] = settings.value("p1k_left", Qt::Key_A).toInt();
920         vjs.p1KeyBindings[BUTTON_R] = settings.value("p1k_right", Qt::Key_D).toInt();
921         vjs.p1KeyBindings[BUTTON_C] = settings.value("p1k_c", Qt::Key_J).toInt();
922         vjs.p1KeyBindings[BUTTON_B] = settings.value("p1k_b", Qt::Key_K).toInt();
923         vjs.p1KeyBindings[BUTTON_A] = settings.value("p1k_a", Qt::Key_L).toInt();
924         vjs.p1KeyBindings[BUTTON_OPTION] = settings.value("p1k_option", Qt::Key_O).toInt();
925         vjs.p1KeyBindings[BUTTON_PAUSE] = settings.value("p1k_pause", Qt::Key_P).toInt();
926         vjs.p1KeyBindings[BUTTON_0] = settings.value("p1k_0", Qt::Key_0).toInt();
927         vjs.p1KeyBindings[BUTTON_1] = settings.value("p1k_1", Qt::Key_1).toInt();
928         vjs.p1KeyBindings[BUTTON_2] = settings.value("p1k_2", Qt::Key_2).toInt();
929         vjs.p1KeyBindings[BUTTON_3] = settings.value("p1k_3", Qt::Key_3).toInt();
930         vjs.p1KeyBindings[BUTTON_4] = settings.value("p1k_4", Qt::Key_4).toInt();
931         vjs.p1KeyBindings[BUTTON_5] = settings.value("p1k_5", Qt::Key_5).toInt();
932         vjs.p1KeyBindings[BUTTON_6] = settings.value("p1k_6", Qt::Key_6).toInt();
933         vjs.p1KeyBindings[BUTTON_7] = settings.value("p1k_7", Qt::Key_7).toInt();
934         vjs.p1KeyBindings[BUTTON_8] = settings.value("p1k_8", Qt::Key_8).toInt();
935         vjs.p1KeyBindings[BUTTON_9] = settings.value("p1k_9", Qt::Key_9).toInt();
936         vjs.p1KeyBindings[BUTTON_d] = settings.value("p1k_pound", Qt::Key_Minus).toInt();
937         vjs.p1KeyBindings[BUTTON_s] = settings.value("p1k_star", Qt::Key_Equal).toInt();
938
939         vjs.p2KeyBindings[BUTTON_U] = settings.value("p2k_up", Qt::Key_Up).toInt();
940         vjs.p2KeyBindings[BUTTON_D] = settings.value("p2k_down", Qt::Key_Down).toInt();
941         vjs.p2KeyBindings[BUTTON_L] = settings.value("p2k_left", Qt::Key_Left).toInt();
942         vjs.p2KeyBindings[BUTTON_R] = settings.value("p2k_right", Qt::Key_Right).toInt();
943         vjs.p2KeyBindings[BUTTON_C] = settings.value("p2k_c", Qt::Key_Z).toInt();
944         vjs.p2KeyBindings[BUTTON_B] = settings.value("p2k_b", Qt::Key_X).toInt();
945         vjs.p2KeyBindings[BUTTON_A] = settings.value("p2k_a", Qt::Key_C).toInt();
946         vjs.p2KeyBindings[BUTTON_OPTION] = settings.value("p2k_option", Qt::Key_Apostrophe).toInt();
947         vjs.p2KeyBindings[BUTTON_PAUSE] = settings.value("p2k_pause", Qt::Key_Return).toInt();
948         vjs.p2KeyBindings[BUTTON_0] = settings.value("p2k_0", Qt::Key_0).toInt();
949         vjs.p2KeyBindings[BUTTON_1] = settings.value("p2k_1", Qt::Key_1).toInt();
950         vjs.p2KeyBindings[BUTTON_2] = settings.value("p2k_2", Qt::Key_2).toInt();
951         vjs.p2KeyBindings[BUTTON_3] = settings.value("p2k_3", Qt::Key_3).toInt();
952         vjs.p2KeyBindings[BUTTON_4] = settings.value("p2k_4", Qt::Key_4).toInt();
953         vjs.p2KeyBindings[BUTTON_5] = settings.value("p2k_5", Qt::Key_5).toInt();
954         vjs.p2KeyBindings[BUTTON_6] = settings.value("p2k_6", Qt::Key_6).toInt();
955         vjs.p2KeyBindings[BUTTON_7] = settings.value("p2k_7", Qt::Key_7).toInt();
956         vjs.p2KeyBindings[BUTTON_8] = settings.value("p2k_8", Qt::Key_8).toInt();
957         vjs.p2KeyBindings[BUTTON_9] = settings.value("p2k_9", Qt::Key_9).toInt();
958         vjs.p2KeyBindings[BUTTON_d] = settings.value("p2k_pound", Qt::Key_Slash).toInt();
959         vjs.p2KeyBindings[BUTTON_s] = settings.value("p2k_star", Qt::Key_Asterisk).toInt();
960 }
961
962
963 void MainWin::WriteSettings(void)
964 {
965         QSettings settings("Underground Software", "Virtual Jaguar");
966         settings.setValue("pos", pos());
967         settings.setValue("size", size());
968         settings.setValue("cartLoadPos", filePickWin->pos());
969
970         settings.setValue("zoom", zoomLevel);
971         settings.setValue("showUnknownSoftware", allowUnknownSoftware);
972
973         settings.setValue("useJoystick", vjs.useJoystick);
974         settings.setValue("joyport", vjs.joyport);
975         settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
976         settings.setValue("frameSkip", vjs.frameSkip);
977         settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
978         settings.setValue("GPUEnabled", vjs.GPUEnabled);
979         settings.setValue("DSPEnabled", vjs.DSPEnabled);
980         settings.setValue("audioEnabled", vjs.audioEnabled);
981         settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
982         settings.setValue("fullscreen", vjs.fullscreen);
983         settings.setValue("useOpenGL", vjs.useOpenGL);
984         settings.setValue("glFilterType", vjs.glFilter);
985         settings.setValue("renderType", vjs.renderType);
986         settings.setValue("writeROM", vjs.allowWritesToROM);
987         settings.setValue("JagBootROM", vjs.jagBootPath);
988         settings.setValue("CDBootROM", vjs.CDBootPath);
989         settings.setValue("EEPROMs", vjs.EEPROMPath);
990         settings.setValue("ROMs", vjs.ROMPath);
991         settings.setValue("DefaultROM", vjs.alpineROMPath);
992         settings.setValue("DefaultABS", vjs.absROMPath);
993
994         settings.setValue("p1k_up", vjs.p1KeyBindings[BUTTON_U]);
995         settings.setValue("p1k_down", vjs.p1KeyBindings[BUTTON_D]);
996         settings.setValue("p1k_left", vjs.p1KeyBindings[BUTTON_L]);
997         settings.setValue("p1k_right", vjs.p1KeyBindings[BUTTON_R]);
998         settings.setValue("p1k_c", vjs.p1KeyBindings[BUTTON_C]);
999         settings.setValue("p1k_b", vjs.p1KeyBindings[BUTTON_B]);
1000         settings.setValue("p1k_a", vjs.p1KeyBindings[BUTTON_A]);
1001         settings.setValue("p1k_option", vjs.p1KeyBindings[BUTTON_OPTION]);
1002         settings.setValue("p1k_pause", vjs.p1KeyBindings[BUTTON_PAUSE]);
1003         settings.setValue("p1k_0", vjs.p1KeyBindings[BUTTON_0]);
1004         settings.setValue("p1k_1", vjs.p1KeyBindings[BUTTON_1]);
1005         settings.setValue("p1k_2", vjs.p1KeyBindings[BUTTON_2]);
1006         settings.setValue("p1k_3", vjs.p1KeyBindings[BUTTON_3]);
1007         settings.setValue("p1k_4", vjs.p1KeyBindings[BUTTON_4]);
1008         settings.setValue("p1k_5", vjs.p1KeyBindings[BUTTON_5]);
1009         settings.setValue("p1k_6", vjs.p1KeyBindings[BUTTON_6]);
1010         settings.setValue("p1k_7", vjs.p1KeyBindings[BUTTON_7]);
1011         settings.setValue("p1k_8", vjs.p1KeyBindings[BUTTON_8]);
1012         settings.setValue("p1k_9", vjs.p1KeyBindings[BUTTON_9]);
1013         settings.setValue("p1k_pound", vjs.p1KeyBindings[BUTTON_d]);
1014         settings.setValue("p1k_star", vjs.p1KeyBindings[BUTTON_s]);
1015
1016         settings.setValue("p2k_up", vjs.p2KeyBindings[BUTTON_U]);
1017         settings.setValue("p2k_down", vjs.p2KeyBindings[BUTTON_D]);
1018         settings.setValue("p2k_left", vjs.p2KeyBindings[BUTTON_L]);
1019         settings.setValue("p2k_right", vjs.p2KeyBindings[BUTTON_R]);
1020         settings.setValue("p2k_c", vjs.p2KeyBindings[BUTTON_C]);
1021         settings.setValue("p2k_b", vjs.p2KeyBindings[BUTTON_B]);
1022         settings.setValue("p2k_a", vjs.p2KeyBindings[BUTTON_A]);
1023         settings.setValue("p2k_option", vjs.p2KeyBindings[BUTTON_OPTION]);
1024         settings.setValue("p2k_pause", vjs.p2KeyBindings[BUTTON_PAUSE]);
1025         settings.setValue("p2k_0", vjs.p2KeyBindings[BUTTON_0]);
1026         settings.setValue("p2k_1", vjs.p2KeyBindings[BUTTON_1]);
1027         settings.setValue("p2k_2", vjs.p2KeyBindings[BUTTON_2]);
1028         settings.setValue("p2k_3", vjs.p2KeyBindings[BUTTON_3]);
1029         settings.setValue("p2k_4", vjs.p2KeyBindings[BUTTON_4]);
1030         settings.setValue("p2k_5", vjs.p2KeyBindings[BUTTON_5]);
1031         settings.setValue("p2k_6", vjs.p2KeyBindings[BUTTON_6]);
1032         settings.setValue("p2k_7", vjs.p2KeyBindings[BUTTON_7]);
1033         settings.setValue("p2k_8", vjs.p2KeyBindings[BUTTON_8]);
1034         settings.setValue("p2k_9", vjs.p2KeyBindings[BUTTON_9]);
1035         settings.setValue("p2k_pound", vjs.p2KeyBindings[BUTTON_d]);
1036         settings.setValue("p2k_star", vjs.p2KeyBindings[BUTTON_s]);
1037 }
1038
1039
1040 void MainWin::WriteUISettings(void)
1041 {
1042         QSettings settings("Underground Software", "Virtual Jaguar");
1043         settings.setValue("pos", pos());
1044         settings.setValue("size", size());
1045         settings.setValue("cartLoadPos", filePickWin->pos());
1046
1047         settings.setValue("zoom", zoomLevel);
1048 }