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