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"
46 #include "debug/memorybrowser.h"
54 #include "jagcdbios.h"
55 #include "jagstub2bios.h"
58 // According to SebRmv, this header isn't seen on Arch Linux either... :-/
60 // Apparently on win32, usleep() is not pulled in by the usual suspects.
64 // The way BSNES controls things is by setting a timer with a zero
65 // timeout, sleeping if not emulating anything. Seems there has to be a
68 // It has a novel approach to plugging-in/using different video/audio/input
69 // methods, can we do something similar or should we just use the built-in
72 // We're going to try to use the built-in OpenGL support and see how it goes.
73 // We'll make the VJ core modular so that it doesn't matter what GUI is in
74 // use, we can drop it in anywhere and use it as-is.
76 //MainWin::MainWin(QString filenameToRun): running(true), powerButtonOn(false),
77 MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
78 showUntunedTankCircuit(true), cartridgeLoaded(false), CDActive(false),
79 //, alpineLoadSuccessful(false),
80 // pauseForFileSelector(false), loadAndGo(false), plzDontKillMyComputer(false)
81 pauseForFileSelector(false), loadAndGo(autoRun), plzDontKillMyComputer(false)
83 for(int i=0; i<8; i++)
86 videoWidget = new GLWidget(this);
87 setCentralWidget(videoWidget);
88 setWindowIcon(QIcon(":/res/vj-icon.png"));
90 QString title = QString(tr("Virtual Jaguar " VJ_RELEASE_VERSION ));
92 if (vjs.hardwareTypeAlpine)
93 title += QString(tr(" - Alpine Mode"));
95 setWindowTitle(title);
97 aboutWin = new AboutWindow(this);
98 helpWin = new HelpWindow(this);
99 filePickWin = new FilePickerWindow(this);
100 memBrowseWin = new MemoryBrowserWindow(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->setShortcut(QKeySequence(tr("Alt+x")));
112 quitAppAct->setShortcut(QKeySequence(tr("Ctrl+q")));
113 quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
114 connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
116 powerGreen.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
117 powerGreen.addFile(":/res/power-on-green.png", QSize(), QIcon::Normal, QIcon::On);
118 powerRed.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
119 powerRed.addFile(":/res/power-on-red.png", QSize(), QIcon::Normal, QIcon::On);
121 // powerAct = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
122 powerAct = new QAction(powerGreen, tr("&Power"), this);
123 powerAct->setStatusTip(tr("Powers Jaguar on/off"));
124 powerAct->setCheckable(true);
125 powerAct->setChecked(false);
126 // powerAct->setDisabled(true);
127 connect(powerAct, SIGNAL(triggered()), this, SLOT(TogglePowerState()));
130 pauseIcon.addFile(":/res/pause-off", QSize(), QIcon::Normal, QIcon::Off);
131 pauseIcon.addFile(":/res/pause-on", QSize(), QIcon::Normal, QIcon::On);
132 // pauseAct = new QAction(QIcon(":/res/pause.png"), tr("Pause"), this);
133 pauseAct = new QAction(pauseIcon, tr("Pause"), this);
134 pauseAct->setStatusTip(tr("Toggles the running state"));
135 pauseAct->setCheckable(true);
136 pauseAct->setDisabled(true);
137 pauseAct->setShortcut(QKeySequence(tr("Esc")));
138 connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
140 zoomActs = new QActionGroup(this);
142 x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
143 x1Act->setStatusTip(tr("Set window zoom to 100%"));
144 x1Act->setCheckable(true);
145 connect(x1Act, SIGNAL(triggered()), this, SLOT(SetZoom100()));
147 x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
148 x2Act->setStatusTip(tr("Set window zoom to 200%"));
149 x2Act->setCheckable(true);
150 connect(x2Act, SIGNAL(triggered()), this, SLOT(SetZoom200()));
152 x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
153 x3Act->setStatusTip(tr("Set window zoom to 300%"));
154 x3Act->setCheckable(true);
155 connect(x3Act, SIGNAL(triggered()), this, SLOT(SetZoom300()));
157 tvTypeActs = new QActionGroup(this);
159 ntscAct = new QAction(QIcon(":/res/ntsc.png"), tr("NTSC"), tvTypeActs);
160 ntscAct->setStatusTip(tr("Sets Jaguar to NTSC mode"));
161 ntscAct->setCheckable(true);
162 connect(ntscAct, SIGNAL(triggered()), this, SLOT(SetNTSC()));
164 palAct = new QAction(QIcon(":/res/pal.png"), tr("PAL"), tvTypeActs);
165 palAct->setStatusTip(tr("Sets Jaguar to PAL mode"));
166 palAct->setCheckable(true);
167 connect(palAct, SIGNAL(triggered()), this, SLOT(SetPAL()));
169 blurAct = new QAction(QIcon(":/res/generic.png"), tr("Blur"), this);
170 blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
171 blurAct->setCheckable(true);
172 connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
174 aboutAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&About..."), this);
175 aboutAct->setStatusTip(tr("Blatant self-promotion"));
176 connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
178 helpAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&Contents..."), this);
179 helpAct->setStatusTip(tr("Help is available, if you should need it"));
180 connect(helpAct, SIGNAL(triggered()), this, SLOT(ShowHelpWin()));
182 filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this);
183 filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar"));
184 filePickAct->setShortcut(QKeySequence(tr("Ctrl+i")));
185 connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart()));
187 configAct = new QAction(QIcon(":/res/wrench.png"), tr("&Configure"), this);
188 configAct->setStatusTip(tr("Configure options for Virtual Jaguar"));
189 configAct->setShortcut(QKeySequence(tr("Ctrl+c")));
190 connect(configAct, SIGNAL(triggered()), this, SLOT(Configure()));
192 useCDAct = new QAction(QIcon(":/res/compact-disc.png"), tr("&Use CD Unit"), this);
193 useCDAct->setStatusTip(tr("Use Jaguar Virtual CD unit"));
194 // useCDAct->setShortcut(QKeySequence(tr("Ctrl+c")));
195 useCDAct->setCheckable(true);
196 connect(useCDAct, SIGNAL(triggered()), this, SLOT(ToggleCDUsage()));
198 frameAdvanceAct = new QAction(QIcon(":/res/frame-advance.png"), tr("&Frame Advance"), this);
199 frameAdvanceAct->setShortcut(QKeySequence(tr("F7")));
200 connect(frameAdvanceAct, SIGNAL(triggered()), this, SLOT(FrameAdvance()));
203 memBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("Memory Browser"), this);
204 memBrowseAct->setStatusTip(tr("Shows the Jaguar memory browser window"));
205 // memBrowseAct->setCheckable(true);
206 connect(memBrowseAct, SIGNAL(triggered()), this, SLOT(ShowMemoryBrowserWin()));
208 // Misc. connections...
209 connect(filePickWin, SIGNAL(RequestLoad(QString)), this, SLOT(LoadSoftware(QString)));
210 connect(filePickWin, SIGNAL(FilePickerHiding()), this, SLOT(Unpause()));
212 // Create menus & toolbars
214 fileMenu = menuBar()->addMenu(tr("&Jaguar"));
215 fileMenu->addAction(powerAct);
216 fileMenu->addAction(pauseAct);
217 fileMenu->addAction(frameAdvanceAct);
218 fileMenu->addAction(filePickAct);
219 fileMenu->addAction(useCDAct);
220 fileMenu->addAction(configAct);
221 fileMenu->addAction(quitAppAct);
223 if (vjs.hardwareTypeAlpine)
225 debugMenu = menuBar()->addMenu(tr("&Debug"));
226 debugMenu->addAction(memBrowseAct);
229 helpMenu = menuBar()->addMenu(tr("&Help"));
230 helpMenu->addAction(helpAct);
231 helpMenu->addAction(aboutAct);
233 toolbar = addToolBar(tr("Stuff"));
234 toolbar->addAction(powerAct);
235 toolbar->addAction(pauseAct);
236 toolbar->addAction(filePickAct);
237 toolbar->addAction(useCDAct);
238 toolbar->addSeparator();
239 toolbar->addAction(x1Act);
240 toolbar->addAction(x2Act);
241 toolbar->addAction(x3Act);
242 toolbar->addSeparator();
243 toolbar->addAction(ntscAct);
244 toolbar->addAction(palAct);
245 toolbar->addSeparator();
246 toolbar->addAction(blurAct);
248 if (vjs.hardwareTypeAlpine)
250 debugbar = addToolBar(tr("&Debug"));
251 debugbar->addAction(memBrowseAct);
255 statusBar()->showMessage(tr("Ready"));
259 // Do this in case original size isn't correct (mostly for the first-run case)
262 // Set up timer based loop for animation...
263 timer = new QTimer(this);
264 connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
265 //This is only correct for PAL. !!! FIX !!! [DONE]
266 //Use timer->setInterval( int msec ) to fix this on the fly
268 // This isn't very accurate for NTSC: This is early by 40 msec per frame.
269 // This is because it's discarding the 0.6666... on the end of the fraction.
270 // Alas, 6 doesn't divide cleanly into 10. :-P
271 timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
273 // We set this initially, to make VJ behave somewhat as it would if no
274 // cart were inserted and the BIOS was set as active...
275 jaguarCartInserted = true;
276 WriteLog("Virtual Jaguar %s (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
277 WriteLog("VJ: Initializing jaguar subsystem...\n");
279 memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
281 // Check for filename passed in on the command line...
282 // if (!filenameToRun.isEmpty())
286 // Attempt to load/run the file the user passed in...
287 // LoadSoftware(filenameToRun);
288 //// memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
289 // Prevent the file scanner from running...
293 // Load up the default ROM if in Alpine mode:
294 if (vjs.hardwareTypeAlpine)
296 bool romLoaded = JaguarLoadFile(vjs.alpineROMPath);
298 // If regular load failed, try just a straight file load
299 // (Dev only! I don't want people to start getting lazy with their releases again! :-P)
301 romLoaded = AlpineLoadFile(vjs.alpineROMPath);
304 WriteLog("Alpine Mode: Successfully loaded file \"%s\".\n", vjs.alpineROMPath);
306 WriteLog("Alpine Mode: Unable to load file \"%s\"!\n", vjs.alpineROMPath);
308 // Attempt to load/run the ABS file...
309 LoadSoftware(vjs.absROMPath);
310 memcpy(jagMemSpace + 0xE00000, jaguarDevBootROM2, 0x20000); // Use the stub BIOS
311 // Prevent the scanner from running...
315 // memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Otherwise, use the stock BIOS
317 // Run the scanner if nothing passed in and *not* Alpine mode...
318 // NB: Really need to look into caching the info scanned in here...
319 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
323 void MainWin::LoadFile(QString file)
329 void MainWin::SyncUI(void)
331 // Set toolbar buttons/menus based on settings read in (sync the UI)...
332 blurAct->setChecked(vjs.glFilter);
333 x1Act->setChecked(zoomLevel == 1);
334 x2Act->setChecked(zoomLevel == 2);
335 x3Act->setChecked(zoomLevel == 3);
336 // running = powerAct->isChecked();
337 ntscAct->setChecked(vjs.hardwareTypeNTSC);
338 palAct->setChecked(!vjs.hardwareTypeNTSC);
339 powerAct->setIcon(vjs.hardwareTypeNTSC ? powerRed : powerGreen);
343 void MainWin::closeEvent(QCloseEvent * event)
346 // This should only be done by the config dialog
349 event->accept(); // ignore() if can't close for some reason
353 void MainWin::keyPressEvent(QKeyEvent * e)
355 // We ignore the Alt key for now, since it causes problems with the GUI
356 if (e->key() == Qt::Key_Alt)
366 void MainWin::keyReleaseEvent(QKeyEvent * e)
368 // We ignore the Alt key for now, since it causes problems with the GUI
369 if (e->key() == Qt::Key_Alt)
375 HandleKeys(e, false);
379 void MainWin::HandleKeys(QKeyEvent * e, bool state)
381 enum { P1LEFT = 0, P1RIGHT, P1UP, P1DOWN, P2LEFT, P2RIGHT, P2UP, P2DOWN };
382 // We kill bad key combos here, before they can get to the emulator...
383 // This also kills the illegal instruction problem that cropped up in Rayman!
384 // May want to do this by killing the old one instead of ignoring the new one...
385 // Seems to work better that way...
387 // The problem with this approach is that it causes bad results because it doesn't do
388 // any checking of previous states. Need to come up with something better because this
389 // causes problems where the keyboard acts as if it were unresponsive. :-P
391 if ((e->key() == vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
392 || (e->key() == vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
393 || (e->key() == vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
394 || (e->key() == vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U]))
398 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
399 joypad_0_buttons[BUTTON_R] = 0;
400 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
401 joypad_0_buttons[BUTTON_L] = 0;
402 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
403 joypad_0_buttons[BUTTON_D] = 0;
404 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U])
405 joypad_0_buttons[BUTTON_U] = 0;
407 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L] && joypad_1_buttons[BUTTON_R])
408 joypad_1_buttons[BUTTON_R] = 0;
409 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R] && joypad_1_buttons[BUTTON_L])
410 joypad_1_buttons[BUTTON_L] = 0;
411 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U] && joypad_1_buttons[BUTTON_D])
412 joypad_1_buttons[BUTTON_D] = 0;
413 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D] && joypad_1_buttons[BUTTON_U])
414 joypad_1_buttons[BUTTON_U] = 0;
416 //hrm, this still has sticky state problems... Ugh!
417 // First, settle key states...
418 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L])
419 keyHeld[P1LEFT] = state;
420 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R])
421 keyHeld[P1RIGHT] = state;
422 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U])
423 keyHeld[P1UP] = state;
424 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D])
425 keyHeld[P1DOWN] = state;
426 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L])
427 keyHeld[P2LEFT] = state;
428 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R])
429 keyHeld[P2RIGHT] = state;
430 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U])
431 keyHeld[P2UP] = state;
432 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D])
433 keyHeld[P2DOWN] = state;
435 // Next, check for conflicts and bail out if there are any...
436 if ((keyHeld[P1LEFT] && keyHeld[P1RIGHT])
437 || (keyHeld[P1UP] && keyHeld[P1DOWN])
438 || (keyHeld[P2LEFT] && keyHeld[P2RIGHT])
439 || (keyHeld[P2UP] && keyHeld[P2DOWN]))
444 // No bad combos exist, let's stuff the emulator key buffers...!
445 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
447 if (e->key() == (int)vjs.p1KeyBindings[i])
448 // joypad_0_buttons[i] = (uint8)state;
449 joypad_0_buttons[i] = (state ? 0x01 : 0x00);
451 // Pad #2 is screwing up pad #1. Prolly a problem in joystick.cpp...
452 // So let's try to fix it there. :-P [DONE]
453 if (e->key() == (int)vjs.p2KeyBindings[i])
454 // joypad_1_buttons[i] = (uint8)state;
455 joypad_1_buttons[i] = (state ? 0x01 : 0x00);
460 void MainWin::Open(void)
465 void MainWin::Configure(void)
467 // Call the configuration dialog and update settings
468 ConfigDialog dlg(this);
470 dlg.generalTab->useUnknownSoftware->setChecked(allowUnknownSoftware);
472 if (dlg.exec() == false)
475 QString before = vjs.ROMPath;
476 QString alpineBefore = vjs.alpineROMPath;
477 QString absBefore = vjs.absROMPath;
478 // bool audioBefore = vjs.audioEnabled;
479 bool audioBefore = vjs.DSPEnabled;
480 dlg.UpdateVJSettings();
481 QString after = vjs.ROMPath;
482 QString alpineAfter = vjs.alpineROMPath;
483 QString absAfter = vjs.absROMPath;
484 // bool audioAfter = vjs.audioEnabled;
485 bool audioAfter = vjs.DSPEnabled;
487 bool allowOld = allowUnknownSoftware;
489 allowUnknownSoftware = dlg.generalTab->useUnknownSoftware->isChecked();
491 // We rescan the "software" folder if the user either changed the path or
492 // checked/unchecked the "Allow unknown files" option in the config dialog.
493 if ((before != after) || (allowOld != allowUnknownSoftware))
494 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
496 // If the "Alpine" ROM is changed, then let's load it...
497 if (alpineBefore != alpineAfter)
499 if (!JaguarLoadFile(vjs.alpineROMPath) && !AlpineLoadFile(vjs.alpineROMPath))
501 // Oh crap, we couldn't get the file! Alert the media!
503 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.alpineROMPath));
504 msg.setIcon(QMessageBox::Warning);
509 // If the "ABS" ROM is changed, then let's load it...
510 if (absBefore != absAfter)
512 if (!JaguarLoadFile(vjs.absROMPath))
514 // Oh crap, we couldn't get the file! Alert the media!
516 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.absROMPath));
517 msg.setIcon(QMessageBox::Warning);
522 // If the "Enable DSP" checkbox changed, then we have to re-init the DAC,
523 // since it's running in the host audio IRQ...
524 if (audioBefore != audioAfter)
530 // Just in case we crash before a clean exit...
536 // Here's the main emulator loop
538 void MainWin::Timer(void)
543 if (showUntunedTankCircuit)
545 // Some machines can't handle this, so we give them the option to disable it. :-)
546 if (!plzDontKillMyComputer)
548 // Random hash & trash
549 // We try to simulate an untuned tank circuit here... :-)
550 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
552 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
554 videoWidget->buffer[(y * videoWidget->textureWidth) + x]
555 = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;
562 // Otherwise, run the Jaguar simulation
566 videoWidget->updateGL();
570 void MainWin::TogglePowerState(void)
572 powerButtonOn = !powerButtonOn;
575 // With the power off, we simulate white noise on the screen. :-)
578 useCDAct->setDisabled(false);
579 palAct->setDisabled(false);
580 ntscAct->setDisabled(false);
581 pauseAct->setChecked(false);
582 pauseAct->setDisabled(true);
583 showUntunedTankCircuit = true;
584 // This is just in case the ROM we were playing was in a narrow or wide field mode,
585 // so the untuned tank sim doesn't look wrong. :-)
590 useCDAct->setDisabled(true);
591 palAct->setDisabled(true);
592 ntscAct->setDisabled(true);
593 pauseAct->setChecked(false);
594 pauseAct->setDisabled(false);
595 showUntunedTankCircuit = false;
597 // Otherwise, we prepare for running regular software...
600 // Should check for cartridgeLoaded here as well...!
601 // We can clear it when toggling CDActive on, so that when we power cycle it does the
602 // expected thing. Otherwise, if we use the file picker to insert a cart, we expect
603 // to run the cart! Maybe have a RemoveCart function that only works if the CD unit
605 setWindowTitle(QString("Virtual Jaguar " VJ_RELEASE_VERSION
606 " - Now playing: Jaguar CD"));
609 WriteLog("GUI: Resetting Jaguar...\n");
615 void MainWin::ToggleRunState(void)
621 for(uint32_t i=0; i<(uint32_t)(videoWidget->textureWidth * 256); i++)
623 uint32_t pixel = videoWidget->buffer[i];
624 uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
625 pixel = ((r + g + b) / 3) & 0x00FF;
626 videoWidget->buffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
629 videoWidget->updateGL();
634 void MainWin::SetZoom100(void)
641 void MainWin::SetZoom200(void)
648 void MainWin::SetZoom300(void)
655 void MainWin::SetNTSC(void)
657 powerAct->setIcon(powerRed);
658 timer->setInterval(16);
659 vjs.hardwareTypeNTSC = true;
665 void MainWin::SetPAL(void)
667 powerAct->setIcon(powerGreen);
668 timer->setInterval(20);
669 vjs.hardwareTypeNTSC = false;
675 void MainWin::ToggleBlur(void)
677 vjs.glFilter = !vjs.glFilter;
682 void MainWin::ShowAboutWin(void)
688 void MainWin::ShowHelpWin(void)
694 void MainWin::InsertCart(void)
696 // If the emulator is running, we pause it here and unpause it later
697 // if we dismiss the file selector without choosing anything
698 if (running && powerButtonOn)
701 pauseForFileSelector = true;
708 void MainWin::Unpause(void)
710 // Here we unpause the emulator if it was paused when we went into the file selector
711 if (pauseForFileSelector)
713 pauseForFileSelector = false;
715 // Some nutter might have unpaused while in the file selector, so check for that
722 void MainWin::LoadSoftware(QString file)
724 running = false; // Prevent bad things(TM) from happening...
725 pauseForFileSelector = false; // Reset the file selector pause flag
726 SET32(jaguarMainRAM, 0, 0x00200000); // Set top of stack...
727 cartridgeLoaded = JaguarLoadFile(file.toAscii().data());
729 char * biosPointer = jaguarBootROM;
731 if (vjs.hardwareTypeAlpine)
732 biosPointer = jaguarDevBootROM2;
734 memcpy(jagMemSpace + 0xE00000, biosPointer, 0x20000);
736 powerAct->setDisabled(false);
737 powerAct->setChecked(true);
738 powerButtonOn = false;
741 if (!vjs.hardwareTypeAlpine && !loadAndGo)
743 QString newTitle = QString("Virtual Jaguar " VJ_RELEASE_VERSION " - Now playing: %1")
744 .arg(filePickWin->GetSelectedPrettyName());
745 setWindowTitle(newTitle);
750 void MainWin::ToggleCDUsage(void)
752 CDActive = !CDActive;
757 powerAct->setDisabled(false);
761 powerAct->setDisabled(true);
764 // Set up the Jaguar CD for execution, otherwise, clear memory
766 memcpy(jagMemSpace + 0x800000, jaguarCDBootROM, 0x40000);
768 memset(jagMemSpace + 0x800000, 0xFF, 0x40000);
773 void MainWin::FrameAdvance(void)
775 //printf("Frame Advance...\n");
776 // Execute 1 frame, then exit (only useful in Pause mode)
778 videoWidget->updateGL();
782 void MainWin::ShowMemoryBrowserWin(void)
784 memBrowseWin->show();
785 memBrowseWin->RefreshContents();
789 void MainWin::ResizeMainWindow(void)
791 videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
794 for(int i=0; i<2; i++)
798 QApplication::processEvents();
803 #warning "!!! Need to check the window geometry to see if the positions are legal !!!"
804 // i.e., someone could drag it to another screen, close it, then disconnect that screen
805 void MainWin::ReadSettings(void)
807 QSettings settings("Underground Software", "Virtual Jaguar");
808 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
809 QSize size = settings.value("size", QSize(400, 400)).toSize();
812 pos = settings.value("cartLoadPos", QPoint(200, 200)).toPoint();
813 filePickWin->move(pos);
815 zoomLevel = settings.value("zoom", 2).toInt();
816 allowUnknownSoftware = settings.value("showUnknownSoftware", false).toBool();
818 vjs.useJoystick = settings.value("useJoystick", false).toBool();
819 vjs.joyport = settings.value("joyport", 0).toInt();
820 vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
821 vjs.frameSkip = settings.value("frameSkip", 0).toInt();
822 vjs.useJaguarBIOS = settings.value("useJaguarBIOS", false).toBool();
823 vjs.GPUEnabled = settings.value("GPUEnabled", true).toBool();
824 vjs.DSPEnabled = settings.value("DSPEnabled", false).toBool();
825 vjs.audioEnabled = settings.value("audioEnabled", true).toBool();
826 vjs.usePipelinedDSP = settings.value("usePipelinedDSP", false).toBool();
827 vjs.fullscreen = settings.value("fullscreen", false).toBool();
828 vjs.useOpenGL = settings.value("useOpenGL", true).toBool();
829 vjs.glFilter = settings.value("glFilterType", 1).toInt();
830 vjs.renderType = settings.value("renderType", 0).toInt();
831 vjs.allowWritesToROM = settings.value("writeROM", false).toBool();
832 // strcpy(vjs.jagBootPath, settings.value("JagBootROM", "./bios/[BIOS] Atari Jaguar (USA, Europe).zip").toString().toAscii().data());
833 // strcpy(vjs.CDBootPath, settings.value("CDBootROM", "./bios/jagcd.rom").toString().toAscii().data());
834 strcpy(vjs.EEPROMPath, settings.value("EEPROMs", "./eeproms/").toString().toAscii().data());
835 strcpy(vjs.ROMPath, settings.value("ROMs", "./software/").toString().toAscii().data());
836 strcpy(vjs.alpineROMPath, settings.value("DefaultROM", "").toString().toAscii().data());
837 strcpy(vjs.absROMPath, settings.value("DefaultABS", "").toString().toAscii().data());
838 WriteLog("MainWin: Paths\n");
839 //WriteLog(" jagBootPath = \"%s\"\n", vjs.jagBootPath);
840 //WriteLog(" CDBootPath = \"%s\"\n", vjs.CDBootPath);
841 WriteLog(" EEPROMPath = \"%s\"\n", vjs.EEPROMPath);
842 WriteLog(" ROMPath = \"%s\"\n", vjs.ROMPath);
843 WriteLog("AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);
844 WriteLog(" absROMPath = \"%s\"\n", vjs.absROMPath);
845 WriteLog("Pipelined DSP = %s\n", (vjs.usePipelinedDSP ? "ON" : "off"));
847 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
848 vjs.p1KeyBindings[BUTTON_U] = settings.value("p1k_up", Qt::Key_S).toInt();
849 vjs.p1KeyBindings[BUTTON_D] = settings.value("p1k_down", Qt::Key_X).toInt();
850 vjs.p1KeyBindings[BUTTON_L] = settings.value("p1k_left", Qt::Key_A).toInt();
851 vjs.p1KeyBindings[BUTTON_R] = settings.value("p1k_right", Qt::Key_D).toInt();
852 vjs.p1KeyBindings[BUTTON_C] = settings.value("p1k_c", Qt::Key_J).toInt();
853 vjs.p1KeyBindings[BUTTON_B] = settings.value("p1k_b", Qt::Key_K).toInt();
854 vjs.p1KeyBindings[BUTTON_A] = settings.value("p1k_a", Qt::Key_L).toInt();
855 vjs.p1KeyBindings[BUTTON_OPTION] = settings.value("p1k_option", Qt::Key_O).toInt();
856 vjs.p1KeyBindings[BUTTON_PAUSE] = settings.value("p1k_pause", Qt::Key_P).toInt();
857 vjs.p1KeyBindings[BUTTON_0] = settings.value("p1k_0", Qt::Key_0).toInt();
858 vjs.p1KeyBindings[BUTTON_1] = settings.value("p1k_1", Qt::Key_1).toInt();
859 vjs.p1KeyBindings[BUTTON_2] = settings.value("p1k_2", Qt::Key_2).toInt();
860 vjs.p1KeyBindings[BUTTON_3] = settings.value("p1k_3", Qt::Key_3).toInt();
861 vjs.p1KeyBindings[BUTTON_4] = settings.value("p1k_4", Qt::Key_4).toInt();
862 vjs.p1KeyBindings[BUTTON_5] = settings.value("p1k_5", Qt::Key_5).toInt();
863 vjs.p1KeyBindings[BUTTON_6] = settings.value("p1k_6", Qt::Key_6).toInt();
864 vjs.p1KeyBindings[BUTTON_7] = settings.value("p1k_7", Qt::Key_7).toInt();
865 vjs.p1KeyBindings[BUTTON_8] = settings.value("p1k_8", Qt::Key_8).toInt();
866 vjs.p1KeyBindings[BUTTON_9] = settings.value("p1k_9", Qt::Key_9).toInt();
867 vjs.p1KeyBindings[BUTTON_d] = settings.value("p1k_pound", Qt::Key_Minus).toInt();
868 vjs.p1KeyBindings[BUTTON_s] = settings.value("p1k_star", Qt::Key_Equal).toInt();
870 vjs.p2KeyBindings[BUTTON_U] = settings.value("p2k_up", Qt::Key_Up).toInt();
871 vjs.p2KeyBindings[BUTTON_D] = settings.value("p2k_down", Qt::Key_Down).toInt();
872 vjs.p2KeyBindings[BUTTON_L] = settings.value("p2k_left", Qt::Key_Left).toInt();
873 vjs.p2KeyBindings[BUTTON_R] = settings.value("p2k_right", Qt::Key_Right).toInt();
874 vjs.p2KeyBindings[BUTTON_C] = settings.value("p2k_c", Qt::Key_Z).toInt();
875 vjs.p2KeyBindings[BUTTON_B] = settings.value("p2k_b", Qt::Key_X).toInt();
876 vjs.p2KeyBindings[BUTTON_A] = settings.value("p2k_a", Qt::Key_C).toInt();
877 vjs.p2KeyBindings[BUTTON_OPTION] = settings.value("p2k_option", Qt::Key_Apostrophe).toInt();
878 vjs.p2KeyBindings[BUTTON_PAUSE] = settings.value("p2k_pause", Qt::Key_Return).toInt();
879 vjs.p2KeyBindings[BUTTON_0] = settings.value("p2k_0", Qt::Key_0).toInt();
880 vjs.p2KeyBindings[BUTTON_1] = settings.value("p2k_1", Qt::Key_1).toInt();
881 vjs.p2KeyBindings[BUTTON_2] = settings.value("p2k_2", Qt::Key_2).toInt();
882 vjs.p2KeyBindings[BUTTON_3] = settings.value("p2k_3", Qt::Key_3).toInt();
883 vjs.p2KeyBindings[BUTTON_4] = settings.value("p2k_4", Qt::Key_4).toInt();
884 vjs.p2KeyBindings[BUTTON_5] = settings.value("p2k_5", Qt::Key_5).toInt();
885 vjs.p2KeyBindings[BUTTON_6] = settings.value("p2k_6", Qt::Key_6).toInt();
886 vjs.p2KeyBindings[BUTTON_7] = settings.value("p2k_7", Qt::Key_7).toInt();
887 vjs.p2KeyBindings[BUTTON_8] = settings.value("p2k_8", Qt::Key_8).toInt();
888 vjs.p2KeyBindings[BUTTON_9] = settings.value("p2k_9", Qt::Key_9).toInt();
889 vjs.p2KeyBindings[BUTTON_d] = settings.value("p2k_pound", Qt::Key_Slash).toInt();
890 vjs.p2KeyBindings[BUTTON_s] = settings.value("p2k_star", Qt::Key_Asterisk).toInt();
894 void MainWin::WriteSettings(void)
896 QSettings settings("Underground Software", "Virtual Jaguar");
897 settings.setValue("pos", pos());
898 settings.setValue("size", size());
899 settings.setValue("cartLoadPos", filePickWin->pos());
901 settings.setValue("zoom", zoomLevel);
902 settings.setValue("showUnknownSoftware", allowUnknownSoftware);
904 settings.setValue("useJoystick", vjs.useJoystick);
905 settings.setValue("joyport", vjs.joyport);
906 settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
907 settings.setValue("frameSkip", vjs.frameSkip);
908 settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
909 settings.setValue("GPUEnabled", vjs.GPUEnabled);
910 settings.setValue("DSPEnabled", vjs.DSPEnabled);
911 settings.setValue("audioEnabled", vjs.audioEnabled);
912 settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
913 settings.setValue("fullscreen", vjs.fullscreen);
914 settings.setValue("useOpenGL", vjs.useOpenGL);
915 settings.setValue("glFilterType", vjs.glFilter);
916 settings.setValue("renderType", vjs.renderType);
917 settings.setValue("writeROM", vjs.allowWritesToROM);
918 settings.setValue("JagBootROM", vjs.jagBootPath);
919 settings.setValue("CDBootROM", vjs.CDBootPath);
920 settings.setValue("EEPROMs", vjs.EEPROMPath);
921 settings.setValue("ROMs", vjs.ROMPath);
922 settings.setValue("DefaultROM", vjs.alpineROMPath);
923 settings.setValue("DefaultABS", vjs.absROMPath);
925 settings.setValue("p1k_up", vjs.p1KeyBindings[BUTTON_U]);
926 settings.setValue("p1k_down", vjs.p1KeyBindings[BUTTON_D]);
927 settings.setValue("p1k_left", vjs.p1KeyBindings[BUTTON_L]);
928 settings.setValue("p1k_right", vjs.p1KeyBindings[BUTTON_R]);
929 settings.setValue("p1k_c", vjs.p1KeyBindings[BUTTON_C]);
930 settings.setValue("p1k_b", vjs.p1KeyBindings[BUTTON_B]);
931 settings.setValue("p1k_a", vjs.p1KeyBindings[BUTTON_A]);
932 settings.setValue("p1k_option", vjs.p1KeyBindings[BUTTON_OPTION]);
933 settings.setValue("p1k_pause", vjs.p1KeyBindings[BUTTON_PAUSE]);
934 settings.setValue("p1k_0", vjs.p1KeyBindings[BUTTON_0]);
935 settings.setValue("p1k_1", vjs.p1KeyBindings[BUTTON_1]);
936 settings.setValue("p1k_2", vjs.p1KeyBindings[BUTTON_2]);
937 settings.setValue("p1k_3", vjs.p1KeyBindings[BUTTON_3]);
938 settings.setValue("p1k_4", vjs.p1KeyBindings[BUTTON_4]);
939 settings.setValue("p1k_5", vjs.p1KeyBindings[BUTTON_5]);
940 settings.setValue("p1k_6", vjs.p1KeyBindings[BUTTON_6]);
941 settings.setValue("p1k_7", vjs.p1KeyBindings[BUTTON_7]);
942 settings.setValue("p1k_8", vjs.p1KeyBindings[BUTTON_8]);
943 settings.setValue("p1k_9", vjs.p1KeyBindings[BUTTON_9]);
944 settings.setValue("p1k_pound", vjs.p1KeyBindings[BUTTON_d]);
945 settings.setValue("p1k_star", vjs.p1KeyBindings[BUTTON_s]);
947 settings.setValue("p2k_up", vjs.p2KeyBindings[BUTTON_U]);
948 settings.setValue("p2k_down", vjs.p2KeyBindings[BUTTON_D]);
949 settings.setValue("p2k_left", vjs.p2KeyBindings[BUTTON_L]);
950 settings.setValue("p2k_right", vjs.p2KeyBindings[BUTTON_R]);
951 settings.setValue("p2k_c", vjs.p2KeyBindings[BUTTON_C]);
952 settings.setValue("p2k_b", vjs.p2KeyBindings[BUTTON_B]);
953 settings.setValue("p2k_a", vjs.p2KeyBindings[BUTTON_A]);
954 settings.setValue("p2k_option", vjs.p2KeyBindings[BUTTON_OPTION]);
955 settings.setValue("p2k_pause", vjs.p2KeyBindings[BUTTON_PAUSE]);
956 settings.setValue("p2k_0", vjs.p2KeyBindings[BUTTON_0]);
957 settings.setValue("p2k_1", vjs.p2KeyBindings[BUTTON_1]);
958 settings.setValue("p2k_2", vjs.p2KeyBindings[BUTTON_2]);
959 settings.setValue("p2k_3", vjs.p2KeyBindings[BUTTON_3]);
960 settings.setValue("p2k_4", vjs.p2KeyBindings[BUTTON_4]);
961 settings.setValue("p2k_5", vjs.p2KeyBindings[BUTTON_5]);
962 settings.setValue("p2k_6", vjs.p2KeyBindings[BUTTON_6]);
963 settings.setValue("p2k_7", vjs.p2KeyBindings[BUTTON_7]);
964 settings.setValue("p2k_8", vjs.p2KeyBindings[BUTTON_8]);
965 settings.setValue("p2k_9", vjs.p2KeyBindings[BUTTON_9]);
966 settings.setValue("p2k_pound", vjs.p2KeyBindings[BUTTON_d]);
967 settings.setValue("p2k_star", vjs.p2KeyBindings[BUTTON_s]);
971 void MainWin::WriteUISettings(void)
973 QSettings settings("Underground Software", "Virtual Jaguar");
974 settings.setValue("pos", pos());
975 settings.setValue("size", size());
976 settings.setValue("cartLoadPos", filePickWin->pos());
978 settings.setValue("zoom", zoomLevel);