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]
23 // - Controller configuration
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...
39 #include "filepicker.h"
40 #include "configdialog.h"
41 #include "generaltab.h"
52 // Apparently on win32, usleep() is not pulled in by the usual suspects.
56 // Uncomment this to use built-in BIOS/CD-ROM BIOS
57 // You'll need a copy of jagboot.h & jagcd.h for this to work...!
58 // Creating those is left as an exercise for the reader. ;-)
59 //#define USE_BUILT_IN_BIOS
61 #ifdef USE_BUILT_IN_BIOS
66 // The way BSNES controls things is by setting a timer with a zero
67 // timeout, sleeping if not emulating anything. Seems there has to be a
70 // It has a novel approach to plugging-in/using different video/audio/input
71 // methods, can we do something similar or should we just use the built-in
74 // We're going to try to use the built-in OpenGL support and see how it goes.
75 // We'll make the VJ core modular so that it doesn't matter what GUI is in
76 // use, we can drop it in anywhere and use it as-is.
78 MainWin::MainWin(): running(false), powerButtonOn(false), showUntunedTankCircuit(true),
79 cartridgeLoaded(false), CDActive(false)//, alpineLoadSuccessful(false)
81 videoWidget = new GLWidget(this);
82 setCentralWidget(videoWidget);
83 setWindowIcon(QIcon(":/res/vj-icon.png"));
84 // setWindowTitle("Virtual Jaguar v2.0.0");
86 QString title = QString(tr("Virtual Jaguar " VJ_RELEASE_VERSION ));
88 if (vjs.hardwareTypeAlpine)
89 title += QString(tr(" - Alpine Mode"));
91 setWindowTitle(title);
93 aboutWin = new AboutWindow(this);
94 filePickWin = new FilePickerWindow(this);
96 videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
97 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
99 setUnifiedTitleAndToolBarOnMac(true);
103 quitAppAct = new QAction(tr("E&xit"), this);
104 quitAppAct->setShortcuts(QKeySequence::Quit);
105 quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
106 connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
108 powerAct = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
109 powerAct->setStatusTip(tr("Powers Jaguar on/off"));
110 powerAct->setCheckable(true);
111 powerAct->setChecked(false);
112 powerAct->setDisabled(true);
113 connect(powerAct, SIGNAL(triggered()), this, SLOT(TogglePowerState()));
115 pauseAct = new QAction(QIcon(":/res/pause.png"), tr("Pause"), this);
116 pauseAct->setStatusTip(tr("Toggles the running state"));
117 pauseAct->setCheckable(true);
118 pauseAct->setDisabled(true);
119 pauseAct->setShortcut(QKeySequence(tr("Esc")));
120 connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
122 zoomActs = new QActionGroup(this);
124 x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
125 x1Act->setStatusTip(tr("Set window zoom to 100%"));
126 x1Act->setCheckable(true);
127 connect(x1Act, SIGNAL(triggered()), this, SLOT(SetZoom100()));
129 x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
130 x2Act->setStatusTip(tr("Set window zoom to 200%"));
131 x2Act->setCheckable(true);
132 connect(x2Act, SIGNAL(triggered()), this, SLOT(SetZoom200()));
134 x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
135 x3Act->setStatusTip(tr("Set window zoom to 300%"));
136 x3Act->setCheckable(true);
137 connect(x3Act, SIGNAL(triggered()), this, SLOT(SetZoom300()));
139 tvTypeActs = new QActionGroup(this);
141 ntscAct = new QAction(QIcon(":/res/ntsc.png"), tr("NTSC"), tvTypeActs);
142 ntscAct->setStatusTip(tr("Sets Jaguar to NTSC mode"));
143 ntscAct->setCheckable(true);
144 connect(ntscAct, SIGNAL(triggered()), this, SLOT(SetNTSC()));
146 palAct = new QAction(QIcon(":/res/pal.png"), tr("PAL"), tvTypeActs);
147 palAct->setStatusTip(tr("Sets Jaguar to PAL mode"));
148 palAct->setCheckable(true);
149 connect(palAct, SIGNAL(triggered()), this, SLOT(SetPAL()));
151 blurAct = new QAction(QIcon(":/res/generic.png"), tr("Blur"), this);
152 blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
153 blurAct->setCheckable(true);
154 connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
156 aboutAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&About..."), this);
157 aboutAct->setStatusTip(tr("Blatant self-promotion"));
158 connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
160 filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this);
161 filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar"));
162 filePickAct->setShortcut(QKeySequence(tr("Ctrl+i")));
163 connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart()));
165 configAct = new QAction(QIcon(":/res/generic.png"), tr("&Configure"), this);
166 configAct->setStatusTip(tr("Configure options for Virtual Jaguar"));
167 configAct->setShortcut(QKeySequence(tr("Ctrl+c")));
168 connect(configAct, SIGNAL(triggered()), this, SLOT(Configure()));
170 useCDAct = new QAction(QIcon(":/res/compact-disc.png"), tr("&Use CD Unit"), this);
171 useCDAct->setStatusTip(tr("Use Jaguar Virtual CD unit"));
172 // useCDAct->setShortcut(QKeySequence(tr("Ctrl+c")));
173 useCDAct->setCheckable(true);
174 connect(useCDAct, SIGNAL(triggered()), this, SLOT(ToggleCDUsage()));
176 // Misc. connections...
177 connect(filePickWin, SIGNAL(RequestLoad(QString)), this, SLOT(LoadSoftware(QString)));
179 // Create menus & toolbars
181 fileMenu = menuBar()->addMenu(tr("&File"));
182 fileMenu->addAction(filePickAct);
183 fileMenu->addAction(useCDAct);
184 fileMenu->addAction(powerAct);
185 fileMenu->addAction(pauseAct);
186 fileMenu->addAction(configAct);
187 fileMenu->addAction(quitAppAct);
189 helpMenu = menuBar()->addMenu(tr("&Help"));
190 helpMenu->addAction(aboutAct);
192 toolbar = addToolBar(tr("Stuff"));
193 toolbar->addAction(powerAct);
194 toolbar->addAction(pauseAct);
195 toolbar->addAction(filePickAct);
196 toolbar->addAction(useCDAct);
197 toolbar->addSeparator();
198 toolbar->addAction(x1Act);
199 toolbar->addAction(x2Act);
200 toolbar->addAction(x3Act);
201 toolbar->addSeparator();
202 toolbar->addAction(ntscAct);
203 toolbar->addAction(palAct);
204 toolbar->addSeparator();
205 toolbar->addAction(blurAct);
208 statusBar()->showMessage(tr("Ready"));
212 // Set toolbar buttons/menus based on settings read in (sync the UI)...
213 blurAct->setChecked(vjs.glFilter);
214 x1Act->setChecked(zoomLevel == 1);
215 x2Act->setChecked(zoomLevel == 2);
216 x3Act->setChecked(zoomLevel == 3);
217 running = powerAct->isChecked();
218 ntscAct->setChecked(vjs.hardwareTypeNTSC);
219 palAct->setChecked(!vjs.hardwareTypeNTSC);
221 // Do this in case original size isn't correct (mostly for the first-run case)
224 // Set up timer based loop for animation...
225 timer = new QTimer(this);
226 connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
229 WriteLog("Virtual Jaguar %s (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
230 WriteLog("VJ: Initializing jaguar subsystem...\n");
234 #ifdef USE_BUILT_IN_BIOS
235 WriteLog("VJ: Using built in BIOS/CD BIOS...\n");
236 memcpy(jaguarBootROM, jagBootROM, 0x20000);
237 memcpy(jaguarCDBootROM, jagCDROM, 0x40000);
238 // BIOSLoaded = CDBIOSLoaded = true;
239 biosAvailable |= (BIOS_NORMAL | BIOS_CD);
241 // What would be nice here would be a way to check if the BIOS was loaded so that we
242 // could disable the pushbutton on the Misc Options menu... !!! FIX !!! [DONE here, but needs to be fixed in GUI as well!]
243 // WriteLog("VJ: About to attempt to load BIOSes...\n");
244 //This is short-circuiting the file finding thread... ??? WHY ???
245 //Not anymore. Was related to a QImage object creation/corruption bug elsewhere.
246 // BIOSLoaded = (JaguarLoadROM(jaguarBootROM, vjs.jagBootPath) == 0x20000 ? true : false);
247 // WriteLog("VJ: BIOS is %savailable...\n", (BIOSLoaded ? "" : "not "));
248 // CDBIOSLoaded = (JaguarLoadROM(jaguarCDBootROM, vjs.CDBootPath) == 0x40000 ? true : false);
249 // WriteLog("VJ: CD BIOS is %savailable...\n", (CDBIOSLoaded ? "" : "not "));
252 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
254 // Load up the default ROM if in Alpine mode:
255 if (vjs.hardwareTypeAlpine)
257 bool romLoaded = JaguarLoadFile(vjs.alpineROMPath);
259 // If regular load failed, try just a straight file load
260 // (Dev only! I don't want people to start getting lazy with their releases again! :-P)
262 romLoaded = AlpineLoadFile(vjs.alpineROMPath);
265 WriteLog("Alpine Mode: Successfully loaded file \"%s\".\n", vjs.alpineROMPath);
267 WriteLog("Alpine Mode: Unable to load file \"%s\"!\n", vjs.alpineROMPath);
269 // Attempt to load/run the ABS file...
270 LoadSoftware(vjs.absROMPath);
274 void MainWin::closeEvent(QCloseEvent * event)
278 event->accept(); // ignore() if can't close for some reason
281 void MainWin::keyPressEvent(QKeyEvent * e)
286 void MainWin::keyReleaseEvent(QKeyEvent * e)
288 HandleKeys(e, false);
291 void MainWin::HandleKeys(QKeyEvent * e, bool state)
293 // We kill bad key combos here, before they can get to the emulator...
294 // This also kills the illegal instruction problem that cropped up in Rayman!
295 // May want to do this by killing the old one instead of ignoring the new one...
296 // Seems to work better that way...
298 if ((e->key() == vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
299 || (e->key() == vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
300 || (e->key() == vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
301 || (e->key() == vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U]))
304 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
305 joypad_0_buttons[BUTTON_R] = 0;
306 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
307 joypad_0_buttons[BUTTON_L] = 0;
308 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
309 joypad_0_buttons[BUTTON_D] = 0;
310 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U])
311 joypad_0_buttons[BUTTON_U] = 0;
314 // No bad combos exist, let's stuff the emulator key buffers...!
315 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
317 if (e->key() == (int)vjs.p1KeyBindings[i])
318 joypad_0_buttons[i] = (uint8)state;
322 void MainWin::Open(void)
326 void MainWin::Configure(void)
328 // Call the configuration dialog and update settings
329 ConfigDialog dlg(this);
331 dlg.generalTab->useUnknownSoftware->setChecked(allowUnknownSoftware);
333 if (dlg.exec() == false)
336 QString before = vjs.ROMPath;
337 QString alpineBefore = vjs.alpineROMPath;
338 QString absBefore = vjs.absROMPath;
339 bool audioBefore = vjs.audioEnabled;
340 dlg.UpdateVJSettings();
341 QString after = vjs.ROMPath;
342 QString alpineAfter = vjs.alpineROMPath;
343 QString absAfter = vjs.absROMPath;
344 bool audioAfter = vjs.audioEnabled;
346 bool allowOld = allowUnknownSoftware;
348 allowUnknownSoftware = dlg.generalTab->useUnknownSoftware->isChecked();
350 // We rescan the "software" folder if the user either changed the path or
351 // checked/unchecked the "Allow unknown files" option in the config dialog.
352 if ((before != after) || (allowOld != allowUnknownSoftware))
353 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
355 // If the "Alpine" ROM is changed, then let's load it...
356 if (alpineBefore != alpineAfter)
358 if (!JaguarLoadFile(vjs.alpineROMPath) || !AlpineLoadFile(vjs.alpineROMPath))
360 // Oh crap, we couldn't get the file! Alert the media!
362 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.alpineROMPath));
363 msg.setIcon(QMessageBox::Warning);
368 // If the "ABS" ROM is changed, then let's load it...
369 if (absBefore != absAfter)
371 if (!JaguarLoadFile(vjs.absROMPath))
373 // Oh crap, we couldn't get the file! Alert the media!
375 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.absROMPath));
376 msg.setIcon(QMessageBox::Warning);
381 // If the "Enable audio" checkbox changed, then we have to re-init the DAC...
382 if (audioBefore != audioAfter)
388 // Just in case we crash before a clean exit...
393 // Here's the main emulator loop
395 void MainWin::Timer(void)
400 if (showUntunedTankCircuit)
402 // Random hash & trash
403 // We try to simulate an untuned tank circuit here... :-)
404 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
406 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
408 videoWidget->buffer[(y * videoWidget->textureWidth) + x] = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;// | (rand() & 0xFF);//0x000000FF;
409 // buffer[(y * textureWidth) + x] = x*y;
415 // Otherwise, run the Jaguar simulation
417 // memcpy(videoWidget->buffer, backbuffer, videoWidget->rasterHeight * videoWidget->rasterWidth);
418 memcpy(videoWidget->buffer, backbuffer, videoWidget->rasterHeight * videoWidget->textureWidth * sizeof(uint32_t));
419 // memcpy(surface->pixels, backbuffer, TOMGetVideoModeWidth() * TOMGetVideoModeHeight() * 4);
422 videoWidget->updateGL();
426 Window * RunEmu(void)
428 // extern uint32 * backbuffer;
429 uint32 * overlayPixels = (uint32 *)sdlemuGetOverlayPixels();
430 memset(overlayPixels, 0x00, 640 * 480 * 4); // Clear out overlay...
432 //This is crappy... !!! FIX !!!
433 // extern bool finished, showGUI;
435 sdlemuDisableOverlay();
437 // uint32 nFrame = 0, nFrameskip = 0;
438 uint32 totalFrames = 0;
440 bool showMessage = true;
441 uint32 showMsgFrames = 120;
442 uint8 transparency = 0xFF;
443 // Pass a message to the "joystick" code to debounce the ESC key...
444 debounceRunKey = true;
447 if (jaguarRomSize == 0x200000)
449 else if (jaguarRomSize == 0x400000)
451 else if (jaguarMainRomCRC32 == 0x687068D5)
453 else if (jaguarMainRomCRC32 == 0x55A0669C)
456 const char * cartTypeName[5] = { "2M Cartridge", "4M Cartridge", "CD BIOS", "CD Dev BIOS", "Homebrew" };
457 uint32 elapsedTicks = SDL_GetTicks(), frameCount = 0, framesPerSecond = 0;
461 // Set up new backbuffer with new pixels and data
464 //WriteLog("Frame #%u...\n", totalFrames);
465 //extern bool doDSPDis;
466 //if (totalFrames == 373)
469 //Problem: Need to do this *only* when the state changes from visible to not...
470 //Also, need to clear out the GUI when not on (when showMessage is active...)
471 if (showGUI || showMessage)
472 sdlemuEnableOverlay();
474 sdlemuDisableOverlay();
476 //Add in a new function for clearing patches of screen (ClearOverlayRect)
478 // Also: Take frame rate into account when calculating fade time...
480 // Some QnD GUI stuff here...
483 FillScreenRectangle(overlayPixels, 8, 1*FONT_HEIGHT, 128, 4*FONT_HEIGHT, 0x00000000);
484 extern uint32 gpu_pc, dsp_pc;
485 DrawString(overlayPixels, 8, 1*FONT_HEIGHT, false, "GPU PC: %08X", gpu_pc);
486 DrawString(overlayPixels, 8, 2*FONT_HEIGHT, false, "DSP PC: %08X", dsp_pc);
487 DrawString(overlayPixels, 8, 4*FONT_HEIGHT, false, "%u FPS", framesPerSecond);
492 DrawString2(overlayPixels, 8, 24*FONT_HEIGHT, 0x007F63FF, transparency, "Running...");
493 DrawString2(overlayPixels, 8, 26*FONT_HEIGHT, 0x001FFF3F, transparency, "%s, run address: %06X", cartTypeName[cartType], jaguarRunAddress);
494 DrawString2(overlayPixels, 8, 27*FONT_HEIGHT, 0x001FFF3F, transparency, "CRC: %08X", jaguarMainRomCRC32);
496 if (showMsgFrames == 0)
500 if (transparency == 0)
503 /*extern bool doGPUDis;
514 if (SDL_GetTicks() - elapsedTicks > 250)
515 elapsedTicks += 250, framesPerSecond = frameCount * 4, frameCount = 0;
518 // Save the background for the GUI...
519 // In this case, we squash the color to monochrome, then force it to blue + green...
520 for(uint32 i=0; i<TOMGetVideoModeWidth() * 256; i++)
522 uint32 pixel = backbuffer[i];
523 uint8 b = (pixel >> 16) & 0xFF, g = (pixel >> 8) & 0xFF, r = pixel & 0xFF;
524 pixel = ((r + g + b) / 3) & 0x00FF;
525 backbuffer[i] = 0xFF000000 | (pixel << 16) | (pixel << 8);
528 sdlemuEnableOverlay();
534 void MainWin::TogglePowerState(void)
536 powerButtonOn = !powerButtonOn;
540 pauseAct->setChecked(false);
541 pauseAct->setDisabled(true);
542 showUntunedTankCircuit = true;
544 // This is just in case the ROM we were playing was in a narrow or wide field mode,
545 // so the untuned tank sim doesn't look wrong. :-)
552 showUntunedTankCircuit = false;//(cartridgeLoaded ? false : true);
553 pauseAct->setChecked(false);
554 pauseAct->setDisabled(!cartridgeLoaded);
558 // Should check for cartridgeLoaded here as well...!
559 // We can clear it when toggling CDActive on, so that when we power cycle it does the
560 // expected thing. Otherwise, if we use the file picker to insert a cart, we expect
561 // to run the cart! Maybe have a RemoveCart function that only works if the CD unit
563 showUntunedTankCircuit = false;
564 pauseAct->setChecked(false);
565 pauseAct->setDisabled(false);
566 memcpy(jagMemSpace + 0x800000, jaguarCDBootROM, 0x40000);
567 setWindowTitle(QString("Virtual Jaguar " VJ_RELEASE_VERSION
568 " - Now playing: Jaguar CD"));
571 //(Err, what's so crappy about this? It seems to do what it's supposed to...)
572 //This is crappy!!! !!! FIX !!!
573 //Is this even needed any more? Hmm. Maybe. Dunno.
574 //Seems like it is... But then again, maybe not. Have to test it to see.
575 WriteLog("GUI: Resetting Jaguar...\n");
581 void MainWin::ToggleRunState(void)
587 for(uint32_t i=0; i<(uint32_t)(videoWidget->textureWidth * 256); i++)
589 uint32_t pixel = backbuffer[i];
590 uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
591 pixel = ((r + g + b) / 3) & 0x00FF;
592 backbuffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
595 memcpy(videoWidget->buffer, backbuffer, videoWidget->rasterHeight * videoWidget->textureWidth * sizeof(uint32_t));
597 videoWidget->updateGL();
601 void MainWin::SetZoom100(void)
607 void MainWin::SetZoom200(void)
613 void MainWin::SetZoom300(void)
619 void MainWin::SetNTSC(void)
621 vjs.hardwareTypeNTSC = true;
625 void MainWin::SetPAL(void)
627 vjs.hardwareTypeNTSC = false;
631 void MainWin::ToggleBlur(void)
633 vjs.glFilter = !vjs.glFilter;
636 void MainWin::ShowAboutWin(void)
641 void MainWin::InsertCart(void)
646 void MainWin::LoadSoftware(QString file)
648 running = false; // Prevent bad things(TM) from happening...
649 SET32(jaguarMainRAM, 0, 0x00200000); // Set top of stack...
650 cartridgeLoaded = (JaguarLoadFile(file.toAscii().data()) ? true : false);
652 uint8_t * biosPointer = jaguarBootROM;
654 if (vjs.hardwareTypeAlpine)
656 if (biosAvailable & BIOS_STUB1)
657 // memcpy(jagMemSpace + 0xE00000, jaguarDevBootROM1, 0x20000);
658 biosPointer = jaguarDevBootROM1;
659 else if (biosAvailable & BIOS_STUB2)
660 // memcpy(jagMemSpace + 0xE00000, jaguarDevBootROM2, 0x20000);
661 biosPointer = jaguarDevBootROM2;
664 // memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000);
666 memcpy(jagMemSpace + 0xE00000, biosPointer, 0x20000);
668 powerAct->setDisabled(false);
669 powerAct->setChecked(true);
670 powerButtonOn = false;
673 if (!vjs.hardwareTypeAlpine)
675 QString newTitle = QString("Virtual Jaguar " VJ_RELEASE_VERSION " - Now playing: %1")
676 .arg(filePickWin->GetSelectedPrettyName());
677 setWindowTitle(newTitle);
681 void MainWin::ToggleCDUsage(void)
683 CDActive = !CDActive;
687 powerAct->setDisabled(false);
691 powerAct->setDisabled(true);
695 void MainWin::ResizeMainWindow(void)
697 videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
700 for(int i=0; i<2; i++)
704 QApplication::processEvents();
708 void MainWin::ReadSettings(void)
710 QSettings settings("Underground Software", "Virtual Jaguar");
711 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
712 QSize size = settings.value("size", QSize(400, 400)).toSize();
715 pos = settings.value("cartLoadPos", QPoint(200, 200)).toPoint();
716 filePickWin->move(pos);
718 zoomLevel = settings.value("zoom", 1).toInt();
719 allowUnknownSoftware = settings.value("showUnknownSoftware", false).toBool();
721 vjs.useJoystick = settings.value("useJoystick", false).toBool();
722 vjs.joyport = settings.value("joyport", 0).toInt();
723 vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
724 vjs.frameSkip = settings.value("frameSkip", 0).toInt();
725 vjs.useJaguarBIOS = settings.value("useJaguarBIOS", false).toBool();
726 vjs.DSPEnabled = settings.value("DSPEnabled", false).toBool();
727 vjs.audioEnabled = settings.value("audioEnabled", true).toBool();
728 vjs.usePipelinedDSP = settings.value("usePipelinedDSP", false).toBool();
729 vjs.fullscreen = settings.value("fullscreen", false).toBool();
730 vjs.useOpenGL = settings.value("useOpenGL", true).toBool();
731 vjs.glFilter = settings.value("glFilterType", 0).toInt();
732 vjs.renderType = settings.value("renderType", 0).toInt();
733 vjs.allowWritesToROM = settings.value("writeROM", false).toBool();
734 // strcpy(vjs.jagBootPath, settings.value("JagBootROM", "./bios/[BIOS] Atari Jaguar (USA, Europe).zip").toString().toAscii().data());
735 // strcpy(vjs.CDBootPath, settings.value("CDBootROM", "./bios/jagcd.rom").toString().toAscii().data());
736 strcpy(vjs.EEPROMPath, settings.value("EEPROMs", "./eeproms/").toString().toAscii().data());
737 strcpy(vjs.ROMPath, settings.value("ROMs", "./software/").toString().toAscii().data());
738 strcpy(vjs.alpineROMPath, settings.value("DefaultROM", "").toString().toAscii().data());
739 strcpy(vjs.absROMPath, settings.value("DefaultABS", "").toString().toAscii().data());
740 WriteLog("MainWin: Paths\n");
741 //WriteLog(" jagBootPath = \"%s\"\n", vjs.jagBootPath);
742 //WriteLog(" CDBootPath = \"%s\"\n", vjs.CDBootPath);
743 WriteLog(" EEPROMPath = \"%s\"\n", vjs.EEPROMPath);
744 WriteLog(" ROMPath = \"%s\"\n", vjs.ROMPath);
745 WriteLog("AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);
746 WriteLog(" absROMPath = \"%s\"\n", vjs.absROMPath);
748 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
749 vjs.p1KeyBindings[BUTTON_U] = settings.value("p1k_up", Qt::Key_Up).toInt();
750 vjs.p1KeyBindings[BUTTON_D] = settings.value("p1k_down", Qt::Key_Down).toInt();
751 vjs.p1KeyBindings[BUTTON_L] = settings.value("p1k_left", Qt::Key_Left).toInt();
752 vjs.p1KeyBindings[BUTTON_R] = settings.value("p1k_right", Qt::Key_Right).toInt();
753 vjs.p1KeyBindings[BUTTON_C] = settings.value("p1k_c", Qt::Key_Z).toInt();
754 vjs.p1KeyBindings[BUTTON_B] = settings.value("p1k_b", Qt::Key_X).toInt();
755 vjs.p1KeyBindings[BUTTON_A] = settings.value("p1k_a", Qt::Key_C).toInt();
756 vjs.p1KeyBindings[BUTTON_OPTION] = settings.value("p1k_option", Qt::Key_Apostrophe).toInt();
757 vjs.p1KeyBindings[BUTTON_PAUSE] = settings.value("p1k_pause", Qt::Key_Return).toInt();
758 vjs.p1KeyBindings[BUTTON_0] = settings.value("p1k_0", Qt::Key_0).toInt();
759 vjs.p1KeyBindings[BUTTON_1] = settings.value("p1k_1", Qt::Key_1).toInt();
760 vjs.p1KeyBindings[BUTTON_2] = settings.value("p1k_2", Qt::Key_2).toInt();
761 vjs.p1KeyBindings[BUTTON_3] = settings.value("p1k_3", Qt::Key_3).toInt();
762 vjs.p1KeyBindings[BUTTON_4] = settings.value("p1k_4", Qt::Key_4).toInt();
763 vjs.p1KeyBindings[BUTTON_5] = settings.value("p1k_5", Qt::Key_5).toInt();
764 vjs.p1KeyBindings[BUTTON_6] = settings.value("p1k_6", Qt::Key_6).toInt();
765 vjs.p1KeyBindings[BUTTON_7] = settings.value("p1k_7", Qt::Key_7).toInt();
766 vjs.p1KeyBindings[BUTTON_8] = settings.value("p1k_8", Qt::Key_8).toInt();
767 vjs.p1KeyBindings[BUTTON_9] = settings.value("p1k_9", Qt::Key_9).toInt();
768 vjs.p1KeyBindings[BUTTON_d] = settings.value("p1k_pound", Qt::Key_Slash).toInt();
769 vjs.p1KeyBindings[BUTTON_s] = settings.value("p1k_star", Qt::Key_Asterisk).toInt();
771 vjs.p2KeyBindings[BUTTON_U] = settings.value("p2k_up", Qt::Key_Up).toInt();
772 vjs.p2KeyBindings[BUTTON_D] = settings.value("p2k_down", Qt::Key_Down).toInt();
773 vjs.p2KeyBindings[BUTTON_L] = settings.value("p2k_left", Qt::Key_Left).toInt();
774 vjs.p2KeyBindings[BUTTON_R] = settings.value("p2k_right", Qt::Key_Right).toInt();
775 vjs.p2KeyBindings[BUTTON_C] = settings.value("p2k_c", Qt::Key_Z).toInt();
776 vjs.p2KeyBindings[BUTTON_B] = settings.value("p2k_b", Qt::Key_X).toInt();
777 vjs.p2KeyBindings[BUTTON_A] = settings.value("p2k_a", Qt::Key_C).toInt();
778 vjs.p2KeyBindings[BUTTON_OPTION] = settings.value("p2k_option", Qt::Key_Apostrophe).toInt();
779 vjs.p2KeyBindings[BUTTON_PAUSE] = settings.value("p2k_pause", Qt::Key_Return).toInt();
780 vjs.p2KeyBindings[BUTTON_0] = settings.value("p2k_0", Qt::Key_0).toInt();
781 vjs.p2KeyBindings[BUTTON_1] = settings.value("p2k_1", Qt::Key_1).toInt();
782 vjs.p2KeyBindings[BUTTON_2] = settings.value("p2k_2", Qt::Key_2).toInt();
783 vjs.p2KeyBindings[BUTTON_3] = settings.value("p2k_3", Qt::Key_3).toInt();
784 vjs.p2KeyBindings[BUTTON_4] = settings.value("p2k_4", Qt::Key_4).toInt();
785 vjs.p2KeyBindings[BUTTON_5] = settings.value("p2k_5", Qt::Key_5).toInt();
786 vjs.p2KeyBindings[BUTTON_6] = settings.value("p2k_6", Qt::Key_6).toInt();
787 vjs.p2KeyBindings[BUTTON_7] = settings.value("p2k_7", Qt::Key_7).toInt();
788 vjs.p2KeyBindings[BUTTON_8] = settings.value("p2k_8", Qt::Key_8).toInt();
789 vjs.p2KeyBindings[BUTTON_9] = settings.value("p2k_9", Qt::Key_9).toInt();
790 vjs.p2KeyBindings[BUTTON_d] = settings.value("p2k_pound", Qt::Key_Slash).toInt();
791 vjs.p2KeyBindings[BUTTON_s] = settings.value("p2k_star", Qt::Key_Asterisk).toInt();
794 void MainWin::WriteSettings(void)
796 QSettings settings("Underground Software", "Virtual Jaguar");
797 settings.setValue("pos", pos());
798 settings.setValue("size", size());
799 settings.setValue("cartLoadPos", filePickWin->pos());
801 settings.setValue("zoom", zoomLevel);
802 settings.setValue("showUnknownSoftware", allowUnknownSoftware);
804 settings.setValue("useJoystick", vjs.useJoystick);
805 settings.setValue("joyport", vjs.joyport);
806 settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
807 settings.setValue("frameSkip", vjs.frameSkip);
808 settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
809 settings.setValue("DSPEnabled", vjs.DSPEnabled);
810 settings.setValue("audioEnabled", vjs.audioEnabled);
811 settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
812 settings.setValue("fullscreen", vjs.fullscreen);
813 settings.setValue("useOpenGL", vjs.useOpenGL);
814 settings.setValue("glFilterType", vjs.glFilter);
815 settings.setValue("renderType", vjs.renderType);
816 settings.setValue("writeROM", vjs.allowWritesToROM);
817 settings.setValue("JagBootROM", vjs.jagBootPath);
818 settings.setValue("CDBootROM", vjs.CDBootPath);
819 settings.setValue("EEPROMs", vjs.EEPROMPath);
820 settings.setValue("ROMs", vjs.ROMPath);
821 settings.setValue("DefaultROM", vjs.alpineROMPath);
822 settings.setValue("DefaultABS", vjs.absROMPath);
824 settings.setValue("p1k_up", vjs.p1KeyBindings[BUTTON_U]);
825 settings.setValue("p1k_down", vjs.p1KeyBindings[BUTTON_D]);
826 settings.setValue("p1k_left", vjs.p1KeyBindings[BUTTON_L]);
827 settings.setValue("p1k_right", vjs.p1KeyBindings[BUTTON_R]);
828 settings.setValue("p1k_c", vjs.p1KeyBindings[BUTTON_C]);
829 settings.setValue("p1k_b", vjs.p1KeyBindings[BUTTON_B]);
830 settings.setValue("p1k_a", vjs.p1KeyBindings[BUTTON_A]);
831 settings.setValue("p1k_option", vjs.p1KeyBindings[BUTTON_OPTION]);
832 settings.setValue("p1k_pause", vjs.p1KeyBindings[BUTTON_PAUSE]);
833 settings.setValue("p1k_0", vjs.p1KeyBindings[BUTTON_0]);
834 settings.setValue("p1k_1", vjs.p1KeyBindings[BUTTON_1]);
835 settings.setValue("p1k_2", vjs.p1KeyBindings[BUTTON_2]);
836 settings.setValue("p1k_3", vjs.p1KeyBindings[BUTTON_3]);
837 settings.setValue("p1k_4", vjs.p1KeyBindings[BUTTON_4]);
838 settings.setValue("p1k_5", vjs.p1KeyBindings[BUTTON_5]);
839 settings.setValue("p1k_6", vjs.p1KeyBindings[BUTTON_6]);
840 settings.setValue("p1k_7", vjs.p1KeyBindings[BUTTON_7]);
841 settings.setValue("p1k_8", vjs.p1KeyBindings[BUTTON_8]);
842 settings.setValue("p1k_9", vjs.p1KeyBindings[BUTTON_9]);
843 settings.setValue("p1k_pound", vjs.p1KeyBindings[BUTTON_d]);
844 settings.setValue("p1k_star", vjs.p1KeyBindings[BUTTON_s]);
846 settings.setValue("p2k_up", vjs.p2KeyBindings[BUTTON_U]);
847 settings.setValue("p2k_down", vjs.p2KeyBindings[BUTTON_D]);
848 settings.setValue("p2k_left", vjs.p2KeyBindings[BUTTON_L]);
849 settings.setValue("p2k_right", vjs.p2KeyBindings[BUTTON_R]);
850 settings.setValue("p2k_c", vjs.p2KeyBindings[BUTTON_C]);
851 settings.setValue("p2k_b", vjs.p2KeyBindings[BUTTON_B]);
852 settings.setValue("p2k_a", vjs.p2KeyBindings[BUTTON_A]);
853 settings.setValue("p2k_option", vjs.p2KeyBindings[BUTTON_OPTION]);
854 settings.setValue("p2k_pause", vjs.p2KeyBindings[BUTTON_PAUSE]);
855 settings.setValue("p2k_0", vjs.p2KeyBindings[BUTTON_0]);
856 settings.setValue("p2k_1", vjs.p2KeyBindings[BUTTON_1]);
857 settings.setValue("p2k_2", vjs.p2KeyBindings[BUTTON_2]);
858 settings.setValue("p2k_3", vjs.p2KeyBindings[BUTTON_3]);
859 settings.setValue("p2k_4", vjs.p2KeyBindings[BUTTON_4]);
860 settings.setValue("p2k_5", vjs.p2KeyBindings[BUTTON_5]);
861 settings.setValue("p2k_6", vjs.p2KeyBindings[BUTTON_6]);
862 settings.setValue("p2k_7", vjs.p2KeyBindings[BUTTON_7]);
863 settings.setValue("p2k_8", vjs.p2KeyBindings[BUTTON_8]);
864 settings.setValue("p2k_9", vjs.p2KeyBindings[BUTTON_9]);
865 settings.setValue("p2k_pound", vjs.p2KeyBindings[BUTTON_d]);
866 settings.setValue("p2k_star", vjs.p2KeyBindings[BUTTON_s]);
869 // Here's how Byuu does it...
870 // I think I have it working now... :-)
872 void Utility::resizeMainWindow()
874 unsigned region = config().video.context->region;
875 unsigned multiplier = config().video.context->multiplier;
876 unsigned width = 256 * multiplier;
877 unsigned height = (region == 0 ? 224 : 239) * multiplier;
879 if(config().video.context->correctAspectRatio)
883 width = (double)width * config().video.ntscAspectRatio + 0.5; //NTSC adjust
887 width = (double)width * config().video.palAspectRatio + 0.5; //PAL adjust
891 if(config().video.isFullscreen == false)
893 //get effective desktop work area region (ignore Windows taskbar, OS X dock, etc.)
894 QRect deskRect = QApplication::desktop()->availableGeometry(mainWindow);
896 //ensure window size will not be larger than viewable desktop area
897 constrainSize(height, width, deskRect.height()); //- frameHeight);
898 constrainSize(width, height, deskRect.width()); //- frameWidth );
900 mainWindow->canvas->setFixedSize(width, height);
905 for(unsigned i = 0; i < 2; i++)
907 unsigned iWidth = width, iHeight = height;
909 constrainSize(iHeight, iWidth, mainWindow->canvasContainer->size().height());
910 constrainSize(iWidth, iHeight, mainWindow->canvasContainer->size().width());
912 //center canvas onscreen; ensure it is not larger than viewable area
913 mainWindow->canvas->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
914 mainWindow->canvas->setFixedSize(iWidth, iHeight);
915 mainWindow->canvas->setMinimumSize(0, 0);
918 QApplication::processEvents();
922 //workaround for Qt/Xlib bug:
923 //if window resize occurs with cursor over it, Qt shows Qt::Size*DiagCursor;
924 //so force it to show Qt::ArrowCursor, as expected
925 mainWindow->setCursor(Qt::ArrowCursor);
926 mainWindow->canvasContainer->setCursor(Qt::ArrowCursor);
927 mainWindow->canvas->setCursor(Qt::ArrowCursor);
929 //workaround for DirectSound(?) bug:
930 //window resizing sometimes breaks audio sync, this call re-initializes it
934 void Utility::setScale(unsigned scale)
936 config().video.context->multiplier = scale;
938 mainWindow->shrink();
939 mainWindow->syncUi();
942 void QbWindow::shrink()
944 if(config().video.isFullscreen == false)
946 for(unsigned i = 0; i < 2; i++)
950 QApplication::processEvents();