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
21 // Uncomment this for debugging...
23 //#define DEBUGFOO // Various tool debugging...
24 //#define DEBUGTP // Toolpalette debugging...
34 #include "filepicker.h"
35 #include "configdialog.h"
44 // Uncomment this to use built-in BIOS/CD-ROM BIOS
45 // You'll need a copy of jagboot.h & jagcd.h for this to work...!
46 //#define USE_BUILT_IN_BIOS
48 // Uncomment this for an official Virtual Jaguar release
49 //#define VJ_RELEASE_VERSION "2.0.0"
50 #warning !!! FIX !!! Figure out how to use this in GUI.CPP as well!
52 #ifdef USE_BUILT_IN_BIOS
57 // The way BSNES controls things is by setting a timer with a zero
58 // timeout, sleeping if not emulating anything. Seems there has to be a
61 // It has a novel approach to plugging-in/using different video/audio/input
62 // methods, can we do something similar or should we just use the built-in
65 // We're going to try to use the built-in OpenGL support and see how it goes.
66 // We'll make the VJ core modular so that it doesn't matter what GUI is in
67 // use, we can drop it in anywhere and use it as-is.
69 MainWin::MainWin(): running(false), powerButtonOn(false), showUntunedTankCircuit(true),
70 cartridgeLoaded(false)
72 videoWidget = new GLWidget(this);
73 setCentralWidget(videoWidget);
74 setWindowIcon(QIcon(":/res/vj-icon.png"));
75 setWindowTitle("Virtual Jaguar v2.0.0");
78 setUnifiedTitleAndToolBarOnMac(true);
80 #warning "!!! Save/Restore window location for FilePickerWindow !!!"
81 aboutWin = new AboutWindow(this);
82 filePickWin = new FilePickerWindow(this);
84 videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
85 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
89 quitAppAct = new QAction(tr("E&xit"), this);
90 quitAppAct->setShortcuts(QKeySequence::Quit);
91 quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
92 connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
94 powerAct = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
95 powerAct->setStatusTip(tr("Powers Jaguar on/off"));
96 powerAct->setCheckable(true);
97 powerAct->setChecked(false);
98 powerAct->setDisabled(true);
99 connect(powerAct, SIGNAL(triggered()), this, SLOT(TogglePowerState()));
101 pauseAct = new QAction(QIcon(":/res/pause.png"), tr("Pause"), this);
102 pauseAct->setStatusTip(tr("Toggles the running state"));
103 pauseAct->setCheckable(true);
104 pauseAct->setDisabled(true);
105 connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
107 zoomActs = new QActionGroup(this);
109 x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
110 x1Act->setStatusTip(tr("Set window zoom to 100%"));
111 x1Act->setCheckable(true);
112 connect(x1Act, SIGNAL(triggered()), this, SLOT(SetZoom100()));
114 x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
115 x2Act->setStatusTip(tr("Set window zoom to 200%"));
116 x2Act->setCheckable(true);
117 connect(x2Act, SIGNAL(triggered()), this, SLOT(SetZoom200()));
119 x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
120 x3Act->setStatusTip(tr("Set window zoom to 300%"));
121 x3Act->setCheckable(true);
122 connect(x3Act, SIGNAL(triggered()), this, SLOT(SetZoom300()));
124 tvTypeActs = new QActionGroup(this);
126 ntscAct = new QAction(QIcon(":/res/generic.png"), tr("NTSC"), tvTypeActs);
127 ntscAct->setStatusTip(tr("Sets Jaguar to NTSC mode"));
128 ntscAct->setCheckable(true);
129 connect(ntscAct, SIGNAL(triggered()), this, SLOT(SetNTSC()));
131 palAct = new QAction(QIcon(":/res/generic.png"), tr("PAL"), tvTypeActs);
132 palAct->setStatusTip(tr("Sets Jaguar to PAL mode"));
133 palAct->setCheckable(true);
134 connect(palAct, SIGNAL(triggered()), this, SLOT(SetPAL()));
136 blurAct = new QAction(QIcon(":/res/generic.png"), tr("Blur"), this);
137 blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
138 blurAct->setCheckable(true);
139 connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
141 aboutAct = new QAction(QIcon(":/res/generic.png"), tr("&About..."), this);
142 aboutAct->setStatusTip(tr("Blatant self-promotion"));
143 connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
145 #warning "!!! Set up a decent keyboard shortcut for Insert Cartridge !!!"
146 filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this);
147 filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar"));
148 connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart()));
150 configAct = new QAction(QIcon(":/res/generic.png"), tr("&Configure"), this);
151 configAct->setStatusTip(tr("Configure options for Virtual Jaguar"));
152 connect(configAct, SIGNAL(triggered()), this, SLOT(Configure()));
154 // Misc. connections...
155 connect(filePickWin, SIGNAL(RequestLoad(QString)), this, SLOT(LoadSoftware(QString)));
157 // Create menus & toolbars
159 fileMenu = menuBar()->addMenu(tr("&File"));
160 fileMenu->addAction(filePickAct);
161 fileMenu->addAction(powerAct);
162 fileMenu->addAction(pauseAct);
163 fileMenu->addAction(configAct);
164 fileMenu->addAction(quitAppAct);
166 helpMenu = menuBar()->addMenu(tr("&Help"));
167 helpMenu->addAction(aboutAct);
169 toolbar = addToolBar(tr("Stuff"));
170 toolbar->addAction(powerAct);
171 toolbar->addAction(pauseAct);
172 toolbar->addAction(filePickAct);
173 toolbar->addSeparator();
174 toolbar->addAction(x1Act);
175 toolbar->addAction(x2Act);
176 toolbar->addAction(x3Act);
177 toolbar->addSeparator();
178 toolbar->addAction(ntscAct);
179 toolbar->addAction(palAct);
180 toolbar->addSeparator();
181 toolbar->addAction(blurAct);
184 statusBar()->showMessage(tr("Ready"));
186 // Set toolbar buttons/menus based on settings read in (sync the UI)...
187 blurAct->setChecked(vjs.glFilter);
188 x1Act->setChecked(zoomLevel == 1);
189 x2Act->setChecked(zoomLevel == 2);
190 x3Act->setChecked(zoomLevel == 3);
191 running = powerAct->isChecked();
192 ntscAct->setChecked(vjs.hardwareTypeNTSC);
193 palAct->setChecked(!vjs.hardwareTypeNTSC);
195 // Do this in case original size isn't correct (mostly for the first-run case)
198 // Set up timer based loop for animation...
199 timer = new QTimer(this);
200 connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
203 // NOTE: Keyboards/joysticks will *not* work until SDL is brought back in, or
204 // the key handling is improved in Qt...
205 // Wait a minute... it seems they already are... So why no keyboard love?
207 #ifdef VJ_RELEASE_VERSION
208 WriteLog("Virtual Jaguar %s (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
210 WriteLog("Virtual Jaguar SVN %s (Last full build was on %s %s)\n", __DATE__, __DATE__, __TIME__);
212 WriteLog("Initializing jaguar subsystem...\n");
216 #ifdef USE_BUILT_IN_BIOS
217 WriteLog("VJ: Using built in BIOS/CD BIOS...\n");
218 memcpy(jaguarBootROM, jagBootROM, 0x20000);
219 memcpy(jaguarCDBootROM, jagCDROM, 0x40000);
220 BIOSLoaded = CDBIOSLoaded = true;
222 // What would be nice here would be a way to check if the BIOS was loaded so that we
223 // could disable the pushbutton on the Misc Options menu... !!! FIX !!! [DONE here, but needs to be fixed in GUI as well!]
224 WriteLog("About to attempt to load BIOSes...\n");
226 //This is short-circuiting the file finding thread... ??? WHY ???
227 BIOSLoaded = (JaguarLoadROM(jaguarBootROM, vjs.jagBootPath) == 0x20000 ? true : false);
231 WriteLog("VJ: BIOS is %savailable...\n", (BIOSLoaded ? "" : "not "));
232 CDBIOSLoaded = (JaguarLoadROM(jaguarCDBootROM, vjs.CDBootPath) == 0x40000 ? true : false);
233 WriteLog("VJ: CD BIOS is %savailable...\n", (CDBIOSLoaded ? "" : "not "));
236 SET32(jaguarMainRAM, 0, 0x00200000); // Set top of stack...
239 // JaguarLoadFile("./software/Rayman (World).j64");
240 // JaguarLoadFile("./software/I-War (World).j64");
241 // JaguarLoadFile("./software/Alien vs Predator (World).j64");
242 //no JaguarLoadFile("./software/battlesphere.bin");
243 // JaguarLoadFile("./software/Battle Sphere Gold (World).j64");
244 // JaguarLoadFile("./software/Rayman (USA, Europe).zip");
245 //This is crappy!!! !!! FIX !!!
246 //Is this even needed any more? Hmm. Maybe. Dunno.
247 //Seems like it is... But then again, maybe not. Have to test it to see.
248 //WriteLog("GUI: Resetting Jaguar...\n");
252 void MainWin::closeEvent(QCloseEvent * event)
255 event->accept(); // ignore() if can't close for some reason
258 void MainWin::keyPressEvent(QKeyEvent * e)
263 void MainWin::keyReleaseEvent(QKeyEvent * e)
265 HandleKeys(e, false);
268 void MainWin::HandleKeys(QKeyEvent * e, bool state)
270 // We kill bad key combos here, before they can get to the emulator...
271 // This also kills the illegal instruction problem that cropped up in Rayman!
272 // May want to do this by killing the old one instead of ignoring the new one...
273 // Seems to work better that way...
275 if ((e->key() == vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
276 || (e->key() == vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
277 || (e->key() == vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
278 || (e->key() == vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U]))
281 if (e->key() == vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
282 joypad_0_buttons[BUTTON_R] = 0;
283 if (e->key() == vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
284 joypad_0_buttons[BUTTON_L] = 0;
285 if (e->key() == vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
286 joypad_0_buttons[BUTTON_D] = 0;
287 if (e->key() == vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U])
288 joypad_0_buttons[BUTTON_U] = 0;
291 // No bad combos exist, let's stuff the emulator key buffers...!
292 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
294 if (e->key() == vjs.p1KeyBindings[i])
295 joypad_0_buttons[i] = (uint8)state;
299 void MainWin::Open(void)
303 void MainWin::Configure(void)
305 // Call the configuration dialog and update settings
306 ConfigDialog dlg(this);
308 if (dlg.exec() == false)
311 dlg.UpdateVJSettings();
315 // Here's the main emulator loop
317 void MainWin::Timer(void)
322 if (showUntunedTankCircuit)
324 // Random hash & trash
325 // We try to simulate an untuned tank circuit here... :-)
326 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
328 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
330 videoWidget->buffer[(y * videoWidget->textureWidth) + x] = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;// | (rand() & 0xFF);//0x000000FF;
331 // buffer[(y * textureWidth) + x] = x*y;
337 // Otherwise, run the Jaguar simulation
339 // memcpy(videoWidget->buffer, backbuffer, videoWidget->rasterHeight * videoWidget->rasterWidth);
340 memcpy(videoWidget->buffer, backbuffer, videoWidget->rasterHeight * videoWidget->textureWidth * sizeof(uint32_t));
341 // memcpy(surface->pixels, backbuffer, TOMGetVideoModeWidth() * TOMGetVideoModeHeight() * 4);
344 videoWidget->updateGL();
348 Window * RunEmu(void)
350 // extern uint32 * backbuffer;
351 uint32 * overlayPixels = (uint32 *)sdlemuGetOverlayPixels();
352 memset(overlayPixels, 0x00, 640 * 480 * 4); // Clear out overlay...
354 //This is crappy... !!! FIX !!!
355 // extern bool finished, showGUI;
357 sdlemuDisableOverlay();
359 // uint32 nFrame = 0, nFrameskip = 0;
360 uint32 totalFrames = 0;
362 bool showMessage = true;
363 uint32 showMsgFrames = 120;
364 uint8 transparency = 0xFF;
365 // Pass a message to the "joystick" code to debounce the ESC key...
366 debounceRunKey = true;
369 if (jaguarRomSize == 0x200000)
371 else if (jaguarRomSize == 0x400000)
373 else if (jaguarMainRomCRC32 == 0x687068D5)
375 else if (jaguarMainRomCRC32 == 0x55A0669C)
378 const char * cartTypeName[5] = { "2M Cartridge", "4M Cartridge", "CD BIOS", "CD Dev BIOS", "Homebrew" };
379 uint32 elapsedTicks = SDL_GetTicks(), frameCount = 0, framesPerSecond = 0;
383 // Set up new backbuffer with new pixels and data
386 //WriteLog("Frame #%u...\n", totalFrames);
387 //extern bool doDSPDis;
388 //if (totalFrames == 373)
391 //Problem: Need to do this *only* when the state changes from visible to not...
392 //Also, need to clear out the GUI when not on (when showMessage is active...)
393 if (showGUI || showMessage)
394 sdlemuEnableOverlay();
396 sdlemuDisableOverlay();
398 //Add in a new function for clearing patches of screen (ClearOverlayRect)
400 // Also: Take frame rate into account when calculating fade time...
402 // Some QnD GUI stuff here...
405 FillScreenRectangle(overlayPixels, 8, 1*FONT_HEIGHT, 128, 4*FONT_HEIGHT, 0x00000000);
406 extern uint32 gpu_pc, dsp_pc;
407 DrawString(overlayPixels, 8, 1*FONT_HEIGHT, false, "GPU PC: %08X", gpu_pc);
408 DrawString(overlayPixels, 8, 2*FONT_HEIGHT, false, "DSP PC: %08X", dsp_pc);
409 DrawString(overlayPixels, 8, 4*FONT_HEIGHT, false, "%u FPS", framesPerSecond);
414 DrawString2(overlayPixels, 8, 24*FONT_HEIGHT, 0x007F63FF, transparency, "Running...");
415 DrawString2(overlayPixels, 8, 26*FONT_HEIGHT, 0x001FFF3F, transparency, "%s, run address: %06X", cartTypeName[cartType], jaguarRunAddress);
416 DrawString2(overlayPixels, 8, 27*FONT_HEIGHT, 0x001FFF3F, transparency, "CRC: %08X", jaguarMainRomCRC32);
418 if (showMsgFrames == 0)
422 if (transparency == 0)
425 /*extern bool doGPUDis;
436 if (SDL_GetTicks() - elapsedTicks > 250)
437 elapsedTicks += 250, framesPerSecond = frameCount * 4, frameCount = 0;
440 // Save the background for the GUI...
441 // In this case, we squash the color to monochrome, then force it to blue + green...
442 for(uint32 i=0; i<TOMGetVideoModeWidth() * 256; i++)
444 uint32 pixel = backbuffer[i];
445 uint8 b = (pixel >> 16) & 0xFF, g = (pixel >> 8) & 0xFF, r = pixel & 0xFF;
446 pixel = ((r + g + b) / 3) & 0x00FF;
447 backbuffer[i] = 0xFF000000 | (pixel << 16) | (pixel << 8);
450 sdlemuEnableOverlay();
456 void MainWin::TogglePowerState(void)
458 powerButtonOn = !powerButtonOn;
462 pauseAct->setChecked(false);
463 pauseAct->setDisabled(true);
464 showUntunedTankCircuit = true;
469 showUntunedTankCircuit = (cartridgeLoaded ? false : true);
470 pauseAct->setDisabled(!cartridgeLoaded);
471 //This is crappy!!! !!! FIX !!!
472 //Is this even needed any more? Hmm. Maybe. Dunno.
473 //Seems like it is... But then again, maybe not. Have to test it to see.
474 WriteLog("GUI: Resetting Jaguar...\n");
480 void MainWin::ToggleRunState(void)
487 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
488 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
489 videoWidget->buffer[(y * videoWidget->textureWidth) + x] = 0x00000000;
491 // for(uint32_t i=0; i<TOMGetVideoModeWidth() * 256; i++)
492 for(uint32_t i=0; i<videoWidget->textureWidth * 256; i++)
494 uint32_t pixel = backbuffer[i];
495 // uint8_t b = (pixel >> 16) & 0xFF, g = (pixel >> 8) & 0xFF, r = pixel & 0xFF;
496 uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
497 pixel = ((r + g + b) / 3) & 0x00FF;
498 // backbuffer[i] = 0xFF000000 | (pixel << 16) | (pixel << 8);
499 backbuffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
502 // memcpy(videoWidget->buffer, backbuffer, videoWidget->rasterHeight * videoWidget->rasterWidth);
503 memcpy(videoWidget->buffer, backbuffer, videoWidget->rasterHeight * videoWidget->textureWidth * sizeof(uint32_t));
506 videoWidget->updateGL();
510 void MainWin::SetZoom100(void)
516 void MainWin::SetZoom200(void)
522 void MainWin::SetZoom300(void)
528 void MainWin::SetNTSC(void)
530 vjs.hardwareTypeNTSC = true;
534 void MainWin::SetPAL(void)
536 vjs.hardwareTypeNTSC = false;
540 void MainWin::ToggleBlur(void)
542 vjs.glFilter = !vjs.glFilter;
545 void MainWin::ShowAboutWin(void)
550 void MainWin::InsertCart(void)
555 void MainWin::LoadSoftware(QString file)
557 running = false; // Prevent bad things(TM) from happening...
558 SET32(jaguarMainRAM, 0, 0x00200000); // Set top of stack...
559 cartridgeLoaded = (JaguarLoadFile(file.toAscii().data()) ? true : false);
562 showUntunedTankCircuit = !cartridgeLoaded;
563 //This is crappy!!! !!! FIX !!!
564 //Is this even needed any more? Hmm. Maybe. Dunno.
565 //Seems like it is... But then again, maybe not. Have to test it to see.
566 WriteLog("GUI: Resetting Jaguar...\n");
570 powerAct->setDisabled(false);
571 powerAct->setChecked(true);
572 powerButtonOn = false;
576 QString newTitle = QString("Virtual Jaguar 2.0.0 - Now playing: %1")
577 .arg(filePickWin->GetSelectedPrettyName());
578 setWindowTitle(newTitle);
581 void MainWin::ResizeMainWindow(void)
583 videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
586 for(int i=0; i<2; i++)
590 QApplication::processEvents();
594 void MainWin::ReadSettings(void)
596 QSettings settings("Underground Software", "Virtual Jaguar");
597 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
598 QSize size = settings.value("size", QSize(400, 400)).toSize();
602 zoomLevel = settings.value("zoom", 1).toInt();
604 vjs.useJoystick = settings.value("useJoystick", false).toBool();
605 vjs.joyport = settings.value("joyport", 0).toInt();
606 vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
607 vjs.frameSkip = settings.value("frameSkip", 0).toInt();
608 vjs.useJaguarBIOS = settings.value("useJaguarBIOS", false).toBool();
609 vjs.DSPEnabled = settings.value("DSPEnabled", false).toBool();
610 vjs.usePipelinedDSP = settings.value("usePipelinedDSP", false).toBool();
611 vjs.fullscreen = settings.value("fullscreen", false).toBool();
612 vjs.useOpenGL = settings.value("useOpenGL", true).toBool();
613 vjs.glFilter = settings.value("glFilterType", 0).toInt();
614 vjs.renderType = settings.value("renderType", 0).toInt();
615 strcpy(vjs.jagBootPath, settings.value("JagBootROM", "./bios/[BIOS] Atari Jaguar (USA, Europe).zip").toString().toAscii().data());
616 strcpy(vjs.CDBootPath, settings.value("CDBootROM", "./bios/jagcd.rom").toString().toAscii().data());
617 strcpy(vjs.EEPROMPath, settings.value("EEPROMs", "./eeproms").toString().toAscii().data());
618 strcpy(vjs.ROMPath, settings.value("ROMs", "./software").toString().toAscii().data());
619 WriteLog("MainWin: Paths\n");
620 WriteLog(" jagBootPath = \"%s\"\n", vjs.jagBootPath);
621 WriteLog(" CDBootPath = \"%s\"\n", vjs.CDBootPath);
622 WriteLog(" EEPROMPath = \"%s\"\n", vjs.EEPROMPath);
623 WriteLog(" ROMPath = \"%s\"\n", vjs.ROMPath);
625 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
626 vjs.p1KeyBindings[BUTTON_U] = settings.value("p1k_up", Qt::Key_Up).toInt();
627 vjs.p1KeyBindings[BUTTON_D] = settings.value("p1k_down", Qt::Key_Down).toInt();
628 vjs.p1KeyBindings[BUTTON_L] = settings.value("p1k_left", Qt::Key_Left).toInt();
629 vjs.p1KeyBindings[BUTTON_R] = settings.value("p1k_right", Qt::Key_Right).toInt();
630 vjs.p1KeyBindings[BUTTON_C] = settings.value("p1k_c", Qt::Key_Z).toInt();
631 vjs.p1KeyBindings[BUTTON_B] = settings.value("p1k_b", Qt::Key_X).toInt();
632 vjs.p1KeyBindings[BUTTON_A] = settings.value("p1k_a", Qt::Key_C).toInt();
633 vjs.p1KeyBindings[BUTTON_OPTION] = settings.value("p1k_option", Qt::Key_Apostrophe).toInt();
634 vjs.p1KeyBindings[BUTTON_PAUSE] = settings.value("p1k_pause", Qt::Key_Return).toInt();
635 vjs.p1KeyBindings[BUTTON_0] = settings.value("p1k_0", Qt::Key_0).toInt();
636 vjs.p1KeyBindings[BUTTON_1] = settings.value("p1k_1", Qt::Key_1).toInt();
637 vjs.p1KeyBindings[BUTTON_2] = settings.value("p1k_2", Qt::Key_2).toInt();
638 vjs.p1KeyBindings[BUTTON_3] = settings.value("p1k_3", Qt::Key_3).toInt();
639 vjs.p1KeyBindings[BUTTON_4] = settings.value("p1k_4", Qt::Key_4).toInt();
640 vjs.p1KeyBindings[BUTTON_5] = settings.value("p1k_5", Qt::Key_5).toInt();
641 vjs.p1KeyBindings[BUTTON_6] = settings.value("p1k_6", Qt::Key_6).toInt();
642 vjs.p1KeyBindings[BUTTON_7] = settings.value("p1k_7", Qt::Key_7).toInt();
643 vjs.p1KeyBindings[BUTTON_8] = settings.value("p1k_8", Qt::Key_8).toInt();
644 vjs.p1KeyBindings[BUTTON_9] = settings.value("p1k_9", Qt::Key_9).toInt();
645 vjs.p1KeyBindings[BUTTON_d] = settings.value("p1k_pound", Qt::Key_Slash).toInt();
646 vjs.p1KeyBindings[BUTTON_s] = settings.value("p1k_star", Qt::Key_Asterisk).toInt();
648 vjs.p2KeyBindings[BUTTON_U] = settings.value("p2k_up", Qt::Key_Up).toInt();
649 vjs.p2KeyBindings[BUTTON_D] = settings.value("p2k_down", Qt::Key_Down).toInt();
650 vjs.p2KeyBindings[BUTTON_L] = settings.value("p2k_left", Qt::Key_Left).toInt();
651 vjs.p2KeyBindings[BUTTON_R] = settings.value("p2k_right", Qt::Key_Right).toInt();
652 vjs.p2KeyBindings[BUTTON_C] = settings.value("p2k_c", Qt::Key_Z).toInt();
653 vjs.p2KeyBindings[BUTTON_B] = settings.value("p2k_b", Qt::Key_X).toInt();
654 vjs.p2KeyBindings[BUTTON_A] = settings.value("p2k_a", Qt::Key_C).toInt();
655 vjs.p2KeyBindings[BUTTON_OPTION] = settings.value("p2k_option", Qt::Key_Apostrophe).toInt();
656 vjs.p2KeyBindings[BUTTON_PAUSE] = settings.value("p2k_pause", Qt::Key_Return).toInt();
657 vjs.p2KeyBindings[BUTTON_0] = settings.value("p2k_0", Qt::Key_0).toInt();
658 vjs.p2KeyBindings[BUTTON_1] = settings.value("p2k_1", Qt::Key_1).toInt();
659 vjs.p2KeyBindings[BUTTON_2] = settings.value("p2k_2", Qt::Key_2).toInt();
660 vjs.p2KeyBindings[BUTTON_3] = settings.value("p2k_3", Qt::Key_3).toInt();
661 vjs.p2KeyBindings[BUTTON_4] = settings.value("p2k_4", Qt::Key_4).toInt();
662 vjs.p2KeyBindings[BUTTON_5] = settings.value("p2k_5", Qt::Key_5).toInt();
663 vjs.p2KeyBindings[BUTTON_6] = settings.value("p2k_6", Qt::Key_6).toInt();
664 vjs.p2KeyBindings[BUTTON_7] = settings.value("p2k_7", Qt::Key_7).toInt();
665 vjs.p2KeyBindings[BUTTON_8] = settings.value("p2k_8", Qt::Key_8).toInt();
666 vjs.p2KeyBindings[BUTTON_9] = settings.value("p2k_9", Qt::Key_9).toInt();
667 vjs.p2KeyBindings[BUTTON_d] = settings.value("p2k_pound", Qt::Key_Slash).toInt();
668 vjs.p2KeyBindings[BUTTON_s] = settings.value("p2k_star", Qt::Key_Asterisk).toInt();
671 void MainWin::WriteSettings(void)
673 QSettings settings("Underground Software", "Virtual Jaguar");
674 settings.setValue("pos", pos());
675 settings.setValue("size", size());
677 settings.setValue("zoom", zoomLevel);
679 settings.setValue("useJoystick", vjs.useJoystick);
680 settings.setValue("joyport", vjs.joyport);
681 settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
682 settings.setValue("frameSkip", vjs.frameSkip);
683 settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
684 settings.setValue("DSPEnabled", vjs.DSPEnabled);
685 settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
686 settings.setValue("fullscreen", vjs.fullscreen);
687 settings.setValue("useOpenGL", vjs.useOpenGL);
688 settings.setValue("glFilterType", vjs.glFilter);
689 settings.setValue("renderType", vjs.renderType);
690 settings.setValue("JagBootROM", vjs.jagBootPath);
691 settings.setValue("CDBootROM", vjs.CDBootPath);
692 settings.setValue("EEPROMs", vjs.EEPROMPath);
693 settings.setValue("ROMs", vjs.ROMPath);
695 settings.setValue("p1k_up", vjs.p1KeyBindings[BUTTON_U]);
696 settings.setValue("p1k_down", vjs.p1KeyBindings[BUTTON_D]);
697 settings.setValue("p1k_left", vjs.p1KeyBindings[BUTTON_L]);
698 settings.setValue("p1k_right", vjs.p1KeyBindings[BUTTON_R]);
699 settings.setValue("p1k_c", vjs.p1KeyBindings[BUTTON_C]);
700 settings.setValue("p1k_b", vjs.p1KeyBindings[BUTTON_B]);
701 settings.setValue("p1k_a", vjs.p1KeyBindings[BUTTON_A]);
702 settings.setValue("p1k_option", vjs.p1KeyBindings[BUTTON_OPTION]);
703 settings.setValue("p1k_pause", vjs.p1KeyBindings[BUTTON_PAUSE]);
704 settings.setValue("p1k_0", vjs.p1KeyBindings[BUTTON_0]);
705 settings.setValue("p1k_1", vjs.p1KeyBindings[BUTTON_1]);
706 settings.setValue("p1k_2", vjs.p1KeyBindings[BUTTON_2]);
707 settings.setValue("p1k_3", vjs.p1KeyBindings[BUTTON_3]);
708 settings.setValue("p1k_4", vjs.p1KeyBindings[BUTTON_4]);
709 settings.setValue("p1k_5", vjs.p1KeyBindings[BUTTON_5]);
710 settings.setValue("p1k_6", vjs.p1KeyBindings[BUTTON_6]);
711 settings.setValue("p1k_7", vjs.p1KeyBindings[BUTTON_7]);
712 settings.setValue("p1k_8", vjs.p1KeyBindings[BUTTON_8]);
713 settings.setValue("p1k_9", vjs.p1KeyBindings[BUTTON_9]);
714 settings.setValue("p1k_pound", vjs.p1KeyBindings[BUTTON_d]);
715 settings.setValue("p1k_star", vjs.p1KeyBindings[BUTTON_s]);
717 settings.setValue("p2k_up", vjs.p2KeyBindings[BUTTON_U]);
718 settings.setValue("p2k_down", vjs.p2KeyBindings[BUTTON_D]);
719 settings.setValue("p2k_left", vjs.p2KeyBindings[BUTTON_L]);
720 settings.setValue("p2k_right", vjs.p2KeyBindings[BUTTON_R]);
721 settings.setValue("p2k_c", vjs.p2KeyBindings[BUTTON_C]);
722 settings.setValue("p2k_b", vjs.p2KeyBindings[BUTTON_B]);
723 settings.setValue("p2k_a", vjs.p2KeyBindings[BUTTON_A]);
724 settings.setValue("p2k_option", vjs.p2KeyBindings[BUTTON_OPTION]);
725 settings.setValue("p2k_pause", vjs.p2KeyBindings[BUTTON_PAUSE]);
726 settings.setValue("p2k_0", vjs.p2KeyBindings[BUTTON_0]);
727 settings.setValue("p2k_1", vjs.p2KeyBindings[BUTTON_1]);
728 settings.setValue("p2k_2", vjs.p2KeyBindings[BUTTON_2]);
729 settings.setValue("p2k_3", vjs.p2KeyBindings[BUTTON_3]);
730 settings.setValue("p2k_4", vjs.p2KeyBindings[BUTTON_4]);
731 settings.setValue("p2k_5", vjs.p2KeyBindings[BUTTON_5]);
732 settings.setValue("p2k_6", vjs.p2KeyBindings[BUTTON_6]);
733 settings.setValue("p2k_7", vjs.p2KeyBindings[BUTTON_7]);
734 settings.setValue("p2k_8", vjs.p2KeyBindings[BUTTON_8]);
735 settings.setValue("p2k_9", vjs.p2KeyBindings[BUTTON_9]);
736 settings.setValue("p2k_pound", vjs.p2KeyBindings[BUTTON_d]);
737 settings.setValue("p2k_star", vjs.p2KeyBindings[BUTTON_s]);
740 // Here's how Byuu does it...
741 // I think I have it working now... :-)
743 void Utility::resizeMainWindow()
745 unsigned region = config().video.context->region;
746 unsigned multiplier = config().video.context->multiplier;
747 unsigned width = 256 * multiplier;
748 unsigned height = (region == 0 ? 224 : 239) * multiplier;
750 if(config().video.context->correctAspectRatio)
754 width = (double)width * config().video.ntscAspectRatio + 0.5; //NTSC adjust
758 width = (double)width * config().video.palAspectRatio + 0.5; //PAL adjust
762 if(config().video.isFullscreen == false)
764 //get effective desktop work area region (ignore Windows taskbar, OS X dock, etc.)
765 QRect deskRect = QApplication::desktop()->availableGeometry(mainWindow);
767 //ensure window size will not be larger than viewable desktop area
768 constrainSize(height, width, deskRect.height()); //- frameHeight);
769 constrainSize(width, height, deskRect.width()); //- frameWidth );
771 mainWindow->canvas->setFixedSize(width, height);
776 for(unsigned i = 0; i < 2; i++)
778 unsigned iWidth = width, iHeight = height;
780 constrainSize(iHeight, iWidth, mainWindow->canvasContainer->size().height());
781 constrainSize(iWidth, iHeight, mainWindow->canvasContainer->size().width());
783 //center canvas onscreen; ensure it is not larger than viewable area
784 mainWindow->canvas->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
785 mainWindow->canvas->setFixedSize(iWidth, iHeight);
786 mainWindow->canvas->setMinimumSize(0, 0);
789 QApplication::processEvents();
793 //workaround for Qt/Xlib bug:
794 //if window resize occurs with cursor over it, Qt shows Qt::Size*DiagCursor;
795 //so force it to show Qt::ArrowCursor, as expected
796 mainWindow->setCursor(Qt::ArrowCursor);
797 mainWindow->canvasContainer->setCursor(Qt::ArrowCursor);
798 mainWindow->canvas->setCursor(Qt::ArrowCursor);
800 //workaround for DirectSound(?) bug:
801 //window resizing sometimes breaks audio sync, this call re-initializes it
805 void Utility::setScale(unsigned scale)
807 config().video.context->multiplier = scale;
809 mainWindow->shrink();
810 mainWindow->syncUi();
813 void QbWindow::shrink()
815 if(config().video.isFullscreen == false)
817 for(unsigned i = 0; i < 2; i++)
821 QApplication::processEvents();