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