]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/mainwin.cpp
739756ed1915251717f35168ebafb1e13689f1a2
[virtualjaguar] / src / gui / mainwin.cpp
1 //
2 // mainwin.cpp - Qt-based GUI for Virtual Jaguar: Main Application Window
3 // by James L. Hammons
4 // (C) 2009 Underground Software
5 //
6 // JLH = James L. Hammons <jlhamm@acm.org>
7 //
8 // Who  When        What
9 // ---  ----------  -------------------------------------------------------------
10 // JLH  12/23/2009  Created this file
11 // JLH  12/20/2010  Added settings, menus & toolbars
12 // JLH  07/05/2011  Added CD BIOS functionality to GUI
13 //
14
15 // FIXED:
16 //
17 // - Add dbl click/enter to select in cart list, ESC to dimiss [DONE]
18 // - Autoscan/autoload all available BIOS from 'software' folder [DONE]
19 // - Add 1 key jumping in cartridge list (press 'R', jumps to carts starting with 'R', etc) [DONE]
20 // - Controller configuration [DONE]
21 //
22 // STILL TO BE DONE:
23 //
24 // - Remove SDL dependencies (sound, mainly) from Jaguar core lib
25 // - Fix inconsistency with trailing slashes in paths (eeproms needs one, software doesn't)
26 //
27 // SFDX CODE: 9XF9TUHFM2359
28
29 // Uncomment this for debugging...
30 //#define DEBUG
31 //#define DEBUGFOO                      // Various tool debugging...
32 //#define DEBUGTP                               // Toolpalette debugging...
33
34 #include "mainwin.h"
35
36 #include "SDL.h"
37 #include "glwidget.h"
38 #include "about.h"
39 #include "help.h"
40 #include "settings.h"
41 #include "filepicker.h"
42 #include "configdialog.h"
43 #include "generaltab.h"
44 #include "version.h"
45
46 #include "dac.h"
47 #include "jaguar.h"
48 #include "tom.h"
49 #include "log.h"
50 #include "file.h"
51 #include "jagbios.h"
52 #include "jagcdbios.h"
53 #include "jagstub2bios.h"
54 #include "joystick.h"
55
56 #ifdef __GCCWIN32__
57 // Apparently on win32, usleep() is not pulled in by the usual suspects.
58 #include <unistd.h>
59 #endif
60
61 // The way BSNES controls things is by setting a timer with a zero
62 // timeout, sleeping if not emulating anything. Seems there has to be a
63 // better way.
64
65 // It has a novel approach to plugging-in/using different video/audio/input
66 // methods, can we do something similar or should we just use the built-in
67 // QOpenGL?
68
69 // We're going to try to use the built-in OpenGL support and see how it goes.
70 // We'll make the VJ core modular so that it doesn't matter what GUI is in
71 // use, we can drop it in anywhere and use it as-is.
72
73 MainWin::MainWin(): running(true), powerButtonOn(false), showUntunedTankCircuit(true),
74         cartridgeLoaded(false), CDActive(false),//, alpineLoadSuccessful(false),
75         pauseForFileSelector(false)
76 {
77         videoWidget = new GLWidget(this);
78         setCentralWidget(videoWidget);
79         setWindowIcon(QIcon(":/res/vj-icon.png"));
80
81         QString title = QString(tr("Virtual Jaguar " VJ_RELEASE_VERSION ));
82
83         if (vjs.hardwareTypeAlpine)
84                 title += QString(tr(" - Alpine Mode"));
85
86         setWindowTitle(title);
87
88         aboutWin = new AboutWindow(this);
89         helpWin = new HelpWindow(this);
90         filePickWin = new FilePickerWindow(this);
91
92     videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
93     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
94
95         setUnifiedTitleAndToolBarOnMac(true);
96
97         // Create actions
98
99         quitAppAct = new QAction(tr("E&xit"), this);
100         quitAppAct->setShortcuts(QKeySequence::Quit);
101         quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
102         connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
103
104         powerAct = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
105         powerAct->setStatusTip(tr("Powers Jaguar on/off"));
106         powerAct->setCheckable(true);
107         powerAct->setChecked(false);
108 //      powerAct->setDisabled(true);
109         connect(powerAct, SIGNAL(triggered()), this, SLOT(TogglePowerState()));
110
111         pauseAct = new QAction(QIcon(":/res/pause.png"), tr("Pause"), this);
112         pauseAct->setStatusTip(tr("Toggles the running state"));
113         pauseAct->setCheckable(true);
114         pauseAct->setDisabled(true);
115         pauseAct->setShortcut(QKeySequence(tr("Esc")));
116         connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
117
118         zoomActs = new QActionGroup(this);
119
120         x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
121         x1Act->setStatusTip(tr("Set window zoom to 100%"));
122         x1Act->setCheckable(true);
123         connect(x1Act, SIGNAL(triggered()), this, SLOT(SetZoom100()));
124
125         x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
126         x2Act->setStatusTip(tr("Set window zoom to 200%"));
127         x2Act->setCheckable(true);
128         connect(x2Act, SIGNAL(triggered()), this, SLOT(SetZoom200()));
129
130         x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
131         x3Act->setStatusTip(tr("Set window zoom to 300%"));
132         x3Act->setCheckable(true);
133         connect(x3Act, SIGNAL(triggered()), this, SLOT(SetZoom300()));
134
135         tvTypeActs = new QActionGroup(this);
136
137         ntscAct = new QAction(QIcon(":/res/ntsc.png"), tr("NTSC"), tvTypeActs);
138         ntscAct->setStatusTip(tr("Sets Jaguar to NTSC mode"));
139         ntscAct->setCheckable(true);
140         connect(ntscAct, SIGNAL(triggered()), this, SLOT(SetNTSC()));
141
142         palAct = new QAction(QIcon(":/res/pal.png"), tr("PAL"), tvTypeActs);
143         palAct->setStatusTip(tr("Sets Jaguar to PAL mode"));
144         palAct->setCheckable(true);
145         connect(palAct, SIGNAL(triggered()), this, SLOT(SetPAL()));
146
147         blurAct = new QAction(QIcon(":/res/generic.png"), tr("Blur"), this);
148         blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
149         blurAct->setCheckable(true);
150         connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
151
152         aboutAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&About..."), this);
153         aboutAct->setStatusTip(tr("Blatant self-promotion"));
154         connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
155
156         helpAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&Contents..."), this);
157         helpAct->setStatusTip(tr("Help is available, if you should need it"));
158         connect(helpAct, SIGNAL(triggered()), this, SLOT(ShowHelpWin()));
159
160         filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this);
161         filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar"));
162         filePickAct->setShortcut(QKeySequence(tr("Ctrl+i")));
163         connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart()));
164
165         configAct = new QAction(QIcon(":/res/wrench.png"), tr("&Configure"), this);
166         configAct->setStatusTip(tr("Configure options for Virtual Jaguar"));
167         configAct->setShortcut(QKeySequence(tr("Ctrl+c")));
168         connect(configAct, SIGNAL(triggered()), this, SLOT(Configure()));
169
170         useCDAct = new QAction(QIcon(":/res/compact-disc.png"), tr("&Use CD Unit"), this);
171         useCDAct->setStatusTip(tr("Use Jaguar Virtual CD unit"));
172 //      useCDAct->setShortcut(QKeySequence(tr("Ctrl+c")));
173         useCDAct->setCheckable(true);
174         connect(useCDAct, SIGNAL(triggered()), this, SLOT(ToggleCDUsage()));
175
176         // Misc. connections...
177         connect(filePickWin, SIGNAL(RequestLoad(QString)), this, SLOT(LoadSoftware(QString)));
178         connect(filePickWin, SIGNAL(FilePickerHiding()), this, SLOT(Unpause()));
179
180         // Create menus & toolbars
181
182         fileMenu = menuBar()->addMenu(tr("&Jaguar"));
183         fileMenu->addAction(powerAct);
184         fileMenu->addAction(pauseAct);
185         fileMenu->addAction(filePickAct);
186         fileMenu->addAction(useCDAct);
187         fileMenu->addAction(configAct);
188         fileMenu->addAction(quitAppAct);
189
190         helpMenu = menuBar()->addMenu(tr("&Help"));
191         helpMenu->addAction(helpAct);
192         helpMenu->addAction(aboutAct);
193
194         toolbar = addToolBar(tr("Stuff"));
195         toolbar->addAction(powerAct);
196         toolbar->addAction(pauseAct);
197         toolbar->addAction(filePickAct);
198         toolbar->addAction(useCDAct);
199         toolbar->addSeparator();
200         toolbar->addAction(x1Act);
201         toolbar->addAction(x2Act);
202         toolbar->addAction(x3Act);
203         toolbar->addSeparator();
204         toolbar->addAction(ntscAct);
205         toolbar->addAction(palAct);
206         toolbar->addSeparator();
207         toolbar->addAction(blurAct);
208
209         //      Create status bar
210         statusBar()->showMessage(tr("Ready"));
211
212         ReadSettings();
213
214         // Set toolbar buttons/menus based on settings read in (sync the UI)...
215         blurAct->setChecked(vjs.glFilter);
216         x1Act->setChecked(zoomLevel == 1);
217         x2Act->setChecked(zoomLevel == 2);
218         x3Act->setChecked(zoomLevel == 3);
219 //      running = powerAct->isChecked();
220         ntscAct->setChecked(vjs.hardwareTypeNTSC);
221         palAct->setChecked(!vjs.hardwareTypeNTSC);
222
223         // Do this in case original size isn't correct (mostly for the first-run case)
224         ResizeMainWindow();
225
226         // Set up timer based loop for animation...
227         timer = new QTimer(this);
228         connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
229 //This is only correct for PAL. !!! FIX !!! [DONE]
230 //Use timer->setInterval( int msec ) to fix this on the fly
231 //      timer->start(20);
232         // This isn't very accurate for NTSC: This is early by 40 msec per frame.
233         // This is because it's discarding the 0.6666... on the end of the fraction.
234         // Alas, 6 doesn't divide cleanly into 10. :-P
235         timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
236
237         // We set this initially, to make VJ behave somewhat as it would if no
238         // cart were inserted and the BIOS was set as active...
239         jaguarCartInserted = true;
240         WriteLog("Virtual Jaguar %s (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
241         WriteLog("VJ: Initializing jaguar subsystem...\n");
242         JaguarInit();
243
244         filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
245
246         // Load up the default ROM if in Alpine mode:
247         if (vjs.hardwareTypeAlpine)
248         {
249                 bool romLoaded = JaguarLoadFile(vjs.alpineROMPath);
250
251                 // If regular load failed, try just a straight file load
252                 // (Dev only! I don't want people to start getting lazy with their releases again! :-P)
253                 if (!romLoaded)
254                         romLoaded = AlpineLoadFile(vjs.alpineROMPath);
255
256                 if (romLoaded)
257                         WriteLog("Alpine Mode: Successfully loaded file \"%s\".\n", vjs.alpineROMPath);
258                 else
259                         WriteLog("Alpine Mode: Unable to load file \"%s\"!\n", vjs.alpineROMPath);
260
261                 // Attempt to load/run the ABS file...
262                 LoadSoftware(vjs.absROMPath);
263                 memcpy(jagMemSpace + 0xE00000, jaguarDevBootROM2, 0x20000);     // Use the stub BIOS
264         }
265         else
266                 memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Otherwise, use the stock BIOS
267 }
268
269 void MainWin::closeEvent(QCloseEvent * event)
270 {
271         JaguarDone();
272         WriteSettings();
273         event->accept(); // ignore() if can't close for some reason
274 }
275
276 void MainWin::keyPressEvent(QKeyEvent * e)
277 {
278         // We ignore the Alt key for now, since it causes problems with the GUI
279         if (e->key() == Qt::Key_Alt)
280         {
281                 e->accept();
282                 return;
283         }
284
285         HandleKeys(e, true);
286 }
287
288 void MainWin::keyReleaseEvent(QKeyEvent * e)
289 {
290         // We ignore the Alt key for now, since it causes problems with the GUI
291         if (e->key() == Qt::Key_Alt)
292         {
293                 e->accept();
294                 return;
295         }
296
297         HandleKeys(e, false);
298 }
299
300 void MainWin::HandleKeys(QKeyEvent * e, bool state)
301 {
302         // We kill bad key combos here, before they can get to the emulator...
303         // This also kills the illegal instruction problem that cropped up in Rayman!
304         // May want to do this by killing the old one instead of ignoring the new one...
305         // Seems to work better that way...
306 #if 0
307         if ((e->key() == vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
308                 || (e->key() == vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
309                 || (e->key() == vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
310                 || (e->key() == vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U]))
311                 return;
312 #else
313         if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
314                 joypad_0_buttons[BUTTON_R] = 0;
315         if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
316                 joypad_0_buttons[BUTTON_L] = 0;
317         if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
318                 joypad_0_buttons[BUTTON_D] = 0;
319         if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U])
320                 joypad_0_buttons[BUTTON_U] = 0;
321
322         if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L] && joypad_1_buttons[BUTTON_R])
323                 joypad_1_buttons[BUTTON_R] = 0;
324         if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R] && joypad_1_buttons[BUTTON_L])
325                 joypad_1_buttons[BUTTON_L] = 0;
326         if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U] && joypad_1_buttons[BUTTON_D])
327                 joypad_1_buttons[BUTTON_D] = 0;
328         if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D] && joypad_1_buttons[BUTTON_U])
329                 joypad_1_buttons[BUTTON_U] = 0;
330 #endif
331
332         // No bad combos exist, let's stuff the emulator key buffers...!
333         for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
334         {
335                 if (e->key() == (int)vjs.p1KeyBindings[i])
336 //                      joypad_0_buttons[i] = (uint8)state;
337                         joypad_0_buttons[i] = (state ? 0x01 : 0x00);
338
339 // Pad #2 is screwing up pad #1. Prolly a problem in joystick.cpp...
340 // So let's try to fix it there. :-P [DONE]
341                 if (e->key() == (int)vjs.p2KeyBindings[i])
342 //                      joypad_1_buttons[i] = (uint8)state;
343                         joypad_1_buttons[i] = (state ? 0x01 : 0x00);
344         }
345 }
346
347 void MainWin::Open(void)
348 {
349 }
350
351 void MainWin::Configure(void)
352 {
353         // Call the configuration dialog and update settings
354         ConfigDialog dlg(this);
355         //ick.
356         dlg.generalTab->useUnknownSoftware->setChecked(allowUnknownSoftware);
357
358         if (dlg.exec() == false)
359                 return;
360
361         QString before = vjs.ROMPath;
362         QString alpineBefore = vjs.alpineROMPath;
363         QString absBefore = vjs.absROMPath;
364         bool audioBefore = vjs.audioEnabled;
365         dlg.UpdateVJSettings();
366         QString after = vjs.ROMPath;
367         QString alpineAfter = vjs.alpineROMPath;
368         QString absAfter = vjs.absROMPath;
369         bool audioAfter = vjs.audioEnabled;
370
371         bool allowOld = allowUnknownSoftware;
372         //ick.
373         allowUnknownSoftware = dlg.generalTab->useUnknownSoftware->isChecked();
374
375         // We rescan the "software" folder if the user either changed the path or
376         // checked/unchecked the "Allow unknown files" option in the config dialog.
377         if ((before != after) || (allowOld != allowUnknownSoftware))
378                 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
379
380         // If the "Alpine" ROM is changed, then let's load it...
381         if (alpineBefore != alpineAfter)
382         {
383                 if (!JaguarLoadFile(vjs.alpineROMPath) && !AlpineLoadFile(vjs.alpineROMPath))
384                 {
385                         // Oh crap, we couldn't get the file! Alert the media!
386                         QMessageBox msg;
387                         msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.alpineROMPath));
388                         msg.setIcon(QMessageBox::Warning);
389                         msg.exec();
390                 }
391         }
392
393         // If the "ABS" ROM is changed, then let's load it...
394         if (absBefore != absAfter)
395         {
396                 if (!JaguarLoadFile(vjs.absROMPath))
397                 {
398                         // Oh crap, we couldn't get the file! Alert the media!
399                         QMessageBox msg;
400                         msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.absROMPath));
401                         msg.setIcon(QMessageBox::Warning);
402                         msg.exec();
403                 }
404         }
405
406         // If the "Enable audio" checkbox changed, then we have to re-init the DAC...
407         if (audioBefore != audioAfter)
408         {
409                 DACDone();
410                 DACInit();
411         }
412
413         // Just in case we crash before a clean exit...
414         WriteSettings();
415 }
416
417 //
418 // Here's the main emulator loop
419 //
420 void MainWin::Timer(void)
421 {
422         if (!running)
423                 return;
424
425         if (showUntunedTankCircuit)
426         {
427                 // Random hash & trash
428                 // We try to simulate an untuned tank circuit here... :-)
429                 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
430                 {
431                         for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
432                         {
433                                 videoWidget->buffer[(y * videoWidget->textureWidth) + x]
434                                         = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;
435                         }
436                 }
437         }
438         else
439         {
440                 // Otherwise, run the Jaguar simulation
441                 JaguarExecuteNew();
442         }
443
444         videoWidget->updateGL();
445 }
446
447 void MainWin::TogglePowerState(void)
448 {
449         powerButtonOn = !powerButtonOn;
450         running = true;
451
452         // With the power off, we simulate white noise on the screen. :-)
453         if (!powerButtonOn)
454         {
455                 useCDAct->setDisabled(false);
456                 palAct->setDisabled(false);
457                 ntscAct->setDisabled(false);
458                 pauseAct->setChecked(false);
459                 pauseAct->setDisabled(true);
460                 showUntunedTankCircuit = true;
461                 // This is just in case the ROM we were playing was in a narrow or wide field mode,
462                 // so the untuned tank sim doesn't look wrong. :-)
463                 TOMReset();
464         }
465         else
466         {
467                 useCDAct->setDisabled(true);
468                 palAct->setDisabled(true);
469                 ntscAct->setDisabled(true);
470                 pauseAct->setChecked(false);
471                 pauseAct->setDisabled(false);
472                 showUntunedTankCircuit = false;
473
474                 // Otherwise, we prepare for running regular software...
475                 if (CDActive)
476                 {
477 // Should check for cartridgeLoaded here as well...!
478 // We can clear it when toggling CDActive on, so that when we power cycle it does the
479 // expected thing. Otherwise, if we use the file picker to insert a cart, we expect
480 // to run the cart! Maybe have a RemoveCart function that only works if the CD unit
481 // is active?
482                         setWindowTitle(QString("Virtual Jaguar " VJ_RELEASE_VERSION
483                                 " - Now playing: Jaguar CD"));
484                 }
485
486                 WriteLog("GUI: Resetting Jaguar...\n");
487                 JaguarReset();
488         }
489 }
490
491 void MainWin::ToggleRunState(void)
492 {
493         running = !running;
494
495         if (!running)
496         {
497                 for(uint32_t i=0; i<(uint32_t)(videoWidget->textureWidth * 256); i++)
498                 {
499                         uint32_t pixel = videoWidget->buffer[i];
500                         uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
501                         pixel = ((r + g + b) / 3) & 0x00FF;
502                         videoWidget->buffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
503                 }
504
505                 videoWidget->updateGL();
506         }
507 }
508
509 void MainWin::SetZoom100(void)
510 {
511         zoomLevel = 1;
512         ResizeMainWindow();
513 }
514
515 void MainWin::SetZoom200(void)
516 {
517         zoomLevel = 2;
518         ResizeMainWindow();
519 }
520
521 void MainWin::SetZoom300(void)
522 {
523         zoomLevel = 3;
524         ResizeMainWindow();
525 }
526
527 void MainWin::SetNTSC(void)
528 {
529         timer->setInterval(16);
530         vjs.hardwareTypeNTSC = true;
531         ResizeMainWindow();
532 }
533
534 void MainWin::SetPAL(void)
535 {
536         timer->setInterval(20);
537         vjs.hardwareTypeNTSC = false;
538         ResizeMainWindow();
539 }
540
541 void MainWin::ToggleBlur(void)
542 {
543         vjs.glFilter = !vjs.glFilter;
544 }
545
546 void MainWin::ShowAboutWin(void)
547 {
548         aboutWin->show();
549 }
550
551 void MainWin::ShowHelpWin(void)
552 {
553         helpWin->show();
554 }
555
556 void MainWin::InsertCart(void)
557 {
558         // If the emulator is running, we pause it here and unpause it later
559         // if we dismiss the file selector without choosing anything
560         if (running && powerButtonOn)
561         {
562                 ToggleRunState();
563                 pauseForFileSelector = true;
564         }
565
566         filePickWin->show();
567 }
568
569 void MainWin::Unpause(void)
570 {
571         // Here we unpause the emulator if it was paused when we went into the file selector
572         if (pauseForFileSelector)
573         {
574                 pauseForFileSelector = false;
575                 ToggleRunState();
576         }
577 }
578
579 void MainWin::LoadSoftware(QString file)
580 {
581         running = false;                                                        // Prevent bad things(TM) from happening...
582         pauseForFileSelector = false;                           // Reset the file selector pause flag
583         SET32(jaguarMainRAM, 0, 0x00200000);            // Set top of stack...
584         cartridgeLoaded = JaguarLoadFile(file.toAscii().data());
585
586         char * biosPointer = jaguarBootROM;
587
588         if (vjs.hardwareTypeAlpine)
589                 biosPointer = jaguarDevBootROM2;
590
591         memcpy(jagMemSpace + 0xE00000, biosPointer, 0x20000);
592
593         powerAct->setDisabled(false);
594         powerAct->setChecked(true);
595         powerButtonOn = false;
596         TogglePowerState();
597
598         if (!vjs.hardwareTypeAlpine)
599         {
600                 QString newTitle = QString("Virtual Jaguar " VJ_RELEASE_VERSION " - Now playing: %1")
601                         .arg(filePickWin->GetSelectedPrettyName());
602                 setWindowTitle(newTitle);
603         }
604 }
605
606 void MainWin::ToggleCDUsage(void)
607 {
608         CDActive = !CDActive;
609
610 #if 0
611         if (CDActive)
612         {
613                 powerAct->setDisabled(false);
614         }
615         else
616         {
617                 powerAct->setDisabled(true);
618         }
619 #else
620         // Set up the Jaguar CD for execution, otherwise, clear memory
621         if (CDActive)
622                 memcpy(jagMemSpace + 0x800000, jaguarCDBootROM, 0x40000);
623         else
624                 memset(jagMemSpace + 0x800000, 0xFF, 0x40000);
625 #endif
626 }
627
628 void MainWin::ResizeMainWindow(void)
629 {
630         videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
631         show();
632
633         for(int i=0; i<2; i++)
634         {
635                 resize(0, 0);
636                 usleep(2000);
637                 QApplication::processEvents();
638         }
639 }
640
641 void MainWin::ReadSettings(void)
642 {
643         QSettings settings("Underground Software", "Virtual Jaguar");
644         QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
645         QSize size = settings.value("size", QSize(400, 400)).toSize();
646         resize(size);
647         move(pos);
648         pos = settings.value("cartLoadPos", QPoint(200, 200)).toPoint();
649         filePickWin->move(pos);
650
651         zoomLevel = settings.value("zoom", 2).toInt();
652         allowUnknownSoftware = settings.value("showUnknownSoftware", false).toBool();
653
654         vjs.useJoystick      = settings.value("useJoystick", false).toBool();
655         vjs.joyport          = settings.value("joyport", 0).toInt();
656         vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
657         vjs.frameSkip        = settings.value("frameSkip", 0).toInt();
658         vjs.useJaguarBIOS    = settings.value("useJaguarBIOS", false).toBool();
659         vjs.GPUEnabled       = settings.value("GPUEnabled", true).toBool();
660         vjs.DSPEnabled       = settings.value("DSPEnabled", false).toBool();
661         vjs.audioEnabled     = settings.value("audioEnabled", true).toBool();
662         vjs.usePipelinedDSP  = settings.value("usePipelinedDSP", false).toBool();
663         vjs.fullscreen       = settings.value("fullscreen", false).toBool();
664         vjs.useOpenGL        = settings.value("useOpenGL", true).toBool();
665         vjs.glFilter         = settings.value("glFilterType", 1).toInt();
666         vjs.renderType       = settings.value("renderType", 0).toInt();
667         vjs.allowWritesToROM = settings.value("writeROM", false).toBool();
668 //      strcpy(vjs.jagBootPath, settings.value("JagBootROM", "./bios/[BIOS] Atari Jaguar (USA, Europe).zip").toString().toAscii().data());
669 //      strcpy(vjs.CDBootPath, settings.value("CDBootROM", "./bios/jagcd.rom").toString().toAscii().data());
670         strcpy(vjs.EEPROMPath, settings.value("EEPROMs", "./eeproms/").toString().toAscii().data());
671         strcpy(vjs.ROMPath, settings.value("ROMs", "./software/").toString().toAscii().data());
672         strcpy(vjs.alpineROMPath, settings.value("DefaultROM", "").toString().toAscii().data());
673         strcpy(vjs.absROMPath, settings.value("DefaultABS", "").toString().toAscii().data());
674 WriteLog("MainWin: Paths\n");
675 //WriteLog("    jagBootPath = \"%s\"\n", vjs.jagBootPath);
676 //WriteLog("    CDBootPath  = \"%s\"\n", vjs.CDBootPath);
677 WriteLog("   EEPROMPath = \"%s\"\n", vjs.EEPROMPath);
678 WriteLog("      ROMPath = \"%s\"\n", vjs.ROMPath);
679 WriteLog("AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);
680 WriteLog("   absROMPath = \"%s\"\n", vjs.absROMPath);
681
682         // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
683         vjs.p1KeyBindings[BUTTON_U] = settings.value("p1k_up", Qt::Key_S).toInt();
684         vjs.p1KeyBindings[BUTTON_D] = settings.value("p1k_down", Qt::Key_X).toInt();
685         vjs.p1KeyBindings[BUTTON_L] = settings.value("p1k_left", Qt::Key_A).toInt();
686         vjs.p1KeyBindings[BUTTON_R] = settings.value("p1k_right", Qt::Key_D).toInt();
687         vjs.p1KeyBindings[BUTTON_C] = settings.value("p1k_c", Qt::Key_J).toInt();
688         vjs.p1KeyBindings[BUTTON_B] = settings.value("p1k_b", Qt::Key_K).toInt();
689         vjs.p1KeyBindings[BUTTON_A] = settings.value("p1k_a", Qt::Key_L).toInt();
690         vjs.p1KeyBindings[BUTTON_OPTION] = settings.value("p1k_option", Qt::Key_O).toInt();
691         vjs.p1KeyBindings[BUTTON_PAUSE] = settings.value("p1k_pause", Qt::Key_P).toInt();
692         vjs.p1KeyBindings[BUTTON_0] = settings.value("p1k_0", Qt::Key_0).toInt();
693         vjs.p1KeyBindings[BUTTON_1] = settings.value("p1k_1", Qt::Key_1).toInt();
694         vjs.p1KeyBindings[BUTTON_2] = settings.value("p1k_2", Qt::Key_2).toInt();
695         vjs.p1KeyBindings[BUTTON_3] = settings.value("p1k_3", Qt::Key_3).toInt();
696         vjs.p1KeyBindings[BUTTON_4] = settings.value("p1k_4", Qt::Key_4).toInt();
697         vjs.p1KeyBindings[BUTTON_5] = settings.value("p1k_5", Qt::Key_5).toInt();
698         vjs.p1KeyBindings[BUTTON_6] = settings.value("p1k_6", Qt::Key_6).toInt();
699         vjs.p1KeyBindings[BUTTON_7] = settings.value("p1k_7", Qt::Key_7).toInt();
700         vjs.p1KeyBindings[BUTTON_8] = settings.value("p1k_8", Qt::Key_8).toInt();
701         vjs.p1KeyBindings[BUTTON_9] = settings.value("p1k_9", Qt::Key_9).toInt();
702         vjs.p1KeyBindings[BUTTON_d] = settings.value("p1k_pound", Qt::Key_Minus).toInt();
703         vjs.p1KeyBindings[BUTTON_s] = settings.value("p1k_star", Qt::Key_Equal).toInt();
704
705         vjs.p2KeyBindings[BUTTON_U] = settings.value("p2k_up", Qt::Key_Up).toInt();
706         vjs.p2KeyBindings[BUTTON_D] = settings.value("p2k_down", Qt::Key_Down).toInt();
707         vjs.p2KeyBindings[BUTTON_L] = settings.value("p2k_left", Qt::Key_Left).toInt();
708         vjs.p2KeyBindings[BUTTON_R] = settings.value("p2k_right", Qt::Key_Right).toInt();
709         vjs.p2KeyBindings[BUTTON_C] = settings.value("p2k_c", Qt::Key_Z).toInt();
710         vjs.p2KeyBindings[BUTTON_B] = settings.value("p2k_b", Qt::Key_X).toInt();
711         vjs.p2KeyBindings[BUTTON_A] = settings.value("p2k_a", Qt::Key_C).toInt();
712         vjs.p2KeyBindings[BUTTON_OPTION] = settings.value("p2k_option", Qt::Key_Apostrophe).toInt();
713         vjs.p2KeyBindings[BUTTON_PAUSE] = settings.value("p2k_pause", Qt::Key_Return).toInt();
714         vjs.p2KeyBindings[BUTTON_0] = settings.value("p2k_0", Qt::Key_0).toInt();
715         vjs.p2KeyBindings[BUTTON_1] = settings.value("p2k_1", Qt::Key_1).toInt();
716         vjs.p2KeyBindings[BUTTON_2] = settings.value("p2k_2", Qt::Key_2).toInt();
717         vjs.p2KeyBindings[BUTTON_3] = settings.value("p2k_3", Qt::Key_3).toInt();
718         vjs.p2KeyBindings[BUTTON_4] = settings.value("p2k_4", Qt::Key_4).toInt();
719         vjs.p2KeyBindings[BUTTON_5] = settings.value("p2k_5", Qt::Key_5).toInt();
720         vjs.p2KeyBindings[BUTTON_6] = settings.value("p2k_6", Qt::Key_6).toInt();
721         vjs.p2KeyBindings[BUTTON_7] = settings.value("p2k_7", Qt::Key_7).toInt();
722         vjs.p2KeyBindings[BUTTON_8] = settings.value("p2k_8", Qt::Key_8).toInt();
723         vjs.p2KeyBindings[BUTTON_9] = settings.value("p2k_9", Qt::Key_9).toInt();
724         vjs.p2KeyBindings[BUTTON_d] = settings.value("p2k_pound", Qt::Key_Slash).toInt();
725         vjs.p2KeyBindings[BUTTON_s] = settings.value("p2k_star", Qt::Key_Asterisk).toInt();
726 }
727
728 void MainWin::WriteSettings(void)
729 {
730         QSettings settings("Underground Software", "Virtual Jaguar");
731         settings.setValue("pos", pos());
732         settings.setValue("size", size());
733         settings.setValue("cartLoadPos", filePickWin->pos());
734
735         settings.setValue("zoom", zoomLevel);
736         settings.setValue("showUnknownSoftware", allowUnknownSoftware);
737
738         settings.setValue("useJoystick", vjs.useJoystick);
739         settings.setValue("joyport", vjs.joyport);
740         settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
741         settings.setValue("frameSkip", vjs.frameSkip);
742         settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
743         settings.setValue("GPUEnabled", vjs.GPUEnabled);
744         settings.setValue("DSPEnabled", vjs.DSPEnabled);
745         settings.setValue("audioEnabled", vjs.audioEnabled);
746         settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
747         settings.setValue("fullscreen", vjs.fullscreen);
748         settings.setValue("useOpenGL", vjs.useOpenGL);
749         settings.setValue("glFilterType", vjs.glFilter);
750         settings.setValue("renderType", vjs.renderType);
751         settings.setValue("writeROM", vjs.allowWritesToROM);
752         settings.setValue("JagBootROM", vjs.jagBootPath);
753         settings.setValue("CDBootROM", vjs.CDBootPath);
754         settings.setValue("EEPROMs", vjs.EEPROMPath);
755         settings.setValue("ROMs", vjs.ROMPath);
756         settings.setValue("DefaultROM", vjs.alpineROMPath);
757         settings.setValue("DefaultABS", vjs.absROMPath);
758
759         settings.setValue("p1k_up", vjs.p1KeyBindings[BUTTON_U]);
760         settings.setValue("p1k_down", vjs.p1KeyBindings[BUTTON_D]);
761         settings.setValue("p1k_left", vjs.p1KeyBindings[BUTTON_L]);
762         settings.setValue("p1k_right", vjs.p1KeyBindings[BUTTON_R]);
763         settings.setValue("p1k_c", vjs.p1KeyBindings[BUTTON_C]);
764         settings.setValue("p1k_b", vjs.p1KeyBindings[BUTTON_B]);
765         settings.setValue("p1k_a", vjs.p1KeyBindings[BUTTON_A]);
766         settings.setValue("p1k_option", vjs.p1KeyBindings[BUTTON_OPTION]);
767         settings.setValue("p1k_pause", vjs.p1KeyBindings[BUTTON_PAUSE]);
768         settings.setValue("p1k_0", vjs.p1KeyBindings[BUTTON_0]);
769         settings.setValue("p1k_1", vjs.p1KeyBindings[BUTTON_1]);
770         settings.setValue("p1k_2", vjs.p1KeyBindings[BUTTON_2]);
771         settings.setValue("p1k_3", vjs.p1KeyBindings[BUTTON_3]);
772         settings.setValue("p1k_4", vjs.p1KeyBindings[BUTTON_4]);
773         settings.setValue("p1k_5", vjs.p1KeyBindings[BUTTON_5]);
774         settings.setValue("p1k_6", vjs.p1KeyBindings[BUTTON_6]);
775         settings.setValue("p1k_7", vjs.p1KeyBindings[BUTTON_7]);
776         settings.setValue("p1k_8", vjs.p1KeyBindings[BUTTON_8]);
777         settings.setValue("p1k_9", vjs.p1KeyBindings[BUTTON_9]);
778         settings.setValue("p1k_pound", vjs.p1KeyBindings[BUTTON_d]);
779         settings.setValue("p1k_star", vjs.p1KeyBindings[BUTTON_s]);
780
781         settings.setValue("p2k_up", vjs.p2KeyBindings[BUTTON_U]);
782         settings.setValue("p2k_down", vjs.p2KeyBindings[BUTTON_D]);
783         settings.setValue("p2k_left", vjs.p2KeyBindings[BUTTON_L]);
784         settings.setValue("p2k_right", vjs.p2KeyBindings[BUTTON_R]);
785         settings.setValue("p2k_c", vjs.p2KeyBindings[BUTTON_C]);
786         settings.setValue("p2k_b", vjs.p2KeyBindings[BUTTON_B]);
787         settings.setValue("p2k_a", vjs.p2KeyBindings[BUTTON_A]);
788         settings.setValue("p2k_option", vjs.p2KeyBindings[BUTTON_OPTION]);
789         settings.setValue("p2k_pause", vjs.p2KeyBindings[BUTTON_PAUSE]);
790         settings.setValue("p2k_0", vjs.p2KeyBindings[BUTTON_0]);
791         settings.setValue("p2k_1", vjs.p2KeyBindings[BUTTON_1]);
792         settings.setValue("p2k_2", vjs.p2KeyBindings[BUTTON_2]);
793         settings.setValue("p2k_3", vjs.p2KeyBindings[BUTTON_3]);
794         settings.setValue("p2k_4", vjs.p2KeyBindings[BUTTON_4]);
795         settings.setValue("p2k_5", vjs.p2KeyBindings[BUTTON_5]);
796         settings.setValue("p2k_6", vjs.p2KeyBindings[BUTTON_6]);
797         settings.setValue("p2k_7", vjs.p2KeyBindings[BUTTON_7]);
798         settings.setValue("p2k_8", vjs.p2KeyBindings[BUTTON_8]);
799         settings.setValue("p2k_9", vjs.p2KeyBindings[BUTTON_9]);
800         settings.setValue("p2k_pound", vjs.p2KeyBindings[BUTTON_d]);
801         settings.setValue("p2k_star", vjs.p2KeyBindings[BUTTON_s]);
802 }