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