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