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