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