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: S1E9T8H5M23YS
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"
51 #include "debug/riscdasmbrowser.h"
60 #include "jagcdbios.h"
61 #include "jagstub2bios.h"
64 // According to SebRmv, this header isn't seen on Arch Linux either... :-/
66 // Apparently on win32, usleep() is not pulled in by the usual suspects.
70 // The way BSNES controls things is by setting a timer with a zero
71 // timeout, sleeping if not emulating anything. Seems there has to be a
74 // It has a novel approach to plugging-in/using different video/audio/input
75 // methods, can we do something similar or should we just use the built-in
78 // We're going to try to use the built-in OpenGL support and see how it goes.
79 // We'll make the VJ core modular so that it doesn't matter what GUI is in
80 // use, we can drop it in anywhere and use it as-is.
82 MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
83 showUntunedTankCircuit(true), cartridgeLoaded(false), CDActive(false),
84 pauseForFileSelector(false), loadAndGo(autoRun), plzDontKillMyComputer(false)
86 for(int i=0; i<8; i++)
89 videoWidget = new GLWidget(this);
90 setCentralWidget(videoWidget);
91 setWindowIcon(QIcon(":/res/vj-icon.png"));
93 QString title = QString(tr("Virtual Jaguar " VJ_RELEASE_VERSION ));
95 if (vjs.hardwareTypeAlpine)
96 title += QString(tr(" - Alpine Mode"));
98 setWindowTitle(title);
100 aboutWin = new AboutWindow(this);
101 helpWin = new HelpWindow(this);
102 filePickWin = new FilePickerWindow(this);
103 memBrowseWin = new MemoryBrowserWindow(this);
104 cpuBrowseWin = new CPUBrowserWindow(this);
105 opBrowseWin = new OPBrowserWindow(this);
106 m68kDasmBrowseWin = new M68KDasmBrowserWindow(this);
107 riscDasmBrowseWin = new RISCDasmBrowserWindow(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/blur.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/fullscreen.png"), tr("F&ull Screen"), this);
210 fullScreenAct->setShortcut(QKeySequence(tr("F9")));
211 fullScreenAct->setCheckable(true);
212 connect(fullScreenAct, SIGNAL(triggered()), this, SLOT(ToggleFullScreen()));
215 memBrowseAct = new QAction(QIcon(":/res/tool-memory.png"), tr("Memory Browser"), this);
216 memBrowseAct->setStatusTip(tr("Shows the Jaguar memory browser window"));
217 // memBrowseAct->setCheckable(true);
218 connect(memBrowseAct, SIGNAL(triggered()), this, SLOT(ShowMemoryBrowserWin()));
220 cpuBrowseAct = new QAction(QIcon(":/res/tool-cpu.png"), tr("CPU Browser"), this);
221 cpuBrowseAct->setStatusTip(tr("Shows the Jaguar CPU browser window"));
222 // memBrowseAct->setCheckable(true);
223 connect(cpuBrowseAct, SIGNAL(triggered()), this, SLOT(ShowCPUBrowserWin()));
225 opBrowseAct = new QAction(QIcon(":/res/tool-op.png"), tr("OP Browser"), this);
226 opBrowseAct->setStatusTip(tr("Shows the Jaguar OP browser window"));
227 // memBrowseAct->setCheckable(true);
228 connect(opBrowseAct, SIGNAL(triggered()), this, SLOT(ShowOPBrowserWin()));
230 m68kDasmBrowseAct = new QAction(QIcon(":/res/tool-68k-dis.png"), tr("68K Listing Browser"), this);
231 m68kDasmBrowseAct->setStatusTip(tr("Shows the 68K disassembly browser window"));
232 // memBrowseAct->setCheckable(true);
233 connect(m68kDasmBrowseAct, SIGNAL(triggered()), this, SLOT(ShowM68KDasmBrowserWin()));
235 riscDasmBrowseAct = new QAction(QIcon(":/res/tool-risc-dis.png"), tr("RISC Listing Browser"), this);
236 riscDasmBrowseAct->setStatusTip(tr("Shows the RISC disassembly browser window"));
237 // memBrowseAct->setCheckable(true);
238 connect(riscDasmBrowseAct, SIGNAL(triggered()), this, SLOT(ShowRISCDasmBrowserWin()));
240 // Misc. connections...
241 connect(filePickWin, SIGNAL(RequestLoad(QString)), this, SLOT(LoadSoftware(QString)));
242 connect(filePickWin, SIGNAL(FilePickerHiding()), this, SLOT(Unpause()));
244 // Create menus & toolbars
246 fileMenu = menuBar()->addMenu(tr("&Jaguar"));
247 fileMenu->addAction(powerAct);
248 fileMenu->addAction(pauseAct);
249 fileMenu->addAction(frameAdvanceAct);
250 fileMenu->addAction(filePickAct);
251 fileMenu->addAction(useCDAct);
252 fileMenu->addAction(configAct);
253 fileMenu->addAction(quitAppAct);
255 if (vjs.hardwareTypeAlpine)
257 debugMenu = menuBar()->addMenu(tr("&Debug"));
258 debugMenu->addAction(memBrowseAct);
259 debugMenu->addAction(cpuBrowseAct);
260 debugMenu->addAction(opBrowseAct);
261 debugMenu->addAction(m68kDasmBrowseAct);
262 debugMenu->addAction(riscDasmBrowseAct);
265 helpMenu = menuBar()->addMenu(tr("&Help"));
266 helpMenu->addAction(helpAct);
267 helpMenu->addAction(aboutAct);
269 toolbar = addToolBar(tr("Stuff"));
270 toolbar->addAction(powerAct);
271 toolbar->addAction(pauseAct);
272 toolbar->addAction(filePickAct);
273 toolbar->addAction(useCDAct);
274 toolbar->addSeparator();
275 toolbar->addAction(x1Act);
276 toolbar->addAction(x2Act);
277 toolbar->addAction(x3Act);
278 toolbar->addSeparator();
279 toolbar->addAction(ntscAct);
280 toolbar->addAction(palAct);
281 toolbar->addSeparator();
282 toolbar->addAction(blurAct);
283 toolbar->addAction(fullScreenAct);
285 if (vjs.hardwareTypeAlpine)
287 debugbar = addToolBar(tr("&Debug"));
288 debugbar->addAction(memBrowseAct);
289 debugbar->addAction(cpuBrowseAct);
290 debugbar->addAction(opBrowseAct);
291 debugbar->addAction(m68kDasmBrowseAct);
292 debugbar->addAction(riscDasmBrowseAct);
296 statusBar()->showMessage(tr("Ready"));
300 // Do this in case original size isn't correct (mostly for the first-run case)
303 // Set up timer based loop for animation...
304 timer = new QTimer(this);
305 connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
307 // This isn't very accurate for NTSC: This is early by 40 msec per frame.
308 // This is because it's discarding the 0.6666... on the end of the fraction.
309 // Alas, 6 doesn't divide cleanly into 10. :-P
310 //Should we defer this until SyncUI? Probably.
311 //No, it doesn't work, because it uses setInterval() instead of start()...
312 // timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
314 // We set this initially, to make VJ behave somewhat as it would if no
315 // cart were inserted and the BIOS was set as active...
316 jaguarCartInserted = true;
317 WriteLog("Virtual Jaguar %s (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
318 WriteLog("VJ: Initializing jaguar subsystem...\n");
320 // memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
321 memcpy(jagMemSpace + 0xE00000, (vjs.biosType == BT_K_SERIES ? jaguarBootROM : jaguarBootROM2), 0x20000); // Use the stock BIOS
323 // Prevent the file scanner from running if filename passed
324 // in on the command line...
328 // Load up the default ROM if in Alpine mode:
329 if (vjs.hardwareTypeAlpine)
331 bool romLoaded = JaguarLoadFile(vjs.alpineROMPath);
333 // If regular load failed, try just a straight file load
334 // (Dev only! I don't want people to start getting lazy with their releases again! :-P)
336 romLoaded = AlpineLoadFile(vjs.alpineROMPath);
339 WriteLog("Alpine Mode: Successfully loaded file \"%s\".\n", vjs.alpineROMPath);
341 WriteLog("Alpine Mode: Unable to load file \"%s\"!\n", vjs.alpineROMPath);
343 // Attempt to load/run the ABS file...
344 LoadSoftware(vjs.absROMPath);
345 memcpy(jagMemSpace + 0xE00000, jaguarDevBootROM2, 0x20000); // Use the stub BIOS
346 // Prevent the scanner from running...
350 // memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Otherwise, use the stock BIOS
352 // Run the scanner if nothing passed in and *not* Alpine mode...
353 // NB: Really need to look into caching the info scanned in here...
354 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
358 void MainWin::LoadFile(QString file)
364 void MainWin::SyncUI(void)
366 // Set toolbar buttons/menus based on settings read in (sync the UI)...
367 // (Really, this is to sync command line options passed in)
368 blurAct->setChecked(vjs.glFilter);
369 x1Act->setChecked(zoomLevel == 1);
370 x2Act->setChecked(zoomLevel == 2);
371 x3Act->setChecked(zoomLevel == 3);
372 // running = powerAct->isChecked();
373 ntscAct->setChecked(vjs.hardwareTypeNTSC);
374 palAct->setChecked(!vjs.hardwareTypeNTSC);
375 powerAct->setIcon(vjs.hardwareTypeNTSC ? powerRed : powerGreen);
377 fullScreenAct->setChecked(vjs.fullscreen);
378 fullScreen = vjs.fullscreen;
379 SetFullScreen(fullScreen);
381 // Reset the timer to be what was set in the command line (if any):
382 // timer->setInterval(vjs.hardwareTypeNTSC ? 16 : 20);
383 timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
387 void MainWin::closeEvent(QCloseEvent * event)
390 // This should only be done by the config dialog
393 event->accept(); // ignore() if can't close for some reason
397 void MainWin::keyPressEvent(QKeyEvent * e)
400 extern bool startM68KTracing;
402 // We ignore the Alt key for now, since it causes problems with the GUI
403 if (e->key() == Qt::Key_Alt)
408 else if (e->key() == Qt::Key_F11)
410 startM68KTracing = true;
416 if (e->key() == Qt::Key_F9)
426 void MainWin::keyReleaseEvent(QKeyEvent * e)
428 // We ignore the Alt key for now, since it causes problems with the GUI
429 if (e->key() == Qt::Key_Alt)
435 HandleKeys(e, false);
439 void MainWin::HandleKeys(QKeyEvent * e, bool state)
441 enum { P1LEFT = 0, P1RIGHT, P1UP, P1DOWN, P2LEFT, P2RIGHT, P2UP, P2DOWN };
442 // We kill bad key combos here, before they can get to the emulator...
443 // This also kills the illegal instruction problem that cropped up in Rayman!
444 // May want to do this by killing the old one instead of ignoring the new one...
445 // Seems to work better that way...
447 // The problem with this approach is that it causes bad results because it doesn't do
448 // any checking of previous states. Need to come up with something better because this
449 // causes problems where the keyboard acts as if it were unresponsive. :-P
451 if ((e->key() == vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
452 || (e->key() == vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
453 || (e->key() == vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
454 || (e->key() == vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U]))
458 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
459 joypad_0_buttons[BUTTON_R] = 0;
460 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
461 joypad_0_buttons[BUTTON_L] = 0;
462 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
463 joypad_0_buttons[BUTTON_D] = 0;
464 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U])
465 joypad_0_buttons[BUTTON_U] = 0;
467 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L] && joypad_1_buttons[BUTTON_R])
468 joypad_1_buttons[BUTTON_R] = 0;
469 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R] && joypad_1_buttons[BUTTON_L])
470 joypad_1_buttons[BUTTON_L] = 0;
471 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U] && joypad_1_buttons[BUTTON_D])
472 joypad_1_buttons[BUTTON_D] = 0;
473 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D] && joypad_1_buttons[BUTTON_U])
474 joypad_1_buttons[BUTTON_U] = 0;
476 //hrm, this still has sticky state problems... Ugh!
477 // First, settle key states...
478 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L])
479 keyHeld[P1LEFT] = state;
480 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R])
481 keyHeld[P1RIGHT] = state;
482 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U])
483 keyHeld[P1UP] = state;
484 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D])
485 keyHeld[P1DOWN] = state;
486 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L])
487 keyHeld[P2LEFT] = state;
488 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R])
489 keyHeld[P2RIGHT] = state;
490 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U])
491 keyHeld[P2UP] = state;
492 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D])
493 keyHeld[P2DOWN] = state;
495 // Next, check for conflicts and bail out if there are any...
496 if ((keyHeld[P1LEFT] && keyHeld[P1RIGHT])
497 || (keyHeld[P1UP] && keyHeld[P1DOWN])
498 || (keyHeld[P2LEFT] && keyHeld[P2RIGHT])
499 || (keyHeld[P2UP] && keyHeld[P2DOWN]))
504 // No bad combos exist, let's stuff the emulator key buffers...!
505 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
507 if (e->key() == (int)vjs.p1KeyBindings[i])
508 // joypad_0_buttons[i] = (uint8)state;
509 joypad_0_buttons[i] = (state ? 0x01 : 0x00);
511 // Pad #2 is screwing up pad #1. Prolly a problem in joystick.cpp...
512 // So let's try to fix it there. :-P [DONE]
513 if (e->key() == (int)vjs.p2KeyBindings[i])
514 // joypad_1_buttons[i] = (uint8)state;
515 joypad_1_buttons[i] = (state ? 0x01 : 0x00);
520 void MainWin::HandleGamepads(void)
524 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
526 if (vjs.p1KeyBindings[i] & (JOY_BUTTON | JOY_HAT))
527 joypad_0_buttons[i] = (Gamepad::GetState(0, vjs.p1KeyBindings[i]) ? 0x01 : 0x00);
529 if (vjs.p2KeyBindings[i] & (JOY_BUTTON | JOY_HAT))
530 joypad_1_buttons[i] = (Gamepad::GetState(1, vjs.p2KeyBindings[i]) ? 0x01 : 0x00);
535 void MainWin::Open(void)
540 void MainWin::Configure(void)
542 // Call the configuration dialog and update settings
543 ConfigDialog dlg(this);
545 dlg.generalTab->useUnknownSoftware->setChecked(allowUnknownSoftware);
547 if (dlg.exec() == false)
550 QString before = vjs.ROMPath;
551 QString alpineBefore = vjs.alpineROMPath;
552 QString absBefore = vjs.absROMPath;
553 // bool audioBefore = vjs.audioEnabled;
554 bool audioBefore = vjs.DSPEnabled;
555 dlg.UpdateVJSettings();
556 QString after = vjs.ROMPath;
557 QString alpineAfter = vjs.alpineROMPath;
558 QString absAfter = vjs.absROMPath;
559 // bool audioAfter = vjs.audioEnabled;
560 bool audioAfter = vjs.DSPEnabled;
562 bool allowOld = allowUnknownSoftware;
564 allowUnknownSoftware = dlg.generalTab->useUnknownSoftware->isChecked();
566 // We rescan the "software" folder if the user either changed the path or
567 // checked/unchecked the "Allow unknown files" option in the config dialog.
568 if ((before != after) || (allowOld != allowUnknownSoftware))
569 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
571 // If the "Alpine" ROM is changed, then let's load it...
572 if (alpineBefore != alpineAfter)
574 if (!JaguarLoadFile(vjs.alpineROMPath) && !AlpineLoadFile(vjs.alpineROMPath))
576 // Oh crap, we couldn't get the file! Alert the media!
578 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.alpineROMPath));
579 msg.setIcon(QMessageBox::Warning);
584 // If the "ABS" ROM is changed, then let's load it...
585 if (absBefore != absAfter)
587 if (!JaguarLoadFile(vjs.absROMPath))
589 // Oh crap, we couldn't get the file! Alert the media!
591 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.absROMPath));
592 msg.setIcon(QMessageBox::Warning);
597 // If the "Enable DSP" checkbox changed, then we have to re-init the DAC,
598 // since it's running in the host audio IRQ...
599 if (audioBefore != audioAfter)
605 // Just in case we crash before a clean exit...
611 // Here's the main emulator loop
613 void MainWin::Timer(void)
618 if (showUntunedTankCircuit)
620 // Some machines can't handle this, so we give them the option to disable it. :-)
621 #warning "!!! Add test pattern here for -z option !!!"
622 // Actually, should put test pattern in buffer in function below :-P
623 if (!plzDontKillMyComputer)
625 // Random hash & trash
626 // We try to simulate an untuned tank circuit here... :-)
627 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
629 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
631 videoWidget->buffer[(y * videoWidget->textureWidth) + x]
632 = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;
639 // Otherwise, run the Jaguar simulation
644 videoWidget->updateGL();
648 void MainWin::TogglePowerState(void)
650 powerButtonOn = !powerButtonOn;
653 // With the power off, we simulate white noise on the screen. :-)
656 useCDAct->setDisabled(false);
657 palAct->setDisabled(false);
658 ntscAct->setDisabled(false);
659 pauseAct->setChecked(false);
660 pauseAct->setDisabled(true);
661 showUntunedTankCircuit = true;
662 // This is just in case the ROM we were playing was in a narrow or wide field mode,
663 // so the untuned tank sim doesn't look wrong. :-)
664 DACPauseAudioThread();
669 useCDAct->setDisabled(true);
670 palAct->setDisabled(true);
671 ntscAct->setDisabled(true);
672 pauseAct->setChecked(false);
673 pauseAct->setDisabled(false);
674 showUntunedTankCircuit = false;
676 // Otherwise, we prepare for running regular software...
679 // Should check for cartridgeLoaded here as well...!
680 // We can clear it when toggling CDActive on, so that when we power cycle it does the
681 // expected thing. Otherwise, if we use the file picker to insert a cart, we expect
682 // to run the cart! Maybe have a RemoveCart function that only works if the CD unit
684 setWindowTitle(QString("Virtual Jaguar " VJ_RELEASE_VERSION
685 " - Now playing: Jaguar CD"));
688 WriteLog("GUI: Resetting Jaguar...\n");
690 DACPauseAudioThread(false);
695 void MainWin::ToggleRunState(void)
701 for(uint32_t i=0; i<(uint32_t)(videoWidget->textureWidth * 256); i++)
703 uint32_t pixel = videoWidget->buffer[i];
704 uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
705 pixel = ((r + g + b) / 3) & 0x00FF;
706 videoWidget->buffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
709 videoWidget->updateGL();
712 // Pause/unpause any running/non-running threads...
713 DACPauseAudioThread(!running);
717 void MainWin::SetZoom100(void)
724 void MainWin::SetZoom200(void)
731 void MainWin::SetZoom300(void)
738 void MainWin::SetNTSC(void)
740 powerAct->setIcon(powerRed);
741 timer->setInterval(16);
742 vjs.hardwareTypeNTSC = true;
748 void MainWin::SetPAL(void)
750 powerAct->setIcon(powerGreen);
751 timer->setInterval(20);
752 vjs.hardwareTypeNTSC = false;
758 void MainWin::ToggleBlur(void)
760 vjs.glFilter = !vjs.glFilter;
765 void MainWin::ShowAboutWin(void)
771 void MainWin::ShowHelpWin(void)
777 void MainWin::InsertCart(void)
779 // If the emulator is running, we pause it here and unpause it later
780 // if we dismiss the file selector without choosing anything
781 if (running && powerButtonOn)
784 pauseForFileSelector = true;
791 void MainWin::Unpause(void)
793 // Here we unpause the emulator if it was paused when we went into the file selector
794 if (pauseForFileSelector)
796 pauseForFileSelector = false;
798 // Some nutter might have unpaused while in the file selector, so check for that
805 void MainWin::LoadSoftware(QString file)
807 running = false; // Prevent bad things(TM) from happening...
808 pauseForFileSelector = false; // Reset the file selector pause flag
809 SET32(jaguarMainRAM, 0, 0x00200000); // Set top of stack...
810 cartridgeLoaded = JaguarLoadFile(file.toAscii().data());
812 char * biosPointer = jaguarBootROM;
814 if (vjs.hardwareTypeAlpine)
815 biosPointer = jaguarDevBootROM2;
817 memcpy(jagMemSpace + 0xE00000, biosPointer, 0x20000);
819 powerAct->setDisabled(false);
820 powerAct->setChecked(true);
821 powerButtonOn = false;
824 if (!vjs.hardwareTypeAlpine && !loadAndGo)
826 QString newTitle = QString("Virtual Jaguar " VJ_RELEASE_VERSION " - Now playing: %1")
827 .arg(filePickWin->GetSelectedPrettyName());
828 setWindowTitle(newTitle);
833 void MainWin::ToggleCDUsage(void)
835 CDActive = !CDActive;
837 // Set up the Jaguar CD for execution, otherwise, clear memory
839 memcpy(jagMemSpace + 0x800000, jaguarCDBootROM, 0x40000);
841 memset(jagMemSpace + 0x800000, 0xFF, 0x40000);
845 void MainWin::FrameAdvance(void)
847 //printf("Frame Advance...\n");
848 // Execute 1 frame, then exit (only useful in Pause mode)
850 videoWidget->updateGL();
854 void MainWin::SetFullScreen(bool state/*= true*/)
858 mainWinPosition = pos();
859 // mainWinSize = size();
862 x1Act->setDisabled(true);
863 x2Act->setDisabled(true);
864 x3Act->setDisabled(true);
866 // This is needed because the fullscreen may happen on a different
867 // screen than screen 0:
868 int screenNum = QApplication::desktop()->screenNumber(videoWidget);
869 QRect r = QApplication::desktop()->availableGeometry(screenNum);
870 // double targetWidth = 320.0, targetHeight = (vjs.hardwareTypeNTSC ? 240.0 : 256.0);
871 double targetWidth = (double)VIRTUAL_SCREEN_WIDTH,
872 targetHeight = (double)(vjs.hardwareTypeNTSC ? VIRTUAL_SCREEN_HEIGHT_NTSC : VIRTUAL_SCREEN_HEIGHT_PAL);
873 double aspectRatio = targetWidth / targetHeight;
874 // NOTE: Really should check here to see which dimension constrains the other.
875 // Right now, we assume that height is the constraint.
876 int newWidth = (int)(aspectRatio * (double)r.height());
877 videoWidget->offset = (r.width() - newWidth) / 2;
878 videoWidget->fullscreen = true;
879 videoWidget->outputWidth = newWidth;
881 // videoWidget->setFixedSize(newWidth, r.height());
882 videoWidget->setFixedSize(r.width(), r.height());
887 // Reset the video widget to windowed mode
888 videoWidget->offset = 0;
889 videoWidget->fullscreen = false;
890 x1Act->setDisabled(false);
891 x2Act->setDisabled(false);
892 x3Act->setDisabled(false);
897 move(mainWinPosition);
900 // For some reason, this doesn't work: If the emu is paused, toggling from
901 // fullscreen to windowed (& vice versa) shows a white screen.
902 // videoWidget->updateGL();
906 void MainWin::ToggleFullScreen(void)
908 fullScreen = !fullScreen;
909 SetFullScreen(fullScreen);
913 void MainWin::ShowMemoryBrowserWin(void)
915 memBrowseWin->show();
916 memBrowseWin->RefreshContents();
920 void MainWin::ShowCPUBrowserWin(void)
922 cpuBrowseWin->show();
923 cpuBrowseWin->RefreshContents();
927 void MainWin::ShowOPBrowserWin(void)
930 opBrowseWin->RefreshContents();
934 void MainWin::ShowM68KDasmBrowserWin(void)
936 m68kDasmBrowseWin->show();
937 m68kDasmBrowseWin->RefreshContents();
941 void MainWin::ShowRISCDasmBrowserWin(void)
943 riscDasmBrowseWin->show();
944 riscDasmBrowseWin->RefreshContents();
948 void MainWin::ResizeMainWindow(void)
950 // videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
951 videoWidget->setFixedSize(zoomLevel * VIRTUAL_SCREEN_WIDTH,
952 zoomLevel * (vjs.hardwareTypeNTSC ? VIRTUAL_SCREEN_HEIGHT_NTSC : VIRTUAL_SCREEN_HEIGHT_PAL));
955 for(int i=0; i<2; i++)
959 QApplication::processEvents();
964 #warning "!!! Need to check the window geometry to see if the positions are legal !!!"
965 // i.e., someone could drag it to another screen, close it, then disconnect that screen
966 void MainWin::ReadSettings(void)
968 QSettings settings("Underground Software", "Virtual Jaguar");
969 mainWinPosition = settings.value("pos", QPoint(200, 200)).toPoint();
970 QSize size = settings.value("size", QSize(400, 400)).toSize();
972 move(mainWinPosition);
973 QPoint pos = settings.value("cartLoadPos", QPoint(200, 200)).toPoint();
974 filePickWin->move(pos);
976 zoomLevel = settings.value("zoom", 2).toInt();
977 allowUnknownSoftware = settings.value("showUnknownSoftware", false).toBool();
979 vjs.useJoystick = settings.value("useJoystick", false).toBool();
980 vjs.joyport = settings.value("joyport", 0).toInt();
981 vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
982 vjs.frameSkip = settings.value("frameSkip", 0).toInt();
983 vjs.useJaguarBIOS = settings.value("useJaguarBIOS", false).toBool();
984 vjs.GPUEnabled = settings.value("GPUEnabled", true).toBool();
985 vjs.DSPEnabled = settings.value("DSPEnabled", false).toBool();
986 vjs.audioEnabled = settings.value("audioEnabled", true).toBool();
987 vjs.usePipelinedDSP = settings.value("usePipelinedDSP", false).toBool();
988 vjs.fullscreen = settings.value("fullscreen", false).toBool();
989 vjs.useOpenGL = settings.value("useOpenGL", true).toBool();
990 vjs.glFilter = settings.value("glFilterType", 1).toInt();
991 vjs.renderType = settings.value("renderType", 0).toInt();
992 vjs.allowWritesToROM = settings.value("writeROM", false).toBool();
993 vjs.biosType = settings.value("biosType", BT_M_SERIES).toInt();
994 strcpy(vjs.EEPROMPath, settings.value("EEPROMs", "./eeproms/").toString().toAscii().data());
995 strcpy(vjs.ROMPath, settings.value("ROMs", "./software/").toString().toAscii().data());
996 strcpy(vjs.alpineROMPath, settings.value("DefaultROM", "").toString().toAscii().data());
997 strcpy(vjs.absROMPath, settings.value("DefaultABS", "").toString().toAscii().data());
999 WriteLog("MainWin: Paths\n");
1000 WriteLog(" EEPROMPath = \"%s\"\n", vjs.EEPROMPath);
1001 WriteLog(" ROMPath = \"%s\"\n", vjs.ROMPath);
1002 WriteLog("AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);
1003 WriteLog(" absROMPath = \"%s\"\n", vjs.absROMPath);
1004 WriteLog("Pipelined DSP = %s\n", (vjs.usePipelinedDSP ? "ON" : "off"));
1006 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
1007 vjs.p1KeyBindings[BUTTON_U] = settings.value("p1k_up", Qt::Key_S).toInt();
1008 vjs.p1KeyBindings[BUTTON_D] = settings.value("p1k_down", Qt::Key_X).toInt();
1009 vjs.p1KeyBindings[BUTTON_L] = settings.value("p1k_left", Qt::Key_A).toInt();
1010 vjs.p1KeyBindings[BUTTON_R] = settings.value("p1k_right", Qt::Key_D).toInt();
1011 vjs.p1KeyBindings[BUTTON_C] = settings.value("p1k_c", Qt::Key_J).toInt();
1012 vjs.p1KeyBindings[BUTTON_B] = settings.value("p1k_b", Qt::Key_K).toInt();
1013 vjs.p1KeyBindings[BUTTON_A] = settings.value("p1k_a", Qt::Key_L).toInt();
1014 vjs.p1KeyBindings[BUTTON_OPTION] = settings.value("p1k_option", Qt::Key_O).toInt();
1015 vjs.p1KeyBindings[BUTTON_PAUSE] = settings.value("p1k_pause", Qt::Key_P).toInt();
1016 vjs.p1KeyBindings[BUTTON_0] = settings.value("p1k_0", Qt::Key_0).toInt();
1017 vjs.p1KeyBindings[BUTTON_1] = settings.value("p1k_1", Qt::Key_1).toInt();
1018 vjs.p1KeyBindings[BUTTON_2] = settings.value("p1k_2", Qt::Key_2).toInt();
1019 vjs.p1KeyBindings[BUTTON_3] = settings.value("p1k_3", Qt::Key_3).toInt();
1020 vjs.p1KeyBindings[BUTTON_4] = settings.value("p1k_4", Qt::Key_4).toInt();
1021 vjs.p1KeyBindings[BUTTON_5] = settings.value("p1k_5", Qt::Key_5).toInt();
1022 vjs.p1KeyBindings[BUTTON_6] = settings.value("p1k_6", Qt::Key_6).toInt();
1023 vjs.p1KeyBindings[BUTTON_7] = settings.value("p1k_7", Qt::Key_7).toInt();
1024 vjs.p1KeyBindings[BUTTON_8] = settings.value("p1k_8", Qt::Key_8).toInt();
1025 vjs.p1KeyBindings[BUTTON_9] = settings.value("p1k_9", Qt::Key_9).toInt();
1026 vjs.p1KeyBindings[BUTTON_d] = settings.value("p1k_pound", Qt::Key_Minus).toInt();
1027 vjs.p1KeyBindings[BUTTON_s] = settings.value("p1k_star", Qt::Key_Equal).toInt();
1029 vjs.p2KeyBindings[BUTTON_U] = settings.value("p2k_up", Qt::Key_Up).toInt();
1030 vjs.p2KeyBindings[BUTTON_D] = settings.value("p2k_down", Qt::Key_Down).toInt();
1031 vjs.p2KeyBindings[BUTTON_L] = settings.value("p2k_left", Qt::Key_Left).toInt();
1032 vjs.p2KeyBindings[BUTTON_R] = settings.value("p2k_right", Qt::Key_Right).toInt();
1033 vjs.p2KeyBindings[BUTTON_C] = settings.value("p2k_c", Qt::Key_Z).toInt();
1034 vjs.p2KeyBindings[BUTTON_B] = settings.value("p2k_b", Qt::Key_X).toInt();
1035 vjs.p2KeyBindings[BUTTON_A] = settings.value("p2k_a", Qt::Key_C).toInt();
1036 vjs.p2KeyBindings[BUTTON_OPTION] = settings.value("p2k_option", Qt::Key_Apostrophe).toInt();
1037 vjs.p2KeyBindings[BUTTON_PAUSE] = settings.value("p2k_pause", Qt::Key_Return).toInt();
1038 vjs.p2KeyBindings[BUTTON_0] = settings.value("p2k_0", Qt::Key_0).toInt();
1039 vjs.p2KeyBindings[BUTTON_1] = settings.value("p2k_1", Qt::Key_1).toInt();
1040 vjs.p2KeyBindings[BUTTON_2] = settings.value("p2k_2", Qt::Key_2).toInt();
1041 vjs.p2KeyBindings[BUTTON_3] = settings.value("p2k_3", Qt::Key_3).toInt();
1042 vjs.p2KeyBindings[BUTTON_4] = settings.value("p2k_4", Qt::Key_4).toInt();
1043 vjs.p2KeyBindings[BUTTON_5] = settings.value("p2k_5", Qt::Key_5).toInt();
1044 vjs.p2KeyBindings[BUTTON_6] = settings.value("p2k_6", Qt::Key_6).toInt();
1045 vjs.p2KeyBindings[BUTTON_7] = settings.value("p2k_7", Qt::Key_7).toInt();
1046 vjs.p2KeyBindings[BUTTON_8] = settings.value("p2k_8", Qt::Key_8).toInt();
1047 vjs.p2KeyBindings[BUTTON_9] = settings.value("p2k_9", Qt::Key_9).toInt();
1048 vjs.p2KeyBindings[BUTTON_d] = settings.value("p2k_pound", Qt::Key_Slash).toInt();
1049 vjs.p2KeyBindings[BUTTON_s] = settings.value("p2k_star", Qt::Key_Asterisk).toInt();
1053 void MainWin::WriteSettings(void)
1055 QSettings settings("Underground Software", "Virtual Jaguar");
1056 settings.setValue("pos", pos());
1057 settings.setValue("size", size());
1058 settings.setValue("cartLoadPos", filePickWin->pos());
1060 settings.setValue("zoom", zoomLevel);
1061 settings.setValue("showUnknownSoftware", allowUnknownSoftware);
1063 settings.setValue("useJoystick", vjs.useJoystick);
1064 settings.setValue("joyport", vjs.joyport);
1065 settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
1066 settings.setValue("frameSkip", vjs.frameSkip);
1067 settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
1068 settings.setValue("GPUEnabled", vjs.GPUEnabled);
1069 settings.setValue("DSPEnabled", vjs.DSPEnabled);
1070 settings.setValue("audioEnabled", vjs.audioEnabled);
1071 settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
1072 settings.setValue("fullscreen", vjs.fullscreen);
1073 settings.setValue("useOpenGL", vjs.useOpenGL);
1074 settings.setValue("glFilterType", vjs.glFilter);
1075 settings.setValue("renderType", vjs.renderType);
1076 settings.setValue("writeROM", vjs.allowWritesToROM);
1077 settings.setValue("biosType", vjs.biosType);
1078 settings.setValue("JagBootROM", vjs.jagBootPath);
1079 settings.setValue("CDBootROM", vjs.CDBootPath);
1080 settings.setValue("EEPROMs", vjs.EEPROMPath);
1081 settings.setValue("ROMs", vjs.ROMPath);
1082 settings.setValue("DefaultROM", vjs.alpineROMPath);
1083 settings.setValue("DefaultABS", vjs.absROMPath);
1085 settings.setValue("p1k_up", vjs.p1KeyBindings[BUTTON_U]);
1086 settings.setValue("p1k_down", vjs.p1KeyBindings[BUTTON_D]);
1087 settings.setValue("p1k_left", vjs.p1KeyBindings[BUTTON_L]);
1088 settings.setValue("p1k_right", vjs.p1KeyBindings[BUTTON_R]);
1089 settings.setValue("p1k_c", vjs.p1KeyBindings[BUTTON_C]);
1090 settings.setValue("p1k_b", vjs.p1KeyBindings[BUTTON_B]);
1091 settings.setValue("p1k_a", vjs.p1KeyBindings[BUTTON_A]);
1092 settings.setValue("p1k_option", vjs.p1KeyBindings[BUTTON_OPTION]);
1093 settings.setValue("p1k_pause", vjs.p1KeyBindings[BUTTON_PAUSE]);
1094 settings.setValue("p1k_0", vjs.p1KeyBindings[BUTTON_0]);
1095 settings.setValue("p1k_1", vjs.p1KeyBindings[BUTTON_1]);
1096 settings.setValue("p1k_2", vjs.p1KeyBindings[BUTTON_2]);
1097 settings.setValue("p1k_3", vjs.p1KeyBindings[BUTTON_3]);
1098 settings.setValue("p1k_4", vjs.p1KeyBindings[BUTTON_4]);
1099 settings.setValue("p1k_5", vjs.p1KeyBindings[BUTTON_5]);
1100 settings.setValue("p1k_6", vjs.p1KeyBindings[BUTTON_6]);
1101 settings.setValue("p1k_7", vjs.p1KeyBindings[BUTTON_7]);
1102 settings.setValue("p1k_8", vjs.p1KeyBindings[BUTTON_8]);
1103 settings.setValue("p1k_9", vjs.p1KeyBindings[BUTTON_9]);
1104 settings.setValue("p1k_pound", vjs.p1KeyBindings[BUTTON_d]);
1105 settings.setValue("p1k_star", vjs.p1KeyBindings[BUTTON_s]);
1107 settings.setValue("p2k_up", vjs.p2KeyBindings[BUTTON_U]);
1108 settings.setValue("p2k_down", vjs.p2KeyBindings[BUTTON_D]);
1109 settings.setValue("p2k_left", vjs.p2KeyBindings[BUTTON_L]);
1110 settings.setValue("p2k_right", vjs.p2KeyBindings[BUTTON_R]);
1111 settings.setValue("p2k_c", vjs.p2KeyBindings[BUTTON_C]);
1112 settings.setValue("p2k_b", vjs.p2KeyBindings[BUTTON_B]);
1113 settings.setValue("p2k_a", vjs.p2KeyBindings[BUTTON_A]);
1114 settings.setValue("p2k_option", vjs.p2KeyBindings[BUTTON_OPTION]);
1115 settings.setValue("p2k_pause", vjs.p2KeyBindings[BUTTON_PAUSE]);
1116 settings.setValue("p2k_0", vjs.p2KeyBindings[BUTTON_0]);
1117 settings.setValue("p2k_1", vjs.p2KeyBindings[BUTTON_1]);
1118 settings.setValue("p2k_2", vjs.p2KeyBindings[BUTTON_2]);
1119 settings.setValue("p2k_3", vjs.p2KeyBindings[BUTTON_3]);
1120 settings.setValue("p2k_4", vjs.p2KeyBindings[BUTTON_4]);
1121 settings.setValue("p2k_5", vjs.p2KeyBindings[BUTTON_5]);
1122 settings.setValue("p2k_6", vjs.p2KeyBindings[BUTTON_6]);
1123 settings.setValue("p2k_7", vjs.p2KeyBindings[BUTTON_7]);
1124 settings.setValue("p2k_8", vjs.p2KeyBindings[BUTTON_8]);
1125 settings.setValue("p2k_9", vjs.p2KeyBindings[BUTTON_9]);
1126 settings.setValue("p2k_pound", vjs.p2KeyBindings[BUTTON_d]);
1127 settings.setValue("p2k_star", vjs.p2KeyBindings[BUTTON_s]);
1131 void MainWin::WriteUISettings(void)
1133 QSettings settings("Underground Software", "Virtual Jaguar");
1134 settings.setValue("pos", pos());
1135 settings.setValue("size", size());
1136 settings.setValue("cartLoadPos", filePickWin->pos());
1138 settings.setValue("zoom", zoomLevel);