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