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"
47 #include "debug/cpubrowser.h"
55 #include "jagcdbios.h"
56 #include "jagstub2bios.h"
59 // According to SebRmv, this header isn't seen on Arch Linux either... :-/
61 // Apparently on win32, usleep() is not pulled in by the usual suspects.
65 // The way BSNES controls things is by setting a timer with a zero
66 // timeout, sleeping if not emulating anything. Seems there has to be a
69 // It has a novel approach to plugging-in/using different video/audio/input
70 // methods, can we do something similar or should we just use the built-in
73 // We're going to try to use the built-in OpenGL support and see how it goes.
74 // We'll make the VJ core modular so that it doesn't matter what GUI is in
75 // use, we can drop it in anywhere and use it as-is.
77 //MainWin::MainWin(QString filenameToRun): running(true), powerButtonOn(false),
78 MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
79 showUntunedTankCircuit(true), cartridgeLoaded(false), CDActive(false),
80 //, alpineLoadSuccessful(false),
81 // pauseForFileSelector(false), loadAndGo(false), plzDontKillMyComputer(false)
82 pauseForFileSelector(false), loadAndGo(autoRun), plzDontKillMyComputer(false)
84 for(int i=0; i<8; i++)
87 videoWidget = new GLWidget(this);
88 setCentralWidget(videoWidget);
89 setWindowIcon(QIcon(":/res/vj-icon.png"));
91 QString title = QString(tr("Virtual Jaguar " VJ_RELEASE_VERSION ));
93 if (vjs.hardwareTypeAlpine)
94 title += QString(tr(" - Alpine Mode"));
96 setWindowTitle(title);
98 aboutWin = new AboutWindow(this);
99 helpWin = new HelpWindow(this);
100 filePickWin = new FilePickerWindow(this);
101 memBrowseWin = new MemoryBrowserWindow(this);
102 cpuBrowseWin = new CPUBrowserWindow(this);
104 videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
105 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
107 setUnifiedTitleAndToolBarOnMac(true);
111 quitAppAct = new QAction(tr("E&xit"), this);
112 // quitAppAct->setShortcuts(QKeySequence::Quit);
113 // quitAppAct->setShortcut(QKeySequence(tr("Alt+x")));
114 quitAppAct->setShortcut(QKeySequence(tr("Ctrl+q")));
115 quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
116 connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
118 powerGreen.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
119 powerGreen.addFile(":/res/power-on-green.png", QSize(), QIcon::Normal, QIcon::On);
120 powerRed.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
121 powerRed.addFile(":/res/power-on-red.png", QSize(), QIcon::Normal, QIcon::On);
123 // powerAct = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
124 powerAct = new QAction(powerGreen, tr("&Power"), this);
125 powerAct->setStatusTip(tr("Powers Jaguar on/off"));
126 powerAct->setCheckable(true);
127 powerAct->setChecked(false);
128 // powerAct->setDisabled(true);
129 connect(powerAct, SIGNAL(triggered()), this, SLOT(TogglePowerState()));
132 pauseIcon.addFile(":/res/pause-off", QSize(), QIcon::Normal, QIcon::Off);
133 pauseIcon.addFile(":/res/pause-on", QSize(), QIcon::Normal, QIcon::On);
134 // pauseAct = new QAction(QIcon(":/res/pause.png"), tr("Pause"), this);
135 pauseAct = new QAction(pauseIcon, tr("Pause"), this);
136 pauseAct->setStatusTip(tr("Toggles the running state"));
137 pauseAct->setCheckable(true);
138 pauseAct->setDisabled(true);
139 pauseAct->setShortcut(QKeySequence(tr("Esc")));
140 connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
142 zoomActs = new QActionGroup(this);
144 x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
145 x1Act->setStatusTip(tr("Set window zoom to 100%"));
146 x1Act->setCheckable(true);
147 connect(x1Act, SIGNAL(triggered()), this, SLOT(SetZoom100()));
149 x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
150 x2Act->setStatusTip(tr("Set window zoom to 200%"));
151 x2Act->setCheckable(true);
152 connect(x2Act, SIGNAL(triggered()), this, SLOT(SetZoom200()));
154 x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
155 x3Act->setStatusTip(tr("Set window zoom to 300%"));
156 x3Act->setCheckable(true);
157 connect(x3Act, SIGNAL(triggered()), this, SLOT(SetZoom300()));
159 tvTypeActs = new QActionGroup(this);
161 ntscAct = new QAction(QIcon(":/res/ntsc.png"), tr("NTSC"), tvTypeActs);
162 ntscAct->setStatusTip(tr("Sets Jaguar to NTSC mode"));
163 ntscAct->setCheckable(true);
164 connect(ntscAct, SIGNAL(triggered()), this, SLOT(SetNTSC()));
166 palAct = new QAction(QIcon(":/res/pal.png"), tr("PAL"), tvTypeActs);
167 palAct->setStatusTip(tr("Sets Jaguar to PAL mode"));
168 palAct->setCheckable(true);
169 connect(palAct, SIGNAL(triggered()), this, SLOT(SetPAL()));
171 blurAct = new QAction(QIcon(":/res/generic.png"), tr("Blur"), this);
172 blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
173 blurAct->setCheckable(true);
174 connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
176 aboutAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&About..."), this);
177 aboutAct->setStatusTip(tr("Blatant self-promotion"));
178 connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
180 helpAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&Contents..."), this);
181 helpAct->setStatusTip(tr("Help is available, if you should need it"));
182 connect(helpAct, SIGNAL(triggered()), this, SLOT(ShowHelpWin()));
184 filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this);
185 filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar"));
186 filePickAct->setShortcut(QKeySequence(tr("Ctrl+i")));
187 connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart()));
189 configAct = new QAction(QIcon(":/res/wrench.png"), tr("&Configure"), this);
190 configAct->setStatusTip(tr("Configure options for Virtual Jaguar"));
191 configAct->setShortcut(QKeySequence(tr("Ctrl+c")));
192 connect(configAct, SIGNAL(triggered()), this, SLOT(Configure()));
194 useCDAct = new QAction(QIcon(":/res/compact-disc.png"), tr("&Use CD Unit"), this);
195 useCDAct->setStatusTip(tr("Use Jaguar Virtual CD unit"));
196 // useCDAct->setShortcut(QKeySequence(tr("Ctrl+c")));
197 useCDAct->setCheckable(true);
198 connect(useCDAct, SIGNAL(triggered()), this, SLOT(ToggleCDUsage()));
200 frameAdvanceAct = new QAction(QIcon(":/res/frame-advance.png"), tr("&Frame Advance"), this);
201 frameAdvanceAct->setShortcut(QKeySequence(tr("F7")));
202 connect(frameAdvanceAct, SIGNAL(triggered()), this, SLOT(FrameAdvance()));
204 fullScreenAct = new QAction(QIcon(":/res/generic.png"), tr("F&ull Screen"), this);
205 fullScreenAct->setShortcut(QKeySequence(tr("F9")));
206 connect(fullScreenAct, SIGNAL(triggered()), this, SLOT(ToggleFullScreen()));
209 memBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("Memory Browser"), this);
210 memBrowseAct->setStatusTip(tr("Shows the Jaguar memory browser window"));
211 // memBrowseAct->setCheckable(true);
212 connect(memBrowseAct, SIGNAL(triggered()), this, SLOT(ShowMemoryBrowserWin()));
214 cpuBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("CPU Browser"), this);
215 cpuBrowseAct->setStatusTip(tr("Shows the Jaguar CPU browser window"));
216 // memBrowseAct->setCheckable(true);
217 connect(cpuBrowseAct, SIGNAL(triggered()), this, SLOT(ShowCPUBrowserWin()));
219 // Misc. connections...
220 connect(filePickWin, SIGNAL(RequestLoad(QString)), this, SLOT(LoadSoftware(QString)));
221 connect(filePickWin, SIGNAL(FilePickerHiding()), this, SLOT(Unpause()));
223 // Create menus & toolbars
225 fileMenu = menuBar()->addMenu(tr("&Jaguar"));
226 fileMenu->addAction(powerAct);
227 fileMenu->addAction(pauseAct);
228 fileMenu->addAction(frameAdvanceAct);
229 fileMenu->addAction(filePickAct);
230 fileMenu->addAction(useCDAct);
231 fileMenu->addAction(configAct);
232 fileMenu->addAction(quitAppAct);
234 if (vjs.hardwareTypeAlpine)
236 debugMenu = menuBar()->addMenu(tr("&Debug"));
237 debugMenu->addAction(memBrowseAct);
238 debugMenu->addAction(cpuBrowseAct);
241 helpMenu = menuBar()->addMenu(tr("&Help"));
242 helpMenu->addAction(helpAct);
243 helpMenu->addAction(aboutAct);
245 toolbar = addToolBar(tr("Stuff"));
246 toolbar->addAction(powerAct);
247 toolbar->addAction(pauseAct);
248 toolbar->addAction(filePickAct);
249 toolbar->addAction(useCDAct);
250 toolbar->addSeparator();
251 toolbar->addAction(x1Act);
252 toolbar->addAction(x2Act);
253 toolbar->addAction(x3Act);
254 toolbar->addSeparator();
255 toolbar->addAction(ntscAct);
256 toolbar->addAction(palAct);
257 toolbar->addSeparator();
258 toolbar->addAction(blurAct);
259 toolbar->addAction(fullScreenAct);
261 if (vjs.hardwareTypeAlpine)
263 debugbar = addToolBar(tr("&Debug"));
264 debugbar->addAction(memBrowseAct);
265 debugbar->addAction(cpuBrowseAct);
269 statusBar()->showMessage(tr("Ready"));
273 // Do this in case original size isn't correct (mostly for the first-run case)
276 // Set up timer based loop for animation...
277 timer = new QTimer(this);
278 connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
279 //This is only correct for PAL. !!! FIX !!! [DONE]
280 //Use timer->setInterval( int msec ) to fix this on the fly
282 // This isn't very accurate for NTSC: This is early by 40 msec per frame.
283 // This is because it's discarding the 0.6666... on the end of the fraction.
284 // Alas, 6 doesn't divide cleanly into 10. :-P
285 timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
287 // We set this initially, to make VJ behave somewhat as it would if no
288 // cart were inserted and the BIOS was set as active...
289 jaguarCartInserted = true;
290 WriteLog("Virtual Jaguar %s (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
291 WriteLog("VJ: Initializing jaguar subsystem...\n");
293 memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
295 // Check for filename passed in on the command line...
296 // if (!filenameToRun.isEmpty())
300 // Attempt to load/run the file the user passed in...
301 // LoadSoftware(filenameToRun);
302 //// memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
303 // Prevent the file scanner from running...
307 // Load up the default ROM if in Alpine mode:
308 if (vjs.hardwareTypeAlpine)
310 bool romLoaded = JaguarLoadFile(vjs.alpineROMPath);
312 // If regular load failed, try just a straight file load
313 // (Dev only! I don't want people to start getting lazy with their releases again! :-P)
315 romLoaded = AlpineLoadFile(vjs.alpineROMPath);
318 WriteLog("Alpine Mode: Successfully loaded file \"%s\".\n", vjs.alpineROMPath);
320 WriteLog("Alpine Mode: Unable to load file \"%s\"!\n", vjs.alpineROMPath);
322 // Attempt to load/run the ABS file...
323 LoadSoftware(vjs.absROMPath);
324 memcpy(jagMemSpace + 0xE00000, jaguarDevBootROM2, 0x20000); // Use the stub BIOS
325 // Prevent the scanner from running...
329 // memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Otherwise, use the stock BIOS
331 // Run the scanner if nothing passed in and *not* Alpine mode...
332 // NB: Really need to look into caching the info scanned in here...
333 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
337 void MainWin::LoadFile(QString file)
343 void MainWin::SyncUI(void)
345 // Set toolbar buttons/menus based on settings read in (sync the UI)...
346 // (Really, this is to sync command line options passed in)
347 blurAct->setChecked(vjs.glFilter);
348 x1Act->setChecked(zoomLevel == 1);
349 x2Act->setChecked(zoomLevel == 2);
350 x3Act->setChecked(zoomLevel == 3);
351 // running = powerAct->isChecked();
352 ntscAct->setChecked(vjs.hardwareTypeNTSC);
353 palAct->setChecked(!vjs.hardwareTypeNTSC);
354 powerAct->setIcon(vjs.hardwareTypeNTSC ? powerRed : powerGreen);
356 fullScreen = vjs.fullscreen;
357 SetFullScreen(fullScreen);
361 void MainWin::closeEvent(QCloseEvent * event)
364 // This should only be done by the config dialog
367 event->accept(); // ignore() if can't close for some reason
371 void MainWin::keyPressEvent(QKeyEvent * e)
373 // We ignore the Alt key for now, since it causes problems with the GUI
374 if (e->key() == Qt::Key_Alt)
380 if (e->key() == Qt::Key_F9)
390 void MainWin::keyReleaseEvent(QKeyEvent * e)
392 // We ignore the Alt key for now, since it causes problems with the GUI
393 if (e->key() == Qt::Key_Alt)
399 HandleKeys(e, false);
403 void MainWin::HandleKeys(QKeyEvent * e, bool state)
405 enum { P1LEFT = 0, P1RIGHT, P1UP, P1DOWN, P2LEFT, P2RIGHT, P2UP, P2DOWN };
406 // We kill bad key combos here, before they can get to the emulator...
407 // This also kills the illegal instruction problem that cropped up in Rayman!
408 // May want to do this by killing the old one instead of ignoring the new one...
409 // Seems to work better that way...
411 // The problem with this approach is that it causes bad results because it doesn't do
412 // any checking of previous states. Need to come up with something better because this
413 // causes problems where the keyboard acts as if it were unresponsive. :-P
415 if ((e->key() == vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
416 || (e->key() == vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
417 || (e->key() == vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
418 || (e->key() == vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U]))
422 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
423 joypad_0_buttons[BUTTON_R] = 0;
424 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
425 joypad_0_buttons[BUTTON_L] = 0;
426 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
427 joypad_0_buttons[BUTTON_D] = 0;
428 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U])
429 joypad_0_buttons[BUTTON_U] = 0;
431 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L] && joypad_1_buttons[BUTTON_R])
432 joypad_1_buttons[BUTTON_R] = 0;
433 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R] && joypad_1_buttons[BUTTON_L])
434 joypad_1_buttons[BUTTON_L] = 0;
435 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U] && joypad_1_buttons[BUTTON_D])
436 joypad_1_buttons[BUTTON_D] = 0;
437 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D] && joypad_1_buttons[BUTTON_U])
438 joypad_1_buttons[BUTTON_U] = 0;
440 //hrm, this still has sticky state problems... Ugh!
441 // First, settle key states...
442 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L])
443 keyHeld[P1LEFT] = state;
444 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R])
445 keyHeld[P1RIGHT] = state;
446 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U])
447 keyHeld[P1UP] = state;
448 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D])
449 keyHeld[P1DOWN] = state;
450 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L])
451 keyHeld[P2LEFT] = state;
452 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R])
453 keyHeld[P2RIGHT] = state;
454 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U])
455 keyHeld[P2UP] = state;
456 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D])
457 keyHeld[P2DOWN] = state;
459 // Next, check for conflicts and bail out if there are any...
460 if ((keyHeld[P1LEFT] && keyHeld[P1RIGHT])
461 || (keyHeld[P1UP] && keyHeld[P1DOWN])
462 || (keyHeld[P2LEFT] && keyHeld[P2RIGHT])
463 || (keyHeld[P2UP] && keyHeld[P2DOWN]))
468 // No bad combos exist, let's stuff the emulator key buffers...!
469 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
471 if (e->key() == (int)vjs.p1KeyBindings[i])
472 // joypad_0_buttons[i] = (uint8)state;
473 joypad_0_buttons[i] = (state ? 0x01 : 0x00);
475 // Pad #2 is screwing up pad #1. Prolly a problem in joystick.cpp...
476 // So let's try to fix it there. :-P [DONE]
477 if (e->key() == (int)vjs.p2KeyBindings[i])
478 // joypad_1_buttons[i] = (uint8)state;
479 joypad_1_buttons[i] = (state ? 0x01 : 0x00);
484 void MainWin::Open(void)
489 void MainWin::Configure(void)
491 // Call the configuration dialog and update settings
492 ConfigDialog dlg(this);
494 dlg.generalTab->useUnknownSoftware->setChecked(allowUnknownSoftware);
496 if (dlg.exec() == false)
499 QString before = vjs.ROMPath;
500 QString alpineBefore = vjs.alpineROMPath;
501 QString absBefore = vjs.absROMPath;
502 // bool audioBefore = vjs.audioEnabled;
503 bool audioBefore = vjs.DSPEnabled;
504 dlg.UpdateVJSettings();
505 QString after = vjs.ROMPath;
506 QString alpineAfter = vjs.alpineROMPath;
507 QString absAfter = vjs.absROMPath;
508 // bool audioAfter = vjs.audioEnabled;
509 bool audioAfter = vjs.DSPEnabled;
511 bool allowOld = allowUnknownSoftware;
513 allowUnknownSoftware = dlg.generalTab->useUnknownSoftware->isChecked();
515 // We rescan the "software" folder if the user either changed the path or
516 // checked/unchecked the "Allow unknown files" option in the config dialog.
517 if ((before != after) || (allowOld != allowUnknownSoftware))
518 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
520 // If the "Alpine" ROM is changed, then let's load it...
521 if (alpineBefore != alpineAfter)
523 if (!JaguarLoadFile(vjs.alpineROMPath) && !AlpineLoadFile(vjs.alpineROMPath))
525 // Oh crap, we couldn't get the file! Alert the media!
527 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.alpineROMPath));
528 msg.setIcon(QMessageBox::Warning);
533 // If the "ABS" ROM is changed, then let's load it...
534 if (absBefore != absAfter)
536 if (!JaguarLoadFile(vjs.absROMPath))
538 // Oh crap, we couldn't get the file! Alert the media!
540 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.absROMPath));
541 msg.setIcon(QMessageBox::Warning);
546 // If the "Enable DSP" checkbox changed, then we have to re-init the DAC,
547 // since it's running in the host audio IRQ...
548 if (audioBefore != audioAfter)
554 // Just in case we crash before a clean exit...
560 // Here's the main emulator loop
562 void MainWin::Timer(void)
567 if (showUntunedTankCircuit)
569 // Some machines can't handle this, so we give them the option to disable it. :-)
570 if (!plzDontKillMyComputer)
572 // Random hash & trash
573 // We try to simulate an untuned tank circuit here... :-)
574 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
576 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
578 videoWidget->buffer[(y * videoWidget->textureWidth) + x]
579 = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;
586 // Otherwise, run the Jaguar simulation
590 videoWidget->updateGL();
594 void MainWin::TogglePowerState(void)
596 powerButtonOn = !powerButtonOn;
599 // With the power off, we simulate white noise on the screen. :-)
602 useCDAct->setDisabled(false);
603 palAct->setDisabled(false);
604 ntscAct->setDisabled(false);
605 pauseAct->setChecked(false);
606 pauseAct->setDisabled(true);
607 showUntunedTankCircuit = true;
608 // This is just in case the ROM we were playing was in a narrow or wide field mode,
609 // so the untuned tank sim doesn't look wrong. :-)
614 useCDAct->setDisabled(true);
615 palAct->setDisabled(true);
616 ntscAct->setDisabled(true);
617 pauseAct->setChecked(false);
618 pauseAct->setDisabled(false);
619 showUntunedTankCircuit = false;
621 // Otherwise, we prepare for running regular software...
624 // Should check for cartridgeLoaded here as well...!
625 // We can clear it when toggling CDActive on, so that when we power cycle it does the
626 // expected thing. Otherwise, if we use the file picker to insert a cart, we expect
627 // to run the cart! Maybe have a RemoveCart function that only works if the CD unit
629 setWindowTitle(QString("Virtual Jaguar " VJ_RELEASE_VERSION
630 " - Now playing: Jaguar CD"));
633 WriteLog("GUI: Resetting Jaguar...\n");
639 void MainWin::ToggleRunState(void)
645 for(uint32_t i=0; i<(uint32_t)(videoWidget->textureWidth * 256); i++)
647 uint32_t pixel = videoWidget->buffer[i];
648 uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
649 pixel = ((r + g + b) / 3) & 0x00FF;
650 videoWidget->buffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
653 videoWidget->updateGL();
658 void MainWin::SetZoom100(void)
665 void MainWin::SetZoom200(void)
672 void MainWin::SetZoom300(void)
679 void MainWin::SetNTSC(void)
681 powerAct->setIcon(powerRed);
682 timer->setInterval(16);
683 vjs.hardwareTypeNTSC = true;
689 void MainWin::SetPAL(void)
691 powerAct->setIcon(powerGreen);
692 timer->setInterval(20);
693 vjs.hardwareTypeNTSC = false;
699 void MainWin::ToggleBlur(void)
701 vjs.glFilter = !vjs.glFilter;
706 void MainWin::ShowAboutWin(void)
712 void MainWin::ShowHelpWin(void)
718 void MainWin::InsertCart(void)
720 // If the emulator is running, we pause it here and unpause it later
721 // if we dismiss the file selector without choosing anything
722 if (running && powerButtonOn)
725 pauseForFileSelector = true;
732 void MainWin::Unpause(void)
734 // Here we unpause the emulator if it was paused when we went into the file selector
735 if (pauseForFileSelector)
737 pauseForFileSelector = false;
739 // Some nutter might have unpaused while in the file selector, so check for that
746 void MainWin::LoadSoftware(QString file)
748 running = false; // Prevent bad things(TM) from happening...
749 pauseForFileSelector = false; // Reset the file selector pause flag
750 SET32(jaguarMainRAM, 0, 0x00200000); // Set top of stack...
751 cartridgeLoaded = JaguarLoadFile(file.toAscii().data());
753 char * biosPointer = jaguarBootROM;
755 if (vjs.hardwareTypeAlpine)
756 biosPointer = jaguarDevBootROM2;
758 memcpy(jagMemSpace + 0xE00000, biosPointer, 0x20000);
760 powerAct->setDisabled(false);
761 powerAct->setChecked(true);
762 powerButtonOn = false;
765 if (!vjs.hardwareTypeAlpine && !loadAndGo)
767 QString newTitle = QString("Virtual Jaguar " VJ_RELEASE_VERSION " - Now playing: %1")
768 .arg(filePickWin->GetSelectedPrettyName());
769 setWindowTitle(newTitle);
774 void MainWin::ToggleCDUsage(void)
776 CDActive = !CDActive;
781 powerAct->setDisabled(false);
785 powerAct->setDisabled(true);
788 // Set up the Jaguar CD for execution, otherwise, clear memory
790 memcpy(jagMemSpace + 0x800000, jaguarCDBootROM, 0x40000);
792 memset(jagMemSpace + 0x800000, 0xFF, 0x40000);
797 void MainWin::FrameAdvance(void)
799 //printf("Frame Advance...\n");
800 // Execute 1 frame, then exit (only useful in Pause mode)
802 videoWidget->updateGL();
806 void MainWin::SetFullScreen(bool state/*= true*/)
813 QRect r = QApplication::desktop()->availableGeometry();
814 double targetWidth = 320.0, targetHeight = (vjs.hardwareTypeNTSC ? 240.0 : 256.0);
815 double aspectRatio = targetWidth / targetHeight;
816 // NOTE: Really should check here to see which dimension constrains the other.
817 // Right now, we assume that height is the constraint.
818 int newWidth = (int)(aspectRatio * (double)r.height());
820 videoWidget->setFixedSize(newWidth, r.height());
831 // For some reason, this doesn't work: If the emu is paused, toggling from
832 // fullscreen to windowed (& vice versa) shows a white screen.
833 // videoWidget->updateGL();
837 void MainWin::ToggleFullScreen(void)
839 fullScreen = !fullScreen;
840 SetFullScreen(fullScreen);
844 void MainWin::ShowMemoryBrowserWin(void)
846 memBrowseWin->show();
847 memBrowseWin->RefreshContents();
851 void MainWin::ShowCPUBrowserWin(void)
853 cpuBrowseWin->show();
854 cpuBrowseWin->RefreshContents();
858 void MainWin::ResizeMainWindow(void)
860 videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
863 for(int i=0; i<2; i++)
867 QApplication::processEvents();
872 #warning "!!! Need to check the window geometry to see if the positions are legal !!!"
873 // i.e., someone could drag it to another screen, close it, then disconnect that screen
874 void MainWin::ReadSettings(void)
876 QSettings settings("Underground Software", "Virtual Jaguar");
877 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
878 QSize size = settings.value("size", QSize(400, 400)).toSize();
881 pos = settings.value("cartLoadPos", QPoint(200, 200)).toPoint();
882 filePickWin->move(pos);
884 zoomLevel = settings.value("zoom", 2).toInt();
885 allowUnknownSoftware = settings.value("showUnknownSoftware", false).toBool();
887 vjs.useJoystick = settings.value("useJoystick", false).toBool();
888 vjs.joyport = settings.value("joyport", 0).toInt();
889 vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
890 vjs.frameSkip = settings.value("frameSkip", 0).toInt();
891 vjs.useJaguarBIOS = settings.value("useJaguarBIOS", false).toBool();
892 vjs.GPUEnabled = settings.value("GPUEnabled", true).toBool();
893 vjs.DSPEnabled = settings.value("DSPEnabled", false).toBool();
894 vjs.audioEnabled = settings.value("audioEnabled", true).toBool();
895 vjs.usePipelinedDSP = settings.value("usePipelinedDSP", false).toBool();
896 vjs.fullscreen = settings.value("fullscreen", false).toBool();
897 vjs.useOpenGL = settings.value("useOpenGL", true).toBool();
898 vjs.glFilter = settings.value("glFilterType", 1).toInt();
899 vjs.renderType = settings.value("renderType", 0).toInt();
900 vjs.allowWritesToROM = settings.value("writeROM", false).toBool();
901 // strcpy(vjs.jagBootPath, settings.value("JagBootROM", "./bios/[BIOS] Atari Jaguar (USA, Europe).zip").toString().toAscii().data());
902 // strcpy(vjs.CDBootPath, settings.value("CDBootROM", "./bios/jagcd.rom").toString().toAscii().data());
903 strcpy(vjs.EEPROMPath, settings.value("EEPROMs", "./eeproms/").toString().toAscii().data());
904 strcpy(vjs.ROMPath, settings.value("ROMs", "./software/").toString().toAscii().data());
905 strcpy(vjs.alpineROMPath, settings.value("DefaultROM", "").toString().toAscii().data());
906 strcpy(vjs.absROMPath, settings.value("DefaultABS", "").toString().toAscii().data());
907 WriteLog("MainWin: Paths\n");
908 //WriteLog(" jagBootPath = \"%s\"\n", vjs.jagBootPath);
909 //WriteLog(" CDBootPath = \"%s\"\n", vjs.CDBootPath);
910 WriteLog(" EEPROMPath = \"%s\"\n", vjs.EEPROMPath);
911 WriteLog(" ROMPath = \"%s\"\n", vjs.ROMPath);
912 WriteLog("AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);
913 WriteLog(" absROMPath = \"%s\"\n", vjs.absROMPath);
914 WriteLog("Pipelined DSP = %s\n", (vjs.usePipelinedDSP ? "ON" : "off"));
916 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
917 vjs.p1KeyBindings[BUTTON_U] = settings.value("p1k_up", Qt::Key_S).toInt();
918 vjs.p1KeyBindings[BUTTON_D] = settings.value("p1k_down", Qt::Key_X).toInt();
919 vjs.p1KeyBindings[BUTTON_L] = settings.value("p1k_left", Qt::Key_A).toInt();
920 vjs.p1KeyBindings[BUTTON_R] = settings.value("p1k_right", Qt::Key_D).toInt();
921 vjs.p1KeyBindings[BUTTON_C] = settings.value("p1k_c", Qt::Key_J).toInt();
922 vjs.p1KeyBindings[BUTTON_B] = settings.value("p1k_b", Qt::Key_K).toInt();
923 vjs.p1KeyBindings[BUTTON_A] = settings.value("p1k_a", Qt::Key_L).toInt();
924 vjs.p1KeyBindings[BUTTON_OPTION] = settings.value("p1k_option", Qt::Key_O).toInt();
925 vjs.p1KeyBindings[BUTTON_PAUSE] = settings.value("p1k_pause", Qt::Key_P).toInt();
926 vjs.p1KeyBindings[BUTTON_0] = settings.value("p1k_0", Qt::Key_0).toInt();
927 vjs.p1KeyBindings[BUTTON_1] = settings.value("p1k_1", Qt::Key_1).toInt();
928 vjs.p1KeyBindings[BUTTON_2] = settings.value("p1k_2", Qt::Key_2).toInt();
929 vjs.p1KeyBindings[BUTTON_3] = settings.value("p1k_3", Qt::Key_3).toInt();
930 vjs.p1KeyBindings[BUTTON_4] = settings.value("p1k_4", Qt::Key_4).toInt();
931 vjs.p1KeyBindings[BUTTON_5] = settings.value("p1k_5", Qt::Key_5).toInt();
932 vjs.p1KeyBindings[BUTTON_6] = settings.value("p1k_6", Qt::Key_6).toInt();
933 vjs.p1KeyBindings[BUTTON_7] = settings.value("p1k_7", Qt::Key_7).toInt();
934 vjs.p1KeyBindings[BUTTON_8] = settings.value("p1k_8", Qt::Key_8).toInt();
935 vjs.p1KeyBindings[BUTTON_9] = settings.value("p1k_9", Qt::Key_9).toInt();
936 vjs.p1KeyBindings[BUTTON_d] = settings.value("p1k_pound", Qt::Key_Minus).toInt();
937 vjs.p1KeyBindings[BUTTON_s] = settings.value("p1k_star", Qt::Key_Equal).toInt();
939 vjs.p2KeyBindings[BUTTON_U] = settings.value("p2k_up", Qt::Key_Up).toInt();
940 vjs.p2KeyBindings[BUTTON_D] = settings.value("p2k_down", Qt::Key_Down).toInt();
941 vjs.p2KeyBindings[BUTTON_L] = settings.value("p2k_left", Qt::Key_Left).toInt();
942 vjs.p2KeyBindings[BUTTON_R] = settings.value("p2k_right", Qt::Key_Right).toInt();
943 vjs.p2KeyBindings[BUTTON_C] = settings.value("p2k_c", Qt::Key_Z).toInt();
944 vjs.p2KeyBindings[BUTTON_B] = settings.value("p2k_b", Qt::Key_X).toInt();
945 vjs.p2KeyBindings[BUTTON_A] = settings.value("p2k_a", Qt::Key_C).toInt();
946 vjs.p2KeyBindings[BUTTON_OPTION] = settings.value("p2k_option", Qt::Key_Apostrophe).toInt();
947 vjs.p2KeyBindings[BUTTON_PAUSE] = settings.value("p2k_pause", Qt::Key_Return).toInt();
948 vjs.p2KeyBindings[BUTTON_0] = settings.value("p2k_0", Qt::Key_0).toInt();
949 vjs.p2KeyBindings[BUTTON_1] = settings.value("p2k_1", Qt::Key_1).toInt();
950 vjs.p2KeyBindings[BUTTON_2] = settings.value("p2k_2", Qt::Key_2).toInt();
951 vjs.p2KeyBindings[BUTTON_3] = settings.value("p2k_3", Qt::Key_3).toInt();
952 vjs.p2KeyBindings[BUTTON_4] = settings.value("p2k_4", Qt::Key_4).toInt();
953 vjs.p2KeyBindings[BUTTON_5] = settings.value("p2k_5", Qt::Key_5).toInt();
954 vjs.p2KeyBindings[BUTTON_6] = settings.value("p2k_6", Qt::Key_6).toInt();
955 vjs.p2KeyBindings[BUTTON_7] = settings.value("p2k_7", Qt::Key_7).toInt();
956 vjs.p2KeyBindings[BUTTON_8] = settings.value("p2k_8", Qt::Key_8).toInt();
957 vjs.p2KeyBindings[BUTTON_9] = settings.value("p2k_9", Qt::Key_9).toInt();
958 vjs.p2KeyBindings[BUTTON_d] = settings.value("p2k_pound", Qt::Key_Slash).toInt();
959 vjs.p2KeyBindings[BUTTON_s] = settings.value("p2k_star", Qt::Key_Asterisk).toInt();
963 void MainWin::WriteSettings(void)
965 QSettings settings("Underground Software", "Virtual Jaguar");
966 settings.setValue("pos", pos());
967 settings.setValue("size", size());
968 settings.setValue("cartLoadPos", filePickWin->pos());
970 settings.setValue("zoom", zoomLevel);
971 settings.setValue("showUnknownSoftware", allowUnknownSoftware);
973 settings.setValue("useJoystick", vjs.useJoystick);
974 settings.setValue("joyport", vjs.joyport);
975 settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
976 settings.setValue("frameSkip", vjs.frameSkip);
977 settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
978 settings.setValue("GPUEnabled", vjs.GPUEnabled);
979 settings.setValue("DSPEnabled", vjs.DSPEnabled);
980 settings.setValue("audioEnabled", vjs.audioEnabled);
981 settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
982 settings.setValue("fullscreen", vjs.fullscreen);
983 settings.setValue("useOpenGL", vjs.useOpenGL);
984 settings.setValue("glFilterType", vjs.glFilter);
985 settings.setValue("renderType", vjs.renderType);
986 settings.setValue("writeROM", vjs.allowWritesToROM);
987 settings.setValue("JagBootROM", vjs.jagBootPath);
988 settings.setValue("CDBootROM", vjs.CDBootPath);
989 settings.setValue("EEPROMs", vjs.EEPROMPath);
990 settings.setValue("ROMs", vjs.ROMPath);
991 settings.setValue("DefaultROM", vjs.alpineROMPath);
992 settings.setValue("DefaultABS", vjs.absROMPath);
994 settings.setValue("p1k_up", vjs.p1KeyBindings[BUTTON_U]);
995 settings.setValue("p1k_down", vjs.p1KeyBindings[BUTTON_D]);
996 settings.setValue("p1k_left", vjs.p1KeyBindings[BUTTON_L]);
997 settings.setValue("p1k_right", vjs.p1KeyBindings[BUTTON_R]);
998 settings.setValue("p1k_c", vjs.p1KeyBindings[BUTTON_C]);
999 settings.setValue("p1k_b", vjs.p1KeyBindings[BUTTON_B]);
1000 settings.setValue("p1k_a", vjs.p1KeyBindings[BUTTON_A]);
1001 settings.setValue("p1k_option", vjs.p1KeyBindings[BUTTON_OPTION]);
1002 settings.setValue("p1k_pause", vjs.p1KeyBindings[BUTTON_PAUSE]);
1003 settings.setValue("p1k_0", vjs.p1KeyBindings[BUTTON_0]);
1004 settings.setValue("p1k_1", vjs.p1KeyBindings[BUTTON_1]);
1005 settings.setValue("p1k_2", vjs.p1KeyBindings[BUTTON_2]);
1006 settings.setValue("p1k_3", vjs.p1KeyBindings[BUTTON_3]);
1007 settings.setValue("p1k_4", vjs.p1KeyBindings[BUTTON_4]);
1008 settings.setValue("p1k_5", vjs.p1KeyBindings[BUTTON_5]);
1009 settings.setValue("p1k_6", vjs.p1KeyBindings[BUTTON_6]);
1010 settings.setValue("p1k_7", vjs.p1KeyBindings[BUTTON_7]);
1011 settings.setValue("p1k_8", vjs.p1KeyBindings[BUTTON_8]);
1012 settings.setValue("p1k_9", vjs.p1KeyBindings[BUTTON_9]);
1013 settings.setValue("p1k_pound", vjs.p1KeyBindings[BUTTON_d]);
1014 settings.setValue("p1k_star", vjs.p1KeyBindings[BUTTON_s]);
1016 settings.setValue("p2k_up", vjs.p2KeyBindings[BUTTON_U]);
1017 settings.setValue("p2k_down", vjs.p2KeyBindings[BUTTON_D]);
1018 settings.setValue("p2k_left", vjs.p2KeyBindings[BUTTON_L]);
1019 settings.setValue("p2k_right", vjs.p2KeyBindings[BUTTON_R]);
1020 settings.setValue("p2k_c", vjs.p2KeyBindings[BUTTON_C]);
1021 settings.setValue("p2k_b", vjs.p2KeyBindings[BUTTON_B]);
1022 settings.setValue("p2k_a", vjs.p2KeyBindings[BUTTON_A]);
1023 settings.setValue("p2k_option", vjs.p2KeyBindings[BUTTON_OPTION]);
1024 settings.setValue("p2k_pause", vjs.p2KeyBindings[BUTTON_PAUSE]);
1025 settings.setValue("p2k_0", vjs.p2KeyBindings[BUTTON_0]);
1026 settings.setValue("p2k_1", vjs.p2KeyBindings[BUTTON_1]);
1027 settings.setValue("p2k_2", vjs.p2KeyBindings[BUTTON_2]);
1028 settings.setValue("p2k_3", vjs.p2KeyBindings[BUTTON_3]);
1029 settings.setValue("p2k_4", vjs.p2KeyBindings[BUTTON_4]);
1030 settings.setValue("p2k_5", vjs.p2KeyBindings[BUTTON_5]);
1031 settings.setValue("p2k_6", vjs.p2KeyBindings[BUTTON_6]);
1032 settings.setValue("p2k_7", vjs.p2KeyBindings[BUTTON_7]);
1033 settings.setValue("p2k_8", vjs.p2KeyBindings[BUTTON_8]);
1034 settings.setValue("p2k_9", vjs.p2KeyBindings[BUTTON_9]);
1035 settings.setValue("p2k_pound", vjs.p2KeyBindings[BUTTON_d]);
1036 settings.setValue("p2k_star", vjs.p2KeyBindings[BUTTON_s]);
1040 void MainWin::WriteUISettings(void)
1042 QSettings settings("Underground Software", "Virtual Jaguar");
1043 settings.setValue("pos", pos());
1044 settings.setValue("size", size());
1045 settings.setValue("cartLoadPos", filePickWin->pos());
1047 settings.setValue("zoom", zoomLevel);