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