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"
48 #include "debug/opbrowser.h"
56 #include "jagcdbios.h"
57 #include "jagstub2bios.h"
60 // According to SebRmv, this header isn't seen on Arch Linux either... :-/
62 // Apparently on win32, usleep() is not pulled in by the usual suspects.
66 // The way BSNES controls things is by setting a timer with a zero
67 // timeout, sleeping if not emulating anything. Seems there has to be a
70 // It has a novel approach to plugging-in/using different video/audio/input
71 // methods, can we do something similar or should we just use the built-in
74 // We're going to try to use the built-in OpenGL support and see how it goes.
75 // We'll make the VJ core modular so that it doesn't matter what GUI is in
76 // use, we can drop it in anywhere and use it as-is.
78 //MainWin::MainWin(QString filenameToRun): running(true), powerButtonOn(false),
79 MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
80 showUntunedTankCircuit(true), cartridgeLoaded(false), CDActive(false),
81 //, alpineLoadSuccessful(false),
82 // pauseForFileSelector(false), loadAndGo(false), plzDontKillMyComputer(false)
83 pauseForFileSelector(false), loadAndGo(autoRun), plzDontKillMyComputer(false)
85 for(int i=0; i<8; i++)
88 videoWidget = new GLWidget(this);
89 setCentralWidget(videoWidget);
90 setWindowIcon(QIcon(":/res/vj-icon.png"));
92 QString title = QString(tr("Virtual Jaguar " VJ_RELEASE_VERSION ));
94 if (vjs.hardwareTypeAlpine)
95 title += QString(tr(" - Alpine Mode"));
97 setWindowTitle(title);
99 aboutWin = new AboutWindow(this);
100 helpWin = new HelpWindow(this);
101 filePickWin = new FilePickerWindow(this);
102 memBrowseWin = new MemoryBrowserWindow(this);
103 cpuBrowseWin = new CPUBrowserWindow(this);
104 opBrowseWin = new OPBrowserWindow(this);
106 videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
107 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
109 setUnifiedTitleAndToolBarOnMac(true);
113 quitAppAct = new QAction(tr("E&xit"), this);
114 // quitAppAct->setShortcuts(QKeySequence::Quit);
115 // quitAppAct->setShortcut(QKeySequence(tr("Alt+x")));
116 quitAppAct->setShortcut(QKeySequence(tr("Ctrl+q")));
117 quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
118 connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
120 powerGreen.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
121 powerGreen.addFile(":/res/power-on-green.png", QSize(), QIcon::Normal, QIcon::On);
122 powerRed.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
123 powerRed.addFile(":/res/power-on-red.png", QSize(), QIcon::Normal, QIcon::On);
125 // powerAct = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
126 powerAct = new QAction(powerGreen, tr("&Power"), this);
127 powerAct->setStatusTip(tr("Powers Jaguar on/off"));
128 powerAct->setCheckable(true);
129 powerAct->setChecked(false);
130 // powerAct->setDisabled(true);
131 connect(powerAct, SIGNAL(triggered()), this, SLOT(TogglePowerState()));
134 pauseIcon.addFile(":/res/pause-off", QSize(), QIcon::Normal, QIcon::Off);
135 pauseIcon.addFile(":/res/pause-on", QSize(), QIcon::Normal, QIcon::On);
136 // pauseAct = new QAction(QIcon(":/res/pause.png"), tr("Pause"), this);
137 pauseAct = new QAction(pauseIcon, tr("Pause"), this);
138 pauseAct->setStatusTip(tr("Toggles the running state"));
139 pauseAct->setCheckable(true);
140 pauseAct->setDisabled(true);
141 pauseAct->setShortcut(QKeySequence(tr("Esc")));
142 connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
144 zoomActs = new QActionGroup(this);
146 x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
147 x1Act->setStatusTip(tr("Set window zoom to 100%"));
148 x1Act->setCheckable(true);
149 connect(x1Act, SIGNAL(triggered()), this, SLOT(SetZoom100()));
151 x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
152 x2Act->setStatusTip(tr("Set window zoom to 200%"));
153 x2Act->setCheckable(true);
154 connect(x2Act, SIGNAL(triggered()), this, SLOT(SetZoom200()));
156 x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
157 x3Act->setStatusTip(tr("Set window zoom to 300%"));
158 x3Act->setCheckable(true);
159 connect(x3Act, SIGNAL(triggered()), this, SLOT(SetZoom300()));
161 tvTypeActs = new QActionGroup(this);
163 ntscAct = new QAction(QIcon(":/res/ntsc.png"), tr("NTSC"), tvTypeActs);
164 ntscAct->setStatusTip(tr("Sets Jaguar to NTSC mode"));
165 ntscAct->setCheckable(true);
166 connect(ntscAct, SIGNAL(triggered()), this, SLOT(SetNTSC()));
168 palAct = new QAction(QIcon(":/res/pal.png"), tr("PAL"), tvTypeActs);
169 palAct->setStatusTip(tr("Sets Jaguar to PAL mode"));
170 palAct->setCheckable(true);
171 connect(palAct, SIGNAL(triggered()), this, SLOT(SetPAL()));
173 blurAct = new QAction(QIcon(":/res/generic.png"), tr("Blur"), this);
174 blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
175 blurAct->setCheckable(true);
176 connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
178 aboutAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&About..."), this);
179 aboutAct->setStatusTip(tr("Blatant self-promotion"));
180 connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
182 helpAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&Contents..."), this);
183 helpAct->setStatusTip(tr("Help is available, if you should need it"));
184 connect(helpAct, SIGNAL(triggered()), this, SLOT(ShowHelpWin()));
186 filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this);
187 filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar"));
188 filePickAct->setShortcut(QKeySequence(tr("Ctrl+i")));
189 connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart()));
191 configAct = new QAction(QIcon(":/res/wrench.png"), tr("&Configure"), this);
192 configAct->setStatusTip(tr("Configure options for Virtual Jaguar"));
193 configAct->setShortcut(QKeySequence(tr("Ctrl+c")));
194 connect(configAct, SIGNAL(triggered()), this, SLOT(Configure()));
196 useCDAct = new QAction(QIcon(":/res/compact-disc.png"), tr("&Use CD Unit"), this);
197 useCDAct->setStatusTip(tr("Use Jaguar Virtual CD unit"));
198 // useCDAct->setShortcut(QKeySequence(tr("Ctrl+c")));
199 useCDAct->setCheckable(true);
200 connect(useCDAct, SIGNAL(triggered()), this, SLOT(ToggleCDUsage()));
202 frameAdvanceAct = new QAction(QIcon(":/res/frame-advance.png"), tr("&Frame Advance"), this);
203 frameAdvanceAct->setShortcut(QKeySequence(tr("F7")));
204 connect(frameAdvanceAct, SIGNAL(triggered()), this, SLOT(FrameAdvance()));
206 fullScreenAct = new QAction(QIcon(":/res/generic.png"), tr("F&ull Screen"), this);
207 fullScreenAct->setShortcut(QKeySequence(tr("F9")));
208 connect(fullScreenAct, SIGNAL(triggered()), this, SLOT(ToggleFullScreen()));
211 memBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("Memory Browser"), this);
212 memBrowseAct->setStatusTip(tr("Shows the Jaguar memory browser window"));
213 // memBrowseAct->setCheckable(true);
214 connect(memBrowseAct, SIGNAL(triggered()), this, SLOT(ShowMemoryBrowserWin()));
216 cpuBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("CPU Browser"), this);
217 cpuBrowseAct->setStatusTip(tr("Shows the Jaguar CPU browser window"));
218 // memBrowseAct->setCheckable(true);
219 connect(cpuBrowseAct, SIGNAL(triggered()), this, SLOT(ShowCPUBrowserWin()));
221 opBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("OP Browser"), this);
222 opBrowseAct->setStatusTip(tr("Shows the Jaguar OP browser window"));
223 // memBrowseAct->setCheckable(true);
224 connect(opBrowseAct, SIGNAL(triggered()), this, SLOT(ShowOPBrowserWin()));
226 // Misc. connections...
227 connect(filePickWin, SIGNAL(RequestLoad(QString)), this, SLOT(LoadSoftware(QString)));
228 connect(filePickWin, SIGNAL(FilePickerHiding()), this, SLOT(Unpause()));
230 // Create menus & toolbars
232 fileMenu = menuBar()->addMenu(tr("&Jaguar"));
233 fileMenu->addAction(powerAct);
234 fileMenu->addAction(pauseAct);
235 fileMenu->addAction(frameAdvanceAct);
236 fileMenu->addAction(filePickAct);
237 fileMenu->addAction(useCDAct);
238 fileMenu->addAction(configAct);
239 fileMenu->addAction(quitAppAct);
241 if (vjs.hardwareTypeAlpine)
243 debugMenu = menuBar()->addMenu(tr("&Debug"));
244 debugMenu->addAction(memBrowseAct);
245 debugMenu->addAction(cpuBrowseAct);
246 debugMenu->addAction(opBrowseAct);
249 helpMenu = menuBar()->addMenu(tr("&Help"));
250 helpMenu->addAction(helpAct);
251 helpMenu->addAction(aboutAct);
253 toolbar = addToolBar(tr("Stuff"));
254 toolbar->addAction(powerAct);
255 toolbar->addAction(pauseAct);
256 toolbar->addAction(filePickAct);
257 toolbar->addAction(useCDAct);
258 toolbar->addSeparator();
259 toolbar->addAction(x1Act);
260 toolbar->addAction(x2Act);
261 toolbar->addAction(x3Act);
262 toolbar->addSeparator();
263 toolbar->addAction(ntscAct);
264 toolbar->addAction(palAct);
265 toolbar->addSeparator();
266 toolbar->addAction(blurAct);
267 toolbar->addAction(fullScreenAct);
269 if (vjs.hardwareTypeAlpine)
271 debugbar = addToolBar(tr("&Debug"));
272 debugbar->addAction(memBrowseAct);
273 debugbar->addAction(cpuBrowseAct);
274 debugbar->addAction(opBrowseAct);
278 statusBar()->showMessage(tr("Ready"));
282 // Do this in case original size isn't correct (mostly for the first-run case)
285 // Set up timer based loop for animation...
286 timer = new QTimer(this);
287 connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
289 // This isn't very accurate for NTSC: This is early by 40 msec per frame.
290 // This is because it's discarding the 0.6666... on the end of the fraction.
291 // Alas, 6 doesn't divide cleanly into 10. :-P
292 //Should we defer this until SyncUI? Probably.
293 //No, it doesn't work, because it uses setInterval() instead of start()...
294 // timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
296 // We set this initially, to make VJ behave somewhat as it would if no
297 // cart were inserted and the BIOS was set as active...
298 jaguarCartInserted = true;
299 WriteLog("Virtual Jaguar %s (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
300 WriteLog("VJ: Initializing jaguar subsystem...\n");
302 memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
304 // Check for filename passed in on the command line...
305 // if (!filenameToRun.isEmpty())
309 // Attempt to load/run the file the user passed in...
310 // LoadSoftware(filenameToRun);
311 //// memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
312 // Prevent the file scanner from running...
316 // Load up the default ROM if in Alpine mode:
317 if (vjs.hardwareTypeAlpine)
319 bool romLoaded = JaguarLoadFile(vjs.alpineROMPath);
321 // If regular load failed, try just a straight file load
322 // (Dev only! I don't want people to start getting lazy with their releases again! :-P)
324 romLoaded = AlpineLoadFile(vjs.alpineROMPath);
327 WriteLog("Alpine Mode: Successfully loaded file \"%s\".\n", vjs.alpineROMPath);
329 WriteLog("Alpine Mode: Unable to load file \"%s\"!\n", vjs.alpineROMPath);
331 // Attempt to load/run the ABS file...
332 LoadSoftware(vjs.absROMPath);
333 memcpy(jagMemSpace + 0xE00000, jaguarDevBootROM2, 0x20000); // Use the stub BIOS
334 // Prevent the scanner from running...
338 // memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Otherwise, use the stock BIOS
340 // Run the scanner if nothing passed in and *not* Alpine mode...
341 // NB: Really need to look into caching the info scanned in here...
342 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
346 void MainWin::LoadFile(QString file)
352 void MainWin::SyncUI(void)
354 // Set toolbar buttons/menus based on settings read in (sync the UI)...
355 // (Really, this is to sync command line options passed in)
356 blurAct->setChecked(vjs.glFilter);
357 x1Act->setChecked(zoomLevel == 1);
358 x2Act->setChecked(zoomLevel == 2);
359 x3Act->setChecked(zoomLevel == 3);
360 // running = powerAct->isChecked();
361 ntscAct->setChecked(vjs.hardwareTypeNTSC);
362 palAct->setChecked(!vjs.hardwareTypeNTSC);
363 powerAct->setIcon(vjs.hardwareTypeNTSC ? powerRed : powerGreen);
365 fullScreen = vjs.fullscreen;
366 SetFullScreen(fullScreen);
368 // Reset the timer to be what was set in the command line (if any):
369 // timer->setInterval(vjs.hardwareTypeNTSC ? 16 : 20);
370 timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
374 void MainWin::closeEvent(QCloseEvent * event)
377 // This should only be done by the config dialog
380 event->accept(); // ignore() if can't close for some reason
384 void MainWin::keyPressEvent(QKeyEvent * e)
386 // We ignore the Alt key for now, since it causes problems with the GUI
387 if (e->key() == Qt::Key_Alt)
393 if (e->key() == Qt::Key_F9)
403 void MainWin::keyReleaseEvent(QKeyEvent * e)
405 // We ignore the Alt key for now, since it causes problems with the GUI
406 if (e->key() == Qt::Key_Alt)
412 HandleKeys(e, false);
416 void MainWin::HandleKeys(QKeyEvent * e, bool state)
418 enum { P1LEFT = 0, P1RIGHT, P1UP, P1DOWN, P2LEFT, P2RIGHT, P2UP, P2DOWN };
419 // We kill bad key combos here, before they can get to the emulator...
420 // This also kills the illegal instruction problem that cropped up in Rayman!
421 // May want to do this by killing the old one instead of ignoring the new one...
422 // Seems to work better that way...
424 // The problem with this approach is that it causes bad results because it doesn't do
425 // any checking of previous states. Need to come up with something better because this
426 // causes problems where the keyboard acts as if it were unresponsive. :-P
428 if ((e->key() == vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
429 || (e->key() == vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
430 || (e->key() == vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
431 || (e->key() == vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U]))
435 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
436 joypad_0_buttons[BUTTON_R] = 0;
437 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
438 joypad_0_buttons[BUTTON_L] = 0;
439 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
440 joypad_0_buttons[BUTTON_D] = 0;
441 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U])
442 joypad_0_buttons[BUTTON_U] = 0;
444 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L] && joypad_1_buttons[BUTTON_R])
445 joypad_1_buttons[BUTTON_R] = 0;
446 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R] && joypad_1_buttons[BUTTON_L])
447 joypad_1_buttons[BUTTON_L] = 0;
448 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U] && joypad_1_buttons[BUTTON_D])
449 joypad_1_buttons[BUTTON_D] = 0;
450 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D] && joypad_1_buttons[BUTTON_U])
451 joypad_1_buttons[BUTTON_U] = 0;
453 //hrm, this still has sticky state problems... Ugh!
454 // First, settle key states...
455 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L])
456 keyHeld[P1LEFT] = state;
457 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R])
458 keyHeld[P1RIGHT] = state;
459 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U])
460 keyHeld[P1UP] = state;
461 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D])
462 keyHeld[P1DOWN] = state;
463 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L])
464 keyHeld[P2LEFT] = state;
465 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R])
466 keyHeld[P2RIGHT] = state;
467 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U])
468 keyHeld[P2UP] = state;
469 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D])
470 keyHeld[P2DOWN] = state;
472 // Next, check for conflicts and bail out if there are any...
473 if ((keyHeld[P1LEFT] && keyHeld[P1RIGHT])
474 || (keyHeld[P1UP] && keyHeld[P1DOWN])
475 || (keyHeld[P2LEFT] && keyHeld[P2RIGHT])
476 || (keyHeld[P2UP] && keyHeld[P2DOWN]))
481 // No bad combos exist, let's stuff the emulator key buffers...!
482 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
484 if (e->key() == (int)vjs.p1KeyBindings[i])
485 // joypad_0_buttons[i] = (uint8)state;
486 joypad_0_buttons[i] = (state ? 0x01 : 0x00);
488 // Pad #2 is screwing up pad #1. Prolly a problem in joystick.cpp...
489 // So let's try to fix it there. :-P [DONE]
490 if (e->key() == (int)vjs.p2KeyBindings[i])
491 // joypad_1_buttons[i] = (uint8)state;
492 joypad_1_buttons[i] = (state ? 0x01 : 0x00);
497 void MainWin::Open(void)
502 void MainWin::Configure(void)
504 // Call the configuration dialog and update settings
505 ConfigDialog dlg(this);
507 dlg.generalTab->useUnknownSoftware->setChecked(allowUnknownSoftware);
509 if (dlg.exec() == false)
512 QString before = vjs.ROMPath;
513 QString alpineBefore = vjs.alpineROMPath;
514 QString absBefore = vjs.absROMPath;
515 // bool audioBefore = vjs.audioEnabled;
516 bool audioBefore = vjs.DSPEnabled;
517 dlg.UpdateVJSettings();
518 QString after = vjs.ROMPath;
519 QString alpineAfter = vjs.alpineROMPath;
520 QString absAfter = vjs.absROMPath;
521 // bool audioAfter = vjs.audioEnabled;
522 bool audioAfter = vjs.DSPEnabled;
524 bool allowOld = allowUnknownSoftware;
526 allowUnknownSoftware = dlg.generalTab->useUnknownSoftware->isChecked();
528 // We rescan the "software" folder if the user either changed the path or
529 // checked/unchecked the "Allow unknown files" option in the config dialog.
530 if ((before != after) || (allowOld != allowUnknownSoftware))
531 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
533 // If the "Alpine" ROM is changed, then let's load it...
534 if (alpineBefore != alpineAfter)
536 if (!JaguarLoadFile(vjs.alpineROMPath) && !AlpineLoadFile(vjs.alpineROMPath))
538 // Oh crap, we couldn't get the file! Alert the media!
540 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.alpineROMPath));
541 msg.setIcon(QMessageBox::Warning);
546 // If the "ABS" ROM is changed, then let's load it...
547 if (absBefore != absAfter)
549 if (!JaguarLoadFile(vjs.absROMPath))
551 // Oh crap, we couldn't get the file! Alert the media!
553 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.absROMPath));
554 msg.setIcon(QMessageBox::Warning);
559 // If the "Enable DSP" checkbox changed, then we have to re-init the DAC,
560 // since it's running in the host audio IRQ...
561 if (audioBefore != audioAfter)
567 // Just in case we crash before a clean exit...
573 // Here's the main emulator loop
575 void MainWin::Timer(void)
580 if (showUntunedTankCircuit)
582 // Some machines can't handle this, so we give them the option to disable it. :-)
583 if (!plzDontKillMyComputer)
585 // Random hash & trash
586 // We try to simulate an untuned tank circuit here... :-)
587 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
589 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
591 videoWidget->buffer[(y * videoWidget->textureWidth) + x]
592 = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;
599 // Otherwise, run the Jaguar simulation
603 videoWidget->updateGL();
607 void MainWin::TogglePowerState(void)
609 powerButtonOn = !powerButtonOn;
612 // With the power off, we simulate white noise on the screen. :-)
615 useCDAct->setDisabled(false);
616 palAct->setDisabled(false);
617 ntscAct->setDisabled(false);
618 pauseAct->setChecked(false);
619 pauseAct->setDisabled(true);
620 showUntunedTankCircuit = true;
621 // This is just in case the ROM we were playing was in a narrow or wide field mode,
622 // so the untuned tank sim doesn't look wrong. :-)
627 useCDAct->setDisabled(true);
628 palAct->setDisabled(true);
629 ntscAct->setDisabled(true);
630 pauseAct->setChecked(false);
631 pauseAct->setDisabled(false);
632 showUntunedTankCircuit = false;
634 // Otherwise, we prepare for running regular software...
637 // Should check for cartridgeLoaded here as well...!
638 // We can clear it when toggling CDActive on, so that when we power cycle it does the
639 // expected thing. Otherwise, if we use the file picker to insert a cart, we expect
640 // to run the cart! Maybe have a RemoveCart function that only works if the CD unit
642 setWindowTitle(QString("Virtual Jaguar " VJ_RELEASE_VERSION
643 " - Now playing: Jaguar CD"));
646 WriteLog("GUI: Resetting Jaguar...\n");
652 void MainWin::ToggleRunState(void)
658 for(uint32_t i=0; i<(uint32_t)(videoWidget->textureWidth * 256); i++)
660 uint32_t pixel = videoWidget->buffer[i];
661 uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
662 pixel = ((r + g + b) / 3) & 0x00FF;
663 videoWidget->buffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
666 videoWidget->updateGL();
671 void MainWin::SetZoom100(void)
678 void MainWin::SetZoom200(void)
685 void MainWin::SetZoom300(void)
692 void MainWin::SetNTSC(void)
694 powerAct->setIcon(powerRed);
695 timer->setInterval(16);
696 vjs.hardwareTypeNTSC = true;
702 void MainWin::SetPAL(void)
704 powerAct->setIcon(powerGreen);
705 timer->setInterval(20);
706 vjs.hardwareTypeNTSC = false;
712 void MainWin::ToggleBlur(void)
714 vjs.glFilter = !vjs.glFilter;
719 void MainWin::ShowAboutWin(void)
725 void MainWin::ShowHelpWin(void)
731 void MainWin::InsertCart(void)
733 // If the emulator is running, we pause it here and unpause it later
734 // if we dismiss the file selector without choosing anything
735 if (running && powerButtonOn)
738 pauseForFileSelector = true;
745 void MainWin::Unpause(void)
747 // Here we unpause the emulator if it was paused when we went into the file selector
748 if (pauseForFileSelector)
750 pauseForFileSelector = false;
752 // Some nutter might have unpaused while in the file selector, so check for that
759 void MainWin::LoadSoftware(QString file)
761 running = false; // Prevent bad things(TM) from happening...
762 pauseForFileSelector = false; // Reset the file selector pause flag
763 SET32(jaguarMainRAM, 0, 0x00200000); // Set top of stack...
764 cartridgeLoaded = JaguarLoadFile(file.toAscii().data());
766 char * biosPointer = jaguarBootROM;
768 if (vjs.hardwareTypeAlpine)
769 biosPointer = jaguarDevBootROM2;
771 memcpy(jagMemSpace + 0xE00000, biosPointer, 0x20000);
773 powerAct->setDisabled(false);
774 powerAct->setChecked(true);
775 powerButtonOn = false;
778 if (!vjs.hardwareTypeAlpine && !loadAndGo)
780 QString newTitle = QString("Virtual Jaguar " VJ_RELEASE_VERSION " - Now playing: %1")
781 .arg(filePickWin->GetSelectedPrettyName());
782 setWindowTitle(newTitle);
787 void MainWin::ToggleCDUsage(void)
789 CDActive = !CDActive;
794 powerAct->setDisabled(false);
798 powerAct->setDisabled(true);
801 // Set up the Jaguar CD for execution, otherwise, clear memory
803 memcpy(jagMemSpace + 0x800000, jaguarCDBootROM, 0x40000);
805 memset(jagMemSpace + 0x800000, 0xFF, 0x40000);
810 void MainWin::FrameAdvance(void)
812 //printf("Frame Advance...\n");
813 // Execute 1 frame, then exit (only useful in Pause mode)
815 videoWidget->updateGL();
819 void MainWin::SetFullScreen(bool state/*= true*/)
822 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
823 QSize size = settings.value("size", QSize(400, 400)).toSize();
826 settings.setValue("pos", pos());
827 settings.setValue("size", size());
831 mainWinPosition = pos();
832 // mainWinSize = size();
836 QRect r = QApplication::desktop()->availableGeometry();
837 // double targetWidth = 320.0, targetHeight = (vjs.hardwareTypeNTSC ? 240.0 : 256.0);
838 double targetWidth = (double)VIRTUAL_SCREEN_WIDTH,
839 targetHeight = (double)(vjs.hardwareTypeNTSC ? VIRTUAL_SCREEN_HEIGHT_NTSC : VIRTUAL_SCREEN_HEIGHT_PAL);
840 double aspectRatio = targetWidth / targetHeight;
841 // NOTE: Really should check here to see which dimension constrains the other.
842 // Right now, we assume that height is the constraint.
843 int newWidth = (int)(aspectRatio * (double)r.height());
845 videoWidget->setFixedSize(newWidth, r.height());
854 move(mainWinPosition);
857 // For some reason, this doesn't work: If the emu is paused, toggling from
858 // fullscreen to windowed (& vice versa) shows a white screen.
859 // videoWidget->updateGL();
863 void MainWin::ToggleFullScreen(void)
865 fullScreen = !fullScreen;
866 SetFullScreen(fullScreen);
870 void MainWin::ShowMemoryBrowserWin(void)
872 memBrowseWin->show();
873 memBrowseWin->RefreshContents();
877 void MainWin::ShowCPUBrowserWin(void)
879 cpuBrowseWin->show();
880 cpuBrowseWin->RefreshContents();
884 void MainWin::ShowOPBrowserWin(void)
887 opBrowseWin->RefreshContents();
891 void MainWin::ResizeMainWindow(void)
893 // videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
894 videoWidget->setFixedSize(zoomLevel * VIRTUAL_SCREEN_WIDTH,
895 zoomLevel * (vjs.hardwareTypeNTSC ? VIRTUAL_SCREEN_HEIGHT_NTSC : VIRTUAL_SCREEN_HEIGHT_PAL));
898 for(int i=0; i<2; i++)
902 QApplication::processEvents();
907 #warning "!!! Need to check the window geometry to see if the positions are legal !!!"
908 // i.e., someone could drag it to another screen, close it, then disconnect that screen
909 void MainWin::ReadSettings(void)
911 QSettings settings("Underground Software", "Virtual Jaguar");
912 mainWinPosition = settings.value("pos", QPoint(200, 200)).toPoint();
913 QSize size = settings.value("size", QSize(400, 400)).toSize();
915 move(mainWinPosition);
916 QPoint pos = settings.value("cartLoadPos", QPoint(200, 200)).toPoint();
917 filePickWin->move(pos);
919 zoomLevel = settings.value("zoom", 2).toInt();
920 allowUnknownSoftware = settings.value("showUnknownSoftware", false).toBool();
922 vjs.useJoystick = settings.value("useJoystick", false).toBool();
923 vjs.joyport = settings.value("joyport", 0).toInt();
924 vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
925 vjs.frameSkip = settings.value("frameSkip", 0).toInt();
926 vjs.useJaguarBIOS = settings.value("useJaguarBIOS", false).toBool();
927 vjs.GPUEnabled = settings.value("GPUEnabled", true).toBool();
928 vjs.DSPEnabled = settings.value("DSPEnabled", false).toBool();
929 vjs.audioEnabled = settings.value("audioEnabled", true).toBool();
930 vjs.usePipelinedDSP = settings.value("usePipelinedDSP", false).toBool();
931 vjs.fullscreen = settings.value("fullscreen", false).toBool();
932 vjs.useOpenGL = settings.value("useOpenGL", true).toBool();
933 vjs.glFilter = settings.value("glFilterType", 1).toInt();
934 vjs.renderType = settings.value("renderType", 0).toInt();
935 vjs.allowWritesToROM = settings.value("writeROM", false).toBool();
936 // strcpy(vjs.jagBootPath, settings.value("JagBootROM", "./bios/[BIOS] Atari Jaguar (USA, Europe).zip").toString().toAscii().data());
937 // strcpy(vjs.CDBootPath, settings.value("CDBootROM", "./bios/jagcd.rom").toString().toAscii().data());
938 strcpy(vjs.EEPROMPath, settings.value("EEPROMs", "./eeproms/").toString().toAscii().data());
939 strcpy(vjs.ROMPath, settings.value("ROMs", "./software/").toString().toAscii().data());
940 strcpy(vjs.alpineROMPath, settings.value("DefaultROM", "").toString().toAscii().data());
941 strcpy(vjs.absROMPath, settings.value("DefaultABS", "").toString().toAscii().data());
942 WriteLog("MainWin: Paths\n");
943 //WriteLog(" jagBootPath = \"%s\"\n", vjs.jagBootPath);
944 //WriteLog(" CDBootPath = \"%s\"\n", vjs.CDBootPath);
945 WriteLog(" EEPROMPath = \"%s\"\n", vjs.EEPROMPath);
946 WriteLog(" ROMPath = \"%s\"\n", vjs.ROMPath);
947 WriteLog("AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);
948 WriteLog(" absROMPath = \"%s\"\n", vjs.absROMPath);
949 WriteLog("Pipelined DSP = %s\n", (vjs.usePipelinedDSP ? "ON" : "off"));
951 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
952 vjs.p1KeyBindings[BUTTON_U] = settings.value("p1k_up", Qt::Key_S).toInt();
953 vjs.p1KeyBindings[BUTTON_D] = settings.value("p1k_down", Qt::Key_X).toInt();
954 vjs.p1KeyBindings[BUTTON_L] = settings.value("p1k_left", Qt::Key_A).toInt();
955 vjs.p1KeyBindings[BUTTON_R] = settings.value("p1k_right", Qt::Key_D).toInt();
956 vjs.p1KeyBindings[BUTTON_C] = settings.value("p1k_c", Qt::Key_J).toInt();
957 vjs.p1KeyBindings[BUTTON_B] = settings.value("p1k_b", Qt::Key_K).toInt();
958 vjs.p1KeyBindings[BUTTON_A] = settings.value("p1k_a", Qt::Key_L).toInt();
959 vjs.p1KeyBindings[BUTTON_OPTION] = settings.value("p1k_option", Qt::Key_O).toInt();
960 vjs.p1KeyBindings[BUTTON_PAUSE] = settings.value("p1k_pause", Qt::Key_P).toInt();
961 vjs.p1KeyBindings[BUTTON_0] = settings.value("p1k_0", Qt::Key_0).toInt();
962 vjs.p1KeyBindings[BUTTON_1] = settings.value("p1k_1", Qt::Key_1).toInt();
963 vjs.p1KeyBindings[BUTTON_2] = settings.value("p1k_2", Qt::Key_2).toInt();
964 vjs.p1KeyBindings[BUTTON_3] = settings.value("p1k_3", Qt::Key_3).toInt();
965 vjs.p1KeyBindings[BUTTON_4] = settings.value("p1k_4", Qt::Key_4).toInt();
966 vjs.p1KeyBindings[BUTTON_5] = settings.value("p1k_5", Qt::Key_5).toInt();
967 vjs.p1KeyBindings[BUTTON_6] = settings.value("p1k_6", Qt::Key_6).toInt();
968 vjs.p1KeyBindings[BUTTON_7] = settings.value("p1k_7", Qt::Key_7).toInt();
969 vjs.p1KeyBindings[BUTTON_8] = settings.value("p1k_8", Qt::Key_8).toInt();
970 vjs.p1KeyBindings[BUTTON_9] = settings.value("p1k_9", Qt::Key_9).toInt();
971 vjs.p1KeyBindings[BUTTON_d] = settings.value("p1k_pound", Qt::Key_Minus).toInt();
972 vjs.p1KeyBindings[BUTTON_s] = settings.value("p1k_star", Qt::Key_Equal).toInt();
974 vjs.p2KeyBindings[BUTTON_U] = settings.value("p2k_up", Qt::Key_Up).toInt();
975 vjs.p2KeyBindings[BUTTON_D] = settings.value("p2k_down", Qt::Key_Down).toInt();
976 vjs.p2KeyBindings[BUTTON_L] = settings.value("p2k_left", Qt::Key_Left).toInt();
977 vjs.p2KeyBindings[BUTTON_R] = settings.value("p2k_right", Qt::Key_Right).toInt();
978 vjs.p2KeyBindings[BUTTON_C] = settings.value("p2k_c", Qt::Key_Z).toInt();
979 vjs.p2KeyBindings[BUTTON_B] = settings.value("p2k_b", Qt::Key_X).toInt();
980 vjs.p2KeyBindings[BUTTON_A] = settings.value("p2k_a", Qt::Key_C).toInt();
981 vjs.p2KeyBindings[BUTTON_OPTION] = settings.value("p2k_option", Qt::Key_Apostrophe).toInt();
982 vjs.p2KeyBindings[BUTTON_PAUSE] = settings.value("p2k_pause", Qt::Key_Return).toInt();
983 vjs.p2KeyBindings[BUTTON_0] = settings.value("p2k_0", Qt::Key_0).toInt();
984 vjs.p2KeyBindings[BUTTON_1] = settings.value("p2k_1", Qt::Key_1).toInt();
985 vjs.p2KeyBindings[BUTTON_2] = settings.value("p2k_2", Qt::Key_2).toInt();
986 vjs.p2KeyBindings[BUTTON_3] = settings.value("p2k_3", Qt::Key_3).toInt();
987 vjs.p2KeyBindings[BUTTON_4] = settings.value("p2k_4", Qt::Key_4).toInt();
988 vjs.p2KeyBindings[BUTTON_5] = settings.value("p2k_5", Qt::Key_5).toInt();
989 vjs.p2KeyBindings[BUTTON_6] = settings.value("p2k_6", Qt::Key_6).toInt();
990 vjs.p2KeyBindings[BUTTON_7] = settings.value("p2k_7", Qt::Key_7).toInt();
991 vjs.p2KeyBindings[BUTTON_8] = settings.value("p2k_8", Qt::Key_8).toInt();
992 vjs.p2KeyBindings[BUTTON_9] = settings.value("p2k_9", Qt::Key_9).toInt();
993 vjs.p2KeyBindings[BUTTON_d] = settings.value("p2k_pound", Qt::Key_Slash).toInt();
994 vjs.p2KeyBindings[BUTTON_s] = settings.value("p2k_star", Qt::Key_Asterisk).toInt();
998 void MainWin::WriteSettings(void)
1000 QSettings settings("Underground Software", "Virtual Jaguar");
1001 settings.setValue("pos", pos());
1002 settings.setValue("size", size());
1003 settings.setValue("cartLoadPos", filePickWin->pos());
1005 settings.setValue("zoom", zoomLevel);
1006 settings.setValue("showUnknownSoftware", allowUnknownSoftware);
1008 settings.setValue("useJoystick", vjs.useJoystick);
1009 settings.setValue("joyport", vjs.joyport);
1010 settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
1011 settings.setValue("frameSkip", vjs.frameSkip);
1012 settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
1013 settings.setValue("GPUEnabled", vjs.GPUEnabled);
1014 settings.setValue("DSPEnabled", vjs.DSPEnabled);
1015 settings.setValue("audioEnabled", vjs.audioEnabled);
1016 settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
1017 settings.setValue("fullscreen", vjs.fullscreen);
1018 settings.setValue("useOpenGL", vjs.useOpenGL);
1019 settings.setValue("glFilterType", vjs.glFilter);
1020 settings.setValue("renderType", vjs.renderType);
1021 settings.setValue("writeROM", vjs.allowWritesToROM);
1022 settings.setValue("JagBootROM", vjs.jagBootPath);
1023 settings.setValue("CDBootROM", vjs.CDBootPath);
1024 settings.setValue("EEPROMs", vjs.EEPROMPath);
1025 settings.setValue("ROMs", vjs.ROMPath);
1026 settings.setValue("DefaultROM", vjs.alpineROMPath);
1027 settings.setValue("DefaultABS", vjs.absROMPath);
1029 settings.setValue("p1k_up", vjs.p1KeyBindings[BUTTON_U]);
1030 settings.setValue("p1k_down", vjs.p1KeyBindings[BUTTON_D]);
1031 settings.setValue("p1k_left", vjs.p1KeyBindings[BUTTON_L]);
1032 settings.setValue("p1k_right", vjs.p1KeyBindings[BUTTON_R]);
1033 settings.setValue("p1k_c", vjs.p1KeyBindings[BUTTON_C]);
1034 settings.setValue("p1k_b", vjs.p1KeyBindings[BUTTON_B]);
1035 settings.setValue("p1k_a", vjs.p1KeyBindings[BUTTON_A]);
1036 settings.setValue("p1k_option", vjs.p1KeyBindings[BUTTON_OPTION]);
1037 settings.setValue("p1k_pause", vjs.p1KeyBindings[BUTTON_PAUSE]);
1038 settings.setValue("p1k_0", vjs.p1KeyBindings[BUTTON_0]);
1039 settings.setValue("p1k_1", vjs.p1KeyBindings[BUTTON_1]);
1040 settings.setValue("p1k_2", vjs.p1KeyBindings[BUTTON_2]);
1041 settings.setValue("p1k_3", vjs.p1KeyBindings[BUTTON_3]);
1042 settings.setValue("p1k_4", vjs.p1KeyBindings[BUTTON_4]);
1043 settings.setValue("p1k_5", vjs.p1KeyBindings[BUTTON_5]);
1044 settings.setValue("p1k_6", vjs.p1KeyBindings[BUTTON_6]);
1045 settings.setValue("p1k_7", vjs.p1KeyBindings[BUTTON_7]);
1046 settings.setValue("p1k_8", vjs.p1KeyBindings[BUTTON_8]);
1047 settings.setValue("p1k_9", vjs.p1KeyBindings[BUTTON_9]);
1048 settings.setValue("p1k_pound", vjs.p1KeyBindings[BUTTON_d]);
1049 settings.setValue("p1k_star", vjs.p1KeyBindings[BUTTON_s]);
1051 settings.setValue("p2k_up", vjs.p2KeyBindings[BUTTON_U]);
1052 settings.setValue("p2k_down", vjs.p2KeyBindings[BUTTON_D]);
1053 settings.setValue("p2k_left", vjs.p2KeyBindings[BUTTON_L]);
1054 settings.setValue("p2k_right", vjs.p2KeyBindings[BUTTON_R]);
1055 settings.setValue("p2k_c", vjs.p2KeyBindings[BUTTON_C]);
1056 settings.setValue("p2k_b", vjs.p2KeyBindings[BUTTON_B]);
1057 settings.setValue("p2k_a", vjs.p2KeyBindings[BUTTON_A]);
1058 settings.setValue("p2k_option", vjs.p2KeyBindings[BUTTON_OPTION]);
1059 settings.setValue("p2k_pause", vjs.p2KeyBindings[BUTTON_PAUSE]);
1060 settings.setValue("p2k_0", vjs.p2KeyBindings[BUTTON_0]);
1061 settings.setValue("p2k_1", vjs.p2KeyBindings[BUTTON_1]);
1062 settings.setValue("p2k_2", vjs.p2KeyBindings[BUTTON_2]);
1063 settings.setValue("p2k_3", vjs.p2KeyBindings[BUTTON_3]);
1064 settings.setValue("p2k_4", vjs.p2KeyBindings[BUTTON_4]);
1065 settings.setValue("p2k_5", vjs.p2KeyBindings[BUTTON_5]);
1066 settings.setValue("p2k_6", vjs.p2KeyBindings[BUTTON_6]);
1067 settings.setValue("p2k_7", vjs.p2KeyBindings[BUTTON_7]);
1068 settings.setValue("p2k_8", vjs.p2KeyBindings[BUTTON_8]);
1069 settings.setValue("p2k_9", vjs.p2KeyBindings[BUTTON_9]);
1070 settings.setValue("p2k_pound", vjs.p2KeyBindings[BUTTON_d]);
1071 settings.setValue("p2k_star", vjs.p2KeyBindings[BUTTON_s]);
1075 void MainWin::WriteUISettings(void)
1077 QSettings settings("Underground Software", "Virtual Jaguar");
1078 settings.setValue("pos", pos());
1079 settings.setValue("size", size());
1080 settings.setValue("cartLoadPos", filePickWin->pos());
1082 settings.setValue("zoom", zoomLevel);