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...
39 #include "configdialog.h"
40 #include "filepicker.h"
42 #include "generaltab.h"
47 #include "debug/cpubrowser.h"
48 #include "debug/m68kdasmbrowser.h"
49 #include "debug/memorybrowser.h"
50 #include "debug/opbrowser.h"
58 #include "jagcdbios.h"
59 #include "jagstub2bios.h"
62 // According to SebRmv, this header isn't seen on Arch Linux either... :-/
64 // Apparently on win32, usleep() is not pulled in by the usual suspects.
68 // The way BSNES controls things is by setting a timer with a zero
69 // timeout, sleeping if not emulating anything. Seems there has to be a
72 // It has a novel approach to plugging-in/using different video/audio/input
73 // methods, can we do something similar or should we just use the built-in
76 // We're going to try to use the built-in OpenGL support and see how it goes.
77 // We'll make the VJ core modular so that it doesn't matter what GUI is in
78 // use, we can drop it in anywhere and use it as-is.
80 //MainWin::MainWin(QString filenameToRun): running(true), powerButtonOn(false),
81 MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
82 showUntunedTankCircuit(true), cartridgeLoaded(false), CDActive(false),
83 //, alpineLoadSuccessful(false),
84 // pauseForFileSelector(false), loadAndGo(false), plzDontKillMyComputer(false)
85 pauseForFileSelector(false), loadAndGo(autoRun), plzDontKillMyComputer(false)
87 for(int i=0; i<8; i++)
90 videoWidget = new GLWidget(this);
91 setCentralWidget(videoWidget);
92 setWindowIcon(QIcon(":/res/vj-icon.png"));
94 QString title = QString(tr("Virtual Jaguar " VJ_RELEASE_VERSION ));
96 if (vjs.hardwareTypeAlpine)
97 title += QString(tr(" - Alpine Mode"));
99 setWindowTitle(title);
101 aboutWin = new AboutWindow(this);
102 helpWin = new HelpWindow(this);
103 filePickWin = new FilePickerWindow(this);
104 memBrowseWin = new MemoryBrowserWindow(this);
105 cpuBrowseWin = new CPUBrowserWindow(this);
106 opBrowseWin = new OPBrowserWindow(this);
107 m68kDasmBrowseWin = new M68KDasmBrowserWindow(this);
109 videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
110 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
112 setUnifiedTitleAndToolBarOnMac(true);
116 quitAppAct = new QAction(tr("E&xit"), this);
117 // quitAppAct->setShortcuts(QKeySequence::Quit);
118 // quitAppAct->setShortcut(QKeySequence(tr("Alt+x")));
119 quitAppAct->setShortcut(QKeySequence(tr("Ctrl+q")));
120 quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
121 connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
123 powerGreen.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
124 powerGreen.addFile(":/res/power-on-green.png", QSize(), QIcon::Normal, QIcon::On);
125 powerRed.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
126 powerRed.addFile(":/res/power-on-red.png", QSize(), QIcon::Normal, QIcon::On);
128 // powerAct = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
129 powerAct = new QAction(powerGreen, tr("&Power"), this);
130 powerAct->setStatusTip(tr("Powers Jaguar on/off"));
131 powerAct->setCheckable(true);
132 powerAct->setChecked(false);
133 // powerAct->setDisabled(true);
134 connect(powerAct, SIGNAL(triggered()), this, SLOT(TogglePowerState()));
137 pauseIcon.addFile(":/res/pause-off", QSize(), QIcon::Normal, QIcon::Off);
138 pauseIcon.addFile(":/res/pause-on", QSize(), QIcon::Normal, QIcon::On);
139 // pauseAct = new QAction(QIcon(":/res/pause.png"), tr("Pause"), this);
140 pauseAct = new QAction(pauseIcon, tr("Pause"), this);
141 pauseAct->setStatusTip(tr("Toggles the running state"));
142 pauseAct->setCheckable(true);
143 pauseAct->setDisabled(true);
144 pauseAct->setShortcut(QKeySequence(tr("Esc")));
145 connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
147 zoomActs = new QActionGroup(this);
149 x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
150 x1Act->setStatusTip(tr("Set window zoom to 100%"));
151 x1Act->setCheckable(true);
152 connect(x1Act, SIGNAL(triggered()), this, SLOT(SetZoom100()));
154 x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
155 x2Act->setStatusTip(tr("Set window zoom to 200%"));
156 x2Act->setCheckable(true);
157 connect(x2Act, SIGNAL(triggered()), this, SLOT(SetZoom200()));
159 x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
160 x3Act->setStatusTip(tr("Set window zoom to 300%"));
161 x3Act->setCheckable(true);
162 connect(x3Act, SIGNAL(triggered()), this, SLOT(SetZoom300()));
164 tvTypeActs = new QActionGroup(this);
166 ntscAct = new QAction(QIcon(":/res/ntsc.png"), tr("NTSC"), tvTypeActs);
167 ntscAct->setStatusTip(tr("Sets Jaguar to NTSC mode"));
168 ntscAct->setCheckable(true);
169 connect(ntscAct, SIGNAL(triggered()), this, SLOT(SetNTSC()));
171 palAct = new QAction(QIcon(":/res/pal.png"), tr("PAL"), tvTypeActs);
172 palAct->setStatusTip(tr("Sets Jaguar to PAL mode"));
173 palAct->setCheckable(true);
174 connect(palAct, SIGNAL(triggered()), this, SLOT(SetPAL()));
176 blurAct = new QAction(QIcon(":/res/generic.png"), tr("Blur"), this);
177 blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
178 blurAct->setCheckable(true);
179 connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
181 aboutAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&About..."), this);
182 aboutAct->setStatusTip(tr("Blatant self-promotion"));
183 connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
185 helpAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&Contents..."), this);
186 helpAct->setStatusTip(tr("Help is available, if you should need it"));
187 connect(helpAct, SIGNAL(triggered()), this, SLOT(ShowHelpWin()));
189 filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this);
190 filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar"));
191 filePickAct->setShortcut(QKeySequence(tr("Ctrl+i")));
192 connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart()));
194 configAct = new QAction(QIcon(":/res/wrench.png"), tr("&Configure"), this);
195 configAct->setStatusTip(tr("Configure options for Virtual Jaguar"));
196 configAct->setShortcut(QKeySequence(tr("Ctrl+c")));
197 connect(configAct, SIGNAL(triggered()), this, SLOT(Configure()));
199 useCDAct = new QAction(QIcon(":/res/compact-disc.png"), tr("&Use CD Unit"), this);
200 useCDAct->setStatusTip(tr("Use Jaguar Virtual CD unit"));
201 // useCDAct->setShortcut(QKeySequence(tr("Ctrl+c")));
202 useCDAct->setCheckable(true);
203 connect(useCDAct, SIGNAL(triggered()), this, SLOT(ToggleCDUsage()));
205 frameAdvanceAct = new QAction(QIcon(":/res/frame-advance.png"), tr("&Frame Advance"), this);
206 frameAdvanceAct->setShortcut(QKeySequence(tr("F7")));
207 connect(frameAdvanceAct, SIGNAL(triggered()), this, SLOT(FrameAdvance()));
209 fullScreenAct = new QAction(QIcon(":/res/generic.png"), tr("F&ull Screen"), this);
210 fullScreenAct->setShortcut(QKeySequence(tr("F9")));
211 connect(fullScreenAct, SIGNAL(triggered()), this, SLOT(ToggleFullScreen()));
214 memBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("Memory Browser"), this);
215 memBrowseAct->setStatusTip(tr("Shows the Jaguar memory browser window"));
216 // memBrowseAct->setCheckable(true);
217 connect(memBrowseAct, SIGNAL(triggered()), this, SLOT(ShowMemoryBrowserWin()));
219 cpuBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("CPU Browser"), this);
220 cpuBrowseAct->setStatusTip(tr("Shows the Jaguar CPU browser window"));
221 // memBrowseAct->setCheckable(true);
222 connect(cpuBrowseAct, SIGNAL(triggered()), this, SLOT(ShowCPUBrowserWin()));
224 opBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("OP Browser"), this);
225 opBrowseAct->setStatusTip(tr("Shows the Jaguar OP browser window"));
226 // memBrowseAct->setCheckable(true);
227 connect(opBrowseAct, SIGNAL(triggered()), this, SLOT(ShowOPBrowserWin()));
229 m68kDasmBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("68K Listing Browser"), this);
230 m68kDasmBrowseAct->setStatusTip(tr("Shows the 68K disassembly browser window"));
231 // memBrowseAct->setCheckable(true);
232 connect(m68kDasmBrowseAct, SIGNAL(triggered()), this, SLOT(ShowM68KDasmBrowserWin()));
234 // Misc. connections...
235 connect(filePickWin, SIGNAL(RequestLoad(QString)), this, SLOT(LoadSoftware(QString)));
236 connect(filePickWin, SIGNAL(FilePickerHiding()), this, SLOT(Unpause()));
238 // Create menus & toolbars
240 fileMenu = menuBar()->addMenu(tr("&Jaguar"));
241 fileMenu->addAction(powerAct);
242 fileMenu->addAction(pauseAct);
243 fileMenu->addAction(frameAdvanceAct);
244 fileMenu->addAction(filePickAct);
245 fileMenu->addAction(useCDAct);
246 fileMenu->addAction(configAct);
247 fileMenu->addAction(quitAppAct);
249 if (vjs.hardwareTypeAlpine)
251 debugMenu = menuBar()->addMenu(tr("&Debug"));
252 debugMenu->addAction(memBrowseAct);
253 debugMenu->addAction(cpuBrowseAct);
254 debugMenu->addAction(opBrowseAct);
255 debugMenu->addAction(m68kDasmBrowseAct);
258 helpMenu = menuBar()->addMenu(tr("&Help"));
259 helpMenu->addAction(helpAct);
260 helpMenu->addAction(aboutAct);
262 toolbar = addToolBar(tr("Stuff"));
263 toolbar->addAction(powerAct);
264 toolbar->addAction(pauseAct);
265 toolbar->addAction(filePickAct);
266 toolbar->addAction(useCDAct);
267 toolbar->addSeparator();
268 toolbar->addAction(x1Act);
269 toolbar->addAction(x2Act);
270 toolbar->addAction(x3Act);
271 toolbar->addSeparator();
272 toolbar->addAction(ntscAct);
273 toolbar->addAction(palAct);
274 toolbar->addSeparator();
275 toolbar->addAction(blurAct);
276 toolbar->addAction(fullScreenAct);
278 if (vjs.hardwareTypeAlpine)
280 debugbar = addToolBar(tr("&Debug"));
281 debugbar->addAction(memBrowseAct);
282 debugbar->addAction(cpuBrowseAct);
283 debugbar->addAction(opBrowseAct);
284 debugbar->addAction(m68kDasmBrowseAct);
288 statusBar()->showMessage(tr("Ready"));
292 // Do this in case original size isn't correct (mostly for the first-run case)
295 // Set up timer based loop for animation...
296 timer = new QTimer(this);
297 connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
299 // This isn't very accurate for NTSC: This is early by 40 msec per frame.
300 // This is because it's discarding the 0.6666... on the end of the fraction.
301 // Alas, 6 doesn't divide cleanly into 10. :-P
302 //Should we defer this until SyncUI? Probably.
303 //No, it doesn't work, because it uses setInterval() instead of start()...
304 // timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
306 // We set this initially, to make VJ behave somewhat as it would if no
307 // cart were inserted and the BIOS was set as active...
308 jaguarCartInserted = true;
309 WriteLog("Virtual Jaguar %s (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
310 WriteLog("VJ: Initializing jaguar subsystem...\n");
312 memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
314 // Check for filename passed in on the command line...
315 // if (!filenameToRun.isEmpty())
319 // Attempt to load/run the file the user passed in...
320 // LoadSoftware(filenameToRun);
321 //// memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
322 // Prevent the file scanner from running...
326 // Load up the default ROM if in Alpine mode:
327 if (vjs.hardwareTypeAlpine)
329 bool romLoaded = JaguarLoadFile(vjs.alpineROMPath);
331 // If regular load failed, try just a straight file load
332 // (Dev only! I don't want people to start getting lazy with their releases again! :-P)
334 romLoaded = AlpineLoadFile(vjs.alpineROMPath);
337 WriteLog("Alpine Mode: Successfully loaded file \"%s\".\n", vjs.alpineROMPath);
339 WriteLog("Alpine Mode: Unable to load file \"%s\"!\n", vjs.alpineROMPath);
341 // Attempt to load/run the ABS file...
342 LoadSoftware(vjs.absROMPath);
343 memcpy(jagMemSpace + 0xE00000, jaguarDevBootROM2, 0x20000); // Use the stub BIOS
344 // Prevent the scanner from running...
348 // memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Otherwise, use the stock BIOS
350 // Run the scanner if nothing passed in and *not* Alpine mode...
351 // NB: Really need to look into caching the info scanned in here...
352 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
356 void MainWin::LoadFile(QString file)
362 void MainWin::SyncUI(void)
364 // Set toolbar buttons/menus based on settings read in (sync the UI)...
365 // (Really, this is to sync command line options passed in)
366 blurAct->setChecked(vjs.glFilter);
367 x1Act->setChecked(zoomLevel == 1);
368 x2Act->setChecked(zoomLevel == 2);
369 x3Act->setChecked(zoomLevel == 3);
370 // running = powerAct->isChecked();
371 ntscAct->setChecked(vjs.hardwareTypeNTSC);
372 palAct->setChecked(!vjs.hardwareTypeNTSC);
373 powerAct->setIcon(vjs.hardwareTypeNTSC ? powerRed : powerGreen);
375 fullScreen = vjs.fullscreen;
376 SetFullScreen(fullScreen);
378 // Reset the timer to be what was set in the command line (if any):
379 // timer->setInterval(vjs.hardwareTypeNTSC ? 16 : 20);
380 timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
384 void MainWin::closeEvent(QCloseEvent * event)
387 // This should only be done by the config dialog
390 event->accept(); // ignore() if can't close for some reason
394 void MainWin::keyPressEvent(QKeyEvent * e)
396 // We ignore the Alt key for now, since it causes problems with the GUI
397 if (e->key() == Qt::Key_Alt)
403 if (e->key() == Qt::Key_F9)
413 void MainWin::keyReleaseEvent(QKeyEvent * e)
415 // We ignore the Alt key for now, since it causes problems with the GUI
416 if (e->key() == Qt::Key_Alt)
422 HandleKeys(e, false);
426 void MainWin::HandleKeys(QKeyEvent * e, bool state)
428 enum { P1LEFT = 0, P1RIGHT, P1UP, P1DOWN, P2LEFT, P2RIGHT, P2UP, P2DOWN };
429 // We kill bad key combos here, before they can get to the emulator...
430 // This also kills the illegal instruction problem that cropped up in Rayman!
431 // May want to do this by killing the old one instead of ignoring the new one...
432 // Seems to work better that way...
434 // The problem with this approach is that it causes bad results because it doesn't do
435 // any checking of previous states. Need to come up with something better because this
436 // causes problems where the keyboard acts as if it were unresponsive. :-P
438 if ((e->key() == vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
439 || (e->key() == vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
440 || (e->key() == vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
441 || (e->key() == vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U]))
445 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
446 joypad_0_buttons[BUTTON_R] = 0;
447 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
448 joypad_0_buttons[BUTTON_L] = 0;
449 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
450 joypad_0_buttons[BUTTON_D] = 0;
451 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U])
452 joypad_0_buttons[BUTTON_U] = 0;
454 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L] && joypad_1_buttons[BUTTON_R])
455 joypad_1_buttons[BUTTON_R] = 0;
456 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R] && joypad_1_buttons[BUTTON_L])
457 joypad_1_buttons[BUTTON_L] = 0;
458 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U] && joypad_1_buttons[BUTTON_D])
459 joypad_1_buttons[BUTTON_D] = 0;
460 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D] && joypad_1_buttons[BUTTON_U])
461 joypad_1_buttons[BUTTON_U] = 0;
463 //hrm, this still has sticky state problems... Ugh!
464 // First, settle key states...
465 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L])
466 keyHeld[P1LEFT] = state;
467 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R])
468 keyHeld[P1RIGHT] = state;
469 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U])
470 keyHeld[P1UP] = state;
471 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D])
472 keyHeld[P1DOWN] = state;
473 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L])
474 keyHeld[P2LEFT] = state;
475 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R])
476 keyHeld[P2RIGHT] = state;
477 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U])
478 keyHeld[P2UP] = state;
479 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D])
480 keyHeld[P2DOWN] = state;
482 // Next, check for conflicts and bail out if there are any...
483 if ((keyHeld[P1LEFT] && keyHeld[P1RIGHT])
484 || (keyHeld[P1UP] && keyHeld[P1DOWN])
485 || (keyHeld[P2LEFT] && keyHeld[P2RIGHT])
486 || (keyHeld[P2UP] && keyHeld[P2DOWN]))
491 // No bad combos exist, let's stuff the emulator key buffers...!
492 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
494 if (e->key() == (int)vjs.p1KeyBindings[i])
495 // joypad_0_buttons[i] = (uint8)state;
496 joypad_0_buttons[i] = (state ? 0x01 : 0x00);
498 // Pad #2 is screwing up pad #1. Prolly a problem in joystick.cpp...
499 // So let's try to fix it there. :-P [DONE]
500 if (e->key() == (int)vjs.p2KeyBindings[i])
501 // joypad_1_buttons[i] = (uint8)state;
502 joypad_1_buttons[i] = (state ? 0x01 : 0x00);
507 void MainWin::HandleGamepads(void)
511 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
513 if (vjs.p1KeyBindings[i] & (JOY_BUTTON | JOY_HAT))
514 joypad_0_buttons[i] = (Gamepad::GetState(0, vjs.p1KeyBindings[i]) ? 0x01 : 0x00);
516 if (vjs.p2KeyBindings[i] & (JOY_BUTTON | JOY_HAT))
517 joypad_1_buttons[i] = (Gamepad::GetState(1, vjs.p2KeyBindings[i]) ? 0x01 : 0x00);
522 void MainWin::Open(void)
527 void MainWin::Configure(void)
529 // Call the configuration dialog and update settings
530 ConfigDialog dlg(this);
532 dlg.generalTab->useUnknownSoftware->setChecked(allowUnknownSoftware);
534 if (dlg.exec() == false)
537 QString before = vjs.ROMPath;
538 QString alpineBefore = vjs.alpineROMPath;
539 QString absBefore = vjs.absROMPath;
540 // bool audioBefore = vjs.audioEnabled;
541 bool audioBefore = vjs.DSPEnabled;
542 dlg.UpdateVJSettings();
543 QString after = vjs.ROMPath;
544 QString alpineAfter = vjs.alpineROMPath;
545 QString absAfter = vjs.absROMPath;
546 // bool audioAfter = vjs.audioEnabled;
547 bool audioAfter = vjs.DSPEnabled;
549 bool allowOld = allowUnknownSoftware;
551 allowUnknownSoftware = dlg.generalTab->useUnknownSoftware->isChecked();
553 // We rescan the "software" folder if the user either changed the path or
554 // checked/unchecked the "Allow unknown files" option in the config dialog.
555 if ((before != after) || (allowOld != allowUnknownSoftware))
556 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
558 // If the "Alpine" ROM is changed, then let's load it...
559 if (alpineBefore != alpineAfter)
561 if (!JaguarLoadFile(vjs.alpineROMPath) && !AlpineLoadFile(vjs.alpineROMPath))
563 // Oh crap, we couldn't get the file! Alert the media!
565 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.alpineROMPath));
566 msg.setIcon(QMessageBox::Warning);
571 // If the "ABS" ROM is changed, then let's load it...
572 if (absBefore != absAfter)
574 if (!JaguarLoadFile(vjs.absROMPath))
576 // Oh crap, we couldn't get the file! Alert the media!
578 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.absROMPath));
579 msg.setIcon(QMessageBox::Warning);
584 // If the "Enable DSP" checkbox changed, then we have to re-init the DAC,
585 // since it's running in the host audio IRQ...
586 if (audioBefore != audioAfter)
592 // Just in case we crash before a clean exit...
598 // Here's the main emulator loop
600 void MainWin::Timer(void)
605 if (showUntunedTankCircuit)
607 // Some machines can't handle this, so we give them the option to disable it. :-)
608 if (!plzDontKillMyComputer)
610 // Random hash & trash
611 // We try to simulate an untuned tank circuit here... :-)
612 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
614 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
616 videoWidget->buffer[(y * videoWidget->textureWidth) + x]
617 = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;
624 // Otherwise, run the Jaguar simulation
629 videoWidget->updateGL();
633 void MainWin::TogglePowerState(void)
635 powerButtonOn = !powerButtonOn;
638 // With the power off, we simulate white noise on the screen. :-)
641 useCDAct->setDisabled(false);
642 palAct->setDisabled(false);
643 ntscAct->setDisabled(false);
644 pauseAct->setChecked(false);
645 pauseAct->setDisabled(true);
646 showUntunedTankCircuit = true;
647 // This is just in case the ROM we were playing was in a narrow or wide field mode,
648 // so the untuned tank sim doesn't look wrong. :-)
653 useCDAct->setDisabled(true);
654 palAct->setDisabled(true);
655 ntscAct->setDisabled(true);
656 pauseAct->setChecked(false);
657 pauseAct->setDisabled(false);
658 showUntunedTankCircuit = false;
660 // Otherwise, we prepare for running regular software...
663 // Should check for cartridgeLoaded here as well...!
664 // We can clear it when toggling CDActive on, so that when we power cycle it does the
665 // expected thing. Otherwise, if we use the file picker to insert a cart, we expect
666 // to run the cart! Maybe have a RemoveCart function that only works if the CD unit
668 setWindowTitle(QString("Virtual Jaguar " VJ_RELEASE_VERSION
669 " - Now playing: Jaguar CD"));
672 WriteLog("GUI: Resetting Jaguar...\n");
678 void MainWin::ToggleRunState(void)
684 for(uint32_t i=0; i<(uint32_t)(videoWidget->textureWidth * 256); i++)
686 uint32_t pixel = videoWidget->buffer[i];
687 uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
688 pixel = ((r + g + b) / 3) & 0x00FF;
689 videoWidget->buffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
692 videoWidget->updateGL();
697 void MainWin::SetZoom100(void)
704 void MainWin::SetZoom200(void)
711 void MainWin::SetZoom300(void)
718 void MainWin::SetNTSC(void)
720 powerAct->setIcon(powerRed);
721 timer->setInterval(16);
722 vjs.hardwareTypeNTSC = true;
728 void MainWin::SetPAL(void)
730 powerAct->setIcon(powerGreen);
731 timer->setInterval(20);
732 vjs.hardwareTypeNTSC = false;
738 void MainWin::ToggleBlur(void)
740 vjs.glFilter = !vjs.glFilter;
745 void MainWin::ShowAboutWin(void)
751 void MainWin::ShowHelpWin(void)
757 void MainWin::InsertCart(void)
759 // If the emulator is running, we pause it here and unpause it later
760 // if we dismiss the file selector without choosing anything
761 if (running && powerButtonOn)
764 pauseForFileSelector = true;
771 void MainWin::Unpause(void)
773 // Here we unpause the emulator if it was paused when we went into the file selector
774 if (pauseForFileSelector)
776 pauseForFileSelector = false;
778 // Some nutter might have unpaused while in the file selector, so check for that
785 void MainWin::LoadSoftware(QString file)
787 running = false; // Prevent bad things(TM) from happening...
788 pauseForFileSelector = false; // Reset the file selector pause flag
789 SET32(jaguarMainRAM, 0, 0x00200000); // Set top of stack...
790 cartridgeLoaded = JaguarLoadFile(file.toAscii().data());
792 char * biosPointer = jaguarBootROM;
794 if (vjs.hardwareTypeAlpine)
795 biosPointer = jaguarDevBootROM2;
797 memcpy(jagMemSpace + 0xE00000, biosPointer, 0x20000);
799 powerAct->setDisabled(false);
800 powerAct->setChecked(true);
801 powerButtonOn = false;
804 if (!vjs.hardwareTypeAlpine && !loadAndGo)
806 QString newTitle = QString("Virtual Jaguar " VJ_RELEASE_VERSION " - Now playing: %1")
807 .arg(filePickWin->GetSelectedPrettyName());
808 setWindowTitle(newTitle);
813 void MainWin::ToggleCDUsage(void)
815 CDActive = !CDActive;
820 powerAct->setDisabled(false);
824 powerAct->setDisabled(true);
827 // Set up the Jaguar CD for execution, otherwise, clear memory
829 memcpy(jagMemSpace + 0x800000, jaguarCDBootROM, 0x40000);
831 memset(jagMemSpace + 0x800000, 0xFF, 0x40000);
836 void MainWin::FrameAdvance(void)
838 //printf("Frame Advance...\n");
839 // Execute 1 frame, then exit (only useful in Pause mode)
841 videoWidget->updateGL();
845 void MainWin::SetFullScreen(bool state/*= true*/)
849 mainWinPosition = pos();
850 // mainWinSize = size();
854 QRect r = QApplication::desktop()->availableGeometry();
855 // double targetWidth = 320.0, targetHeight = (vjs.hardwareTypeNTSC ? 240.0 : 256.0);
856 double targetWidth = (double)VIRTUAL_SCREEN_WIDTH,
857 targetHeight = (double)(vjs.hardwareTypeNTSC ? VIRTUAL_SCREEN_HEIGHT_NTSC : VIRTUAL_SCREEN_HEIGHT_PAL);
858 double aspectRatio = targetWidth / targetHeight;
859 // NOTE: Really should check here to see which dimension constrains the other.
860 // Right now, we assume that height is the constraint.
861 int newWidth = (int)(aspectRatio * (double)r.height());
863 videoWidget->setFixedSize(newWidth, r.height());
872 move(mainWinPosition);
875 // For some reason, this doesn't work: If the emu is paused, toggling from
876 // fullscreen to windowed (& vice versa) shows a white screen.
877 // videoWidget->updateGL();
881 void MainWin::ToggleFullScreen(void)
883 fullScreen = !fullScreen;
884 SetFullScreen(fullScreen);
888 void MainWin::ShowMemoryBrowserWin(void)
890 memBrowseWin->show();
891 memBrowseWin->RefreshContents();
895 void MainWin::ShowCPUBrowserWin(void)
897 cpuBrowseWin->show();
898 cpuBrowseWin->RefreshContents();
902 void MainWin::ShowOPBrowserWin(void)
905 opBrowseWin->RefreshContents();
909 void MainWin::ShowM68KDasmBrowserWin(void)
911 m68kDasmBrowseWin->show();
912 m68kDasmBrowseWin->RefreshContents();
916 void MainWin::ResizeMainWindow(void)
918 // videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
919 videoWidget->setFixedSize(zoomLevel * VIRTUAL_SCREEN_WIDTH,
920 zoomLevel * (vjs.hardwareTypeNTSC ? VIRTUAL_SCREEN_HEIGHT_NTSC : VIRTUAL_SCREEN_HEIGHT_PAL));
923 for(int i=0; i<2; i++)
927 QApplication::processEvents();
932 #warning "!!! Need to check the window geometry to see if the positions are legal !!!"
933 // i.e., someone could drag it to another screen, close it, then disconnect that screen
934 void MainWin::ReadSettings(void)
936 QSettings settings("Underground Software", "Virtual Jaguar");
937 mainWinPosition = settings.value("pos", QPoint(200, 200)).toPoint();
938 QSize size = settings.value("size", QSize(400, 400)).toSize();
940 move(mainWinPosition);
941 QPoint pos = settings.value("cartLoadPos", QPoint(200, 200)).toPoint();
942 filePickWin->move(pos);
944 zoomLevel = settings.value("zoom", 2).toInt();
945 allowUnknownSoftware = settings.value("showUnknownSoftware", false).toBool();
947 vjs.useJoystick = settings.value("useJoystick", false).toBool();
948 vjs.joyport = settings.value("joyport", 0).toInt();
949 vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
950 vjs.frameSkip = settings.value("frameSkip", 0).toInt();
951 vjs.useJaguarBIOS = settings.value("useJaguarBIOS", false).toBool();
952 vjs.GPUEnabled = settings.value("GPUEnabled", true).toBool();
953 vjs.DSPEnabled = settings.value("DSPEnabled", false).toBool();
954 vjs.audioEnabled = settings.value("audioEnabled", true).toBool();
955 vjs.usePipelinedDSP = settings.value("usePipelinedDSP", false).toBool();
956 vjs.fullscreen = settings.value("fullscreen", false).toBool();
957 vjs.useOpenGL = settings.value("useOpenGL", true).toBool();
958 vjs.glFilter = settings.value("glFilterType", 1).toInt();
959 vjs.renderType = settings.value("renderType", 0).toInt();
960 vjs.allowWritesToROM = settings.value("writeROM", false).toBool();
961 // strcpy(vjs.jagBootPath, settings.value("JagBootROM", "./bios/[BIOS] Atari Jaguar (USA, Europe).zip").toString().toAscii().data());
962 // strcpy(vjs.CDBootPath, settings.value("CDBootROM", "./bios/jagcd.rom").toString().toAscii().data());
963 strcpy(vjs.EEPROMPath, settings.value("EEPROMs", "./eeproms/").toString().toAscii().data());
964 strcpy(vjs.ROMPath, settings.value("ROMs", "./software/").toString().toAscii().data());
965 strcpy(vjs.alpineROMPath, settings.value("DefaultROM", "").toString().toAscii().data());
966 strcpy(vjs.absROMPath, settings.value("DefaultABS", "").toString().toAscii().data());
967 WriteLog("MainWin: Paths\n");
968 //WriteLog(" jagBootPath = \"%s\"\n", vjs.jagBootPath);
969 //WriteLog(" CDBootPath = \"%s\"\n", vjs.CDBootPath);
970 WriteLog(" EEPROMPath = \"%s\"\n", vjs.EEPROMPath);
971 WriteLog(" ROMPath = \"%s\"\n", vjs.ROMPath);
972 WriteLog("AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);
973 WriteLog(" absROMPath = \"%s\"\n", vjs.absROMPath);
974 WriteLog("Pipelined DSP = %s\n", (vjs.usePipelinedDSP ? "ON" : "off"));
976 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
977 vjs.p1KeyBindings[BUTTON_U] = settings.value("p1k_up", Qt::Key_S).toInt();
978 vjs.p1KeyBindings[BUTTON_D] = settings.value("p1k_down", Qt::Key_X).toInt();
979 vjs.p1KeyBindings[BUTTON_L] = settings.value("p1k_left", Qt::Key_A).toInt();
980 vjs.p1KeyBindings[BUTTON_R] = settings.value("p1k_right", Qt::Key_D).toInt();
981 vjs.p1KeyBindings[BUTTON_C] = settings.value("p1k_c", Qt::Key_J).toInt();
982 vjs.p1KeyBindings[BUTTON_B] = settings.value("p1k_b", Qt::Key_K).toInt();
983 vjs.p1KeyBindings[BUTTON_A] = settings.value("p1k_a", Qt::Key_L).toInt();
984 vjs.p1KeyBindings[BUTTON_OPTION] = settings.value("p1k_option", Qt::Key_O).toInt();
985 vjs.p1KeyBindings[BUTTON_PAUSE] = settings.value("p1k_pause", Qt::Key_P).toInt();
986 vjs.p1KeyBindings[BUTTON_0] = settings.value("p1k_0", Qt::Key_0).toInt();
987 vjs.p1KeyBindings[BUTTON_1] = settings.value("p1k_1", Qt::Key_1).toInt();
988 vjs.p1KeyBindings[BUTTON_2] = settings.value("p1k_2", Qt::Key_2).toInt();
989 vjs.p1KeyBindings[BUTTON_3] = settings.value("p1k_3", Qt::Key_3).toInt();
990 vjs.p1KeyBindings[BUTTON_4] = settings.value("p1k_4", Qt::Key_4).toInt();
991 vjs.p1KeyBindings[BUTTON_5] = settings.value("p1k_5", Qt::Key_5).toInt();
992 vjs.p1KeyBindings[BUTTON_6] = settings.value("p1k_6", Qt::Key_6).toInt();
993 vjs.p1KeyBindings[BUTTON_7] = settings.value("p1k_7", Qt::Key_7).toInt();
994 vjs.p1KeyBindings[BUTTON_8] = settings.value("p1k_8", Qt::Key_8).toInt();
995 vjs.p1KeyBindings[BUTTON_9] = settings.value("p1k_9", Qt::Key_9).toInt();
996 vjs.p1KeyBindings[BUTTON_d] = settings.value("p1k_pound", Qt::Key_Minus).toInt();
997 vjs.p1KeyBindings[BUTTON_s] = settings.value("p1k_star", Qt::Key_Equal).toInt();
999 vjs.p2KeyBindings[BUTTON_U] = settings.value("p2k_up", Qt::Key_Up).toInt();
1000 vjs.p2KeyBindings[BUTTON_D] = settings.value("p2k_down", Qt::Key_Down).toInt();
1001 vjs.p2KeyBindings[BUTTON_L] = settings.value("p2k_left", Qt::Key_Left).toInt();
1002 vjs.p2KeyBindings[BUTTON_R] = settings.value("p2k_right", Qt::Key_Right).toInt();
1003 vjs.p2KeyBindings[BUTTON_C] = settings.value("p2k_c", Qt::Key_Z).toInt();
1004 vjs.p2KeyBindings[BUTTON_B] = settings.value("p2k_b", Qt::Key_X).toInt();
1005 vjs.p2KeyBindings[BUTTON_A] = settings.value("p2k_a", Qt::Key_C).toInt();
1006 vjs.p2KeyBindings[BUTTON_OPTION] = settings.value("p2k_option", Qt::Key_Apostrophe).toInt();
1007 vjs.p2KeyBindings[BUTTON_PAUSE] = settings.value("p2k_pause", Qt::Key_Return).toInt();
1008 vjs.p2KeyBindings[BUTTON_0] = settings.value("p2k_0", Qt::Key_0).toInt();
1009 vjs.p2KeyBindings[BUTTON_1] = settings.value("p2k_1", Qt::Key_1).toInt();
1010 vjs.p2KeyBindings[BUTTON_2] = settings.value("p2k_2", Qt::Key_2).toInt();
1011 vjs.p2KeyBindings[BUTTON_3] = settings.value("p2k_3", Qt::Key_3).toInt();
1012 vjs.p2KeyBindings[BUTTON_4] = settings.value("p2k_4", Qt::Key_4).toInt();
1013 vjs.p2KeyBindings[BUTTON_5] = settings.value("p2k_5", Qt::Key_5).toInt();
1014 vjs.p2KeyBindings[BUTTON_6] = settings.value("p2k_6", Qt::Key_6).toInt();
1015 vjs.p2KeyBindings[BUTTON_7] = settings.value("p2k_7", Qt::Key_7).toInt();
1016 vjs.p2KeyBindings[BUTTON_8] = settings.value("p2k_8", Qt::Key_8).toInt();
1017 vjs.p2KeyBindings[BUTTON_9] = settings.value("p2k_9", Qt::Key_9).toInt();
1018 vjs.p2KeyBindings[BUTTON_d] = settings.value("p2k_pound", Qt::Key_Slash).toInt();
1019 vjs.p2KeyBindings[BUTTON_s] = settings.value("p2k_star", Qt::Key_Asterisk).toInt();
1023 void MainWin::WriteSettings(void)
1025 QSettings settings("Underground Software", "Virtual Jaguar");
1026 settings.setValue("pos", pos());
1027 settings.setValue("size", size());
1028 settings.setValue("cartLoadPos", filePickWin->pos());
1030 settings.setValue("zoom", zoomLevel);
1031 settings.setValue("showUnknownSoftware", allowUnknownSoftware);
1033 settings.setValue("useJoystick", vjs.useJoystick);
1034 settings.setValue("joyport", vjs.joyport);
1035 settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
1036 settings.setValue("frameSkip", vjs.frameSkip);
1037 settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
1038 settings.setValue("GPUEnabled", vjs.GPUEnabled);
1039 settings.setValue("DSPEnabled", vjs.DSPEnabled);
1040 settings.setValue("audioEnabled", vjs.audioEnabled);
1041 settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
1042 settings.setValue("fullscreen", vjs.fullscreen);
1043 settings.setValue("useOpenGL", vjs.useOpenGL);
1044 settings.setValue("glFilterType", vjs.glFilter);
1045 settings.setValue("renderType", vjs.renderType);
1046 settings.setValue("writeROM", vjs.allowWritesToROM);
1047 settings.setValue("JagBootROM", vjs.jagBootPath);
1048 settings.setValue("CDBootROM", vjs.CDBootPath);
1049 settings.setValue("EEPROMs", vjs.EEPROMPath);
1050 settings.setValue("ROMs", vjs.ROMPath);
1051 settings.setValue("DefaultROM", vjs.alpineROMPath);
1052 settings.setValue("DefaultABS", vjs.absROMPath);
1054 settings.setValue("p1k_up", vjs.p1KeyBindings[BUTTON_U]);
1055 settings.setValue("p1k_down", vjs.p1KeyBindings[BUTTON_D]);
1056 settings.setValue("p1k_left", vjs.p1KeyBindings[BUTTON_L]);
1057 settings.setValue("p1k_right", vjs.p1KeyBindings[BUTTON_R]);
1058 settings.setValue("p1k_c", vjs.p1KeyBindings[BUTTON_C]);
1059 settings.setValue("p1k_b", vjs.p1KeyBindings[BUTTON_B]);
1060 settings.setValue("p1k_a", vjs.p1KeyBindings[BUTTON_A]);
1061 settings.setValue("p1k_option", vjs.p1KeyBindings[BUTTON_OPTION]);
1062 settings.setValue("p1k_pause", vjs.p1KeyBindings[BUTTON_PAUSE]);
1063 settings.setValue("p1k_0", vjs.p1KeyBindings[BUTTON_0]);
1064 settings.setValue("p1k_1", vjs.p1KeyBindings[BUTTON_1]);
1065 settings.setValue("p1k_2", vjs.p1KeyBindings[BUTTON_2]);
1066 settings.setValue("p1k_3", vjs.p1KeyBindings[BUTTON_3]);
1067 settings.setValue("p1k_4", vjs.p1KeyBindings[BUTTON_4]);
1068 settings.setValue("p1k_5", vjs.p1KeyBindings[BUTTON_5]);
1069 settings.setValue("p1k_6", vjs.p1KeyBindings[BUTTON_6]);
1070 settings.setValue("p1k_7", vjs.p1KeyBindings[BUTTON_7]);
1071 settings.setValue("p1k_8", vjs.p1KeyBindings[BUTTON_8]);
1072 settings.setValue("p1k_9", vjs.p1KeyBindings[BUTTON_9]);
1073 settings.setValue("p1k_pound", vjs.p1KeyBindings[BUTTON_d]);
1074 settings.setValue("p1k_star", vjs.p1KeyBindings[BUTTON_s]);
1076 settings.setValue("p2k_up", vjs.p2KeyBindings[BUTTON_U]);
1077 settings.setValue("p2k_down", vjs.p2KeyBindings[BUTTON_D]);
1078 settings.setValue("p2k_left", vjs.p2KeyBindings[BUTTON_L]);
1079 settings.setValue("p2k_right", vjs.p2KeyBindings[BUTTON_R]);
1080 settings.setValue("p2k_c", vjs.p2KeyBindings[BUTTON_C]);
1081 settings.setValue("p2k_b", vjs.p2KeyBindings[BUTTON_B]);
1082 settings.setValue("p2k_a", vjs.p2KeyBindings[BUTTON_A]);
1083 settings.setValue("p2k_option", vjs.p2KeyBindings[BUTTON_OPTION]);
1084 settings.setValue("p2k_pause", vjs.p2KeyBindings[BUTTON_PAUSE]);
1085 settings.setValue("p2k_0", vjs.p2KeyBindings[BUTTON_0]);
1086 settings.setValue("p2k_1", vjs.p2KeyBindings[BUTTON_1]);
1087 settings.setValue("p2k_2", vjs.p2KeyBindings[BUTTON_2]);
1088 settings.setValue("p2k_3", vjs.p2KeyBindings[BUTTON_3]);
1089 settings.setValue("p2k_4", vjs.p2KeyBindings[BUTTON_4]);
1090 settings.setValue("p2k_5", vjs.p2KeyBindings[BUTTON_5]);
1091 settings.setValue("p2k_6", vjs.p2KeyBindings[BUTTON_6]);
1092 settings.setValue("p2k_7", vjs.p2KeyBindings[BUTTON_7]);
1093 settings.setValue("p2k_8", vjs.p2KeyBindings[BUTTON_8]);
1094 settings.setValue("p2k_9", vjs.p2KeyBindings[BUTTON_9]);
1095 settings.setValue("p2k_pound", vjs.p2KeyBindings[BUTTON_d]);
1096 settings.setValue("p2k_star", vjs.p2KeyBindings[BUTTON_s]);
1100 void MainWin::WriteUISettings(void)
1102 QSettings settings("Underground Software", "Virtual Jaguar");
1103 settings.setValue("pos", pos());
1104 settings.setValue("size", size());
1105 settings.setValue("cartLoadPos", filePickWin->pos());
1107 settings.setValue("zoom", zoomLevel);