2 // mainwin.cpp - Qt-based GUI for Virtual Jaguar: Main Application Window
4 // (C) 2009 Underground Software
6 // JLH = James Hammons <jlhamm@acm.org>
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
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]
24 // - Remove SDL dependencies (sound, mainly) from Jaguar core lib
25 // - Fix inconsistency with trailing slashes in paths (eeproms needs one, software doesn't)
27 // SFDX CODE: 9XF9TUHFM2359
29 // Uncomment this for debugging...
31 //#define DEBUGFOO // Various tool debugging...
32 //#define DEBUGTP // Toolpalette debugging...
42 #include "filepicker.h"
43 #include "configdialog.h"
44 #include "generaltab.h"
53 #include "jagcdbios.h"
54 #include "jagstub2bios.h"
57 // According to SebRmv, this header isn't seen on Arch Linux either... :-/
59 // Apparently on win32, usleep() is not pulled in by the usual suspects.
63 // The way BSNES controls things is by setting a timer with a zero
64 // timeout, sleeping if not emulating anything. Seems there has to be a
67 // It has a novel approach to plugging-in/using different video/audio/input
68 // methods, can we do something similar or should we just use the built-in
71 // We're going to try to use the built-in OpenGL support and see how it goes.
72 // We'll make the VJ core modular so that it doesn't matter what GUI is in
73 // use, we can drop it in anywhere and use it as-is.
75 //MainWin::MainWin(QString filenameToRun): running(true), powerButtonOn(false),
76 MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
77 showUntunedTankCircuit(true), cartridgeLoaded(false), CDActive(false),
78 //, alpineLoadSuccessful(false),
79 // pauseForFileSelector(false), loadAndGo(false), plzDontKillMyComputer(false)
80 pauseForFileSelector(false), loadAndGo(autoRun), plzDontKillMyComputer(false)
82 for(int i=0; i<8; i++)
85 videoWidget = new GLWidget(this);
86 setCentralWidget(videoWidget);
87 setWindowIcon(QIcon(":/res/vj-icon.png"));
89 QString title = QString(tr("Virtual Jaguar " VJ_RELEASE_VERSION ));
91 if (vjs.hardwareTypeAlpine)
92 title += QString(tr(" - Alpine Mode"));
94 setWindowTitle(title);
96 aboutWin = new AboutWindow(this);
97 helpWin = new HelpWindow(this);
98 filePickWin = new FilePickerWindow(this);
100 videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
101 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
103 setUnifiedTitleAndToolBarOnMac(true);
107 quitAppAct = new QAction(tr("E&xit"), this);
108 // quitAppAct->setShortcuts(QKeySequence::Quit);
109 // quitAppAct->setShortcut(QKeySequence(tr("Alt+x")));
110 quitAppAct->setShortcut(QKeySequence(tr("Ctrl+q")));
111 quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
112 connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
114 powerGreen.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
115 powerGreen.addFile(":/res/power-on-green.png", QSize(), QIcon::Normal, QIcon::On);
116 powerRed.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
117 powerRed.addFile(":/res/power-on-red.png", QSize(), QIcon::Normal, QIcon::On);
119 // powerAct = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
120 powerAct = new QAction(powerGreen, tr("&Power"), this);
121 powerAct->setStatusTip(tr("Powers Jaguar on/off"));
122 powerAct->setCheckable(true);
123 powerAct->setChecked(false);
124 // powerAct->setDisabled(true);
125 connect(powerAct, SIGNAL(triggered()), this, SLOT(TogglePowerState()));
128 pauseIcon.addFile(":/res/pause-off", QSize(), QIcon::Normal, QIcon::Off);
129 pauseIcon.addFile(":/res/pause-on", QSize(), QIcon::Normal, QIcon::On);
130 // pauseAct = new QAction(QIcon(":/res/pause.png"), tr("Pause"), this);
131 pauseAct = new QAction(pauseIcon, tr("Pause"), this);
132 pauseAct->setStatusTip(tr("Toggles the running state"));
133 pauseAct->setCheckable(true);
134 pauseAct->setDisabled(true);
135 pauseAct->setShortcut(QKeySequence(tr("Esc")));
136 connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
138 zoomActs = new QActionGroup(this);
140 x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
141 x1Act->setStatusTip(tr("Set window zoom to 100%"));
142 x1Act->setCheckable(true);
143 connect(x1Act, SIGNAL(triggered()), this, SLOT(SetZoom100()));
145 x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
146 x2Act->setStatusTip(tr("Set window zoom to 200%"));
147 x2Act->setCheckable(true);
148 connect(x2Act, SIGNAL(triggered()), this, SLOT(SetZoom200()));
150 x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
151 x3Act->setStatusTip(tr("Set window zoom to 300%"));
152 x3Act->setCheckable(true);
153 connect(x3Act, SIGNAL(triggered()), this, SLOT(SetZoom300()));
155 tvTypeActs = new QActionGroup(this);
157 ntscAct = new QAction(QIcon(":/res/ntsc.png"), tr("NTSC"), tvTypeActs);
158 ntscAct->setStatusTip(tr("Sets Jaguar to NTSC mode"));
159 ntscAct->setCheckable(true);
160 connect(ntscAct, SIGNAL(triggered()), this, SLOT(SetNTSC()));
162 palAct = new QAction(QIcon(":/res/pal.png"), tr("PAL"), tvTypeActs);
163 palAct->setStatusTip(tr("Sets Jaguar to PAL mode"));
164 palAct->setCheckable(true);
165 connect(palAct, SIGNAL(triggered()), this, SLOT(SetPAL()));
167 blurAct = new QAction(QIcon(":/res/generic.png"), tr("Blur"), this);
168 blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
169 blurAct->setCheckable(true);
170 connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
172 aboutAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&About..."), this);
173 aboutAct->setStatusTip(tr("Blatant self-promotion"));
174 connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
176 helpAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&Contents..."), this);
177 helpAct->setStatusTip(tr("Help is available, if you should need it"));
178 connect(helpAct, SIGNAL(triggered()), this, SLOT(ShowHelpWin()));
180 filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this);
181 filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar"));
182 filePickAct->setShortcut(QKeySequence(tr("Ctrl+i")));
183 connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart()));
185 configAct = new QAction(QIcon(":/res/wrench.png"), tr("&Configure"), this);
186 configAct->setStatusTip(tr("Configure options for Virtual Jaguar"));
187 configAct->setShortcut(QKeySequence(tr("Ctrl+c")));
188 connect(configAct, SIGNAL(triggered()), this, SLOT(Configure()));
190 useCDAct = new QAction(QIcon(":/res/compact-disc.png"), tr("&Use CD Unit"), this);
191 useCDAct->setStatusTip(tr("Use Jaguar Virtual CD unit"));
192 // useCDAct->setShortcut(QKeySequence(tr("Ctrl+c")));
193 useCDAct->setCheckable(true);
194 connect(useCDAct, SIGNAL(triggered()), this, SLOT(ToggleCDUsage()));
196 frameAdvanceAct = new QAction(QIcon(":/res/frame-advance.png"), tr("&Frame Advance"), this);
197 frameAdvanceAct->setShortcut(QKeySequence(tr("F7")));
198 connect(frameAdvanceAct, SIGNAL(triggered()), this, SLOT(FrameAdvance()));
200 // Misc. connections...
201 connect(filePickWin, SIGNAL(RequestLoad(QString)), this, SLOT(LoadSoftware(QString)));
202 connect(filePickWin, SIGNAL(FilePickerHiding()), this, SLOT(Unpause()));
204 // Create menus & toolbars
206 fileMenu = menuBar()->addMenu(tr("&Jaguar"));
207 fileMenu->addAction(powerAct);
208 fileMenu->addAction(pauseAct);
209 fileMenu->addAction(frameAdvanceAct);
210 fileMenu->addAction(filePickAct);
211 fileMenu->addAction(useCDAct);
212 fileMenu->addAction(configAct);
213 fileMenu->addAction(quitAppAct);
215 helpMenu = menuBar()->addMenu(tr("&Help"));
216 helpMenu->addAction(helpAct);
217 helpMenu->addAction(aboutAct);
219 toolbar = addToolBar(tr("Stuff"));
220 toolbar->addAction(powerAct);
221 toolbar->addAction(pauseAct);
222 toolbar->addAction(filePickAct);
223 toolbar->addAction(useCDAct);
224 toolbar->addSeparator();
225 toolbar->addAction(x1Act);
226 toolbar->addAction(x2Act);
227 toolbar->addAction(x3Act);
228 toolbar->addSeparator();
229 toolbar->addAction(ntscAct);
230 toolbar->addAction(palAct);
231 toolbar->addSeparator();
232 toolbar->addAction(blurAct);
235 statusBar()->showMessage(tr("Ready"));
239 // Do this in case original size isn't correct (mostly for the first-run case)
242 // Set up timer based loop for animation...
243 timer = new QTimer(this);
244 connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
245 //This is only correct for PAL. !!! FIX !!! [DONE]
246 //Use timer->setInterval( int msec ) to fix this on the fly
248 // This isn't very accurate for NTSC: This is early by 40 msec per frame.
249 // This is because it's discarding the 0.6666... on the end of the fraction.
250 // Alas, 6 doesn't divide cleanly into 10. :-P
251 timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
253 // We set this initially, to make VJ behave somewhat as it would if no
254 // cart were inserted and the BIOS was set as active...
255 jaguarCartInserted = true;
256 WriteLog("Virtual Jaguar %s (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
257 WriteLog("VJ: Initializing jaguar subsystem...\n");
259 memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
261 // Check for filename passed in on the command line...
262 // if (!filenameToRun.isEmpty())
266 // Attempt to load/run the file the user passed in...
267 // LoadSoftware(filenameToRun);
268 //// memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
269 // Prevent the file scanner from running...
273 // Load up the default ROM if in Alpine mode:
274 if (vjs.hardwareTypeAlpine)
276 bool romLoaded = JaguarLoadFile(vjs.alpineROMPath);
278 // If regular load failed, try just a straight file load
279 // (Dev only! I don't want people to start getting lazy with their releases again! :-P)
281 romLoaded = AlpineLoadFile(vjs.alpineROMPath);
284 WriteLog("Alpine Mode: Successfully loaded file \"%s\".\n", vjs.alpineROMPath);
286 WriteLog("Alpine Mode: Unable to load file \"%s\"!\n", vjs.alpineROMPath);
288 // Attempt to load/run the ABS file...
289 LoadSoftware(vjs.absROMPath);
290 memcpy(jagMemSpace + 0xE00000, jaguarDevBootROM2, 0x20000); // Use the stub BIOS
291 // Prevent the scanner from running...
295 // memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Otherwise, use the stock BIOS
297 // Run the scanner if nothing passed in and *not* Alpine mode...
298 // NB: Really need to look into caching the info scanned in here...
299 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
303 void MainWin::LoadFile(QString file)
309 void MainWin::SyncUI(void)
311 // Set toolbar buttons/menus based on settings read in (sync the UI)...
312 blurAct->setChecked(vjs.glFilter);
313 x1Act->setChecked(zoomLevel == 1);
314 x2Act->setChecked(zoomLevel == 2);
315 x3Act->setChecked(zoomLevel == 3);
316 // running = powerAct->isChecked();
317 ntscAct->setChecked(vjs.hardwareTypeNTSC);
318 palAct->setChecked(!vjs.hardwareTypeNTSC);
319 powerAct->setIcon(vjs.hardwareTypeNTSC ? powerRed : powerGreen);
323 void MainWin::closeEvent(QCloseEvent * event)
326 // This should only be done by the config dialog
329 event->accept(); // ignore() if can't close for some reason
333 void MainWin::keyPressEvent(QKeyEvent * e)
335 // We ignore the Alt key for now, since it causes problems with the GUI
336 if (e->key() == Qt::Key_Alt)
346 void MainWin::keyReleaseEvent(QKeyEvent * e)
348 // We ignore the Alt key for now, since it causes problems with the GUI
349 if (e->key() == Qt::Key_Alt)
355 HandleKeys(e, false);
359 void MainWin::HandleKeys(QKeyEvent * e, bool state)
361 enum { P1LEFT = 0, P1RIGHT, P1UP, P1DOWN, P2LEFT, P2RIGHT, P2UP, P2DOWN };
362 // We kill bad key combos here, before they can get to the emulator...
363 // This also kills the illegal instruction problem that cropped up in Rayman!
364 // May want to do this by killing the old one instead of ignoring the new one...
365 // Seems to work better that way...
367 // The problem with this approach is that it causes bad results because it doesn't do
368 // any checking of previous states. Need to come up with something better because this
369 // causes problems where the keyboard acts as if it were unresponsive. :-P
371 if ((e->key() == vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
372 || (e->key() == vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
373 || (e->key() == vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
374 || (e->key() == vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U]))
378 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
379 joypad_0_buttons[BUTTON_R] = 0;
380 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
381 joypad_0_buttons[BUTTON_L] = 0;
382 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
383 joypad_0_buttons[BUTTON_D] = 0;
384 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U])
385 joypad_0_buttons[BUTTON_U] = 0;
387 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L] && joypad_1_buttons[BUTTON_R])
388 joypad_1_buttons[BUTTON_R] = 0;
389 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R] && joypad_1_buttons[BUTTON_L])
390 joypad_1_buttons[BUTTON_L] = 0;
391 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U] && joypad_1_buttons[BUTTON_D])
392 joypad_1_buttons[BUTTON_D] = 0;
393 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D] && joypad_1_buttons[BUTTON_U])
394 joypad_1_buttons[BUTTON_U] = 0;
396 //hrm, this still has sticky state problems... Ugh!
397 // First, settle key states...
398 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L])
399 keyHeld[P1LEFT] = state;
400 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R])
401 keyHeld[P1RIGHT] = state;
402 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U])
403 keyHeld[P1UP] = state;
404 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D])
405 keyHeld[P1DOWN] = state;
406 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L])
407 keyHeld[P2LEFT] = state;
408 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R])
409 keyHeld[P2RIGHT] = state;
410 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U])
411 keyHeld[P2UP] = state;
412 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D])
413 keyHeld[P2DOWN] = state;
415 // Next, check for conflicts and bail out if there are any...
416 if ((keyHeld[P1LEFT] && keyHeld[P1RIGHT])
417 || (keyHeld[P1UP] && keyHeld[P1DOWN])
418 || (keyHeld[P2LEFT] && keyHeld[P2RIGHT])
419 || (keyHeld[P2UP] && keyHeld[P2DOWN]))
424 // No bad combos exist, let's stuff the emulator key buffers...!
425 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
427 if (e->key() == (int)vjs.p1KeyBindings[i])
428 // joypad_0_buttons[i] = (uint8)state;
429 joypad_0_buttons[i] = (state ? 0x01 : 0x00);
431 // Pad #2 is screwing up pad #1. Prolly a problem in joystick.cpp...
432 // So let's try to fix it there. :-P [DONE]
433 if (e->key() == (int)vjs.p2KeyBindings[i])
434 // joypad_1_buttons[i] = (uint8)state;
435 joypad_1_buttons[i] = (state ? 0x01 : 0x00);
440 void MainWin::Open(void)
445 void MainWin::Configure(void)
447 // Call the configuration dialog and update settings
448 ConfigDialog dlg(this);
450 dlg.generalTab->useUnknownSoftware->setChecked(allowUnknownSoftware);
452 if (dlg.exec() == false)
455 QString before = vjs.ROMPath;
456 QString alpineBefore = vjs.alpineROMPath;
457 QString absBefore = vjs.absROMPath;
458 bool audioBefore = vjs.audioEnabled;
459 dlg.UpdateVJSettings();
460 QString after = vjs.ROMPath;
461 QString alpineAfter = vjs.alpineROMPath;
462 QString absAfter = vjs.absROMPath;
463 bool audioAfter = vjs.audioEnabled;
465 bool allowOld = allowUnknownSoftware;
467 allowUnknownSoftware = dlg.generalTab->useUnknownSoftware->isChecked();
469 // We rescan the "software" folder if the user either changed the path or
470 // checked/unchecked the "Allow unknown files" option in the config dialog.
471 if ((before != after) || (allowOld != allowUnknownSoftware))
472 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
474 // If the "Alpine" ROM is changed, then let's load it...
475 if (alpineBefore != alpineAfter)
477 if (!JaguarLoadFile(vjs.alpineROMPath) && !AlpineLoadFile(vjs.alpineROMPath))
479 // Oh crap, we couldn't get the file! Alert the media!
481 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.alpineROMPath));
482 msg.setIcon(QMessageBox::Warning);
487 // If the "ABS" ROM is changed, then let's load it...
488 if (absBefore != absAfter)
490 if (!JaguarLoadFile(vjs.absROMPath))
492 // Oh crap, we couldn't get the file! Alert the media!
494 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.absROMPath));
495 msg.setIcon(QMessageBox::Warning);
500 // If the "Enable audio" checkbox changed, then we have to re-init the DAC...
501 if (audioBefore != audioAfter)
507 // Just in case we crash before a clean exit...
513 // Here's the main emulator loop
515 void MainWin::Timer(void)
520 if (showUntunedTankCircuit)
522 // Some machines can't handle this, so we give them the option to disable it. :-)
523 if (!plzDontKillMyComputer)
525 // Random hash & trash
526 // We try to simulate an untuned tank circuit here... :-)
527 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
529 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
531 videoWidget->buffer[(y * videoWidget->textureWidth) + x]
532 = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;
539 // Otherwise, run the Jaguar simulation
543 videoWidget->updateGL();
547 void MainWin::TogglePowerState(void)
549 powerButtonOn = !powerButtonOn;
552 // With the power off, we simulate white noise on the screen. :-)
555 useCDAct->setDisabled(false);
556 palAct->setDisabled(false);
557 ntscAct->setDisabled(false);
558 pauseAct->setChecked(false);
559 pauseAct->setDisabled(true);
560 showUntunedTankCircuit = true;
561 // This is just in case the ROM we were playing was in a narrow or wide field mode,
562 // so the untuned tank sim doesn't look wrong. :-)
567 useCDAct->setDisabled(true);
568 palAct->setDisabled(true);
569 ntscAct->setDisabled(true);
570 pauseAct->setChecked(false);
571 pauseAct->setDisabled(false);
572 showUntunedTankCircuit = false;
574 // Otherwise, we prepare for running regular software...
577 // Should check for cartridgeLoaded here as well...!
578 // We can clear it when toggling CDActive on, so that when we power cycle it does the
579 // expected thing. Otherwise, if we use the file picker to insert a cart, we expect
580 // to run the cart! Maybe have a RemoveCart function that only works if the CD unit
582 setWindowTitle(QString("Virtual Jaguar " VJ_RELEASE_VERSION
583 " - Now playing: Jaguar CD"));
586 WriteLog("GUI: Resetting Jaguar...\n");
592 void MainWin::ToggleRunState(void)
598 for(uint32_t i=0; i<(uint32_t)(videoWidget->textureWidth * 256); i++)
600 uint32_t pixel = videoWidget->buffer[i];
601 uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
602 pixel = ((r + g + b) / 3) & 0x00FF;
603 videoWidget->buffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
606 videoWidget->updateGL();
611 void MainWin::SetZoom100(void)
618 void MainWin::SetZoom200(void)
625 void MainWin::SetZoom300(void)
632 void MainWin::SetNTSC(void)
634 powerAct->setIcon(powerRed);
635 timer->setInterval(16);
636 vjs.hardwareTypeNTSC = true;
642 void MainWin::SetPAL(void)
644 powerAct->setIcon(powerGreen);
645 timer->setInterval(20);
646 vjs.hardwareTypeNTSC = false;
652 void MainWin::ToggleBlur(void)
654 vjs.glFilter = !vjs.glFilter;
659 void MainWin::ShowAboutWin(void)
665 void MainWin::ShowHelpWin(void)
671 void MainWin::InsertCart(void)
673 // If the emulator is running, we pause it here and unpause it later
674 // if we dismiss the file selector without choosing anything
675 if (running && powerButtonOn)
678 pauseForFileSelector = true;
685 void MainWin::Unpause(void)
687 // Here we unpause the emulator if it was paused when we went into the file selector
688 if (pauseForFileSelector)
690 pauseForFileSelector = false;
692 // Some nutter might have unpaused while in the file selector, so check for that
699 void MainWin::LoadSoftware(QString file)
701 running = false; // Prevent bad things(TM) from happening...
702 pauseForFileSelector = false; // Reset the file selector pause flag
703 SET32(jaguarMainRAM, 0, 0x00200000); // Set top of stack...
704 cartridgeLoaded = JaguarLoadFile(file.toAscii().data());
706 char * biosPointer = jaguarBootROM;
708 if (vjs.hardwareTypeAlpine)
709 biosPointer = jaguarDevBootROM2;
711 memcpy(jagMemSpace + 0xE00000, biosPointer, 0x20000);
713 powerAct->setDisabled(false);
714 powerAct->setChecked(true);
715 powerButtonOn = false;
718 if (!vjs.hardwareTypeAlpine && !loadAndGo)
720 QString newTitle = QString("Virtual Jaguar " VJ_RELEASE_VERSION " - Now playing: %1")
721 .arg(filePickWin->GetSelectedPrettyName());
722 setWindowTitle(newTitle);
727 void MainWin::ToggleCDUsage(void)
729 CDActive = !CDActive;
734 powerAct->setDisabled(false);
738 powerAct->setDisabled(true);
741 // Set up the Jaguar CD for execution, otherwise, clear memory
743 memcpy(jagMemSpace + 0x800000, jaguarCDBootROM, 0x40000);
745 memset(jagMemSpace + 0x800000, 0xFF, 0x40000);
750 void MainWin::FrameAdvance(void)
752 //printf("Frame Advance...\n");
753 // Execute 1 frame, then exit (only useful in Pause mode)
755 videoWidget->updateGL();
759 void MainWin::ResizeMainWindow(void)
761 videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
764 for(int i=0; i<2; i++)
768 QApplication::processEvents();
773 #warning "!!! Need to check the window geometry to see if the positions are legal !!!"
774 // i.e., someone could drag it to another screen, close it, then disconnect that screen
775 void MainWin::ReadSettings(void)
777 QSettings settings("Underground Software", "Virtual Jaguar");
778 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
779 QSize size = settings.value("size", QSize(400, 400)).toSize();
782 pos = settings.value("cartLoadPos", QPoint(200, 200)).toPoint();
783 filePickWin->move(pos);
785 zoomLevel = settings.value("zoom", 2).toInt();
786 allowUnknownSoftware = settings.value("showUnknownSoftware", false).toBool();
788 vjs.useJoystick = settings.value("useJoystick", false).toBool();
789 vjs.joyport = settings.value("joyport", 0).toInt();
790 vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
791 vjs.frameSkip = settings.value("frameSkip", 0).toInt();
792 vjs.useJaguarBIOS = settings.value("useJaguarBIOS", false).toBool();
793 vjs.GPUEnabled = settings.value("GPUEnabled", true).toBool();
794 vjs.DSPEnabled = settings.value("DSPEnabled", false).toBool();
795 vjs.audioEnabled = settings.value("audioEnabled", true).toBool();
796 vjs.usePipelinedDSP = settings.value("usePipelinedDSP", false).toBool();
797 vjs.fullscreen = settings.value("fullscreen", false).toBool();
798 vjs.useOpenGL = settings.value("useOpenGL", true).toBool();
799 vjs.glFilter = settings.value("glFilterType", 1).toInt();
800 vjs.renderType = settings.value("renderType", 0).toInt();
801 vjs.allowWritesToROM = settings.value("writeROM", false).toBool();
802 // strcpy(vjs.jagBootPath, settings.value("JagBootROM", "./bios/[BIOS] Atari Jaguar (USA, Europe).zip").toString().toAscii().data());
803 // strcpy(vjs.CDBootPath, settings.value("CDBootROM", "./bios/jagcd.rom").toString().toAscii().data());
804 strcpy(vjs.EEPROMPath, settings.value("EEPROMs", "./eeproms/").toString().toAscii().data());
805 strcpy(vjs.ROMPath, settings.value("ROMs", "./software/").toString().toAscii().data());
806 strcpy(vjs.alpineROMPath, settings.value("DefaultROM", "").toString().toAscii().data());
807 strcpy(vjs.absROMPath, settings.value("DefaultABS", "").toString().toAscii().data());
808 WriteLog("MainWin: Paths\n");
809 //WriteLog(" jagBootPath = \"%s\"\n", vjs.jagBootPath);
810 //WriteLog(" CDBootPath = \"%s\"\n", vjs.CDBootPath);
811 WriteLog(" EEPROMPath = \"%s\"\n", vjs.EEPROMPath);
812 WriteLog(" ROMPath = \"%s\"\n", vjs.ROMPath);
813 WriteLog("AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);
814 WriteLog(" absROMPath = \"%s\"\n", vjs.absROMPath);
815 WriteLog("Pipelined DSP = %s\n", (vjs.usePipelinedDSP ? "ON" : "off"));
817 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
818 vjs.p1KeyBindings[BUTTON_U] = settings.value("p1k_up", Qt::Key_S).toInt();
819 vjs.p1KeyBindings[BUTTON_D] = settings.value("p1k_down", Qt::Key_X).toInt();
820 vjs.p1KeyBindings[BUTTON_L] = settings.value("p1k_left", Qt::Key_A).toInt();
821 vjs.p1KeyBindings[BUTTON_R] = settings.value("p1k_right", Qt::Key_D).toInt();
822 vjs.p1KeyBindings[BUTTON_C] = settings.value("p1k_c", Qt::Key_J).toInt();
823 vjs.p1KeyBindings[BUTTON_B] = settings.value("p1k_b", Qt::Key_K).toInt();
824 vjs.p1KeyBindings[BUTTON_A] = settings.value("p1k_a", Qt::Key_L).toInt();
825 vjs.p1KeyBindings[BUTTON_OPTION] = settings.value("p1k_option", Qt::Key_O).toInt();
826 vjs.p1KeyBindings[BUTTON_PAUSE] = settings.value("p1k_pause", Qt::Key_P).toInt();
827 vjs.p1KeyBindings[BUTTON_0] = settings.value("p1k_0", Qt::Key_0).toInt();
828 vjs.p1KeyBindings[BUTTON_1] = settings.value("p1k_1", Qt::Key_1).toInt();
829 vjs.p1KeyBindings[BUTTON_2] = settings.value("p1k_2", Qt::Key_2).toInt();
830 vjs.p1KeyBindings[BUTTON_3] = settings.value("p1k_3", Qt::Key_3).toInt();
831 vjs.p1KeyBindings[BUTTON_4] = settings.value("p1k_4", Qt::Key_4).toInt();
832 vjs.p1KeyBindings[BUTTON_5] = settings.value("p1k_5", Qt::Key_5).toInt();
833 vjs.p1KeyBindings[BUTTON_6] = settings.value("p1k_6", Qt::Key_6).toInt();
834 vjs.p1KeyBindings[BUTTON_7] = settings.value("p1k_7", Qt::Key_7).toInt();
835 vjs.p1KeyBindings[BUTTON_8] = settings.value("p1k_8", Qt::Key_8).toInt();
836 vjs.p1KeyBindings[BUTTON_9] = settings.value("p1k_9", Qt::Key_9).toInt();
837 vjs.p1KeyBindings[BUTTON_d] = settings.value("p1k_pound", Qt::Key_Minus).toInt();
838 vjs.p1KeyBindings[BUTTON_s] = settings.value("p1k_star", Qt::Key_Equal).toInt();
840 vjs.p2KeyBindings[BUTTON_U] = settings.value("p2k_up", Qt::Key_Up).toInt();
841 vjs.p2KeyBindings[BUTTON_D] = settings.value("p2k_down", Qt::Key_Down).toInt();
842 vjs.p2KeyBindings[BUTTON_L] = settings.value("p2k_left", Qt::Key_Left).toInt();
843 vjs.p2KeyBindings[BUTTON_R] = settings.value("p2k_right", Qt::Key_Right).toInt();
844 vjs.p2KeyBindings[BUTTON_C] = settings.value("p2k_c", Qt::Key_Z).toInt();
845 vjs.p2KeyBindings[BUTTON_B] = settings.value("p2k_b", Qt::Key_X).toInt();
846 vjs.p2KeyBindings[BUTTON_A] = settings.value("p2k_a", Qt::Key_C).toInt();
847 vjs.p2KeyBindings[BUTTON_OPTION] = settings.value("p2k_option", Qt::Key_Apostrophe).toInt();
848 vjs.p2KeyBindings[BUTTON_PAUSE] = settings.value("p2k_pause", Qt::Key_Return).toInt();
849 vjs.p2KeyBindings[BUTTON_0] = settings.value("p2k_0", Qt::Key_0).toInt();
850 vjs.p2KeyBindings[BUTTON_1] = settings.value("p2k_1", Qt::Key_1).toInt();
851 vjs.p2KeyBindings[BUTTON_2] = settings.value("p2k_2", Qt::Key_2).toInt();
852 vjs.p2KeyBindings[BUTTON_3] = settings.value("p2k_3", Qt::Key_3).toInt();
853 vjs.p2KeyBindings[BUTTON_4] = settings.value("p2k_4", Qt::Key_4).toInt();
854 vjs.p2KeyBindings[BUTTON_5] = settings.value("p2k_5", Qt::Key_5).toInt();
855 vjs.p2KeyBindings[BUTTON_6] = settings.value("p2k_6", Qt::Key_6).toInt();
856 vjs.p2KeyBindings[BUTTON_7] = settings.value("p2k_7", Qt::Key_7).toInt();
857 vjs.p2KeyBindings[BUTTON_8] = settings.value("p2k_8", Qt::Key_8).toInt();
858 vjs.p2KeyBindings[BUTTON_9] = settings.value("p2k_9", Qt::Key_9).toInt();
859 vjs.p2KeyBindings[BUTTON_d] = settings.value("p2k_pound", Qt::Key_Slash).toInt();
860 vjs.p2KeyBindings[BUTTON_s] = settings.value("p2k_star", Qt::Key_Asterisk).toInt();
864 void MainWin::WriteSettings(void)
866 QSettings settings("Underground Software", "Virtual Jaguar");
867 settings.setValue("pos", pos());
868 settings.setValue("size", size());
869 settings.setValue("cartLoadPos", filePickWin->pos());
871 settings.setValue("zoom", zoomLevel);
872 settings.setValue("showUnknownSoftware", allowUnknownSoftware);
874 settings.setValue("useJoystick", vjs.useJoystick);
875 settings.setValue("joyport", vjs.joyport);
876 settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
877 settings.setValue("frameSkip", vjs.frameSkip);
878 settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
879 settings.setValue("GPUEnabled", vjs.GPUEnabled);
880 settings.setValue("DSPEnabled", vjs.DSPEnabled);
881 settings.setValue("audioEnabled", vjs.audioEnabled);
882 settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
883 settings.setValue("fullscreen", vjs.fullscreen);
884 settings.setValue("useOpenGL", vjs.useOpenGL);
885 settings.setValue("glFilterType", vjs.glFilter);
886 settings.setValue("renderType", vjs.renderType);
887 settings.setValue("writeROM", vjs.allowWritesToROM);
888 settings.setValue("JagBootROM", vjs.jagBootPath);
889 settings.setValue("CDBootROM", vjs.CDBootPath);
890 settings.setValue("EEPROMs", vjs.EEPROMPath);
891 settings.setValue("ROMs", vjs.ROMPath);
892 settings.setValue("DefaultROM", vjs.alpineROMPath);
893 settings.setValue("DefaultABS", vjs.absROMPath);
895 settings.setValue("p1k_up", vjs.p1KeyBindings[BUTTON_U]);
896 settings.setValue("p1k_down", vjs.p1KeyBindings[BUTTON_D]);
897 settings.setValue("p1k_left", vjs.p1KeyBindings[BUTTON_L]);
898 settings.setValue("p1k_right", vjs.p1KeyBindings[BUTTON_R]);
899 settings.setValue("p1k_c", vjs.p1KeyBindings[BUTTON_C]);
900 settings.setValue("p1k_b", vjs.p1KeyBindings[BUTTON_B]);
901 settings.setValue("p1k_a", vjs.p1KeyBindings[BUTTON_A]);
902 settings.setValue("p1k_option", vjs.p1KeyBindings[BUTTON_OPTION]);
903 settings.setValue("p1k_pause", vjs.p1KeyBindings[BUTTON_PAUSE]);
904 settings.setValue("p1k_0", vjs.p1KeyBindings[BUTTON_0]);
905 settings.setValue("p1k_1", vjs.p1KeyBindings[BUTTON_1]);
906 settings.setValue("p1k_2", vjs.p1KeyBindings[BUTTON_2]);
907 settings.setValue("p1k_3", vjs.p1KeyBindings[BUTTON_3]);
908 settings.setValue("p1k_4", vjs.p1KeyBindings[BUTTON_4]);
909 settings.setValue("p1k_5", vjs.p1KeyBindings[BUTTON_5]);
910 settings.setValue("p1k_6", vjs.p1KeyBindings[BUTTON_6]);
911 settings.setValue("p1k_7", vjs.p1KeyBindings[BUTTON_7]);
912 settings.setValue("p1k_8", vjs.p1KeyBindings[BUTTON_8]);
913 settings.setValue("p1k_9", vjs.p1KeyBindings[BUTTON_9]);
914 settings.setValue("p1k_pound", vjs.p1KeyBindings[BUTTON_d]);
915 settings.setValue("p1k_star", vjs.p1KeyBindings[BUTTON_s]);
917 settings.setValue("p2k_up", vjs.p2KeyBindings[BUTTON_U]);
918 settings.setValue("p2k_down", vjs.p2KeyBindings[BUTTON_D]);
919 settings.setValue("p2k_left", vjs.p2KeyBindings[BUTTON_L]);
920 settings.setValue("p2k_right", vjs.p2KeyBindings[BUTTON_R]);
921 settings.setValue("p2k_c", vjs.p2KeyBindings[BUTTON_C]);
922 settings.setValue("p2k_b", vjs.p2KeyBindings[BUTTON_B]);
923 settings.setValue("p2k_a", vjs.p2KeyBindings[BUTTON_A]);
924 settings.setValue("p2k_option", vjs.p2KeyBindings[BUTTON_OPTION]);
925 settings.setValue("p2k_pause", vjs.p2KeyBindings[BUTTON_PAUSE]);
926 settings.setValue("p2k_0", vjs.p2KeyBindings[BUTTON_0]);
927 settings.setValue("p2k_1", vjs.p2KeyBindings[BUTTON_1]);
928 settings.setValue("p2k_2", vjs.p2KeyBindings[BUTTON_2]);
929 settings.setValue("p2k_3", vjs.p2KeyBindings[BUTTON_3]);
930 settings.setValue("p2k_4", vjs.p2KeyBindings[BUTTON_4]);
931 settings.setValue("p2k_5", vjs.p2KeyBindings[BUTTON_5]);
932 settings.setValue("p2k_6", vjs.p2KeyBindings[BUTTON_6]);
933 settings.setValue("p2k_7", vjs.p2KeyBindings[BUTTON_7]);
934 settings.setValue("p2k_8", vjs.p2KeyBindings[BUTTON_8]);
935 settings.setValue("p2k_9", vjs.p2KeyBindings[BUTTON_9]);
936 settings.setValue("p2k_pound", vjs.p2KeyBindings[BUTTON_d]);
937 settings.setValue("p2k_star", vjs.p2KeyBindings[BUTTON_s]);
941 void MainWin::WriteUISettings(void)
943 QSettings settings("Underground Software", "Virtual Jaguar");
944 settings.setValue("pos", pos());
945 settings.setValue("size", size());
946 settings.setValue("cartLoadPos", filePickWin->pos());
948 settings.setValue("zoom", zoomLevel);