2 // mainwin.cpp - Qt-based GUI for Virtual Jaguar: Main Application Window
4 // (C) 2009 Underground Software
6 // JLH = James L. 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)
28 // Uncomment this for debugging...
30 //#define DEBUGFOO // Various tool debugging...
31 //#define DEBUGTP // Toolpalette debugging...
40 #include "filepicker.h"
41 #include "configdialog.h"
42 #include "generaltab.h"
51 #include "jagcdbios.h"
52 #include "jagstub2bios.h"
56 // Apparently on win32, usleep() is not pulled in by the usual suspects.
60 // Uncomment this to use built-in BIOS/CD-ROM BIOS
61 // You'll need a copy of jagboot.h & jagcd.h for this to work...!
62 // Creating those is left as an exercise for the reader. ;-)
63 //#define USE_BUILT_IN_BIOS
65 //#ifdef USE_BUILT_IN_BIOS
66 //#include "jagboot.h"
70 // The way BSNES controls things is by setting a timer with a zero
71 // timeout, sleeping if not emulating anything. Seems there has to be a
74 // It has a novel approach to plugging-in/using different video/audio/input
75 // methods, can we do something similar or should we just use the built-in
78 // We're going to try to use the built-in OpenGL support and see how it goes.
79 // We'll make the VJ core modular so that it doesn't matter what GUI is in
80 // use, we can drop it in anywhere and use it as-is.
82 MainWin::MainWin(): running(false), powerButtonOn(false), showUntunedTankCircuit(true),
83 cartridgeLoaded(false), CDActive(false),//, alpineLoadSuccessful(false),
84 pauseForFileSelector(false)
86 videoWidget = new GLWidget(this);
87 setCentralWidget(videoWidget);
88 setWindowIcon(QIcon(":/res/vj-icon.png"));
89 // setWindowTitle("Virtual Jaguar v2.0.0");
91 QString title = QString(tr("Virtual Jaguar " VJ_RELEASE_VERSION ));
93 if (vjs.hardwareTypeAlpine)
94 title += QString(tr(" - Alpine Mode"));
96 setWindowTitle(title);
98 aboutWin = new AboutWindow(this);
99 helpWin = new HelpWindow(this);
100 filePickWin = new FilePickerWindow(this);
102 videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
103 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
105 setUnifiedTitleAndToolBarOnMac(true);
109 quitAppAct = new QAction(tr("E&xit"), this);
110 quitAppAct->setShortcuts(QKeySequence::Quit);
111 quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
112 connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
114 powerAct = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
115 powerAct->setStatusTip(tr("Powers Jaguar on/off"));
116 powerAct->setCheckable(true);
117 powerAct->setChecked(false);
118 powerAct->setDisabled(true);
119 connect(powerAct, SIGNAL(triggered()), this, SLOT(TogglePowerState()));
121 pauseAct = new QAction(QIcon(":/res/pause.png"), tr("Pause"), this);
122 pauseAct->setStatusTip(tr("Toggles the running state"));
123 pauseAct->setCheckable(true);
124 pauseAct->setDisabled(true);
125 pauseAct->setShortcut(QKeySequence(tr("Esc")));
126 connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
128 zoomActs = new QActionGroup(this);
130 x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
131 x1Act->setStatusTip(tr("Set window zoom to 100%"));
132 x1Act->setCheckable(true);
133 connect(x1Act, SIGNAL(triggered()), this, SLOT(SetZoom100()));
135 x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
136 x2Act->setStatusTip(tr("Set window zoom to 200%"));
137 x2Act->setCheckable(true);
138 connect(x2Act, SIGNAL(triggered()), this, SLOT(SetZoom200()));
140 x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
141 x3Act->setStatusTip(tr("Set window zoom to 300%"));
142 x3Act->setCheckable(true);
143 connect(x3Act, SIGNAL(triggered()), this, SLOT(SetZoom300()));
145 tvTypeActs = new QActionGroup(this);
147 ntscAct = new QAction(QIcon(":/res/ntsc.png"), tr("NTSC"), tvTypeActs);
148 ntscAct->setStatusTip(tr("Sets Jaguar to NTSC mode"));
149 ntscAct->setCheckable(true);
150 connect(ntscAct, SIGNAL(triggered()), this, SLOT(SetNTSC()));
152 palAct = new QAction(QIcon(":/res/pal.png"), tr("PAL"), tvTypeActs);
153 palAct->setStatusTip(tr("Sets Jaguar to PAL mode"));
154 palAct->setCheckable(true);
155 connect(palAct, SIGNAL(triggered()), this, SLOT(SetPAL()));
157 blurAct = new QAction(QIcon(":/res/generic.png"), tr("Blur"), this);
158 blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
159 blurAct->setCheckable(true);
160 connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
162 aboutAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&About..."), this);
163 aboutAct->setStatusTip(tr("Blatant self-promotion"));
164 connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
166 helpAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&Contents..."), this);
167 helpAct->setStatusTip(tr("Help is available, if you should need it"));
168 connect(helpAct, SIGNAL(triggered()), this, SLOT(ShowHelpWin()));
170 filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this);
171 filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar"));
172 filePickAct->setShortcut(QKeySequence(tr("Ctrl+i")));
173 connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart()));
175 configAct = new QAction(QIcon(":/res/wrench.png"), tr("&Configure"), this);
176 configAct->setStatusTip(tr("Configure options for Virtual Jaguar"));
177 configAct->setShortcut(QKeySequence(tr("Ctrl+c")));
178 connect(configAct, SIGNAL(triggered()), this, SLOT(Configure()));
180 useCDAct = new QAction(QIcon(":/res/compact-disc.png"), tr("&Use CD Unit"), this);
181 useCDAct->setStatusTip(tr("Use Jaguar Virtual CD unit"));
182 // useCDAct->setShortcut(QKeySequence(tr("Ctrl+c")));
183 useCDAct->setCheckable(true);
184 connect(useCDAct, SIGNAL(triggered()), this, SLOT(ToggleCDUsage()));
186 // Misc. connections...
187 connect(filePickWin, SIGNAL(RequestLoad(QString)), this, SLOT(LoadSoftware(QString)));
188 connect(filePickWin, SIGNAL(FilePickerHiding()), this, SLOT(Unpause()));
190 // Create menus & toolbars
192 fileMenu = menuBar()->addMenu(tr("&Jaguar"));
193 fileMenu->addAction(powerAct);
194 fileMenu->addAction(pauseAct);
195 fileMenu->addAction(filePickAct);
196 fileMenu->addAction(useCDAct);
197 fileMenu->addAction(configAct);
198 fileMenu->addAction(quitAppAct);
200 helpMenu = menuBar()->addMenu(tr("&Help"));
201 helpMenu->addAction(helpAct);
202 helpMenu->addAction(aboutAct);
204 toolbar = addToolBar(tr("Stuff"));
205 toolbar->addAction(powerAct);
206 toolbar->addAction(pauseAct);
207 toolbar->addAction(filePickAct);
208 toolbar->addAction(useCDAct);
209 toolbar->addSeparator();
210 toolbar->addAction(x1Act);
211 toolbar->addAction(x2Act);
212 toolbar->addAction(x3Act);
213 toolbar->addSeparator();
214 toolbar->addAction(ntscAct);
215 toolbar->addAction(palAct);
216 toolbar->addSeparator();
217 toolbar->addAction(blurAct);
220 statusBar()->showMessage(tr("Ready"));
224 // Set toolbar buttons/menus based on settings read in (sync the UI)...
225 blurAct->setChecked(vjs.glFilter);
226 x1Act->setChecked(zoomLevel == 1);
227 x2Act->setChecked(zoomLevel == 2);
228 x3Act->setChecked(zoomLevel == 3);
229 running = powerAct->isChecked();
230 ntscAct->setChecked(vjs.hardwareTypeNTSC);
231 palAct->setChecked(!vjs.hardwareTypeNTSC);
233 // Do this in case original size isn't correct (mostly for the first-run case)
236 // Set up timer based loop for animation...
237 timer = new QTimer(this);
238 connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
241 WriteLog("Virtual Jaguar %s (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
242 WriteLog("VJ: Initializing jaguar subsystem...\n");
246 #ifdef USE_BUILT_IN_BIOS
247 // WriteLog("VJ: Using built in BIOS/CD BIOS...\n");
248 // memcpy(jaguarBootROM, jagBootROM, 0x20000);
249 // memcpy(jaguarCDBootROM, jagCDROM, 0x40000);
250 //// BIOSLoaded = CDBIOSLoaded = true;
251 // biosAvailable |= (BIOS_NORMAL | BIOS_CD);
253 // What would be nice here would be a way to check if the BIOS was loaded so that we
254 // could disable the pushbutton on the Misc Options menu... !!! FIX !!! [DONE here, but needs to be fixed in GUI as well!]
255 // WriteLog("VJ: About to attempt to load BIOSes...\n");
256 //This is short-circuiting the file finding thread... ??? WHY ???
257 //Not anymore. Was related to a QImage object creation/corruption bug elsewhere.
258 // BIOSLoaded = (JaguarLoadROM(jaguarBootROM, vjs.jagBootPath) == 0x20000 ? true : false);
259 // WriteLog("VJ: BIOS is %savailable...\n", (BIOSLoaded ? "" : "not "));
260 // CDBIOSLoaded = (JaguarLoadROM(jaguarCDBootROM, vjs.CDBootPath) == 0x40000 ? true : false);
261 // WriteLog("VJ: CD BIOS is %savailable...\n", (CDBIOSLoaded ? "" : "not "));
264 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
266 // Load up the default ROM if in Alpine mode:
267 if (vjs.hardwareTypeAlpine)
269 bool romLoaded = JaguarLoadFile(vjs.alpineROMPath);
271 // If regular load failed, try just a straight file load
272 // (Dev only! I don't want people to start getting lazy with their releases again! :-P)
274 romLoaded = AlpineLoadFile(vjs.alpineROMPath);
277 WriteLog("Alpine Mode: Successfully loaded file \"%s\".\n", vjs.alpineROMPath);
279 WriteLog("Alpine Mode: Unable to load file \"%s\"!\n", vjs.alpineROMPath);
281 // Attempt to load/run the ABS file...
282 LoadSoftware(vjs.absROMPath);
285 memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Otherwise, use the stock BIOS
288 void MainWin::closeEvent(QCloseEvent * event)
292 event->accept(); // ignore() if can't close for some reason
295 void MainWin::keyPressEvent(QKeyEvent * e)
300 void MainWin::keyReleaseEvent(QKeyEvent * e)
302 HandleKeys(e, false);
305 void MainWin::HandleKeys(QKeyEvent * e, bool state)
307 // We kill bad key combos here, before they can get to the emulator...
308 // This also kills the illegal instruction problem that cropped up in Rayman!
309 // May want to do this by killing the old one instead of ignoring the new one...
310 // Seems to work better that way...
312 if ((e->key() == vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
313 || (e->key() == vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
314 || (e->key() == vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
315 || (e->key() == vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U]))
318 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
319 joypad_0_buttons[BUTTON_R] = 0;
320 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
321 joypad_0_buttons[BUTTON_L] = 0;
322 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
323 joypad_0_buttons[BUTTON_D] = 0;
324 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U])
325 joypad_0_buttons[BUTTON_U] = 0;
327 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L] && joypad_1_buttons[BUTTON_R])
328 joypad_1_buttons[BUTTON_R] = 0;
329 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R] && joypad_1_buttons[BUTTON_L])
330 joypad_1_buttons[BUTTON_L] = 0;
331 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U] && joypad_1_buttons[BUTTON_D])
332 joypad_1_buttons[BUTTON_D] = 0;
333 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D] && joypad_1_buttons[BUTTON_U])
334 joypad_1_buttons[BUTTON_U] = 0;
337 // No bad combos exist, let's stuff the emulator key buffers...!
338 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
340 if (e->key() == (int)vjs.p1KeyBindings[i])
341 // joypad_0_buttons[i] = (uint8)state;
342 joypad_0_buttons[i] = (state ? 0x01 : 0x00);
344 // Pad #2 is screwing up pad #1. Prolly a problem in joystick.cpp...
345 // So let's try to fix it there. :-P
346 if (e->key() == (int)vjs.p2KeyBindings[i])
347 // joypad_1_buttons[i] = (uint8)state;
348 joypad_1_buttons[i] = (state ? 0x01 : 0x00);
352 void MainWin::Open(void)
356 void MainWin::Configure(void)
358 // Call the configuration dialog and update settings
359 ConfigDialog dlg(this);
361 dlg.generalTab->useUnknownSoftware->setChecked(allowUnknownSoftware);
363 if (dlg.exec() == false)
366 QString before = vjs.ROMPath;
367 QString alpineBefore = vjs.alpineROMPath;
368 QString absBefore = vjs.absROMPath;
369 bool audioBefore = vjs.audioEnabled;
370 dlg.UpdateVJSettings();
371 QString after = vjs.ROMPath;
372 QString alpineAfter = vjs.alpineROMPath;
373 QString absAfter = vjs.absROMPath;
374 bool audioAfter = vjs.audioEnabled;
376 bool allowOld = allowUnknownSoftware;
378 allowUnknownSoftware = dlg.generalTab->useUnknownSoftware->isChecked();
380 // We rescan the "software" folder if the user either changed the path or
381 // checked/unchecked the "Allow unknown files" option in the config dialog.
382 if ((before != after) || (allowOld != allowUnknownSoftware))
383 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
385 // If the "Alpine" ROM is changed, then let's load it...
386 if (alpineBefore != alpineAfter)
388 if (!JaguarLoadFile(vjs.alpineROMPath) && !AlpineLoadFile(vjs.alpineROMPath))
390 // Oh crap, we couldn't get the file! Alert the media!
392 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.alpineROMPath));
393 msg.setIcon(QMessageBox::Warning);
398 // If the "ABS" ROM is changed, then let's load it...
399 if (absBefore != absAfter)
401 if (!JaguarLoadFile(vjs.absROMPath))
403 // Oh crap, we couldn't get the file! Alert the media!
405 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.absROMPath));
406 msg.setIcon(QMessageBox::Warning);
411 // If the "Enable audio" checkbox changed, then we have to re-init the DAC...
412 if (audioBefore != audioAfter)
418 // Just in case we crash before a clean exit...
423 // Here's the main emulator loop
425 void MainWin::Timer(void)
430 if (showUntunedTankCircuit)
432 // Random hash & trash
433 // We try to simulate an untuned tank circuit here... :-)
434 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
436 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
438 videoWidget->buffer[(y * videoWidget->textureWidth) + x] = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;// | (rand() & 0xFF);//0x000000FF;
439 // buffer[(y * textureWidth) + x] = x*y;
445 // Otherwise, run the Jaguar simulation
447 // memcpy(videoWidget->buffer, backbuffer, videoWidget->rasterHeight * videoWidget->rasterWidth);
448 memcpy(videoWidget->buffer, backbuffer, videoWidget->rasterHeight * videoWidget->textureWidth * sizeof(uint32_t));
449 // memcpy(surface->pixels, backbuffer, TOMGetVideoModeWidth() * TOMGetVideoModeHeight() * 4);
452 videoWidget->updateGL();
455 void MainWin::TogglePowerState(void)
457 powerButtonOn = !powerButtonOn;
459 // With the power off, we simulate white noise on the screen. :-)
462 pauseAct->setChecked(false);
463 pauseAct->setDisabled(true);
464 showUntunedTankCircuit = true;
466 // This is just in case the ROM we were playing was in a narrow or wide field mode,
467 // so the untuned tank sim doesn't look wrong. :-)
472 //NOTE: Low hanging fruit: We can simplify this a lot...
473 // Otherwise, we prepare for running regular software...
476 showUntunedTankCircuit = false;//(cartridgeLoaded ? false : true);
477 pauseAct->setChecked(false);
478 pauseAct->setDisabled(false);//!cartridgeLoaded);
480 // Or, set up for the Jaguar CD
483 // Should check for cartridgeLoaded here as well...!
484 // We can clear it when toggling CDActive on, so that when we power cycle it does the
485 // expected thing. Otherwise, if we use the file picker to insert a cart, we expect
486 // to run the cart! Maybe have a RemoveCart function that only works if the CD unit
488 showUntunedTankCircuit = false;
489 pauseAct->setChecked(false);
490 pauseAct->setDisabled(false);
491 memcpy(jagMemSpace + 0x800000, jaguarCDBootROM, 0x40000);
492 setWindowTitle(QString("Virtual Jaguar " VJ_RELEASE_VERSION
493 " - Now playing: Jaguar CD"));
496 WriteLog("GUI: Resetting Jaguar...\n");
502 void MainWin::ToggleRunState(void)
508 for(uint32_t i=0; i<(uint32_t)(videoWidget->textureWidth * 256); i++)
510 uint32_t pixel = backbuffer[i];
511 uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
512 pixel = ((r + g + b) / 3) & 0x00FF;
513 backbuffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
516 memcpy(videoWidget->buffer, backbuffer, videoWidget->rasterHeight * videoWidget->textureWidth * sizeof(uint32_t));
518 videoWidget->updateGL();
522 void MainWin::SetZoom100(void)
528 void MainWin::SetZoom200(void)
534 void MainWin::SetZoom300(void)
540 void MainWin::SetNTSC(void)
542 vjs.hardwareTypeNTSC = true;
546 void MainWin::SetPAL(void)
548 vjs.hardwareTypeNTSC = false;
552 void MainWin::ToggleBlur(void)
554 vjs.glFilter = !vjs.glFilter;
557 void MainWin::ShowAboutWin(void)
562 void MainWin::ShowHelpWin(void)
567 void MainWin::InsertCart(void)
569 // If the emulator is running, we pause it here and unpause it later
570 // if we dismiss the file selector without choosing anything
574 pauseForFileSelector = true;
580 void MainWin::Unpause(void)
582 // Here we unpause the emulator if it was paused when we went into the file selector
583 if (pauseForFileSelector)
585 pauseForFileSelector = false;
590 void MainWin::LoadSoftware(QString file)
592 running = false; // Prevent bad things(TM) from happening...
593 pauseForFileSelector = false; // Reset the file selector pause flag
594 SET32(jaguarMainRAM, 0, 0x00200000); // Set top of stack...
595 cartridgeLoaded = JaguarLoadFile(file.toAscii().data());
597 char * biosPointer = jaguarBootROM;
599 if (vjs.hardwareTypeAlpine)
600 biosPointer = jaguarDevBootROM2;
602 memcpy(jagMemSpace + 0xE00000, biosPointer, 0x20000);
604 powerAct->setDisabled(false);
605 powerAct->setChecked(true);
606 powerButtonOn = false;
609 if (!vjs.hardwareTypeAlpine)
611 QString newTitle = QString("Virtual Jaguar " VJ_RELEASE_VERSION " - Now playing: %1")
612 .arg(filePickWin->GetSelectedPrettyName());
613 setWindowTitle(newTitle);
617 void MainWin::ToggleCDUsage(void)
619 CDActive = !CDActive;
623 powerAct->setDisabled(false);
627 powerAct->setDisabled(true);
631 void MainWin::ResizeMainWindow(void)
633 videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
636 for(int i=0; i<2; i++)
640 QApplication::processEvents();
644 void MainWin::ReadSettings(void)
646 QSettings settings("Underground Software", "Virtual Jaguar");
647 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
648 QSize size = settings.value("size", QSize(400, 400)).toSize();
651 pos = settings.value("cartLoadPos", QPoint(200, 200)).toPoint();
652 filePickWin->move(pos);
654 zoomLevel = settings.value("zoom", 2).toInt();
655 allowUnknownSoftware = settings.value("showUnknownSoftware", false).toBool();
657 vjs.useJoystick = settings.value("useJoystick", false).toBool();
658 vjs.joyport = settings.value("joyport", 0).toInt();
659 vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
660 vjs.frameSkip = settings.value("frameSkip", 0).toInt();
661 vjs.useJaguarBIOS = settings.value("useJaguarBIOS", false).toBool();
662 vjs.GPUEnabled = settings.value("GPUEnabled", true).toBool();
663 vjs.DSPEnabled = settings.value("DSPEnabled", false).toBool();
664 vjs.audioEnabled = settings.value("audioEnabled", true).toBool();
665 vjs.usePipelinedDSP = settings.value("usePipelinedDSP", false).toBool();
666 vjs.fullscreen = settings.value("fullscreen", false).toBool();
667 vjs.useOpenGL = settings.value("useOpenGL", true).toBool();
668 vjs.glFilter = settings.value("glFilterType", 1).toInt();
669 vjs.renderType = settings.value("renderType", 0).toInt();
670 vjs.allowWritesToROM = settings.value("writeROM", false).toBool();
671 // strcpy(vjs.jagBootPath, settings.value("JagBootROM", "./bios/[BIOS] Atari Jaguar (USA, Europe).zip").toString().toAscii().data());
672 // strcpy(vjs.CDBootPath, settings.value("CDBootROM", "./bios/jagcd.rom").toString().toAscii().data());
673 strcpy(vjs.EEPROMPath, settings.value("EEPROMs", "./eeproms/").toString().toAscii().data());
674 strcpy(vjs.ROMPath, settings.value("ROMs", "./software/").toString().toAscii().data());
675 strcpy(vjs.alpineROMPath, settings.value("DefaultROM", "").toString().toAscii().data());
676 strcpy(vjs.absROMPath, settings.value("DefaultABS", "").toString().toAscii().data());
677 WriteLog("MainWin: Paths\n");
678 //WriteLog(" jagBootPath = \"%s\"\n", vjs.jagBootPath);
679 //WriteLog(" CDBootPath = \"%s\"\n", vjs.CDBootPath);
680 WriteLog(" EEPROMPath = \"%s\"\n", vjs.EEPROMPath);
681 WriteLog(" ROMPath = \"%s\"\n", vjs.ROMPath);
682 WriteLog("AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);
683 WriteLog(" absROMPath = \"%s\"\n", vjs.absROMPath);
685 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
686 vjs.p1KeyBindings[BUTTON_U] = settings.value("p1k_up", Qt::Key_S).toInt();
687 vjs.p1KeyBindings[BUTTON_D] = settings.value("p1k_down", Qt::Key_X).toInt();
688 vjs.p1KeyBindings[BUTTON_L] = settings.value("p1k_left", Qt::Key_A).toInt();
689 vjs.p1KeyBindings[BUTTON_R] = settings.value("p1k_right", Qt::Key_D).toInt();
690 vjs.p1KeyBindings[BUTTON_C] = settings.value("p1k_c", Qt::Key_J).toInt();
691 vjs.p1KeyBindings[BUTTON_B] = settings.value("p1k_b", Qt::Key_K).toInt();
692 vjs.p1KeyBindings[BUTTON_A] = settings.value("p1k_a", Qt::Key_L).toInt();
693 vjs.p1KeyBindings[BUTTON_OPTION] = settings.value("p1k_option", Qt::Key_O).toInt();
694 vjs.p1KeyBindings[BUTTON_PAUSE] = settings.value("p1k_pause", Qt::Key_P).toInt();
695 vjs.p1KeyBindings[BUTTON_0] = settings.value("p1k_0", Qt::Key_0).toInt();
696 vjs.p1KeyBindings[BUTTON_1] = settings.value("p1k_1", Qt::Key_1).toInt();
697 vjs.p1KeyBindings[BUTTON_2] = settings.value("p1k_2", Qt::Key_2).toInt();
698 vjs.p1KeyBindings[BUTTON_3] = settings.value("p1k_3", Qt::Key_3).toInt();
699 vjs.p1KeyBindings[BUTTON_4] = settings.value("p1k_4", Qt::Key_4).toInt();
700 vjs.p1KeyBindings[BUTTON_5] = settings.value("p1k_5", Qt::Key_5).toInt();
701 vjs.p1KeyBindings[BUTTON_6] = settings.value("p1k_6", Qt::Key_6).toInt();
702 vjs.p1KeyBindings[BUTTON_7] = settings.value("p1k_7", Qt::Key_7).toInt();
703 vjs.p1KeyBindings[BUTTON_8] = settings.value("p1k_8", Qt::Key_8).toInt();
704 vjs.p1KeyBindings[BUTTON_9] = settings.value("p1k_9", Qt::Key_9).toInt();
705 vjs.p1KeyBindings[BUTTON_d] = settings.value("p1k_pound", Qt::Key_Minus).toInt();
706 vjs.p1KeyBindings[BUTTON_s] = settings.value("p1k_star", Qt::Key_Equal).toInt();
708 vjs.p2KeyBindings[BUTTON_U] = settings.value("p2k_up", Qt::Key_Up).toInt();
709 vjs.p2KeyBindings[BUTTON_D] = settings.value("p2k_down", Qt::Key_Down).toInt();
710 vjs.p2KeyBindings[BUTTON_L] = settings.value("p2k_left", Qt::Key_Left).toInt();
711 vjs.p2KeyBindings[BUTTON_R] = settings.value("p2k_right", Qt::Key_Right).toInt();
712 vjs.p2KeyBindings[BUTTON_C] = settings.value("p2k_c", Qt::Key_Z).toInt();
713 vjs.p2KeyBindings[BUTTON_B] = settings.value("p2k_b", Qt::Key_X).toInt();
714 vjs.p2KeyBindings[BUTTON_A] = settings.value("p2k_a", Qt::Key_C).toInt();
715 vjs.p2KeyBindings[BUTTON_OPTION] = settings.value("p2k_option", Qt::Key_Apostrophe).toInt();
716 vjs.p2KeyBindings[BUTTON_PAUSE] = settings.value("p2k_pause", Qt::Key_Return).toInt();
717 vjs.p2KeyBindings[BUTTON_0] = settings.value("p2k_0", Qt::Key_0).toInt();
718 vjs.p2KeyBindings[BUTTON_1] = settings.value("p2k_1", Qt::Key_1).toInt();
719 vjs.p2KeyBindings[BUTTON_2] = settings.value("p2k_2", Qt::Key_2).toInt();
720 vjs.p2KeyBindings[BUTTON_3] = settings.value("p2k_3", Qt::Key_3).toInt();
721 vjs.p2KeyBindings[BUTTON_4] = settings.value("p2k_4", Qt::Key_4).toInt();
722 vjs.p2KeyBindings[BUTTON_5] = settings.value("p2k_5", Qt::Key_5).toInt();
723 vjs.p2KeyBindings[BUTTON_6] = settings.value("p2k_6", Qt::Key_6).toInt();
724 vjs.p2KeyBindings[BUTTON_7] = settings.value("p2k_7", Qt::Key_7).toInt();
725 vjs.p2KeyBindings[BUTTON_8] = settings.value("p2k_8", Qt::Key_8).toInt();
726 vjs.p2KeyBindings[BUTTON_9] = settings.value("p2k_9", Qt::Key_9).toInt();
727 vjs.p2KeyBindings[BUTTON_d] = settings.value("p2k_pound", Qt::Key_Slash).toInt();
728 vjs.p2KeyBindings[BUTTON_s] = settings.value("p2k_star", Qt::Key_Asterisk).toInt();
731 void MainWin::WriteSettings(void)
733 QSettings settings("Underground Software", "Virtual Jaguar");
734 settings.setValue("pos", pos());
735 settings.setValue("size", size());
736 settings.setValue("cartLoadPos", filePickWin->pos());
738 settings.setValue("zoom", zoomLevel);
739 settings.setValue("showUnknownSoftware", allowUnknownSoftware);
741 settings.setValue("useJoystick", vjs.useJoystick);
742 settings.setValue("joyport", vjs.joyport);
743 settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
744 settings.setValue("frameSkip", vjs.frameSkip);
745 settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
746 settings.setValue("GPUEnabled", vjs.GPUEnabled);
747 settings.setValue("DSPEnabled", vjs.DSPEnabled);
748 settings.setValue("audioEnabled", vjs.audioEnabled);
749 settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
750 settings.setValue("fullscreen", vjs.fullscreen);
751 settings.setValue("useOpenGL", vjs.useOpenGL);
752 settings.setValue("glFilterType", vjs.glFilter);
753 settings.setValue("renderType", vjs.renderType);
754 settings.setValue("writeROM", vjs.allowWritesToROM);
755 settings.setValue("JagBootROM", vjs.jagBootPath);
756 settings.setValue("CDBootROM", vjs.CDBootPath);
757 settings.setValue("EEPROMs", vjs.EEPROMPath);
758 settings.setValue("ROMs", vjs.ROMPath);
759 settings.setValue("DefaultROM", vjs.alpineROMPath);
760 settings.setValue("DefaultABS", vjs.absROMPath);
762 settings.setValue("p1k_up", vjs.p1KeyBindings[BUTTON_U]);
763 settings.setValue("p1k_down", vjs.p1KeyBindings[BUTTON_D]);
764 settings.setValue("p1k_left", vjs.p1KeyBindings[BUTTON_L]);
765 settings.setValue("p1k_right", vjs.p1KeyBindings[BUTTON_R]);
766 settings.setValue("p1k_c", vjs.p1KeyBindings[BUTTON_C]);
767 settings.setValue("p1k_b", vjs.p1KeyBindings[BUTTON_B]);
768 settings.setValue("p1k_a", vjs.p1KeyBindings[BUTTON_A]);
769 settings.setValue("p1k_option", vjs.p1KeyBindings[BUTTON_OPTION]);
770 settings.setValue("p1k_pause", vjs.p1KeyBindings[BUTTON_PAUSE]);
771 settings.setValue("p1k_0", vjs.p1KeyBindings[BUTTON_0]);
772 settings.setValue("p1k_1", vjs.p1KeyBindings[BUTTON_1]);
773 settings.setValue("p1k_2", vjs.p1KeyBindings[BUTTON_2]);
774 settings.setValue("p1k_3", vjs.p1KeyBindings[BUTTON_3]);
775 settings.setValue("p1k_4", vjs.p1KeyBindings[BUTTON_4]);
776 settings.setValue("p1k_5", vjs.p1KeyBindings[BUTTON_5]);
777 settings.setValue("p1k_6", vjs.p1KeyBindings[BUTTON_6]);
778 settings.setValue("p1k_7", vjs.p1KeyBindings[BUTTON_7]);
779 settings.setValue("p1k_8", vjs.p1KeyBindings[BUTTON_8]);
780 settings.setValue("p1k_9", vjs.p1KeyBindings[BUTTON_9]);
781 settings.setValue("p1k_pound", vjs.p1KeyBindings[BUTTON_d]);
782 settings.setValue("p1k_star", vjs.p1KeyBindings[BUTTON_s]);
784 settings.setValue("p2k_up", vjs.p2KeyBindings[BUTTON_U]);
785 settings.setValue("p2k_down", vjs.p2KeyBindings[BUTTON_D]);
786 settings.setValue("p2k_left", vjs.p2KeyBindings[BUTTON_L]);
787 settings.setValue("p2k_right", vjs.p2KeyBindings[BUTTON_R]);
788 settings.setValue("p2k_c", vjs.p2KeyBindings[BUTTON_C]);
789 settings.setValue("p2k_b", vjs.p2KeyBindings[BUTTON_B]);
790 settings.setValue("p2k_a", vjs.p2KeyBindings[BUTTON_A]);
791 settings.setValue("p2k_option", vjs.p2KeyBindings[BUTTON_OPTION]);
792 settings.setValue("p2k_pause", vjs.p2KeyBindings[BUTTON_PAUSE]);
793 settings.setValue("p2k_0", vjs.p2KeyBindings[BUTTON_0]);
794 settings.setValue("p2k_1", vjs.p2KeyBindings[BUTTON_1]);
795 settings.setValue("p2k_2", vjs.p2KeyBindings[BUTTON_2]);
796 settings.setValue("p2k_3", vjs.p2KeyBindings[BUTTON_3]);
797 settings.setValue("p2k_4", vjs.p2KeyBindings[BUTTON_4]);
798 settings.setValue("p2k_5", vjs.p2KeyBindings[BUTTON_5]);
799 settings.setValue("p2k_6", vjs.p2KeyBindings[BUTTON_6]);
800 settings.setValue("p2k_7", vjs.p2KeyBindings[BUTTON_7]);
801 settings.setValue("p2k_8", vjs.p2KeyBindings[BUTTON_8]);
802 settings.setValue("p2k_9", vjs.p2KeyBindings[BUTTON_9]);
803 settings.setValue("p2k_pound", vjs.p2KeyBindings[BUTTON_d]);
804 settings.setValue("p2k_star", vjs.p2KeyBindings[BUTTON_s]);
807 // Here's how Byuu does it...
808 // I think I have it working now... :-)
810 void Utility::resizeMainWindow()
812 unsigned region = config().video.context->region;
813 unsigned multiplier = config().video.context->multiplier;
814 unsigned width = 256 * multiplier;
815 unsigned height = (region == 0 ? 224 : 239) * multiplier;
817 if(config().video.context->correctAspectRatio)
821 width = (double)width * config().video.ntscAspectRatio + 0.5; //NTSC adjust
825 width = (double)width * config().video.palAspectRatio + 0.5; //PAL adjust
829 if(config().video.isFullscreen == false)
831 //get effective desktop work area region (ignore Windows taskbar, OS X dock, etc.)
832 QRect deskRect = QApplication::desktop()->availableGeometry(mainWindow);
834 //ensure window size will not be larger than viewable desktop area
835 constrainSize(height, width, deskRect.height()); //- frameHeight);
836 constrainSize(width, height, deskRect.width()); //- frameWidth );
838 mainWindow->canvas->setFixedSize(width, height);
843 for(unsigned i = 0; i < 2; i++)
845 unsigned iWidth = width, iHeight = height;
847 constrainSize(iHeight, iWidth, mainWindow->canvasContainer->size().height());
848 constrainSize(iWidth, iHeight, mainWindow->canvasContainer->size().width());
850 //center canvas onscreen; ensure it is not larger than viewable area
851 mainWindow->canvas->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
852 mainWindow->canvas->setFixedSize(iWidth, iHeight);
853 mainWindow->canvas->setMinimumSize(0, 0);
856 QApplication::processEvents();
860 //workaround for Qt/Xlib bug:
861 //if window resize occurs with cursor over it, Qt shows Qt::Size*DiagCursor;
862 //so force it to show Qt::ArrowCursor, as expected
863 mainWindow->setCursor(Qt::ArrowCursor);
864 mainWindow->canvasContainer->setCursor(Qt::ArrowCursor);
865 mainWindow->canvas->setCursor(Qt::ArrowCursor);
867 //workaround for DirectSound(?) bug:
868 //window resizing sometimes breaks audio sync, this call re-initializes it
872 void Utility::setScale(unsigned scale)
874 config().video.context->multiplier = scale;
876 mainWindow->shrink();
877 mainWindow->syncUi();
880 void QbWindow::shrink()
882 if(config().video.isFullscreen == false)
884 for(unsigned i = 0; i < 2; i++)
888 QApplication::processEvents();