2 // mainwin.cpp - Qt-based GUI for Virtual Jaguar: Main Application Window
4 // (C) 2009 Underground Software
6 // JLH = James Hammons <jlhamm@acm.org>
9 // --- ---------- -------------------------------------------------------------
10 // JLH 12/23/2009 Created this file
11 // JLH 12/20/2010 Added settings, menus & toolbars
12 // JLH 07/05/2011 Added CD BIOS functionality to GUI
17 // - Add dbl click/enter to select in cart list, ESC to dimiss [DONE]
18 // - Autoscan/autoload all available BIOS from 'software' folder [DONE]
19 // - Add 1 key jumping in cartridge list (press 'R', jumps to carts starting with 'R', etc) [DONE]
20 // - Controller configuration [DONE]
24 // - Remove SDL dependencies (sound, mainly) from Jaguar core lib
25 // - Fix inconsistency with trailing slashes in paths (eeproms needs one, software doesn't)
27 // SFDX CODE: 9XF9TUHFM2359
29 // Uncomment this for debugging...
31 //#define DEBUGFOO // Various tool debugging...
32 //#define DEBUGTP // Toolpalette debugging...
42 #include "filepicker.h"
43 #include "configdialog.h"
44 #include "generaltab.h"
46 #include "debug/memorybrowser.h"
47 #include "debug/cpubrowser.h"
55 #include "jagcdbios.h"
56 #include "jagstub2bios.h"
59 // According to SebRmv, this header isn't seen on Arch Linux either... :-/
61 // Apparently on win32, usleep() is not pulled in by the usual suspects.
65 // The way BSNES controls things is by setting a timer with a zero
66 // timeout, sleeping if not emulating anything. Seems there has to be a
69 // It has a novel approach to plugging-in/using different video/audio/input
70 // methods, can we do something similar or should we just use the built-in
73 // We're going to try to use the built-in OpenGL support and see how it goes.
74 // We'll make the VJ core modular so that it doesn't matter what GUI is in
75 // use, we can drop it in anywhere and use it as-is.
77 //MainWin::MainWin(QString filenameToRun): running(true), powerButtonOn(false),
78 MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
79 showUntunedTankCircuit(true), cartridgeLoaded(false), CDActive(false),
80 //, alpineLoadSuccessful(false),
81 // pauseForFileSelector(false), loadAndGo(false), plzDontKillMyComputer(false)
82 pauseForFileSelector(false), loadAndGo(autoRun), plzDontKillMyComputer(false)
84 for(int i=0; i<8; i++)
87 videoWidget = new GLWidget(this);
88 setCentralWidget(videoWidget);
89 setWindowIcon(QIcon(":/res/vj-icon.png"));
91 QString title = QString(tr("Virtual Jaguar " VJ_RELEASE_VERSION ));
93 if (vjs.hardwareTypeAlpine)
94 title += QString(tr(" - Alpine Mode"));
96 setWindowTitle(title);
98 aboutWin = new AboutWindow(this);
99 helpWin = new HelpWindow(this);
100 filePickWin = new FilePickerWindow(this);
101 memBrowseWin = new MemoryBrowserWindow(this);
102 cpuBrowseWin = new CPUBrowserWindow(this);
104 videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
105 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
107 setUnifiedTitleAndToolBarOnMac(true);
111 quitAppAct = new QAction(tr("E&xit"), this);
112 // quitAppAct->setShortcuts(QKeySequence::Quit);
113 // quitAppAct->setShortcut(QKeySequence(tr("Alt+x")));
114 quitAppAct->setShortcut(QKeySequence(tr("Ctrl+q")));
115 quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
116 connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
118 powerGreen.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
119 powerGreen.addFile(":/res/power-on-green.png", QSize(), QIcon::Normal, QIcon::On);
120 powerRed.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
121 powerRed.addFile(":/res/power-on-red.png", QSize(), QIcon::Normal, QIcon::On);
123 // powerAct = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
124 powerAct = new QAction(powerGreen, tr("&Power"), this);
125 powerAct->setStatusTip(tr("Powers Jaguar on/off"));
126 powerAct->setCheckable(true);
127 powerAct->setChecked(false);
128 // powerAct->setDisabled(true);
129 connect(powerAct, SIGNAL(triggered()), this, SLOT(TogglePowerState()));
132 pauseIcon.addFile(":/res/pause-off", QSize(), QIcon::Normal, QIcon::Off);
133 pauseIcon.addFile(":/res/pause-on", QSize(), QIcon::Normal, QIcon::On);
134 // pauseAct = new QAction(QIcon(":/res/pause.png"), tr("Pause"), this);
135 pauseAct = new QAction(pauseIcon, tr("Pause"), this);
136 pauseAct->setStatusTip(tr("Toggles the running state"));
137 pauseAct->setCheckable(true);
138 pauseAct->setDisabled(true);
139 pauseAct->setShortcut(QKeySequence(tr("Esc")));
140 connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
142 zoomActs = new QActionGroup(this);
144 x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
145 x1Act->setStatusTip(tr("Set window zoom to 100%"));
146 x1Act->setCheckable(true);
147 connect(x1Act, SIGNAL(triggered()), this, SLOT(SetZoom100()));
149 x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
150 x2Act->setStatusTip(tr("Set window zoom to 200%"));
151 x2Act->setCheckable(true);
152 connect(x2Act, SIGNAL(triggered()), this, SLOT(SetZoom200()));
154 x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
155 x3Act->setStatusTip(tr("Set window zoom to 300%"));
156 x3Act->setCheckable(true);
157 connect(x3Act, SIGNAL(triggered()), this, SLOT(SetZoom300()));
159 tvTypeActs = new QActionGroup(this);
161 ntscAct = new QAction(QIcon(":/res/ntsc.png"), tr("NTSC"), tvTypeActs);
162 ntscAct->setStatusTip(tr("Sets Jaguar to NTSC mode"));
163 ntscAct->setCheckable(true);
164 connect(ntscAct, SIGNAL(triggered()), this, SLOT(SetNTSC()));
166 palAct = new QAction(QIcon(":/res/pal.png"), tr("PAL"), tvTypeActs);
167 palAct->setStatusTip(tr("Sets Jaguar to PAL mode"));
168 palAct->setCheckable(true);
169 connect(palAct, SIGNAL(triggered()), this, SLOT(SetPAL()));
171 blurAct = new QAction(QIcon(":/res/generic.png"), tr("Blur"), this);
172 blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
173 blurAct->setCheckable(true);
174 connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
176 aboutAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&About..."), this);
177 aboutAct->setStatusTip(tr("Blatant self-promotion"));
178 connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
180 helpAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&Contents..."), this);
181 helpAct->setStatusTip(tr("Help is available, if you should need it"));
182 connect(helpAct, SIGNAL(triggered()), this, SLOT(ShowHelpWin()));
184 filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this);
185 filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar"));
186 filePickAct->setShortcut(QKeySequence(tr("Ctrl+i")));
187 connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart()));
189 configAct = new QAction(QIcon(":/res/wrench.png"), tr("&Configure"), this);
190 configAct->setStatusTip(tr("Configure options for Virtual Jaguar"));
191 configAct->setShortcut(QKeySequence(tr("Ctrl+c")));
192 connect(configAct, SIGNAL(triggered()), this, SLOT(Configure()));
194 useCDAct = new QAction(QIcon(":/res/compact-disc.png"), tr("&Use CD Unit"), this);
195 useCDAct->setStatusTip(tr("Use Jaguar Virtual CD unit"));
196 // useCDAct->setShortcut(QKeySequence(tr("Ctrl+c")));
197 useCDAct->setCheckable(true);
198 connect(useCDAct, SIGNAL(triggered()), this, SLOT(ToggleCDUsage()));
200 frameAdvanceAct = new QAction(QIcon(":/res/frame-advance.png"), tr("&Frame Advance"), this);
201 frameAdvanceAct->setShortcut(QKeySequence(tr("F7")));
202 connect(frameAdvanceAct, SIGNAL(triggered()), this, SLOT(FrameAdvance()));
205 memBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("Memory Browser"), this);
206 memBrowseAct->setStatusTip(tr("Shows the Jaguar memory browser window"));
207 // memBrowseAct->setCheckable(true);
208 connect(memBrowseAct, SIGNAL(triggered()), this, SLOT(ShowMemoryBrowserWin()));
210 cpuBrowseAct = new QAction(QIcon(":/res/generic.png"), tr("CPU Browser"), this);
211 cpuBrowseAct->setStatusTip(tr("Shows the Jaguar CPU browser window"));
212 // memBrowseAct->setCheckable(true);
213 connect(cpuBrowseAct, SIGNAL(triggered()), this, SLOT(ShowCPUBrowserWin()));
215 // Misc. connections...
216 connect(filePickWin, SIGNAL(RequestLoad(QString)), this, SLOT(LoadSoftware(QString)));
217 connect(filePickWin, SIGNAL(FilePickerHiding()), this, SLOT(Unpause()));
219 // Create menus & toolbars
221 fileMenu = menuBar()->addMenu(tr("&Jaguar"));
222 fileMenu->addAction(powerAct);
223 fileMenu->addAction(pauseAct);
224 fileMenu->addAction(frameAdvanceAct);
225 fileMenu->addAction(filePickAct);
226 fileMenu->addAction(useCDAct);
227 fileMenu->addAction(configAct);
228 fileMenu->addAction(quitAppAct);
230 if (vjs.hardwareTypeAlpine)
232 debugMenu = menuBar()->addMenu(tr("&Debug"));
233 debugMenu->addAction(memBrowseAct);
234 debugMenu->addAction(cpuBrowseAct);
237 helpMenu = menuBar()->addMenu(tr("&Help"));
238 helpMenu->addAction(helpAct);
239 helpMenu->addAction(aboutAct);
241 toolbar = addToolBar(tr("Stuff"));
242 toolbar->addAction(powerAct);
243 toolbar->addAction(pauseAct);
244 toolbar->addAction(filePickAct);
245 toolbar->addAction(useCDAct);
246 toolbar->addSeparator();
247 toolbar->addAction(x1Act);
248 toolbar->addAction(x2Act);
249 toolbar->addAction(x3Act);
250 toolbar->addSeparator();
251 toolbar->addAction(ntscAct);
252 toolbar->addAction(palAct);
253 toolbar->addSeparator();
254 toolbar->addAction(blurAct);
256 if (vjs.hardwareTypeAlpine)
258 debugbar = addToolBar(tr("&Debug"));
259 debugbar->addAction(memBrowseAct);
260 debugbar->addAction(cpuBrowseAct);
264 statusBar()->showMessage(tr("Ready"));
268 // Do this in case original size isn't correct (mostly for the first-run case)
271 // Set up timer based loop for animation...
272 timer = new QTimer(this);
273 connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
274 //This is only correct for PAL. !!! FIX !!! [DONE]
275 //Use timer->setInterval( int msec ) to fix this on the fly
277 // This isn't very accurate for NTSC: This is early by 40 msec per frame.
278 // This is because it's discarding the 0.6666... on the end of the fraction.
279 // Alas, 6 doesn't divide cleanly into 10. :-P
280 timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
282 // We set this initially, to make VJ behave somewhat as it would if no
283 // cart were inserted and the BIOS was set as active...
284 jaguarCartInserted = true;
285 WriteLog("Virtual Jaguar %s (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
286 WriteLog("VJ: Initializing jaguar subsystem...\n");
288 memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
290 // Check for filename passed in on the command line...
291 // if (!filenameToRun.isEmpty())
295 // Attempt to load/run the file the user passed in...
296 // LoadSoftware(filenameToRun);
297 //// memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
298 // Prevent the file scanner from running...
302 // Load up the default ROM if in Alpine mode:
303 if (vjs.hardwareTypeAlpine)
305 bool romLoaded = JaguarLoadFile(vjs.alpineROMPath);
307 // If regular load failed, try just a straight file load
308 // (Dev only! I don't want people to start getting lazy with their releases again! :-P)
310 romLoaded = AlpineLoadFile(vjs.alpineROMPath);
313 WriteLog("Alpine Mode: Successfully loaded file \"%s\".\n", vjs.alpineROMPath);
315 WriteLog("Alpine Mode: Unable to load file \"%s\"!\n", vjs.alpineROMPath);
317 // Attempt to load/run the ABS file...
318 LoadSoftware(vjs.absROMPath);
319 memcpy(jagMemSpace + 0xE00000, jaguarDevBootROM2, 0x20000); // Use the stub BIOS
320 // Prevent the scanner from running...
324 // memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Otherwise, use the stock BIOS
326 // Run the scanner if nothing passed in and *not* Alpine mode...
327 // NB: Really need to look into caching the info scanned in here...
328 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
332 void MainWin::LoadFile(QString file)
338 void MainWin::SyncUI(void)
340 // Set toolbar buttons/menus based on settings read in (sync the UI)...
341 blurAct->setChecked(vjs.glFilter);
342 x1Act->setChecked(zoomLevel == 1);
343 x2Act->setChecked(zoomLevel == 2);
344 x3Act->setChecked(zoomLevel == 3);
345 // running = powerAct->isChecked();
346 ntscAct->setChecked(vjs.hardwareTypeNTSC);
347 palAct->setChecked(!vjs.hardwareTypeNTSC);
348 powerAct->setIcon(vjs.hardwareTypeNTSC ? powerRed : powerGreen);
352 void MainWin::closeEvent(QCloseEvent * event)
355 // This should only be done by the config dialog
358 event->accept(); // ignore() if can't close for some reason
362 void MainWin::keyPressEvent(QKeyEvent * e)
364 // We ignore the Alt key for now, since it causes problems with the GUI
365 if (e->key() == Qt::Key_Alt)
375 void MainWin::keyReleaseEvent(QKeyEvent * e)
377 // We ignore the Alt key for now, since it causes problems with the GUI
378 if (e->key() == Qt::Key_Alt)
384 HandleKeys(e, false);
388 void MainWin::HandleKeys(QKeyEvent * e, bool state)
390 enum { P1LEFT = 0, P1RIGHT, P1UP, P1DOWN, P2LEFT, P2RIGHT, P2UP, P2DOWN };
391 // We kill bad key combos here, before they can get to the emulator...
392 // This also kills the illegal instruction problem that cropped up in Rayman!
393 // May want to do this by killing the old one instead of ignoring the new one...
394 // Seems to work better that way...
396 // The problem with this approach is that it causes bad results because it doesn't do
397 // any checking of previous states. Need to come up with something better because this
398 // causes problems where the keyboard acts as if it were unresponsive. :-P
400 if ((e->key() == vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
401 || (e->key() == vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
402 || (e->key() == vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
403 || (e->key() == vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U]))
407 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L] && joypad_0_buttons[BUTTON_R])
408 joypad_0_buttons[BUTTON_R] = 0;
409 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R] && joypad_0_buttons[BUTTON_L])
410 joypad_0_buttons[BUTTON_L] = 0;
411 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U] && joypad_0_buttons[BUTTON_D])
412 joypad_0_buttons[BUTTON_D] = 0;
413 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D] && joypad_0_buttons[BUTTON_U])
414 joypad_0_buttons[BUTTON_U] = 0;
416 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L] && joypad_1_buttons[BUTTON_R])
417 joypad_1_buttons[BUTTON_R] = 0;
418 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R] && joypad_1_buttons[BUTTON_L])
419 joypad_1_buttons[BUTTON_L] = 0;
420 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U] && joypad_1_buttons[BUTTON_D])
421 joypad_1_buttons[BUTTON_D] = 0;
422 if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D] && joypad_1_buttons[BUTTON_U])
423 joypad_1_buttons[BUTTON_U] = 0;
425 //hrm, this still has sticky state problems... Ugh!
426 // First, settle key states...
427 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L])
428 keyHeld[P1LEFT] = state;
429 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R])
430 keyHeld[P1RIGHT] = state;
431 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U])
432 keyHeld[P1UP] = state;
433 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D])
434 keyHeld[P1DOWN] = state;
435 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L])
436 keyHeld[P2LEFT] = state;
437 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R])
438 keyHeld[P2RIGHT] = state;
439 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U])
440 keyHeld[P2UP] = state;
441 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D])
442 keyHeld[P2DOWN] = state;
444 // Next, check for conflicts and bail out if there are any...
445 if ((keyHeld[P1LEFT] && keyHeld[P1RIGHT])
446 || (keyHeld[P1UP] && keyHeld[P1DOWN])
447 || (keyHeld[P2LEFT] && keyHeld[P2RIGHT])
448 || (keyHeld[P2UP] && keyHeld[P2DOWN]))
453 // No bad combos exist, let's stuff the emulator key buffers...!
454 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
456 if (e->key() == (int)vjs.p1KeyBindings[i])
457 // joypad_0_buttons[i] = (uint8)state;
458 joypad_0_buttons[i] = (state ? 0x01 : 0x00);
460 // Pad #2 is screwing up pad #1. Prolly a problem in joystick.cpp...
461 // So let's try to fix it there. :-P [DONE]
462 if (e->key() == (int)vjs.p2KeyBindings[i])
463 // joypad_1_buttons[i] = (uint8)state;
464 joypad_1_buttons[i] = (state ? 0x01 : 0x00);
469 void MainWin::Open(void)
474 void MainWin::Configure(void)
476 // Call the configuration dialog and update settings
477 ConfigDialog dlg(this);
479 dlg.generalTab->useUnknownSoftware->setChecked(allowUnknownSoftware);
481 if (dlg.exec() == false)
484 QString before = vjs.ROMPath;
485 QString alpineBefore = vjs.alpineROMPath;
486 QString absBefore = vjs.absROMPath;
487 // bool audioBefore = vjs.audioEnabled;
488 bool audioBefore = vjs.DSPEnabled;
489 dlg.UpdateVJSettings();
490 QString after = vjs.ROMPath;
491 QString alpineAfter = vjs.alpineROMPath;
492 QString absAfter = vjs.absROMPath;
493 // bool audioAfter = vjs.audioEnabled;
494 bool audioAfter = vjs.DSPEnabled;
496 bool allowOld = allowUnknownSoftware;
498 allowUnknownSoftware = dlg.generalTab->useUnknownSoftware->isChecked();
500 // We rescan the "software" folder if the user either changed the path or
501 // checked/unchecked the "Allow unknown files" option in the config dialog.
502 if ((before != after) || (allowOld != allowUnknownSoftware))
503 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
505 // If the "Alpine" ROM is changed, then let's load it...
506 if (alpineBefore != alpineAfter)
508 if (!JaguarLoadFile(vjs.alpineROMPath) && !AlpineLoadFile(vjs.alpineROMPath))
510 // Oh crap, we couldn't get the file! Alert the media!
512 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.alpineROMPath));
513 msg.setIcon(QMessageBox::Warning);
518 // If the "ABS" ROM is changed, then let's load it...
519 if (absBefore != absAfter)
521 if (!JaguarLoadFile(vjs.absROMPath))
523 // Oh crap, we couldn't get the file! Alert the media!
525 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.absROMPath));
526 msg.setIcon(QMessageBox::Warning);
531 // If the "Enable DSP" checkbox changed, then we have to re-init the DAC,
532 // since it's running in the host audio IRQ...
533 if (audioBefore != audioAfter)
539 // Just in case we crash before a clean exit...
545 // Here's the main emulator loop
547 void MainWin::Timer(void)
552 if (showUntunedTankCircuit)
554 // Some machines can't handle this, so we give them the option to disable it. :-)
555 if (!plzDontKillMyComputer)
557 // Random hash & trash
558 // We try to simulate an untuned tank circuit here... :-)
559 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
561 for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
563 videoWidget->buffer[(y * videoWidget->textureWidth) + x]
564 = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;
571 // Otherwise, run the Jaguar simulation
575 videoWidget->updateGL();
579 void MainWin::TogglePowerState(void)
581 powerButtonOn = !powerButtonOn;
584 // With the power off, we simulate white noise on the screen. :-)
587 useCDAct->setDisabled(false);
588 palAct->setDisabled(false);
589 ntscAct->setDisabled(false);
590 pauseAct->setChecked(false);
591 pauseAct->setDisabled(true);
592 showUntunedTankCircuit = true;
593 // This is just in case the ROM we were playing was in a narrow or wide field mode,
594 // so the untuned tank sim doesn't look wrong. :-)
599 useCDAct->setDisabled(true);
600 palAct->setDisabled(true);
601 ntscAct->setDisabled(true);
602 pauseAct->setChecked(false);
603 pauseAct->setDisabled(false);
604 showUntunedTankCircuit = false;
606 // Otherwise, we prepare for running regular software...
609 // Should check for cartridgeLoaded here as well...!
610 // We can clear it when toggling CDActive on, so that when we power cycle it does the
611 // expected thing. Otherwise, if we use the file picker to insert a cart, we expect
612 // to run the cart! Maybe have a RemoveCart function that only works if the CD unit
614 setWindowTitle(QString("Virtual Jaguar " VJ_RELEASE_VERSION
615 " - Now playing: Jaguar CD"));
618 WriteLog("GUI: Resetting Jaguar...\n");
624 void MainWin::ToggleRunState(void)
630 for(uint32_t i=0; i<(uint32_t)(videoWidget->textureWidth * 256); i++)
632 uint32_t pixel = videoWidget->buffer[i];
633 uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
634 pixel = ((r + g + b) / 3) & 0x00FF;
635 videoWidget->buffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
638 videoWidget->updateGL();
643 void MainWin::SetZoom100(void)
650 void MainWin::SetZoom200(void)
657 void MainWin::SetZoom300(void)
664 void MainWin::SetNTSC(void)
666 powerAct->setIcon(powerRed);
667 timer->setInterval(16);
668 vjs.hardwareTypeNTSC = true;
674 void MainWin::SetPAL(void)
676 powerAct->setIcon(powerGreen);
677 timer->setInterval(20);
678 vjs.hardwareTypeNTSC = false;
684 void MainWin::ToggleBlur(void)
686 vjs.glFilter = !vjs.glFilter;
691 void MainWin::ShowAboutWin(void)
697 void MainWin::ShowHelpWin(void)
703 void MainWin::InsertCart(void)
705 // If the emulator is running, we pause it here and unpause it later
706 // if we dismiss the file selector without choosing anything
707 if (running && powerButtonOn)
710 pauseForFileSelector = true;
717 void MainWin::Unpause(void)
719 // Here we unpause the emulator if it was paused when we went into the file selector
720 if (pauseForFileSelector)
722 pauseForFileSelector = false;
724 // Some nutter might have unpaused while in the file selector, so check for that
731 void MainWin::LoadSoftware(QString file)
733 running = false; // Prevent bad things(TM) from happening...
734 pauseForFileSelector = false; // Reset the file selector pause flag
735 SET32(jaguarMainRAM, 0, 0x00200000); // Set top of stack...
736 cartridgeLoaded = JaguarLoadFile(file.toAscii().data());
738 char * biosPointer = jaguarBootROM;
740 if (vjs.hardwareTypeAlpine)
741 biosPointer = jaguarDevBootROM2;
743 memcpy(jagMemSpace + 0xE00000, biosPointer, 0x20000);
745 powerAct->setDisabled(false);
746 powerAct->setChecked(true);
747 powerButtonOn = false;
750 if (!vjs.hardwareTypeAlpine && !loadAndGo)
752 QString newTitle = QString("Virtual Jaguar " VJ_RELEASE_VERSION " - Now playing: %1")
753 .arg(filePickWin->GetSelectedPrettyName());
754 setWindowTitle(newTitle);
759 void MainWin::ToggleCDUsage(void)
761 CDActive = !CDActive;
766 powerAct->setDisabled(false);
770 powerAct->setDisabled(true);
773 // Set up the Jaguar CD for execution, otherwise, clear memory
775 memcpy(jagMemSpace + 0x800000, jaguarCDBootROM, 0x40000);
777 memset(jagMemSpace + 0x800000, 0xFF, 0x40000);
782 void MainWin::FrameAdvance(void)
784 //printf("Frame Advance...\n");
785 // Execute 1 frame, then exit (only useful in Pause mode)
787 videoWidget->updateGL();
791 void MainWin::ShowMemoryBrowserWin(void)
793 memBrowseWin->show();
794 memBrowseWin->RefreshContents();
798 void MainWin::ShowCPUBrowserWin(void)
800 cpuBrowseWin->show();
801 cpuBrowseWin->RefreshContents();
805 void MainWin::ResizeMainWindow(void)
807 videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
810 for(int i=0; i<2; i++)
814 QApplication::processEvents();
819 #warning "!!! Need to check the window geometry to see if the positions are legal !!!"
820 // i.e., someone could drag it to another screen, close it, then disconnect that screen
821 void MainWin::ReadSettings(void)
823 QSettings settings("Underground Software", "Virtual Jaguar");
824 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
825 QSize size = settings.value("size", QSize(400, 400)).toSize();
828 pos = settings.value("cartLoadPos", QPoint(200, 200)).toPoint();
829 filePickWin->move(pos);
831 zoomLevel = settings.value("zoom", 2).toInt();
832 allowUnknownSoftware = settings.value("showUnknownSoftware", false).toBool();
834 vjs.useJoystick = settings.value("useJoystick", false).toBool();
835 vjs.joyport = settings.value("joyport", 0).toInt();
836 vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
837 vjs.frameSkip = settings.value("frameSkip", 0).toInt();
838 vjs.useJaguarBIOS = settings.value("useJaguarBIOS", false).toBool();
839 vjs.GPUEnabled = settings.value("GPUEnabled", true).toBool();
840 vjs.DSPEnabled = settings.value("DSPEnabled", false).toBool();
841 vjs.audioEnabled = settings.value("audioEnabled", true).toBool();
842 vjs.usePipelinedDSP = settings.value("usePipelinedDSP", false).toBool();
843 vjs.fullscreen = settings.value("fullscreen", false).toBool();
844 vjs.useOpenGL = settings.value("useOpenGL", true).toBool();
845 vjs.glFilter = settings.value("glFilterType", 1).toInt();
846 vjs.renderType = settings.value("renderType", 0).toInt();
847 vjs.allowWritesToROM = settings.value("writeROM", false).toBool();
848 // strcpy(vjs.jagBootPath, settings.value("JagBootROM", "./bios/[BIOS] Atari Jaguar (USA, Europe).zip").toString().toAscii().data());
849 // strcpy(vjs.CDBootPath, settings.value("CDBootROM", "./bios/jagcd.rom").toString().toAscii().data());
850 strcpy(vjs.EEPROMPath, settings.value("EEPROMs", "./eeproms/").toString().toAscii().data());
851 strcpy(vjs.ROMPath, settings.value("ROMs", "./software/").toString().toAscii().data());
852 strcpy(vjs.alpineROMPath, settings.value("DefaultROM", "").toString().toAscii().data());
853 strcpy(vjs.absROMPath, settings.value("DefaultABS", "").toString().toAscii().data());
854 WriteLog("MainWin: Paths\n");
855 //WriteLog(" jagBootPath = \"%s\"\n", vjs.jagBootPath);
856 //WriteLog(" CDBootPath = \"%s\"\n", vjs.CDBootPath);
857 WriteLog(" EEPROMPath = \"%s\"\n", vjs.EEPROMPath);
858 WriteLog(" ROMPath = \"%s\"\n", vjs.ROMPath);
859 WriteLog("AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);
860 WriteLog(" absROMPath = \"%s\"\n", vjs.absROMPath);
861 WriteLog("Pipelined DSP = %s\n", (vjs.usePipelinedDSP ? "ON" : "off"));
863 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
864 vjs.p1KeyBindings[BUTTON_U] = settings.value("p1k_up", Qt::Key_S).toInt();
865 vjs.p1KeyBindings[BUTTON_D] = settings.value("p1k_down", Qt::Key_X).toInt();
866 vjs.p1KeyBindings[BUTTON_L] = settings.value("p1k_left", Qt::Key_A).toInt();
867 vjs.p1KeyBindings[BUTTON_R] = settings.value("p1k_right", Qt::Key_D).toInt();
868 vjs.p1KeyBindings[BUTTON_C] = settings.value("p1k_c", Qt::Key_J).toInt();
869 vjs.p1KeyBindings[BUTTON_B] = settings.value("p1k_b", Qt::Key_K).toInt();
870 vjs.p1KeyBindings[BUTTON_A] = settings.value("p1k_a", Qt::Key_L).toInt();
871 vjs.p1KeyBindings[BUTTON_OPTION] = settings.value("p1k_option", Qt::Key_O).toInt();
872 vjs.p1KeyBindings[BUTTON_PAUSE] = settings.value("p1k_pause", Qt::Key_P).toInt();
873 vjs.p1KeyBindings[BUTTON_0] = settings.value("p1k_0", Qt::Key_0).toInt();
874 vjs.p1KeyBindings[BUTTON_1] = settings.value("p1k_1", Qt::Key_1).toInt();
875 vjs.p1KeyBindings[BUTTON_2] = settings.value("p1k_2", Qt::Key_2).toInt();
876 vjs.p1KeyBindings[BUTTON_3] = settings.value("p1k_3", Qt::Key_3).toInt();
877 vjs.p1KeyBindings[BUTTON_4] = settings.value("p1k_4", Qt::Key_4).toInt();
878 vjs.p1KeyBindings[BUTTON_5] = settings.value("p1k_5", Qt::Key_5).toInt();
879 vjs.p1KeyBindings[BUTTON_6] = settings.value("p1k_6", Qt::Key_6).toInt();
880 vjs.p1KeyBindings[BUTTON_7] = settings.value("p1k_7", Qt::Key_7).toInt();
881 vjs.p1KeyBindings[BUTTON_8] = settings.value("p1k_8", Qt::Key_8).toInt();
882 vjs.p1KeyBindings[BUTTON_9] = settings.value("p1k_9", Qt::Key_9).toInt();
883 vjs.p1KeyBindings[BUTTON_d] = settings.value("p1k_pound", Qt::Key_Minus).toInt();
884 vjs.p1KeyBindings[BUTTON_s] = settings.value("p1k_star", Qt::Key_Equal).toInt();
886 vjs.p2KeyBindings[BUTTON_U] = settings.value("p2k_up", Qt::Key_Up).toInt();
887 vjs.p2KeyBindings[BUTTON_D] = settings.value("p2k_down", Qt::Key_Down).toInt();
888 vjs.p2KeyBindings[BUTTON_L] = settings.value("p2k_left", Qt::Key_Left).toInt();
889 vjs.p2KeyBindings[BUTTON_R] = settings.value("p2k_right", Qt::Key_Right).toInt();
890 vjs.p2KeyBindings[BUTTON_C] = settings.value("p2k_c", Qt::Key_Z).toInt();
891 vjs.p2KeyBindings[BUTTON_B] = settings.value("p2k_b", Qt::Key_X).toInt();
892 vjs.p2KeyBindings[BUTTON_A] = settings.value("p2k_a", Qt::Key_C).toInt();
893 vjs.p2KeyBindings[BUTTON_OPTION] = settings.value("p2k_option", Qt::Key_Apostrophe).toInt();
894 vjs.p2KeyBindings[BUTTON_PAUSE] = settings.value("p2k_pause", Qt::Key_Return).toInt();
895 vjs.p2KeyBindings[BUTTON_0] = settings.value("p2k_0", Qt::Key_0).toInt();
896 vjs.p2KeyBindings[BUTTON_1] = settings.value("p2k_1", Qt::Key_1).toInt();
897 vjs.p2KeyBindings[BUTTON_2] = settings.value("p2k_2", Qt::Key_2).toInt();
898 vjs.p2KeyBindings[BUTTON_3] = settings.value("p2k_3", Qt::Key_3).toInt();
899 vjs.p2KeyBindings[BUTTON_4] = settings.value("p2k_4", Qt::Key_4).toInt();
900 vjs.p2KeyBindings[BUTTON_5] = settings.value("p2k_5", Qt::Key_5).toInt();
901 vjs.p2KeyBindings[BUTTON_6] = settings.value("p2k_6", Qt::Key_6).toInt();
902 vjs.p2KeyBindings[BUTTON_7] = settings.value("p2k_7", Qt::Key_7).toInt();
903 vjs.p2KeyBindings[BUTTON_8] = settings.value("p2k_8", Qt::Key_8).toInt();
904 vjs.p2KeyBindings[BUTTON_9] = settings.value("p2k_9", Qt::Key_9).toInt();
905 vjs.p2KeyBindings[BUTTON_d] = settings.value("p2k_pound", Qt::Key_Slash).toInt();
906 vjs.p2KeyBindings[BUTTON_s] = settings.value("p2k_star", Qt::Key_Asterisk).toInt();
910 void MainWin::WriteSettings(void)
912 QSettings settings("Underground Software", "Virtual Jaguar");
913 settings.setValue("pos", pos());
914 settings.setValue("size", size());
915 settings.setValue("cartLoadPos", filePickWin->pos());
917 settings.setValue("zoom", zoomLevel);
918 settings.setValue("showUnknownSoftware", allowUnknownSoftware);
920 settings.setValue("useJoystick", vjs.useJoystick);
921 settings.setValue("joyport", vjs.joyport);
922 settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
923 settings.setValue("frameSkip", vjs.frameSkip);
924 settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
925 settings.setValue("GPUEnabled", vjs.GPUEnabled);
926 settings.setValue("DSPEnabled", vjs.DSPEnabled);
927 settings.setValue("audioEnabled", vjs.audioEnabled);
928 settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
929 settings.setValue("fullscreen", vjs.fullscreen);
930 settings.setValue("useOpenGL", vjs.useOpenGL);
931 settings.setValue("glFilterType", vjs.glFilter);
932 settings.setValue("renderType", vjs.renderType);
933 settings.setValue("writeROM", vjs.allowWritesToROM);
934 settings.setValue("JagBootROM", vjs.jagBootPath);
935 settings.setValue("CDBootROM", vjs.CDBootPath);
936 settings.setValue("EEPROMs", vjs.EEPROMPath);
937 settings.setValue("ROMs", vjs.ROMPath);
938 settings.setValue("DefaultROM", vjs.alpineROMPath);
939 settings.setValue("DefaultABS", vjs.absROMPath);
941 settings.setValue("p1k_up", vjs.p1KeyBindings[BUTTON_U]);
942 settings.setValue("p1k_down", vjs.p1KeyBindings[BUTTON_D]);
943 settings.setValue("p1k_left", vjs.p1KeyBindings[BUTTON_L]);
944 settings.setValue("p1k_right", vjs.p1KeyBindings[BUTTON_R]);
945 settings.setValue("p1k_c", vjs.p1KeyBindings[BUTTON_C]);
946 settings.setValue("p1k_b", vjs.p1KeyBindings[BUTTON_B]);
947 settings.setValue("p1k_a", vjs.p1KeyBindings[BUTTON_A]);
948 settings.setValue("p1k_option", vjs.p1KeyBindings[BUTTON_OPTION]);
949 settings.setValue("p1k_pause", vjs.p1KeyBindings[BUTTON_PAUSE]);
950 settings.setValue("p1k_0", vjs.p1KeyBindings[BUTTON_0]);
951 settings.setValue("p1k_1", vjs.p1KeyBindings[BUTTON_1]);
952 settings.setValue("p1k_2", vjs.p1KeyBindings[BUTTON_2]);
953 settings.setValue("p1k_3", vjs.p1KeyBindings[BUTTON_3]);
954 settings.setValue("p1k_4", vjs.p1KeyBindings[BUTTON_4]);
955 settings.setValue("p1k_5", vjs.p1KeyBindings[BUTTON_5]);
956 settings.setValue("p1k_6", vjs.p1KeyBindings[BUTTON_6]);
957 settings.setValue("p1k_7", vjs.p1KeyBindings[BUTTON_7]);
958 settings.setValue("p1k_8", vjs.p1KeyBindings[BUTTON_8]);
959 settings.setValue("p1k_9", vjs.p1KeyBindings[BUTTON_9]);
960 settings.setValue("p1k_pound", vjs.p1KeyBindings[BUTTON_d]);
961 settings.setValue("p1k_star", vjs.p1KeyBindings[BUTTON_s]);
963 settings.setValue("p2k_up", vjs.p2KeyBindings[BUTTON_U]);
964 settings.setValue("p2k_down", vjs.p2KeyBindings[BUTTON_D]);
965 settings.setValue("p2k_left", vjs.p2KeyBindings[BUTTON_L]);
966 settings.setValue("p2k_right", vjs.p2KeyBindings[BUTTON_R]);
967 settings.setValue("p2k_c", vjs.p2KeyBindings[BUTTON_C]);
968 settings.setValue("p2k_b", vjs.p2KeyBindings[BUTTON_B]);
969 settings.setValue("p2k_a", vjs.p2KeyBindings[BUTTON_A]);
970 settings.setValue("p2k_option", vjs.p2KeyBindings[BUTTON_OPTION]);
971 settings.setValue("p2k_pause", vjs.p2KeyBindings[BUTTON_PAUSE]);
972 settings.setValue("p2k_0", vjs.p2KeyBindings[BUTTON_0]);
973 settings.setValue("p2k_1", vjs.p2KeyBindings[BUTTON_1]);
974 settings.setValue("p2k_2", vjs.p2KeyBindings[BUTTON_2]);
975 settings.setValue("p2k_3", vjs.p2KeyBindings[BUTTON_3]);
976 settings.setValue("p2k_4", vjs.p2KeyBindings[BUTTON_4]);
977 settings.setValue("p2k_5", vjs.p2KeyBindings[BUTTON_5]);
978 settings.setValue("p2k_6", vjs.p2KeyBindings[BUTTON_6]);
979 settings.setValue("p2k_7", vjs.p2KeyBindings[BUTTON_7]);
980 settings.setValue("p2k_8", vjs.p2KeyBindings[BUTTON_8]);
981 settings.setValue("p2k_9", vjs.p2KeyBindings[BUTTON_9]);
982 settings.setValue("p2k_pound", vjs.p2KeyBindings[BUTTON_d]);
983 settings.setValue("p2k_star", vjs.p2KeyBindings[BUTTON_s]);
987 void MainWin::WriteUISettings(void)
989 QSettings settings("Underground Software", "Virtual Jaguar");
990 settings.setValue("pos", pos());
991 settings.setValue("size", size());
992 settings.setValue("cartLoadPos", filePickWin->pos());
994 settings.setValue("zoom", zoomLevel);