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