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