a25fad14c1702e53bb7dcd0d171a4659ad9bd464
[clinton/Virtual-Jaguar-Rx.git] / src / gui / mainwin.cpp
1 //
2 // mainwin.cpp - Qt-based GUI for Virtual Jaguar: Main Application Window
3 // by James Hammons
4 // (C) 2009 Underground Software
5 //
6 // JLH = James Hammons <jlhamm@acm.org>
7 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
8 //
9 // Who When What
10 // --- ---------- ------------------------------------------------------------
11 // JLH 12/23/2009 Created this file
12 // JLH 12/20/2010 Added settings, menus & toolbars
13 // JLH 07/05/2011 Added CD BIOS functionality to GUI
14 // JPM June/2016 Visual Studio support & Soft debugger integration
15 // JPM 01/11/2017 Added stack browser
16 // JPM Feb./2017 Added GPU/DSP disassembly
17 // JPM 07/12/2017 Added all Watch window
18 // JPM Aug./2017 Added heap allocator and memories window, a restart feature, and a [Not Supported] breakpoints window
19 // JPM Sept./2017 Save position, size & visibility windows status in the settings; added Exception Vector Table window, the 'Rx' word to the emulator window name, and the keybindings in the settings
20 // JPM 11/04/2017 Added the local window
21 // JPM 08/31/2018 Added the call stack window
22 // JPM Sept./2018 Added the new Models and BIOS handler, a screenshot feature and source code files browsing
23 // JPM Oct./2018 Added search paths in the settings, breakpoints feature, cartridge view menu
24 // JPM 11/18/2018 Fix crash with non-debugger mode
25 // JPM April/2019 Added ELF sections check, added a save memory dump
26 // JPM Aug./2019 Update texts descriptions, set cartridge view menu for debugger mode only
27 //
28
29 // FIXED:
30 //
31 // - Add dbl click/enter to select in cart list, ESC to dimiss [DONE]
32 // - Autoscan/autoload all available BIOS from 'software' folder [DONE]
33 // - Add 1 key jumping in cartridge list (press 'R', jumps to carts starting
34 // with 'R', etc) [DONE]
35 // - Controller configuration [DONE]
36 //
37 // STILL TO BE DONE:
38 //
39 // - Fix bug in switching between PAL & NTSC in fullscreen mode.
40 // - Remove SDL dependencies (sound, mainly) from Jaguar core lib
41 // - Fix inconsistency with trailing slashes in paths (eeproms needs one,
42 // software doesn't)
43 //
44 // SFDX CODE: S1E9T8H5M23YS
45
46 // Uncomment this for debugging...
47 //#define DEBUG
48 //#define DEBUGFOO // Various tool debugging... but not used
49 //#define DEBUGTP // Toolpalette debugging... but not used
50
51 #include "mainwin.h"
52
53 #include "SDL.h"
54 #include "app.h"
55 #include "about.h"
56 #include "configdialog.h"
57 #include "controllertab.h"
58 #include "keybindingstab.h"
59 #include "filepicker.h"
60 #include "gamepad.h"
61 #include "generaltab.h"
62 #include "glwidget.h"
63 #include "help.h"
64 #include "profile.h"
65 #include "settings.h"
66 #include "version.h"
67 #include "emustatus.h"
68 #include "debug/cpubrowser.h"
69 #include "debug/m68kdasmbrowser.h"
70 #include "debug/memorybrowser.h"
71 #include "debug/stackbrowser.h"
72 #include "debug/opbrowser.h"
73 #include "debug/riscdasmbrowser.h"
74
75 #include "dac.h"
76 #include "jaguar.h"
77 #include "log.h"
78 #include "file.h"
79 #ifndef NEWMODELSBIOSHANDLER
80 #include "jagbios.h"
81 #include "jagbios2.h"
82 #include "jagstub2bios.h"
83 #else
84 #include "modelsBIOS.h"
85 #endif
86 #include "jagcdbios.h"
87 #include "joystick.h"
88 #include "m68000/m68kinterface.h"
89
90 #include "debugger/DBGManager.h"
91 //#include "debugger/VideoWin.h"
92 //#include "debugger/DasmWin.h"
93 #include "debugger/m68KDasmWin.h"
94 #include "debugger/GPUDasmWin.h"
95 #include "debugger/DSPDasmWin.h"
96 #include "debugger/memory1browser.h"
97 #include "debugger/BreakpointsWin.h"
98 #include "debugger/NewFnctBreakpointWin.h"
99 #include "debugger/FilesrcListWin.h"
100 #include "debugger/exceptionvectortablebrowser.h"
101 #include "debugger/allwatchbrowser.h"
102 #include "debugger/localbrowser.h"
103 #include "debugger/heapallocatorbrowser.h"
104 #include "debugger/callstackbrowser.h"
105 #include "debugger/CartFilesListWin.h"
106 #include "debugger/SaveDumpAsWin.h"
107
108
109 // According to SebRmv, this header isn't seen on Arch Linux either... :-/
110 //#ifdef __GCCWIN32__
111 // Apparently on win32, usleep() is not pulled in by the usual suspects.
112 #ifndef _MSC_VER
113 #include <unistd.h>
114 #else
115 #include "_MSC_VER/unistd.h"
116 #endif // !_MSC_VER
117 //#endif
118
119 // The way BSNES controls things is by setting a timer with a zero
120 // timeout, sleeping if not emulating anything. Seems there has to be a
121 // better way.
122
123 // It has a novel approach to plugging-in/using different video/audio/input
124 // methods, can we do something similar or should we just use the built-in
125 // QOpenGL?
126
127 // We're going to try to use the built-in OpenGL support and see how it goes.
128 // We'll make the VJ core modular so that it doesn't matter what GUI is in
129 // use, we can drop it in anywhere and use it as-is.
130
131 MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
132 showUntunedTankCircuit(true), cartridgeLoaded(false), CDActive(false),
133 pauseForFileSelector(false), loadAndGo(autoRun), scannedSoftwareFolder(false), plzDontKillMyComputer(false)
134 {
135 ReadSettings();
136
137 debugbar = NULL;
138
139 for(int i=0; i<8; i++)
140 keyHeld[i] = false;
141
142 // FPS management
143 for(int i=0; i<RING_BUFFER_SIZE; i++)
144 ringBuffer[i] = 0;
145
146 ringBufferPointer = RING_BUFFER_SIZE - 1;
147
148 // main window
149 //if (vjs.softTypeDebugger)
150 //{
151 // mainWindowCentrale = new QMdiArea;
152 // setCentralWidget(mainWindowCentrale);
153 //}
154
155 WriteLog("Window creation start\n");
156
157 // video output
158 videoWidget = new GLWidget(this);
159 videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
160
161 // set central output window
162 if (!vjs.softTypeDebugger)
163 {
164 setCentralWidget(videoWidget);
165 }
166 else
167 {
168 mainWindowCentrale = new QMdiArea(this);
169 setCentralWidget(mainWindowCentrale);
170 }
171
172 setWindowIcon(QIcon(":/res/vj-icon.png"));
173
174 QString title = QString(tr("Virtual Jaguar " VJ_RELEASE_VERSION " Rx"));
175
176 if (vjs.hardwareTypeAlpine)
177 title += QString(tr(" - Alpine Mode"));
178
179 if (vjs.softTypeDebugger)
180 title += QString(tr(" - Debugger Mode"));
181
182 setWindowTitle(title);
183
184 // Windows common features
185 aboutWin = new AboutWindow(this);
186 helpWin = new HelpWindow(this);
187 filePickWin = new FilePickerWindow(this);
188 emuStatusWin = new EmuStatusWindow(this);
189
190 // Windows alpine mode features
191 memBrowseWin = new MemoryBrowserWindow(this);
192 stackBrowseWin = new StackBrowserWindow(this);
193 cpuBrowseWin = new CPUBrowserWindow(this);
194 opBrowseWin = new OPBrowserWindow(this);
195 m68kDasmBrowseWin = new M68KDasmBrowserWindow(this);
196 riscDasmBrowseWin = new RISCDasmBrowserWindow(this);
197
198 // Windows debugger mode features
199 if (vjs.softTypeDebugger)
200 {
201 //VideoOutputWin = new VideoOutputWindow(this);
202 //VideoOutputWin->setCentralWidget()
203 //DasmWin = new DasmWindow();
204 //DasmWin = new DasmWindow(this);
205 allWatchBrowseWin = new AllWatchBrowserWindow(this);
206 LocalBrowseWin = new LocalBrowserWindow(this);
207 heapallocatorBrowseWin = new HeapAllocatorBrowserWindow(this);
208 BreakpointsWin = new BreakpointsWindow(this);
209 NewFunctionBreakpointWin = new NewFnctBreakpointWindow(this);
210 SaveDumpAsWin = new SaveDumpAsWindow(this);
211 exceptionvectortableBrowseWin = new ExceptionVectorTableBrowserWindow(this);
212 CallStackBrowseWin = new CallStackBrowserWindow(this);
213 CartFilesListWin = new CartFilesListWindow(this);
214
215 mem1BrowseWin = (Memory1BrowserWindow **)calloc(vjs.nbrmemory1browserwindow, sizeof(Memory1BrowserWindow));
216 #ifdef _MSC_VER
217 #pragma message("Warning: !!! Need to do the memory desalocation for mem1BrowseWin !!!")
218 #else
219 #warning "!!! Need to do the memory desalocation for mem1BrowseWin !!!"
220 #endif // _MSC_VER
221 for (size_t i = 0; i < vjs.nbrmemory1browserwindow; i++)
222 {
223 mem1BrowseWin[i] = new Memory1BrowserWindow(this);
224 }
225
226 // Setup dock to display source code filenames tree
227 QDockWidget *dockFiles = new QDockWidget(tr("Files"), this);
228 dockFiles->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
229 dockFiles->hide();
230 addDockWidget(Qt::LeftDockWidgetArea, dockFiles);
231 mainWindowCentrale->addAction(dockFiles->toggleViewAction());
232 dockFiles->setWidget(FilesrcListWin = new FilesrcListWindow(this));
233 #if 0
234 // Setup dock to display disassembly
235 QDockWidget *dockDisasm = new QDockWidget(tr("Disassembly"), this);
236 dockDisasm->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
237 addDockWidget(Qt::RightDockWidgetArea, dockDisasm);
238 mainWindowCentrale->addAction(dockDisasm->toggleViewAction());
239 dockDisasm->setWidget(dasmtabWidget = new QTabWidget(this));
240 #else
241 dasmtabWidget = new QTabWidget(this);
242 #endif
243 // Setup disasm tabs
244 dasmtabWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
245 dasmtabWidget->addTab(m68kDasmWin = new m68KDasmWindow(this), tr("M68000"));
246 dasmtabWidget->addTab(GPUDasmWin = new GPUDasmWindow(this), tr("GPU"));
247 dasmtabWidget->addTab(DSPDasmWin = new DSPDasmWindow(this), tr("DSP"));
248 #if 1
249 setCentralWidget(dasmtabWidget);
250 #endif
251 }
252
253 // videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
254 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
255
256 setUnifiedTitleAndToolBarOnMac(true);
257
258 // Quit actions
259 quitAppAct = new QAction(QIcon(":/res/exit.png"), tr("E&xit"), this);
260 quitAppAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBQUIT].KBSettingValue)));
261 quitAppAct->setShortcutContext(Qt::ApplicationShortcut);
262 quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
263 connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
264
265 // Power action
266 powerGreen.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
267 powerGreen.addFile(":/res/power-on-green.png", QSize(), QIcon::Normal, QIcon::On);
268 powerRed.addFile(":/res/power-off.png", QSize(), QIcon::Normal, QIcon::Off);
269 powerRed.addFile(":/res/power-on-red.png", QSize(), QIcon::Normal, QIcon::On);
270 powerAct = new QAction(powerGreen, tr("&Power"), this);
271 powerAct->setStatusTip(tr("Powers Jaguar on/off"));
272 powerAct->setCheckable(true);
273 powerAct->setChecked(false);
274 connect(powerAct, SIGNAL(triggered()), this, SLOT(TogglePowerState()));
275
276 // Pause action
277 QIcon pauseIcon;
278 pauseIcon.addFile(":/res/pause-off.png", QSize(), QIcon::Normal, QIcon::Off);
279 pauseIcon.addFile(":/res/pause-on.png", QSize(), QIcon::Normal, QIcon::On);
280 pauseAct = new QAction(pauseIcon, tr("Pause"), this);
281 pauseAct->setStatusTip(tr("Toggles the running state"));
282 pauseAct->setCheckable(true);
283 pauseAct->setDisabled(true);
284 pauseAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBPAUSE].KBSettingValue)));
285 pauseAct->setShortcutContext(Qt::ApplicationShortcut);
286 connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
287
288 // Screenshot action
289 screenshotAct = new QAction(QIcon(":/res/screenshot.png"), tr("&Screenshot"), this);
290 screenshotAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBSCREENSHOT].KBSettingValue)));
291 screenshotAct->setShortcutContext(Qt::ApplicationShortcut);
292 screenshotAct->setCheckable(false);
293 screenshotAct->setDisabled(false);
294 connect(screenshotAct, SIGNAL(triggered()), this, SLOT(MakeScreenshot()));
295
296 // Zoom actions
297 zoomActs = new QActionGroup(this);
298 x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
299 x1Act->setStatusTip(tr("Set window zoom to 100%"));
300 x1Act->setCheckable(true);
301 connect(x1Act, SIGNAL(triggered()), this, SLOT(SetZoom100()));
302 x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
303 x2Act->setStatusTip(tr("Set window zoom to 200%"));
304 x2Act->setCheckable(true);
305 connect(x2Act, SIGNAL(triggered()), this, SLOT(SetZoom200()));
306 x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
307 x3Act->setStatusTip(tr("Set window zoom to 300%"));
308 x3Act->setCheckable(true);
309 connect(x3Act, SIGNAL(triggered()), this, SLOT(SetZoom300()));
310
311 // TV type actions
312 tvTypeActs = new QActionGroup(this);
313 ntscAct = new QAction(QIcon(":/res/ntsc.png"), tr("NTSC"), tvTypeActs);
314 ntscAct->setStatusTip(tr("Sets Jaguar to NTSC mode"));
315 ntscAct->setCheckable(true);
316 connect(ntscAct, SIGNAL(triggered()), this, SLOT(SetNTSC()));
317 palAct = new QAction(QIcon(":/res/pal.png"), tr("PAL"), tvTypeActs);
318 palAct->setStatusTip(tr("Sets Jaguar to PAL mode"));
319 palAct->setCheckable(true);
320 connect(palAct, SIGNAL(triggered()), this, SLOT(SetPAL()));
321
322 // Blur action
323 blur.addFile(":/res/blur-off.png", QSize(), QIcon::Normal, QIcon::Off);
324 blur.addFile(":/res/blur-on.png", QSize(), QIcon::Normal, QIcon::On);
325 blurAct = new QAction(blur, tr("Blur"), this);
326 blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
327 blurAct->setCheckable(true);
328 connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
329
330 // About action
331 aboutAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&About..."), this);
332 aboutAct->setStatusTip(tr("Blatant self-promotion"));
333 connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
334
335 // Help action
336 helpAct = new QAction(QIcon(":/res/vj-icon.png"), tr("&Contents..."), this);
337 helpAct->setStatusTip(tr("Help is available, if you should need it"));
338 connect(helpAct, SIGNAL(triggered()), this, SLOT(ShowHelpWin()));
339
340 // File pickup action
341 if (!vjs.softTypeDebugger)
342 {
343 filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this);
344 filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar"));
345 }
346 else
347 {
348 filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert executable file..."), this);
349 filePickAct->setStatusTip(tr("Insert an executable into Virtual Jaguar"));
350 }
351 filePickAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBPICKFILE].KBSettingValue)));
352 filePickAct->setShortcutContext(Qt::ApplicationShortcut);
353 connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart()));
354
355 // Configuration action
356 configAct = new QAction(QIcon(":/res/wrench.png"), tr("&Configure"), this);
357 configAct->setStatusTip(tr("Configure options for Virtual Jaguar"));
358 configAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBCONFIGURE].KBSettingValue)));
359 configAct->setShortcutContext(Qt::ApplicationShortcut);
360 connect(configAct, SIGNAL(triggered()), this, SLOT(Configure()));
361
362 // Emulation status action
363 emustatusAct = new QAction(QIcon(":/res/status.png"), tr("&Status"), this);
364 emustatusAct->setStatusTip(tr("Emulator status"));
365 emustatusAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBEMUSTATUS].KBSettingValue)));
366 emustatusAct->setShortcutContext(Qt::ApplicationShortcut);
367 connect(emustatusAct, SIGNAL(triggered()), this, SLOT(ShowEmuStatusWin()));
368
369 // Use CD action
370 useCDAct = new QAction(QIcon(":/res/compact-disc.png"), tr("&Use CD Unit"), this);
371 useCDAct->setStatusTip(tr("Use Jaguar Virtual CD unit"));
372 useCDAct->setCheckable(true);
373 connect(useCDAct, SIGNAL(triggered()), this, SLOT(ToggleCDUsage()));
374
375 // Frame advance action
376 frameAdvanceAct = new QAction(QIcon(":/res/frame-advance.png"), tr("&Frame Advance"), this);
377 frameAdvanceAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBFRAMEADVANCE].KBSettingValue)));
378 frameAdvanceAct->setShortcutContext(Qt::ApplicationShortcut);
379 frameAdvanceAct->setDisabled(true);
380 connect(frameAdvanceAct, SIGNAL(triggered()), this, SLOT(FrameAdvance()));
381
382 // Fullscreen action
383 fullScreenAct = new QAction(QIcon(":/res/fullscreen.png"), tr("F&ull Screen"), this);
384 fullScreenAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBFULLSCREEN].KBSettingValue)));
385 fullScreenAct->setShortcutContext(Qt::ApplicationShortcut);
386 fullScreenAct->setCheckable(true);
387 connect(fullScreenAct, SIGNAL(triggered()), this, SLOT(ToggleFullScreen()));
388
389 // Actions dedicated to debugger mode
390 if (vjs.softTypeDebugger)
391 {
392 // Restart
393 restartAct = new QAction(QIcon(":/res/debug-restart.png"), tr("&Restart"), this);
394 restartAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBRESTART].KBSettingValue)));
395 restartAct->setShortcutContext(Qt::ApplicationShortcut);
396 restartAct->setCheckable(false);
397 restartAct->setDisabled(true);
398 connect(restartAct, SIGNAL(triggered()), this, SLOT(DebuggerRestart()));
399
400 // Step over trace
401 traceStepOverAct = new QAction(QIcon(":/res/debug-stepover.png"), tr("&Step Over"), this);
402 traceStepOverAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBSTEPOVER].KBSettingValue)));
403 traceStepOverAct->setShortcutContext(Qt::ApplicationShortcut);
404 traceStepOverAct->setCheckable(false);
405 traceStepOverAct->setDisabled(true);
406 connect(traceStepOverAct, SIGNAL(triggered()), this, SLOT(DebuggerTraceStepOver()));
407
408 // Trace into tracing
409 traceStepIntoAct = new QAction(QIcon(":/res/debug-stepinto.png"), tr("&Step Into"), this);
410 traceStepIntoAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBSTEPINTO].KBSettingValue)));
411 traceStepIntoAct->setShortcutContext(Qt::ApplicationShortcut);
412 traceStepIntoAct->setCheckable(false);
413 traceStepIntoAct->setDisabled(true);
414 connect(traceStepIntoAct, SIGNAL(triggered()), this, SLOT(DebuggerTraceStepInto()));
415
416 // Function breakpoint
417 newFunctionBreakpointAct = new QAction(QIcon(""), tr("&Function Breakpoint"), this);
418 newFunctionBreakpointAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBFUNCTIONBREAKPOINT].KBSettingValue)));
419 connect(newFunctionBreakpointAct, SIGNAL(triggered()), this, SLOT(ShowNewFunctionBreakpointWin()));
420 BreakpointsAct = new QAction(QIcon(":/res/debug-breakpoints.png"), tr("&Breakpoints"), this);
421 BreakpointsAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBBREAKPOINTS].KBSettingValue)));
422 connect(BreakpointsAct, SIGNAL(triggered()), this, SLOT(ShowBreakpointsWin()));
423 deleteAllBreakpointsAct = new QAction(QIcon(":/res/debug-deleteallbreakpoints.png"), tr("&Delete All Breakpoints"), this);
424 deleteAllBreakpointsAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBDELETEALLBREAKPOINTS].KBSettingValue)));
425 connect(deleteAllBreakpointsAct, SIGNAL(triggered()), this, SLOT(DeleteAllBreakpoints()));
426 disableAllBreakpointsAct = new QAction(QIcon(":/res/debug-disableallbreakpoints.png"), tr("&Disable All Breakpoints"), this);
427 connect(disableAllBreakpointsAct, SIGNAL(triggered()), this, SLOT(DisableAllBreakpoints()));
428
429 // Save dump
430 saveDumpAsAct = new QAction(tr("&Save Dump As..."), this);
431 saveDumpAsAct->setCheckable(false);
432 saveDumpAsAct->setDisabled(false);
433 connect(saveDumpAsAct, SIGNAL(triggered()), this, SLOT(ShowSaveDumpAsWin()));
434
435 //VideoOutputAct = new QAction(tr("Output Video"), this);
436 //VideoOutputAct->setStatusTip(tr("Shows the output video window"));
437 //connect(VideoOutputAct, SIGNAL(triggered()), this, SLOT(ShowVideoOutputWin()));
438
439 //DasmAct = new QAction(tr("Disassembly"), this);
440 //DasmAct->setStatusTip(tr("Shows the disassembly window"));
441 //connect(DasmAct, SIGNAL(triggered()), this, SLOT(ShowDasmWin()));
442
443 // Exception vector table window
444 exceptionVectorTableBrowseAct = new QAction(QIcon(""), tr("Exception Vector Table"), this);
445 exceptionVectorTableBrowseAct->setStatusTip(tr("Shows all Exception Vector Table browser window"));
446 connect(exceptionVectorTableBrowseAct, SIGNAL(triggered()), this, SLOT(ShowExceptionVectorTableBrowserWin()));
447
448 // All watch variables window
449 allWatchBrowseAct = new QAction(QIcon(":/res/debug-watch.png"), tr("All Watch"), this);
450 allWatchBrowseAct->setStatusTip(tr("Shows all Watch browser window"));
451 connect(allWatchBrowseAct, SIGNAL(triggered()), this, SLOT(ShowAllWatchBrowserWin()));
452
453 // Local variables window
454 LocalBrowseAct = new QAction(QIcon(":/res/debug-local.png"), tr("Locals"), this);
455 LocalBrowseAct->setStatusTip(tr("Shows Locals browser window"));
456 connect(LocalBrowseAct, SIGNAL(triggered()), this, SLOT(ShowLocalBrowserWin()));
457
458 // Heap (memory) allocation window
459 heapallocatorBrowseAct = new QAction(QIcon(""), tr("Heap allocator"), this);
460 heapallocatorBrowseAct->setStatusTip(tr("Shows the heap allocator browser window"));
461 connect(heapallocatorBrowseAct, SIGNAL(triggered()), this, SLOT(ShowHeapAllocatorBrowserWin()));
462
463 // Call stack window
464 CallStackBrowseAct = new QAction(QIcon(":/res/debug-callstack.png"), tr("Call Stack"), this);
465 CallStackBrowseAct->setStatusTip(tr("Shows Call Stack browser window"));
466 connect(CallStackBrowseAct, SIGNAL(triggered()), this, SLOT(ShowCallStackBrowserWin()));
467
468 // Cart files list
469 CartFilesListAct = new QAction(QIcon(""), tr("Directory and files"), this);
470 CartFilesListAct->setStatusTip(tr("List of the files in the cartridge's directory structure"));
471 connect(CartFilesListAct, SIGNAL(triggered()), this, SLOT(ShowCartFilesListWin()));
472
473 // Memory windows
474 mem1BrowseAct = (QAction **)calloc(vjs.nbrmemory1browserwindow, sizeof(QAction));
475 QSignalMapper *signalMapper = new QSignalMapper(this);
476 #ifdef _MSC_VER
477 #pragma message("Warning: !!! Need to do the memory desalocation for mem1BrowseAct !!!")
478 #else
479 #warning "!!! Need to do the memory desalocation for mem1BrowseAct !!!"
480 #endif // _MSC_VER
481 for (int i = 0; i < vjs.nbrmemory1browserwindow; i++)
482 {
483 char MB[100];
484 sprintf(MB, "Memory %i", (unsigned int)(i+1));
485 mem1BrowseAct[i] = new QAction(QIcon(":/res/debug-memory.png"), tr(MB), this);
486 mem1BrowseAct[i]->setStatusTip(tr("Shows a Jaguar memory browser window"));
487 connect(mem1BrowseAct[i], SIGNAL(triggered()), signalMapper, SLOT(map()));
488 signalMapper->setMapping(mem1BrowseAct[i], (int)i);
489 connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(ShowMemory1BrowserWin(int)));
490 }
491 }
492
493 // Memory browser window action
494 memBrowseAct = new QAction(QIcon(":/res/tool-memory.png"), tr("Memory Browser"), this);
495 memBrowseAct->setStatusTip(tr("Shows the Jaguar memory browser window"));
496 connect(memBrowseAct, SIGNAL(triggered()), this, SLOT(ShowMemoryBrowserWin()));
497
498 // Stack browser window action
499 stackBrowseAct = new QAction(QIcon(":/res/tool-stack.png"), tr("Stack Browser"), this);
500 stackBrowseAct->setStatusTip(tr("Shows the Jaguar stack browser window"));
501 connect(stackBrowseAct, SIGNAL(triggered()), this, SLOT(ShowStackBrowserWin()));
502
503 // CPUs (M68000, GPU & DSP browser window action
504 cpuBrowseAct = new QAction(QIcon(":/res/tool-cpu.png"), tr("CPU Browser"), this);
505 cpuBrowseAct->setStatusTip(tr("Shows the Jaguar CPU browser window"));
506 connect(cpuBrowseAct, SIGNAL(triggered()), this, SLOT(ShowCPUBrowserWin()));
507
508 // OP browser window action
509 opBrowseAct = new QAction(QIcon(":/res/tool-op.png"), tr("OP Browser"), this);
510 opBrowseAct->setStatusTip(tr("Shows the Jaguar OP browser window"));
511 connect(opBrowseAct, SIGNAL(triggered()), this, SLOT(ShowOPBrowserWin()));
512
513 // M68000 disassembly browser window
514 m68kDasmBrowseAct = new QAction(QIcon(":/res/tool-68k-dis.png"), tr("68K Listing Browser"), this);
515 m68kDasmBrowseAct->setStatusTip(tr("Shows the 68K disassembly browser window"));
516 connect(m68kDasmBrowseAct, SIGNAL(triggered()), this, SLOT(ShowM68KDasmBrowserWin()));
517
518 // Risc (DSP / GPU) disassembly browser window
519 riscDasmBrowseAct = new QAction(QIcon(":/res/tool-risc-dis.png"), tr("RISC Listing Browser"), this);
520 riscDasmBrowseAct->setStatusTip(tr("Shows the RISC disassembly browser window"));
521 connect(riscDasmBrowseAct, SIGNAL(triggered()), this, SLOT(ShowRISCDasmBrowserWin()));
522
523 // Misc. connections...
524 connect(filePickWin, SIGNAL(RequestLoad(QString)), this, SLOT(LoadSoftware(QString)));
525 connect(filePickWin, SIGNAL(FilePickerHiding()), this, SLOT(Unpause()));
526
527 // Create menus
528
529 fileMenu = menuBar()->addMenu(tr("&Jaguar"));
530 fileMenu->addAction(powerAct);
531 if (!vjs.softTypeDebugger)
532 {
533 fileMenu->addAction(pauseAct);
534 // fileMenu->addAction(frameAdvanceAct);
535 }
536 fileMenu->addAction(filePickAct);
537 fileMenu->addAction(useCDAct);
538 fileMenu->addAction(configAct);
539 fileMenu->addAction(emustatusAct);
540 fileMenu->addSeparator();
541 fileMenu->addAction(quitAppAct);
542
543 // Alpine and debugger menus
544 if (vjs.hardwareTypeAlpine || vjs.softTypeDebugger)
545 {
546 // Create debug menu
547 debugMenu = menuBar()->addMenu(tr("&Debug"));
548
549 // Create debugger menu
550 if (vjs.softTypeDebugger)
551 {
552 // Create view menu
553 viewMenu = menuBar()->addMenu(tr("&View"));
554
555 // Cart menu
556 viewCartMenu = viewMenu->addMenu(tr("&Cartridge"));
557 viewCartMenu->addAction(CartFilesListAct);
558 #if 0
559 viewCartMenu->addSeparator();
560 viewCartMenu->addAction(CartStreamsAct);
561 #endif
562
563 // Windows menu
564 debugWindowsMenu = debugMenu->addMenu(tr("&Windows"));
565 debugWindowsMenu->addAction(BreakpointsAct);
566 debugWindowExceptionMenu = debugWindowsMenu->addMenu(tr("&Exception"));
567 debugWindowExceptionMenu->addAction(exceptionVectorTableBrowseAct);
568 debugWindowsMenu->addSeparator();
569 #if 0
570 debugWindowOutputMenu = debugWindowsMenu->addMenu(tr("&Output"));
571 debugWindowOutputMenu->addAction(VideoOutputAct);
572 debugWindowsMenu->addSeparator();
573 #endif
574 debugWindowsWatchMenu = debugWindowsMenu->addMenu(tr("&Watch"));
575 debugWindowsWatchMenu->addAction(allWatchBrowseAct);
576 debugWindowsMenu->addAction(LocalBrowseAct);
577 debugWindowsMenu->addSeparator();
578 debugWindowsMenu->addAction(CallStackBrowseAct);
579 debugWindowsMenu->addSeparator();
580 debugWindowsMemoryMenu = debugWindowsMenu->addMenu(tr("&Memory"));
581 debugWindowsMemoryMenu->addAction(heapallocatorBrowseAct);
582 debugWindowsMemoryMenu->addSeparator();
583 for (int i = 0; i < vjs.nbrmemory1browserwindow; i++)
584 {
585 debugWindowsMemoryMenu->addAction(mem1BrowseAct[i]);
586 }
587 debugWindowsMenu->addSeparator();
588 debugWindowsBrowsesMenu = debugWindowsMenu->addMenu(tr("&Browsers"));
589 debugWindowsBrowsesMenu->addAction(memBrowseAct);
590 debugWindowsBrowsesMenu->addAction(stackBrowseAct);
591 debugWindowsBrowsesMenu->addAction(cpuBrowseAct);
592 debugWindowsBrowsesMenu->addAction(opBrowseAct);
593 debugWindowsBrowsesMenu->addAction(m68kDasmBrowseAct);
594 debugWindowsBrowsesMenu->addAction(riscDasmBrowseAct);
595 debugMenu->addSeparator();
596 debugMenu->addAction(pauseAct);
597 debugMenu->addAction(frameAdvanceAct);
598 debugMenu->addAction(restartAct);
599 debugMenu->addSeparator();
600 debugMenu->addAction(traceStepIntoAct);
601 debugMenu->addAction(traceStepOverAct);
602 debugMenu->addSeparator();
603 debugNewBreakpointMenu = debugMenu->addMenu(tr("&New Breakpoint"));
604 debugNewBreakpointMenu->addAction(newFunctionBreakpointAct);
605 debugMenu->addAction(deleteAllBreakpointsAct);
606 debugMenu->addAction(disableAllBreakpointsAct);
607 debugMenu->addSeparator();
608 debugMenu->addAction(saveDumpAsAct);
609 #if 0
610 debugMenu->addSeparator();
611 debugMenu->addAction(DasmAct);
612 #endif
613 }
614 else
615 {
616 // Create alpine menu
617 debugMenu->addAction(memBrowseAct);
618 debugMenu->addAction(stackBrowseAct);
619 debugMenu->addAction(cpuBrowseAct);
620 debugMenu->addAction(opBrowseAct);
621 debugMenu->addAction(m68kDasmBrowseAct);
622 debugMenu->addAction(riscDasmBrowseAct);
623 }
624 }
625
626 // Help menus
627 helpMenu = menuBar()->addMenu(tr("&Help"));
628 helpMenu->addAction(helpAct);
629 helpMenu->addAction(aboutAct);
630
631 // Create toolbars
632
633 toolbar = addToolBar(tr("System"));
634 toolbar->addAction(powerAct);
635 if (!vjs.softTypeDebugger)
636 {
637 toolbar->addAction(pauseAct);
638 toolbar->addAction(frameAdvanceAct);
639 }
640 toolbar->addAction(filePickAct);
641 toolbar->addAction(useCDAct);
642 toolbar->addSeparator();
643 if (!vjs.softTypeDebugger)
644 {
645 toolbar->addAction(screenshotAct);
646 toolbar->addSeparator();
647 toolbar->addAction(x1Act);
648 toolbar->addAction(x2Act);
649 toolbar->addAction(x3Act);
650 toolbar->addSeparator();
651 toolbar->addAction(ntscAct);
652 toolbar->addAction(palAct);
653 toolbar->addSeparator();
654 toolbar->addAction(blurAct);
655 toolbar->addAction(fullScreenAct);
656 }
657 else
658 {
659 debuggerbar = addToolBar(tr("&Debugger"));
660 debuggerbar->addAction(pauseAct);
661 debuggerbar->addAction(frameAdvanceAct);
662 debuggerbar->addAction(restartAct);
663 debuggerbar->addSeparator();
664 debuggerbar->addAction(traceStepIntoAct);
665 debuggerbar->addAction(traceStepOverAct);
666 debuggerbar->addSeparator();
667 debuggerbar->addAction(BreakpointsAct);
668 }
669
670 if (vjs.hardwareTypeAlpine)
671 {
672 debugbar = addToolBar(tr("&Debug"));
673 debugbar->addAction(memBrowseAct);
674 debugbar->addAction(stackBrowseAct);
675 debugbar->addAction(cpuBrowseAct);
676 debugbar->addAction(opBrowseAct);
677 debugbar->addAction(m68kDasmBrowseAct);
678 debugbar->addAction(riscDasmBrowseAct);
679 }
680
681 // Add actions to the main window, as hiding widgets with them
682 // disables them :-P
683 addAction(fullScreenAct);
684 addAction(quitAppAct);
685 addAction(configAct);
686 addAction(emustatusAct);
687 addAction(pauseAct);
688 addAction(filePickAct);
689 addAction(frameAdvanceAct);
690
691 // Create status bar
692 statusBar()->showMessage(tr("Ready"));
693 ReadUISettings();
694 // Do this in case original size isn't correct (mostly for the first-run case)
695 ResizeMainWindow();
696
697 WriteLog("Window creation done\n");
698
699 // Create our test pattern NTSC bitmap
700 WriteLog("Test pattern 1 bitmap\n");
701
702 QImage tempImg(":/res/test-pattern.jpg");
703 QImage tempImgScaled = tempImg.scaled(VIRTUAL_SCREEN_WIDTH, VIRTUAL_SCREEN_HEIGHT_PAL, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
704
705 for(uint32_t y=0; y<VIRTUAL_SCREEN_HEIGHT_PAL; y++)
706 {
707 const QRgb * scanline = (QRgb *)tempImgScaled.constScanLine(y);
708
709 for(uint32_t x=0; x<VIRTUAL_SCREEN_WIDTH; x++)
710 {
711 uint32_t pixel = (qRed(scanline[x]) << 24) | (qGreen(scanline[x]) << 16) | (qBlue(scanline[x]) << 8) | 0xFF;
712 testPattern[(y * VIRTUAL_SCREEN_WIDTH) + x] = pixel;
713 }
714 }
715
716 // Create our test pattern PAL bitmap
717 WriteLog("Test pattern 2 bitmap\n");
718
719 QImage tempImg2(":/res/test-pattern-pal.jpg");
720 QImage tempImgScaled2 = tempImg2.scaled(VIRTUAL_SCREEN_WIDTH, VIRTUAL_SCREEN_HEIGHT_PAL, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
721
722 for(uint32_t y=0; y<VIRTUAL_SCREEN_HEIGHT_PAL; y++)
723 {
724 const QRgb * scanline = (QRgb *)tempImgScaled2.constScanLine(y);
725
726 for(uint32_t x=0; x<VIRTUAL_SCREEN_WIDTH; x++)
727 {
728 uint32_t pixel = (qRed(scanline[x]) << 24) | (qGreen(scanline[x]) << 16) | (qBlue(scanline[x]) << 8) | 0xFF;
729 testPattern2[(y * VIRTUAL_SCREEN_WIDTH) + x] = pixel;
730 }
731 }
732
733 // Set up timer based loop for animation...
734 timer = new QTimer(this);
735 connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
736
737 // This isn't very accurate for NTSC: This is early by 40 msec per frame.
738 // This is because it's discarding the 0.6666... on the end of the fraction.
739 // Alas, 6 doesn't divide cleanly into 10. :-P
740 //Should we defer this until SyncUI? Probably.
741 //No, it doesn't work, because it uses setInterval() instead of start()...
742 // timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
743
744 // We set this initially, to make VJ behave somewhat as it would if no
745 // cart were inserted and the BIOS was set as active...
746 jaguarCartInserted = true;
747 WriteLog("Virtual Jaguar %s Rx (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
748 WriteLog("VJ: Initializing jaguar subsystem...\n");
749 JaguarInit();
750
751 #ifndef NEWMODELSBIOSHANDLER
752 // memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Use the stock BIOS
753 memcpy(jagMemSpace + 0xE00000, (vjs.biosType == BT_K_SERIES ? jaguarBootROM : jaguarBootROM2), 0x20000); // Use the stock BIOS
754 #else
755 SelectBIOS(vjs.biosType);
756 #endif
757
758 // Prevent the file scanner from running if filename passed
759 // in on the command line...
760 if (autoRun)
761 return;
762
763 // Load up the default ROM if in Alpine mode:
764 if (vjs.hardwareTypeAlpine)
765 {
766 bool romLoaded = JaguarLoadFile(vjs.alpineROMPath);
767
768 // If regular load failed, try just a straight file load
769 // (Dev only! I don't want people to start getting lazy with their releases again! :-P)
770 if (!romLoaded)
771 romLoaded = AlpineLoadFile(vjs.alpineROMPath);
772
773 if (romLoaded)
774 WriteLog("Alpine Mode: Successfully loaded file \"%s\".\n", vjs.alpineROMPath);
775 else
776 WriteLog("Alpine Mode: Unable to load file \"%s\"!\n", vjs.alpineROMPath);
777
778 // Attempt to load/run the ABS file...
779 LoadSoftware(vjs.absROMPath);
780 #ifndef NEWMODELSBIOSHANDLER
781 memcpy(jagMemSpace + 0xE00000, jaguarDevBootROM2, 0x20000); // Use the stub BIOS
782 #else
783 SelectBIOS(vjs.biosType);
784 #endif
785 // Prevent the scanner from running...
786 return;
787 }
788
789 // Load up the default ROM if in Debugger mode:
790 if (vjs.softTypeDebugger)
791 {
792 bool romLoaded = JaguarLoadFile(vjs.debuggerROMPath);
793
794 // If regular load failed, try just a straight file load
795 // (Dev only! I don't want people to start getting lazy with their releases again! :-P)
796 if (!romLoaded)
797 romLoaded = DebuggerLoadFile(vjs.debuggerROMPath);
798
799 if (romLoaded)
800 WriteLog("Debugger Mode: Successfully loaded file \"%s\".\n", vjs.debuggerROMPath);
801 else
802 WriteLog("Debugger Mode: Unable to load file \"%s\"!\n", vjs.debuggerROMPath);
803
804 // Attempt to load/run the ABS file...
805 LoadSoftware(vjs.absROMPath);
806 #ifndef NEWMODELSBIOSHANDLER
807 memcpy(jagMemSpace + 0xE00000, jaguarDevBootROM2, 0x20000); // Use the stub BIOS
808 // Prevent the scanner from running...
809 #else
810 SelectBIOS(vjs.biosType);
811 #endif
812 return;
813 }
814
815 // Run the scanner if nothing passed in and *not* Alpine mode...
816 // NB: Really need to look into caching the info scanned in here...
817 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
818 scannedSoftwareFolder = true;
819 }
820
821
822 void MainWin::LoadFile(QString file)
823 {
824 LoadSoftware(file);
825 }
826
827
828 void MainWin::SyncUI(void)
829 {
830 // Set toolbar buttons/menus based on settings read in (sync the UI)...
831 // (Really, this is to sync command line options passed in)
832 blurAct->setChecked(vjs.glFilter);
833 x1Act->setChecked(zoomLevel == 1);
834 x2Act->setChecked(zoomLevel == 2);
835 x3Act->setChecked(zoomLevel == 3);
836 // running = powerAct->isChecked();
837 ntscAct->setChecked(vjs.hardwareTypeNTSC);
838 palAct->setChecked(!vjs.hardwareTypeNTSC);
839 powerAct->setIcon(vjs.hardwareTypeNTSC ? powerRed : powerGreen);
840
841 fullScreenAct->setChecked(vjs.fullscreen);
842 fullScreen = vjs.fullscreen;
843 SetFullScreen(fullScreen);
844
845 // Reset the timer to be what was set in the command line (if any):
846 // timer->setInterval(vjs.hardwareTypeNTSC ? 16 : 20);
847 timer->start(vjs.hardwareTypeNTSC ? 16 : 20);
848 }
849
850
851 void MainWin::closeEvent(QCloseEvent * event)
852 {
853 JaguarDone();
854 // This should only be done by the config dialog
855 // WriteSettings();
856 WriteUISettings();
857 event->accept(); // ignore() if can't close for some reason
858 }
859
860
861 void MainWin::keyPressEvent(QKeyEvent * e)
862 {
863 #ifndef VJ_REMOVE_DEV_CODE
864 // From jaguar.cpp
865 //extern bool startM68KTracing; // moved to jaguar.h
866 // From joystick.cpp
867 extern int blit_start_log;
868 // From blitter.cpp
869 extern bool startConciseBlitLogging;
870 #endif
871
872 // We ignore the Alt key for now, since it causes problems with the GUI
873 if (e->key() == Qt::Key_Alt)
874 {
875 e->accept();
876 return;
877 }
878 // Bar this shite from release versions kthxbai
879 #ifndef VJ_REMOVE_DEV_CODE
880 else if (e->key() == Qt::Key_F11)
881 {
882 startM68KTracing = true;
883 e->accept();
884 return;
885 }
886 else if (e->key() == Qt::Key_F12)
887 {
888 blit_start_log = true;
889 e->accept();
890 return;
891 }
892 else if (e->key() == Qt::Key_F10)
893 {
894 startConciseBlitLogging = true;
895 e->accept();
896 return;
897 }
898 #endif
899 else if (e->key() == Qt::Key_F8)
900 {
901 // ggn: For extra NYAN pleasure...
902 // ggn: There you go James :P
903 // Shamus: Thanks for the patch! :-D
904 WriteLog(" o + + +\n");
905 WriteLog("+ o o + o\n");
906 WriteLog("-_-_-_-_-_-_-_,------, o \n");
907 WriteLog("_-_-_-_-_-_-_-| /\\_/\\ \n");
908 WriteLog("-_-_-_-_-_-_-~|__( ^ .^) + + \n");
909 WriteLog("_-_-_-_-_-_-_-\"\" \"\" \n");
910 WriteLog("+ o o + o\n");
911 WriteLog(" + +\n");
912 e->accept();
913 return;
914 }
915
916 /*
917 This is done now by a QAction...
918 if (e->key() == Qt::Key_F9)
919 {
920 ToggleFullScreen();
921 return;
922 }
923 */
924 HandleKeys(e, true);
925 }
926
927
928 void MainWin::keyReleaseEvent(QKeyEvent * e)
929 {
930 // We ignore the Alt key for now, since it causes problems with the GUI
931 if (e->key() == Qt::Key_Alt)
932 {
933 e->accept();
934 return;
935 }
936
937 HandleKeys(e, false);
938 }
939
940
941 void MainWin::HandleKeys(QKeyEvent * e, bool state)
942 {
943 enum { P1LEFT = 0, P1RIGHT, P1UP, P1DOWN, P2LEFT, P2RIGHT, P2UP, P2DOWN };
944 // We kill bad key combos here, before they can get to the emulator...
945 // This also kills the illegal instruction problem that cropped up in
946 // Rayman!
947
948 // First, settle key states...
949 if (e->key() == (int)vjs.p1KeyBindings[BUTTON_L])
950 keyHeld[P1LEFT] = state;
951 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_R])
952 keyHeld[P1RIGHT] = state;
953 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_U])
954 keyHeld[P1UP] = state;
955 else if (e->key() == (int)vjs.p1KeyBindings[BUTTON_D])
956 keyHeld[P1DOWN] = state;
957 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_L])
958 keyHeld[P2LEFT] = state;
959 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_R])
960 keyHeld[P2RIGHT] = state;
961 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_U])
962 keyHeld[P2UP] = state;
963 else if (e->key() == (int)vjs.p2KeyBindings[BUTTON_D])
964 keyHeld[P2DOWN] = state;
965
966 // Next, check for conflicts and kill 'em if there are any...
967 if (keyHeld[P1LEFT] && keyHeld[P1RIGHT])
968 keyHeld[P1LEFT] = keyHeld[P1RIGHT] = false;
969
970 if (keyHeld[P1UP] && keyHeld[P1DOWN])
971 keyHeld[P1UP] = keyHeld[P1DOWN] = false;
972
973 if (keyHeld[P2LEFT] && keyHeld[P2RIGHT])
974 keyHeld[P2LEFT] = keyHeld[P2RIGHT] = false;
975
976 if (keyHeld[P2UP] && keyHeld[P2DOWN])
977 keyHeld[P2UP] = keyHeld[P2DOWN] = false;
978
979 // No bad combos exist now, let's stuff the emulator key buffers...!
980 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
981 {
982 if (e->key() == (int)vjs.p1KeyBindings[i])
983 joypad0Buttons[i] = (state ? 0x01 : 0x00);
984
985 if (e->key() == (int)vjs.p2KeyBindings[i])
986 joypad1Buttons[i] = (state ? 0x01 : 0x00);
987 }
988 }
989
990
991 //
992 // N.B.: The profile system AutoConnect functionality sets the gamepad IDs here.
993 //
994 void MainWin::HandleGamepads(void)
995 {
996 Gamepad::Update();
997
998 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
999 {
1000 if (vjs.p1KeyBindings[i] & (JOY_BUTTON | JOY_HAT | JOY_AXIS))
1001 joypad0Buttons[i] = (Gamepad::GetState(gamepadIDSlot1, vjs.p1KeyBindings[i]) ? 0x01 : 0x00);
1002
1003 if (vjs.p2KeyBindings[i] & (JOY_BUTTON | JOY_HAT | JOY_AXIS))
1004 joypad1Buttons[i] = (Gamepad::GetState(gamepadIDSlot2, vjs.p2KeyBindings[i]) ? 0x01 : 0x00);
1005 }
1006 }
1007
1008
1009 void MainWin::Open(void)
1010 {
1011 }
1012
1013
1014 void MainWin::Configure(void)
1015 {
1016 // Call the configuration dialog and update settings
1017 ConfigDialog dlg(this);
1018 //ick.
1019 dlg.generalTab->useUnknownSoftware->setChecked(allowUnknownSoftware);
1020 dlg.controllerTab1->profileNum = lastEditedProfile;
1021 dlg.controllerTab1->SetupLastUsedProfile();
1022 // maybe instead of this, we tell the controller tab to work on a copy that gets
1023 // written if the user hits 'OK'.
1024 SaveProfiles(); // Just in case user cancels
1025
1026 if (dlg.exec() == false)
1027 {
1028 RestoreProfiles();
1029 return;
1030 }
1031
1032 QString before = vjs.ROMPath;
1033 QString alpineBefore = vjs.alpineROMPath;
1034 QString absBefore = vjs.absROMPath;
1035 // bool audioBefore = vjs.audioEnabled;
1036 bool audioBefore = vjs.DSPEnabled;
1037 dlg.UpdateVJSettings();
1038 QString after = vjs.ROMPath;
1039 QString alpineAfter = vjs.alpineROMPath;
1040 QString absAfter = vjs.absROMPath;
1041 // bool audioAfter = vjs.audioEnabled;
1042 bool audioAfter = vjs.DSPEnabled;
1043
1044 bool allowOld = allowUnknownSoftware;
1045 //ick.
1046 allowUnknownSoftware = dlg.generalTab->useUnknownSoftware->isChecked();
1047 lastEditedProfile = dlg.controllerTab1->profileNum;
1048 AutoConnectProfiles();
1049
1050 // We rescan the "software" folder if the user either changed the path or
1051 // checked/unchecked the "Allow unknown files" option in the config dialog.
1052 if ((before != after) || (allowOld != allowUnknownSoftware))
1053 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
1054
1055 // If the "Alpine" ROM is changed, then let's load it...
1056 if (alpineBefore != alpineAfter)
1057 {
1058 if (!JaguarLoadFile(vjs.alpineROMPath) && !AlpineLoadFile(vjs.alpineROMPath))
1059 {
1060 // Oh crap, we couldn't get the file! Alert the media!
1061 QMessageBox msg;
1062 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.alpineROMPath));
1063 msg.setIcon(QMessageBox::Warning);
1064 msg.exec();
1065 }
1066 }
1067
1068 // If the "ABS" ROM is changed, then let's load it...
1069 if (absBefore != absAfter)
1070 {
1071 if (!JaguarLoadFile(vjs.absROMPath))
1072 {
1073 // Oh crap, we couldn't get the file! Alert the media!
1074 QMessageBox msg;
1075 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(vjs.absROMPath));
1076 msg.setIcon(QMessageBox::Warning);
1077 msg.exec();
1078 }
1079 }
1080
1081 // If the "Enable DSP" checkbox changed, then we have to re-init the DAC,
1082 // since it's running in the host audio IRQ...
1083 if (audioBefore != audioAfter)
1084 {
1085 DACDone();
1086 DACInit();
1087 }
1088
1089 // Just in case we crash before a clean exit...
1090 WriteSettings();
1091
1092 RefreshWindows();
1093 }
1094
1095
1096 //
1097 // Here's the main emulator loop
1098 //
1099 void MainWin::Timer(void)
1100 {
1101 #if 0
1102 static uint32_t ntscTickCount;
1103 if (vjs.hardwareTypeNTSC)
1104 {
1105 ntscTickCount++;
1106 ntscTickCount %= 3;
1107 timer->start(16 + (ntscTickCount == 0 ? 1 : 0));
1108 }
1109 #endif
1110
1111 if (!running)
1112 return;
1113
1114 if (showUntunedTankCircuit)
1115 {
1116 // Some machines can't handle this, so we give them the option to disable it. :-)
1117 if (!plzDontKillMyComputer)
1118 {
1119 // if (!vjs.softTypeDebugger)
1120 {
1121 // Random hash & trash
1122 // We try to simulate an untuned tank circuit here... :-)
1123 for (uint32_t x = 0; x < videoWidget->rasterWidth; x++)
1124 {
1125 for (uint32_t y = 0; y < videoWidget->rasterHeight; y++)
1126 {
1127 videoWidget->buffer[(y * videoWidget->textureWidth) + x] = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;
1128 }
1129 }
1130 }
1131 }
1132 }
1133 else
1134 {
1135 // Otherwise, run the Jaguar simulation
1136 HandleGamepads();
1137 JaguarExecuteNew();
1138 //if (!vjs.softTypeDebugger)
1139 videoWidget->HandleMouseHiding();
1140
1141 static uint32_t refresh = 0;
1142 // Do autorefresh on debug windows
1143 // Have to be careful, too much causes the emulator to slow way down!
1144 if (refresh == vjs.refresh)
1145 {
1146 if (vjs.hardwareTypeAlpine || vjs.softTypeDebugger)
1147 {
1148 AlpineRefreshWindows();
1149 //memBrowseWin->RefreshContents();
1150 //cpuBrowseWin->RefreshContents();
1151 }
1152 CommonRefreshWindows();
1153 refresh = 0;
1154 }
1155 else
1156 {
1157 refresh++;
1158 }
1159 }
1160
1161 //if (!vjs.softTypeDebugger)
1162 videoWidget->updateGL();
1163
1164 // FPS handling
1165 // Approach: We use a ring buffer to store times (in ms) over a given
1166 // amount of frames, then sum them to figure out the FPS.
1167 uint32_t timestamp = SDL_GetTicks();
1168 // This assumes the ring buffer size is a power of 2
1169 // ringBufferPointer = (ringBufferPointer + 1) & (RING_BUFFER_SIZE - 1);
1170 // Doing it this way is better. Ring buffer size can be arbitrary then.
1171 ringBufferPointer = (ringBufferPointer + 1) % RING_BUFFER_SIZE;
1172 ringBuffer[ringBufferPointer] = timestamp - oldTimestamp;
1173 uint32_t elapsedTime = 0;
1174
1175 for(uint32_t i=0; i<RING_BUFFER_SIZE; i++)
1176 elapsedTime += ringBuffer[i];
1177
1178 // elapsedTime must be non-zero
1179 if (elapsedTime == 0)
1180 elapsedTime = 1;
1181
1182 // This is in frames per 10 seconds, so we can have 1 decimal
1183 uint32_t framesPerSecond = (uint32_t)(((float)RING_BUFFER_SIZE / (float)elapsedTime) * 10000.0);
1184 uint32_t fpsIntegerPart = framesPerSecond / 10;
1185 uint32_t fpsDecimalPart = framesPerSecond % 10;
1186 // If this is updated too frequently to be useful, we can throttle it down
1187 // so that it only updates every 10th frame or so
1188 statusBar()->showMessage(QString("%1.%2 FPS").arg(fpsIntegerPart).arg(fpsDecimalPart));
1189 oldTimestamp = timestamp;
1190
1191 if (M68KDebugHaltStatus())
1192 ToggleRunState();
1193 }
1194
1195
1196 // Toggle the power state, it can be either on or off
1197 void MainWin::TogglePowerState(void)
1198 {
1199 powerButtonOn = !powerButtonOn;
1200 running = true;
1201
1202 // With the power off, we simulate white noise on the screen. :-)
1203 if (!powerButtonOn)
1204 {
1205 // Restore the mouse pointer, if hidden:
1206 //if (!vjs.softTypeDebugger)
1207 {
1208 videoWidget->CheckAndRestoreMouseCursor();
1209 }
1210
1211 useCDAct->setDisabled(false);
1212 palAct->setDisabled(false);
1213 ntscAct->setDisabled(false);
1214 pauseAct->setChecked(false);
1215 pauseAct->setDisabled(true);
1216 showUntunedTankCircuit = true;
1217
1218 DACPauseAudioThread();
1219 // This is just in case the ROM we were playing was in a narrow or wide field mode, so the untuned tank sim doesn't look wrong. :-)
1220 TOMReset();
1221
1222 if (plzDontKillMyComputer)
1223 {
1224 // We have to do it line by line, because the texture pitch is not the same as the picture buffer's pitch.
1225 for (uint32_t y = 0; y < videoWidget->rasterHeight; y++)
1226 {
1227 if (vjs.hardwareTypeNTSC)
1228 {
1229 memcpy(videoWidget->buffer + (y * videoWidget->textureWidth), testPattern + (y * VIRTUAL_SCREEN_WIDTH), VIRTUAL_SCREEN_WIDTH * sizeof(uint32_t));
1230 }
1231 else
1232 {
1233 memcpy(videoWidget->buffer + (y * videoWidget->textureWidth), testPattern2 + (y * VIRTUAL_SCREEN_WIDTH), VIRTUAL_SCREEN_WIDTH * sizeof(uint32_t));
1234 }
1235 }
1236 }
1237 }
1238 else
1239 {
1240 useCDAct->setDisabled(true);
1241 palAct->setDisabled(true);
1242 ntscAct->setDisabled(true);
1243 pauseAct->setChecked(false);
1244 pauseAct->setDisabled(false);
1245 showUntunedTankCircuit = false;
1246
1247 // Otherwise, we prepare for running regular software...
1248 if (CDActive)
1249 {
1250 // Should check for cartridgeLoaded here as well...!
1251 // We can clear it when toggling CDActive on, so that when we power cycle it
1252 // does the expected thing. Otherwise, if we use the file picker to insert a
1253 // cart, we expect to run the cart! Maybe have a RemoveCart function that only
1254 // works if the CD unit is active?
1255 setWindowTitle(QString("Virtual Jaguar " VJ_RELEASE_VERSION " Rx - Now playing: Jaguar CD"));
1256 }
1257
1258 WriteLog("GUI: Resetting Jaguar...\n");
1259 JaguarReset();
1260 DebuggerReset();
1261 CommonReset();
1262 DebuggerResetWindows();
1263 CommonResetWindows();
1264 DACPauseAudioThread(false);
1265 }
1266 }
1267
1268
1269 // Toggle the emulator state, it can be either on or off
1270 void MainWin::ToggleRunState(void)
1271 {
1272 startM68KTracing = running;
1273 running = !running;
1274
1275 // Pause mode
1276 if (!running)
1277 {
1278 // Set action buttons for the pause mode
1279 frameAdvanceAct->setDisabled(false);
1280 pauseAct->setChecked(true);
1281 pauseAct->setDisabled(false);
1282 if (vjs.softTypeDebugger)
1283 {
1284 traceStepIntoAct->setDisabled(false);
1285 traceStepOverAct->setDisabled(false);
1286 restartAct->setDisabled(false);
1287 m68kDasmWin->Use68KPCAddress();
1288 GPUDasmWin->UseGPUPCAddress();
1289 DSPDasmWin->UseDSPPCAddress();
1290 }
1291
1292 //if (!vjs.softTypeDebugger)
1293 {
1294 // Restore the mouse pointer, if hidden:
1295 videoWidget->CheckAndRestoreMouseCursor();
1296
1297 for (uint32_t i = 0; i < (uint32_t)(videoWidget->textureWidth * 256); i++)
1298 {
1299 uint32_t pixel = videoWidget->buffer[i];
1300 uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
1301 pixel = ((r + g + b) / 3) & 0x00FF;
1302 videoWidget->buffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
1303 }
1304
1305 videoWidget->updateGL();
1306
1307 cpuBrowseWin->HoldBPM();
1308 cpuBrowseWin->HandleBPMContinue();
1309 RefreshWindows();
1310 }
1311 }
1312 else
1313 {
1314 frameAdvanceAct->setDisabled(true);
1315 pauseAct->setChecked(false);
1316 pauseAct->setDisabled(false);
1317 if (vjs.softTypeDebugger)
1318 {
1319 traceStepIntoAct->setDisabled(true);
1320 traceStepOverAct->setDisabled(true);
1321 restartAct->setDisabled(true);
1322 BreakpointsWin->RefreshContents();
1323 }
1324
1325 cpuBrowseWin->UnholdBPM();
1326 }
1327
1328 // Pause/unpause any running/non-running threads...
1329 DACPauseAudioThread(!running);
1330 }
1331
1332
1333 void MainWin::SetZoom100(void)
1334 {
1335 zoomLevel = 1;
1336 ResizeMainWindow();
1337 }
1338
1339
1340 void MainWin::SetZoom200(void)
1341 {
1342 zoomLevel = 2;
1343 ResizeMainWindow();
1344 }
1345
1346
1347 void MainWin::SetZoom300(void)
1348 {
1349 zoomLevel = 3;
1350 ResizeMainWindow();
1351 }
1352
1353
1354 void MainWin::SetNTSC(void)
1355 {
1356 powerAct->setIcon(powerRed);
1357 timer->setInterval(16);
1358 vjs.hardwareTypeNTSC = true;
1359 ResizeMainWindow();
1360 WriteSettings();
1361 }
1362
1363
1364 void MainWin::SetPAL(void)
1365 {
1366 powerAct->setIcon(powerGreen);
1367 timer->setInterval(20);
1368 vjs.hardwareTypeNTSC = false;
1369 ResizeMainWindow();
1370 WriteSettings();
1371 }
1372
1373
1374 void MainWin::ToggleBlur(void)
1375 {
1376 vjs.glFilter = !vjs.glFilter;
1377 WriteSettings();
1378 }
1379
1380
1381 void MainWin::ShowAboutWin(void)
1382 {
1383 aboutWin->show();
1384 }
1385
1386
1387 void MainWin::ShowHelpWin(void)
1388 {
1389 helpWin->show();
1390 }
1391
1392
1393 void MainWin::InsertCart(void)
1394 {
1395 // Check to see if we did autorun, 'cause we didn't load anything in that
1396 // case
1397 if (!scannedSoftwareFolder)
1398 {
1399 filePickWin->ScanSoftwareFolder(allowUnknownSoftware);
1400 scannedSoftwareFolder = true;
1401 }
1402
1403 // If the emulator is running, we pause it here and unpause it later
1404 // if we dismiss the file selector without choosing anything
1405 if (running && powerButtonOn)
1406 {
1407 ToggleRunState();
1408 pauseForFileSelector = true;
1409 }
1410
1411 filePickWin->show();
1412 }
1413
1414
1415 void MainWin::Unpause(void)
1416 {
1417 // Here we unpause the emulator if it was paused when we went into the file selector
1418 if (pauseForFileSelector)
1419 {
1420 pauseForFileSelector = false;
1421
1422 // Some nutter might have unpaused while in the file selector, so check for that
1423 if (!running)
1424 ToggleRunState();
1425 }
1426 }
1427
1428
1429 // Jaguar initialisation and load software file
1430 void MainWin::LoadSoftware(QString file)
1431 {
1432 running = false; // Prevent bad things(TM) from happening...
1433 pauseForFileSelector = false; // Reset the file selector pause flag
1434
1435 // Setup BIOS in his own dedicated Jaguar memory
1436 #ifndef NEWMODELSBIOSHANDLER
1437 uint8_t * biosPointer = jaguarBootROM;
1438
1439 if (vjs.hardwareTypeAlpine || vjs.softTypeDebugger)
1440 {
1441 biosPointer = jaguarDevBootROM2;
1442 }
1443
1444 memcpy(jagMemSpace + 0xE00000, biosPointer, 0x20000);
1445 #else
1446 SelectBIOS(vjs.biosType);
1447 #endif
1448
1449 // Turn 'on' the power to initialize the Jaguar
1450 powerAct->setDisabled(false);
1451 powerAct->setChecked(true);
1452 powerButtonOn = false;
1453 TogglePowerState();
1454
1455 // We have to load our software *after* the Jaguar RESET
1456 cartridgeLoaded = JaguarLoadFile(file.toUtf8().data());
1457 SET32(jaguarMainRAM, 0, vjs.DRAM_size); // Set stack in the M68000's Reset SP
1458
1459 // This is icky because we've already done it
1460 // it gets worse :-P
1461 if (!vjs.useJaguarBIOS)
1462 {
1463 SET32(jaguarMainRAM, 4, jaguarRunAddress);
1464 }
1465
1466 m68k_pulse_reset();
1467
1468 // set the M68K in halt mode in case of a debug mode is used, so control is at user side
1469 if (vjs.softTypeDebugger)
1470 {
1471 m68k_set_reg(M68K_REG_A6, 0);
1472 m68kDasmWin->SetAddress(jaguarRunAddress);
1473 //pauseAct->setDisabled(false);
1474 //pauseAct->setChecked(true);
1475 ToggleRunState();
1476 //RefreshWindows();
1477 }
1478 else
1479 {
1480 // Prevent the launch in case of software without a start address and without BIOS presence
1481 if (!vjs.useJaguarBIOS && !jaguarRunAddress)
1482 {
1483 ToggleRunState();
1484 }
1485 }
1486
1487 // Display the Atari Jaguar software which is running
1488 if ((!vjs.hardwareTypeAlpine || !vjs.softTypeDebugger) && !loadAndGo && jaguarRunAddress)
1489 {
1490 QString newTitle = QString("Virtual Jaguar " VJ_RELEASE_VERSION " Rx - Now playing: %1").arg(filePickWin->GetSelectedPrettyName());
1491 setWindowTitle(newTitle);
1492 }
1493 }
1494
1495
1496 void MainWin::ToggleCDUsage(void)
1497 {
1498 CDActive = !CDActive;
1499
1500 // Set up the Jaguar CD for execution, otherwise, clear memory
1501 if (CDActive)
1502 memcpy(jagMemSpace + 0x800000, jaguarCDBootROM, 0x40000);
1503 else
1504 memset(jagMemSpace + 0x800000, 0xFF, 0x40000);
1505 }
1506
1507
1508 // Open, or display, the breakpoints list window
1509 void MainWin::ShowBreakpointsWin(void)
1510 {
1511 BreakpointsWin->show();
1512 BreakpointsWin->RefreshContents();
1513 }
1514
1515
1516 // Delete all breakpoints
1517 void MainWin::DeleteAllBreakpoints(void)
1518 {
1519 cpuBrowseWin->ResetBPM();
1520 m68k_brk_reset();
1521 ShowBreakpointsWin();
1522 }
1523
1524
1525 // Disable all breakpoints
1526 void MainWin::DisableAllBreakpoints(void)
1527 {
1528 cpuBrowseWin->DisableBPM();
1529 m68k_brk_disable();
1530 ShowBreakpointsWin();
1531 }
1532
1533
1534 // Open, or display, the new breakpoint function window
1535 void MainWin::ShowNewFunctionBreakpointWin(void)
1536 {
1537 NewFunctionBreakpointWin->show();
1538 ShowBreakpointsWin();
1539 }
1540
1541
1542 // Display list of files found in cartridge
1543 void MainWin::ShowCartFilesListWin(void)
1544 {
1545 CartFilesListWin->show();
1546 CartFilesListWin->RefreshContents();
1547 }
1548
1549
1550 // Display the save dump pickup file
1551 void MainWin::ShowSaveDumpAsWin(void)
1552 {
1553 SaveDumpAsWin->show();
1554 }
1555
1556
1557 // Step Into trace
1558 void MainWin::DebuggerTraceStepInto(void)
1559 {
1560 JaguarStepInto();
1561 videoWidget->updateGL();
1562 RefreshWindows();
1563 #ifdef _MSC_VER
1564 #pragma message("Warning: !!! Need to verify the Step Into function !!!")
1565 #else
1566 #warning "!!! Need to verify the Step Into function !!!"
1567 #endif // _MSC_VER
1568 }
1569
1570
1571 // Restart the Jaguar executable
1572 void MainWin::DebuggerRestart(void)
1573 {
1574 #if 1
1575 m68k_pulse_reset();
1576 #else
1577 m68k_set_reg(M68K_REG_PC, jaguarRunAddress);
1578 m68k_set_reg(M68K_REG_SP, vjs.DRAM_size);
1579 #endif
1580 m68k_set_reg(M68K_REG_A6, 0);
1581 m68k_brk_hitcounts_reset();
1582 bpmHitCounts = 0;
1583 DebuggerResetWindows();
1584 CommonResetWindows();
1585 RefreshWindows();
1586 #ifdef _MSC_VER
1587 #pragma message("Warning: !!! Need to verify the Restart function !!!")
1588 #else
1589 #warning "!!! Need to verify the Restart function !!!"
1590 #endif // _MSC_VER
1591 }
1592
1593
1594 // Step Over trace
1595 void MainWin::DebuggerTraceStepOver(void)
1596 {
1597 JaguarStepOver(0);
1598 videoWidget->updateGL();
1599 RefreshWindows();
1600 #ifdef _MSC_VER
1601 #pragma message("Warning: !!! Need to verify the Step Over function !!!")
1602 #else
1603 #warning "!!! Need to verify the Step Over function !!!"
1604 #endif // _MSC_VER
1605 }
1606
1607
1608 // Advance / Execute for one frame
1609 void MainWin::FrameAdvance(void)
1610 {
1611 //printf("Frame Advance...\n");
1612 ToggleRunState();
1613 // Execute 1 frame, then exit (only useful in Pause mode)
1614 JaguarExecuteNew();
1615 //if (!vjs.softTypeDebugger)
1616 videoWidget->updateGL();
1617 ToggleRunState();
1618 // Need to execute 1 frames' worth of DSP thread as well :-/
1619
1620 //m68kDasmWin->Use68KPCAddress();
1621 //RefreshWindows();
1622 #ifdef _MSC_VER
1623 #pragma message("Warning: !!! Need to execute the DSP thread for 1 frame too !!!")
1624 #else
1625 #warning "!!! Need to execute the DSP thread for 1 frame too !!!"
1626 #endif // _MSC_VER
1627 }
1628
1629
1630 void MainWin::SetFullScreen(bool state/*= true*/)
1631 {
1632 if (!vjs.softTypeDebugger)
1633 {
1634 if (state)
1635 {
1636 mainWinPosition = pos();
1637 menuBar()->hide();
1638 statusBar()->hide();
1639 toolbar->hide();
1640
1641 if (debugbar)
1642 debugbar->hide();
1643
1644 // This is needed because the fullscreen may happen on a different
1645 // screen than screen 0:
1646 int screenNum = QApplication::desktop()->screenNumber(videoWidget);
1647 QRect r = QApplication::desktop()->screenGeometry(screenNum);
1648 double targetWidth = (double)VIRTUAL_SCREEN_WIDTH,
1649 targetHeight = (double)(vjs.hardwareTypeNTSC ? VIRTUAL_SCREEN_HEIGHT_NTSC : VIRTUAL_SCREEN_HEIGHT_PAL);
1650 double aspectRatio = targetWidth / targetHeight;
1651 // NOTE: Really should check here to see which dimension constrains the
1652 // other. Right now, we assume that height is the constraint.
1653 int newWidth = (int)(aspectRatio * (double)r.height());
1654 videoWidget->offset = (r.width() - newWidth) / 2;
1655 videoWidget->fullscreen = true;
1656 videoWidget->outputWidth = newWidth;
1657 videoWidget->setFixedSize(r.width(), r.height());
1658 showFullScreen();
1659 }
1660 else
1661 {
1662 // Seems Qt is fussy about this: showNormal() has to go first, or it
1663 // will keep the window stuck in a psuedo-fullscreen mode with no way
1664 // to get out of it (except closing the app).
1665 showNormal();
1666
1667 // Reset the video widget to windowed mode
1668 videoWidget->offset = 0;
1669 videoWidget->fullscreen = false;
1670 menuBar()->show();
1671 statusBar()->show();
1672 toolbar->show();
1673
1674 if (debugbar)
1675 debugbar->show();
1676
1677 ResizeMainWindow();
1678 move(mainWinPosition);
1679 }
1680 }
1681 }
1682
1683
1684 void MainWin::ToggleFullScreen(void)
1685 {
1686 fullScreen = !fullScreen;
1687 SetFullScreen(fullScreen);
1688 }
1689
1690
1691 //
1692 void MainWin::ShowExceptionVectorTableBrowserWin(void)
1693 {
1694 exceptionvectortableBrowseWin->show();
1695 exceptionvectortableBrowseWin->RefreshContents();
1696 }
1697
1698
1699 //
1700 void MainWin::ShowLocalBrowserWin(void)
1701 {
1702 LocalBrowseWin->show();
1703 LocalBrowseWin->RefreshContents();
1704 }
1705
1706
1707 //
1708 void MainWin::ShowCallStackBrowserWin(void)
1709 {
1710 CallStackBrowseWin->show();
1711 CallStackBrowseWin->RefreshContents();
1712 }
1713
1714
1715 void MainWin::ShowAllWatchBrowserWin(void)
1716 {
1717 allWatchBrowseWin->show();
1718 allWatchBrowseWin->RefreshContents();
1719 }
1720
1721
1722 void MainWin::ShowHeapAllocatorBrowserWin(void)
1723 {
1724 heapallocatorBrowseWin->show();
1725 heapallocatorBrowseWin->RefreshContents();
1726 }
1727
1728
1729 void MainWin::ShowMemoryBrowserWin(void)
1730 {
1731 memBrowseWin->show();
1732 memBrowseWin->RefreshContents();
1733 }
1734
1735
1736 void MainWin::ShowMemory1BrowserWin(int NumWin)
1737 {
1738 // for (int i = 0; i < vjs.nbrmemory1browserwindow; i++)
1739 {
1740 mem1BrowseWin[NumWin]->show();
1741 mem1BrowseWin[NumWin]->RefreshContents(NumWin);
1742 }
1743 }
1744
1745
1746 void MainWin::ShowEmuStatusWin(void)
1747 {
1748 emuStatusWin->show();
1749 emuStatusWin->RefreshContents();
1750 }
1751
1752
1753 void MainWin::ShowStackBrowserWin(void)
1754 {
1755 stackBrowseWin->show();
1756 stackBrowseWin->RefreshContents();
1757 }
1758
1759
1760 void MainWin::ShowCPUBrowserWin(void)
1761 {
1762 cpuBrowseWin->show();
1763 cpuBrowseWin->RefreshContents();
1764 }
1765
1766
1767 void MainWin::ShowOPBrowserWin(void)
1768 {
1769 opBrowseWin->show();
1770 opBrowseWin->RefreshContents();
1771 }
1772
1773
1774 void MainWin::ShowM68KDasmBrowserWin(void)
1775 {
1776 m68kDasmBrowseWin->show();
1777 m68kDasmBrowseWin->RefreshContents();
1778 }
1779
1780
1781 void MainWin::ShowRISCDasmBrowserWin(void)
1782 {
1783 riscDasmBrowseWin->show();
1784 riscDasmBrowseWin->RefreshContents();
1785 }
1786
1787
1788 //
1789 #if 0
1790 void MainWin::ShowDasmWin(void)
1791 {
1792 // DasmWin->show();
1793 // DasmWin->RefreshContents();
1794 }
1795 #endif
1796
1797
1798 //
1799 #if 0
1800 void MainWin::ShowVideoOutputWin(void)
1801 {
1802 //VideoOutputWindowCentrale = mainWindowCentrale->addSubWindow(videoWidget);
1803 //VideoOutputWindowCentrale->setWindowTitle(QString(tr("Video output")));
1804 //VideoOutputWindowCentrale->show();
1805 //memBrowseWin->show();
1806 //VideoOutputWin->show();
1807 //VideoOutputWin->RefreshContents(videoWidget);
1808 }
1809 #endif
1810
1811
1812 // Resize video window based on zoom factor
1813 // It doesn't apply in debugger mode as we use this window to display disassembly
1814 void MainWin::ResizeMainWindow(void)
1815 {
1816 if (!vjs.softTypeDebugger)
1817 {
1818 videoWidget->setFixedSize(zoomLevel * VIRTUAL_SCREEN_WIDTH, zoomLevel * (vjs.hardwareTypeNTSC ? VIRTUAL_SCREEN_HEIGHT_NTSC : VIRTUAL_SCREEN_HEIGHT_PAL));
1819
1820 // Show the test pattern if user requested plzDontKillMyComputer mode
1821 if (!powerButtonOn && plzDontKillMyComputer)
1822 {
1823 for (uint32_t y = 0; y < videoWidget->rasterHeight; y++)
1824 {
1825 if (vjs.hardwareTypeNTSC)
1826 {
1827 memcpy(videoWidget->buffer + (y * videoWidget->textureWidth), testPattern + (y * VIRTUAL_SCREEN_WIDTH), VIRTUAL_SCREEN_WIDTH * sizeof(uint32_t));
1828 }
1829 else
1830 {
1831 memcpy(videoWidget->buffer + (y * videoWidget->textureWidth), testPattern2 + (y * VIRTUAL_SCREEN_WIDTH), VIRTUAL_SCREEN_WIDTH * sizeof(uint32_t));
1832 }
1833 }
1834 }
1835
1836 adjustSize();
1837 }
1838 }
1839
1840
1841 // Read settings
1842 void MainWin::ReadSettings(void)
1843 {
1844 size_t i;
1845
1846 QSettings settings("Underground Software", "Virtual Jaguar");
1847
1848 //zoomLevel = settings.value("zoom", 2).toInt();
1849 allowUnknownSoftware = settings.value("showUnknownSoftware", false).toBool();
1850 lastEditedProfile = settings.value("lastEditedProfile", 0).toInt();
1851
1852 vjs.useJoystick = settings.value("useJoystick", false).toBool();
1853 vjs.joyport = settings.value("joyport", 0).toInt();
1854 vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
1855 vjs.frameSkip = settings.value("frameSkip", 0).toInt();
1856 vjs.useJaguarBIOS = settings.value("useJaguarBIOS", false).toBool();
1857 vjs.useRetailBIOS = settings.value("useRetailBIOS", false).toBool();
1858 vjs.useDevBIOS = settings.value("useDevBIOS", false).toBool();
1859 vjs.GPUEnabled = settings.value("GPUEnabled", true).toBool();
1860 vjs.DSPEnabled = settings.value("DSPEnabled", true).toBool();
1861 vjs.audioEnabled = settings.value("audioEnabled", true).toBool();
1862 vjs.usePipelinedDSP = settings.value("usePipelinedDSP", false).toBool();
1863 vjs.fullscreen = settings.value("fullscreen", false).toBool();
1864 vjs.useOpenGL = settings.value("useOpenGL", true).toBool();
1865 vjs.glFilter = settings.value("glFilterType", 1).toInt();
1866 vjs.renderType = settings.value("renderType", 0).toInt();
1867 vjs.biosType = settings.value("biosType", BT_M_SERIES).toInt();
1868 vjs.jaguarModel = settings.value("jaguarModel", JAG_M_SERIES).toInt();
1869 vjs.useFastBlitter = settings.value("useFastBlitter", false).toBool();
1870 strcpy(vjs.EEPROMPath, settings.value("EEPROMs", QStandardPaths::writableLocation(QStandardPaths::DataLocation).append("/eeproms/")).toString().toUtf8().data());
1871 strcpy(vjs.ROMPath, settings.value("ROMs", QStandardPaths::writableLocation(QStandardPaths::DataLocation).append("/software/")).toString().toUtf8().data());
1872 strcpy(vjs.screenshotPath, settings.value("Screenshots", QStandardPaths::writableLocation(QStandardPaths::DataLocation).append("/screenshots/")).toString().toUtf8().data());
1873
1874 // Read settings from the Debugger mode
1875 settings.beginGroup("debugger");
1876 strcpy(vjs.debuggerROMPath, settings.value("DefaultROM", "").toString().toUtf8().data());
1877 strcpy(vjs.sourcefilesearchPaths, settings.value("SourceFileSearchPaths", "").toString().toUtf8().data());
1878 vjs.nbrdisasmlines = settings.value("NbrDisasmLines", 32).toUInt();
1879 vjs.disasmopcodes = settings.value("DisasmOpcodes", true).toBool();
1880 vjs.displayHWlabels = settings.value("DisplayHWLabels", true).toBool();
1881 vjs.displayFullSourceFilename = settings.value("displayFullSourceFilename", true).toBool();
1882 vjs.ELFSectionsCheck = settings.value("ELFSectionsCheck", false).toBool();
1883 vjs.nbrmemory1browserwindow = settings.value("NbrMemory1BrowserWindow", MaxMemory1BrowserWindow).toUInt();
1884 settings.endGroup();
1885
1886 // Read settings from the Alpine mode
1887 settings.beginGroup("alpine");
1888 strcpy(vjs.alpineROMPath, settings.value("DefaultROM", "").toString().toUtf8().data());
1889 strcpy(vjs.absROMPath, settings.value("DefaultABS", "").toString().toUtf8().data());
1890 vjs.refresh = settings.value("refresh", 60).toUInt();
1891 vjs.allowWritesToROM = settings.value("writeROM", false).toBool();
1892 settings.endGroup();
1893
1894 // Read settings from the Keybindings
1895 settings.beginGroup("keybindings");
1896 for (i = 0; i < KB_END; i++)
1897 {
1898 strcpy(vjs.KBContent[i].KBSettingValue, settings.value(KeyBindingsTable[i].KBNameSetting, KeyBindingsTable[i].KBDefaultValue).toString().toUtf8().data());
1899 }
1900 settings.endGroup();
1901
1902 // Write important settings to the log file
1903 WriteLog("MainWin: Paths\n");
1904 WriteLog(" EEPROMPath = \"%s\"\n", vjs.EEPROMPath);
1905 WriteLog(" ROMPath = \"%s\"\n", vjs.ROMPath);
1906 WriteLog(" AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);
1907 WriteLog(" DebuggerROMPath = \"%s\"\n", vjs.debuggerROMPath);
1908 WriteLog(" absROMPath = \"%s\"\n", vjs.absROMPath);
1909 WriteLog(" ScreenshotsPath = \"%s\"\n", vjs.screenshotPath);
1910 WriteLog("SourceFileSearchPaths = \"%s\"\n", vjs.sourcefilesearchPaths);
1911 WriteLog("MainWin: Misc.\n");
1912 WriteLog(" Pipelined DSP = %s\n", (vjs.usePipelinedDSP ? "ON" : "off"));
1913
1914 #if 0
1915 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
1916 vjs.p1KeyBindings[BUTTON_U] = settings.value("p1k_up", Qt::Key_S).toInt();
1917 vjs.p1KeyBindings[BUTTON_D] = settings.value("p1k_down", Qt::Key_X).toInt();
1918 vjs.p1KeyBindings[BUTTON_L] = settings.value("p1k_left", Qt::Key_A).toInt();
1919 vjs.p1KeyBindings[BUTTON_R] = settings.value("p1k_right", Qt::Key_D).toInt();
1920 vjs.p1KeyBindings[BUTTON_C] = settings.value("p1k_c", Qt::Key_J).toInt();
1921 vjs.p1KeyBindings[BUTTON_B] = settings.value("p1k_b", Qt::Key_K).toInt();
1922 vjs.p1KeyBindings[BUTTON_A] = settings.value("p1k_a", Qt::Key_L).toInt();
1923 vjs.p1KeyBindings[BUTTON_OPTION] = settings.value("p1k_option", Qt::Key_O).toInt();
1924 vjs.p1KeyBindings[BUTTON_PAUSE] = settings.value("p1k_pause", Qt::Key_P).toInt();
1925 vjs.p1KeyBindings[BUTTON_0] = settings.value("p1k_0", Qt::Key_0).toInt();
1926 vjs.p1KeyBindings[BUTTON_1] = settings.value("p1k_1", Qt::Key_1).toInt();
1927 vjs.p1KeyBindings[BUTTON_2] = settings.value("p1k_2", Qt::Key_2).toInt();
1928 vjs.p1KeyBindings[BUTTON_3] = settings.value("p1k_3", Qt::Key_3).toInt();
1929 vjs.p1KeyBindings[BUTTON_4] = settings.value("p1k_4", Qt::Key_4).toInt();
1930 vjs.p1KeyBindings[BUTTON_5] = settings.value("p1k_5", Qt::Key_5).toInt();
1931 vjs.p1KeyBindings[BUTTON_6] = settings.value("p1k_6", Qt::Key_6).toInt();
1932 vjs.p1KeyBindings[BUTTON_7] = settings.value("p1k_7", Qt::Key_7).toInt();
1933 vjs.p1KeyBindings[BUTTON_8] = settings.value("p1k_8", Qt::Key_8).toInt();
1934 vjs.p1KeyBindings[BUTTON_9] = settings.value("p1k_9", Qt::Key_9).toInt();
1935 vjs.p1KeyBindings[BUTTON_d] = settings.value("p1k_pound", Qt::Key_Minus).toInt();
1936 vjs.p1KeyBindings[BUTTON_s] = settings.value("p1k_star", Qt::Key_Equal).toInt();
1937
1938 vjs.p2KeyBindings[BUTTON_U] = settings.value("p2k_up", Qt::Key_Up).toInt();
1939 vjs.p2KeyBindings[BUTTON_D] = settings.value("p2k_down", Qt::Key_Down).toInt();
1940 vjs.p2KeyBindings[BUTTON_L] = settings.value("p2k_left", Qt::Key_Left).toInt();
1941 vjs.p2KeyBindings[BUTTON_R] = settings.value("p2k_right", Qt::Key_Right).toInt();
1942 vjs.p2KeyBindings[BUTTON_C] = settings.value("p2k_c", Qt::Key_Z).toInt();
1943 vjs.p2KeyBindings[BUTTON_B] = settings.value("p2k_b", Qt::Key_X).toInt();
1944 vjs.p2KeyBindings[BUTTON_A] = settings.value("p2k_a", Qt::Key_C).toInt();
1945 vjs.p2KeyBindings[BUTTON_OPTION] = settings.value("p2k_option", Qt::Key_Apostrophe).toInt();
1946 vjs.p2KeyBindings[BUTTON_PAUSE] = settings.value("p2k_pause", Qt::Key_Return).toInt();
1947 vjs.p2KeyBindings[BUTTON_0] = settings.value("p2k_0", Qt::Key_0).toInt();
1948 vjs.p2KeyBindings[BUTTON_1] = settings.value("p2k_1", Qt::Key_1).toInt();
1949 vjs.p2KeyBindings[BUTTON_2] = settings.value("p2k_2", Qt::Key_2).toInt();
1950 vjs.p2KeyBindings[BUTTON_3] = settings.value("p2k_3", Qt::Key_3).toInt();
1951 vjs.p2KeyBindings[BUTTON_4] = settings.value("p2k_4", Qt::Key_4).toInt();
1952 vjs.p2KeyBindings[BUTTON_5] = settings.value("p2k_5", Qt::Key_5).toInt();
1953 vjs.p2KeyBindings[BUTTON_6] = settings.value("p2k_6", Qt::Key_6).toInt();
1954 vjs.p2KeyBindings[BUTTON_7] = settings.value("p2k_7", Qt::Key_7).toInt();
1955 vjs.p2KeyBindings[BUTTON_8] = settings.value("p2k_8", Qt::Key_8).toInt();
1956 vjs.p2KeyBindings[BUTTON_9] = settings.value("p2k_9", Qt::Key_9).toInt();
1957 vjs.p2KeyBindings[BUTTON_d] = settings.value("p2k_pound", Qt::Key_Slash).toInt();
1958 vjs.p2KeyBindings[BUTTON_s] = settings.value("p2k_star", Qt::Key_Asterisk).toInt();
1959 #endif
1960
1961 WriteLog("Read setting = Done\n");
1962
1963 ReadProfiles(&settings);
1964 DBGManager_SourceFileSearchPathsSet(vjs.sourcefilesearchPaths);
1965 }
1966
1967
1968 // Read UI settings
1969 // Default values will be used in case of no settings can be found
1970 #ifdef _MSC_VER
1971 #pragma message("Warning: !!! Need to check the window geometry to see if the positions are legal !!!")
1972 #else
1973 #warning "!!! Need to check the window geometry to see if the positions are legal !!!"
1974 #endif // _MSC_VER
1975 // i.e., someone could drag it to another screen, close it, then disconnect that screen
1976 void MainWin::ReadUISettings(void)
1977 {
1978 QPoint pos;
1979 char mem1Name[100];
1980 size_t i;
1981 QSize size;
1982
1983 // Point on the emulator settings
1984 QSettings settings("Underground Software", "Virtual Jaguar");
1985 settings.beginGroup("ui");
1986
1987 // Emulator main window UI information
1988 mainWinPosition = settings.value("pos", QPoint(200, 200)).toPoint();
1989 size = settings.value("size", QSize(400, 400)).toSize();
1990 resize(size);
1991 move(mainWinPosition);
1992 pos = settings.value("cartLoadPos", QPoint(200, 200)).toPoint();
1993 filePickWin->move(pos);
1994
1995 // Video output information
1996 zoomLevel = settings.value("zoom", 2).toInt();
1997
1998 // Emulator status UI information
1999 pos = settings.value("emuStatusWinPos", QPoint(200, 200)).toPoint();
2000 emuStatusWin->move(pos);
2001 settings.value("emuStatusWinIsVisible", false).toBool() ? ShowEmuStatusWin() : void();
2002
2003 // Alpine debug UI information (also needed by the Debugger)
2004 if (vjs.hardwareTypeAlpine || vjs.softTypeDebugger)
2005 {
2006 // CPU registers UI information
2007 pos = settings.value("cpuBrowseWinPos", QPoint(200, 200)).toPoint();
2008 cpuBrowseWin->move(pos);
2009 settings.value("cpuBrowseWinIsVisible", false).toBool() ? ShowCPUBrowserWin() : void();
2010
2011 // Memory browser UI information
2012 pos = settings.value("memBrowseWinPos", QPoint(200, 200)).toPoint();
2013 memBrowseWin->move(pos);
2014 settings.value("memBrowseWinIsVisible", false).toBool() ? ShowMemoryBrowserWin() : void();
2015
2016 // Stack browser UI information
2017 pos = settings.value("stackBrowseWinPos", QPoint(200, 200)).toPoint();
2018 stackBrowseWin->move(pos);
2019 settings.value("stackBrowseWinIsVisible", false).toBool() ? ShowStackBrowserWin() : void();
2020 size = settings.value("stackBrowseWinSize", QSize(400, 400)).toSize();
2021 stackBrowseWin->resize(size);
2022
2023 // OP (Object Processor) UI information
2024 pos = settings.value("opBrowseWinPos", QPoint(200, 200)).toPoint();
2025 opBrowseWin->move(pos);
2026 settings.value("opBrowseWinIsVisible", false).toBool() ? ShowOPBrowserWin() : void();
2027 size = settings.value("opBrowseWinSize", QSize(400, 400)).toSize();
2028 opBrowseWin->resize(size);
2029
2030 // RISC disassembly UI information
2031 pos = settings.value("riscDasmBrowseWinPos", QPoint(200, 200)).toPoint();
2032 riscDasmBrowseWin->move(pos);
2033 settings.value("riscDasmBrowseWinIsVisible", false).toBool() ? ShowRISCDasmBrowserWin() : void();
2034
2035 // M68k disassembly UI information
2036 pos = settings.value("m68kDasmBrowseWinPos", QPoint(200, 200)).toPoint();
2037 m68kDasmBrowseWin->move(pos);
2038 //settings.value("m68kDasmBrowseWinIsVisible", false).toBool() ? ShowM68KDasmBrowserWin() : void();
2039 #ifdef _MSC_VER
2040 #pragma message("Warning: !!! Need to check the M68k disassembly window position crashing !!!")
2041 #else
2042 #warning "!!! Need to check the M68k disassembly window position crashing !!!"
2043 #endif // _MSC_VER
2044 }
2045
2046 // Debugger UI information
2047 if (vjs.softTypeDebugger)
2048 {
2049 #if 0
2050 pos = settings.value("m68kDasmWinPos", QPoint(200, 200)).toPoint();
2051 m68kDasmWin->move(pos);
2052 //settings.value("m68kDasmWinIsVisible", false).toBool() ? m68kDasmWin->show() : m68kDasmWin->hide();
2053 pos = settings.value("GPUDasmWinPos", QPoint(200, 200)).toPoint();
2054 GPUDasmWin->move(pos);
2055 pos = settings.value("DSPDasmWinPos", QPoint(200, 200)).toPoint();
2056 DSPDasmWin->move(pos);
2057 #endif
2058 // All watch browser UI information
2059 pos = settings.value("allWatchBrowseWinPos", QPoint(200, 200)).toPoint();
2060 allWatchBrowseWin->move(pos);
2061 settings.value("allWatchBrowseWinIsVisible", false).toBool() ? ShowAllWatchBrowserWin() : void();
2062 size = settings.value("allWatchBrowseWinSize", QSize(400, 400)).toSize();
2063 allWatchBrowseWin->resize(size);
2064
2065 // Local browser UI information
2066 pos = settings.value("LocalBrowseWinPos", QPoint(200, 200)).toPoint();
2067 LocalBrowseWin->move(pos);
2068 settings.value("LocalBrowseWinIsVisible", false).toBool() ? ShowLocalBrowserWin() : void();
2069 size = settings.value("LocalBrowseWinSize", QSize(400, 400)).toSize();
2070 LocalBrowseWin->resize(size);
2071
2072 // Heap memory allocation browser UI information
2073 pos = settings.value("heapallocatorBrowseWinPos", QPoint(200, 200)).toPoint();
2074 heapallocatorBrowseWin->move(pos);
2075 settings.value("heapallocatorBrowseWinIsVisible", false).toBool() ? ShowHeapAllocatorBrowserWin() : void();
2076 size = settings.value("heapallocatorBrowseWinSize", QSize(400, 400)).toSize();
2077 heapallocatorBrowseWin->resize(size);
2078
2079 // Exception Vector Table UI Information
2080 pos = settings.value("exceptionVectorTableBrowseWinPos", QPoint(200, 200)).toPoint();
2081 exceptionvectortableBrowseWin->move(pos);
2082 settings.value("exceptionVectorTableBrowseWinIsVisible", false).toBool() ? ShowExceptionVectorTableBrowserWin() : void();
2083 size = settings.value("exceptionVectorTableBrowseWinSize", QSize(400, 400)).toSize();
2084 exceptionvectortableBrowseWin->resize(size);
2085
2086 // Call Stack browser UI information
2087 pos = settings.value("CallStackBrowseWinPos", QPoint(200, 200)).toPoint();
2088 CallStackBrowseWin->move(pos);
2089 settings.value("CallStackBrowseWinIsVisible", false).toBool() ? ShowCallStackBrowserWin() : void();
2090 size = settings.value("CallStackBrowseWinSize", QSize(400, 400)).toSize();
2091 CallStackBrowseWin->resize(size);
2092
2093 // cartridge directory and files UI information
2094 pos = settings.value("CartFilesListWinPos", QPoint(200, 200)).toPoint();
2095 CartFilesListWin->move(pos);
2096 settings.value("CartFilesListWinIsVisible", false).toBool() ? ShowCartFilesListWin() : void();
2097 size = settings.value("CartFilesListWinSize", QSize(400, 400)).toSize();
2098 CartFilesListWin->resize(size);
2099
2100 // Save dump UI information
2101 pos = settings.value("SaveDumpAsWinPos", QPoint(200, 200)).toPoint();
2102 SaveDumpAsWin->move(pos);
2103 settings.value("SaveDumpAsWinIsVisible", false).toBool() ? ShowSaveDumpAsWin() : void();
2104 size = settings.value("SaveDumpAsWinSize", QSize(400, 400)).toSize();
2105 SaveDumpAsWin->resize(size);
2106
2107 // Breakpoints UI information
2108 pos = settings.value("BreakpointsWinPos", QPoint(200, 200)).toPoint();
2109 BreakpointsWin->move(pos);
2110 settings.value("BreakpointsWinIsVisible", false).toBool() ? ShowBreakpointsWin() : void();
2111 size = settings.value("BreakpointsWinSize", QSize(400, 400)).toSize();
2112 BreakpointsWin->resize(size);
2113 // New function breakpoint UI information
2114 pos = settings.value("NewFunctionBreakpointWinPos", QPoint(200, 200)).toPoint();
2115 NewFunctionBreakpointWin->move(pos);
2116 settings.value("NewFunctionBreakpointWinIsVisible", false).toBool() ? ShowNewFunctionBreakpointWin() : void();
2117 size = settings.value("NewFunctionBreakpointWinSize", QSize(400, 400)).toSize();
2118 NewFunctionBreakpointWin->resize(size);
2119
2120 // Memories browser UI information
2121 for (i = 0; i < vjs.nbrmemory1browserwindow; i++)
2122 {
2123 sprintf(mem1Name, "mem1BrowseWinPos[%i]", (unsigned int)i);
2124 pos = settings.value(mem1Name, QPoint(200, 200)).toPoint();
2125 mem1BrowseWin[i]->move(pos);
2126 sprintf(mem1Name, "mem1BrowseWinIsVisible[%i]", (unsigned int)i);
2127 settings.value(mem1Name, false).toBool() ? ShowMemory1BrowserWin((int)i) : void();
2128 sprintf(mem1Name, "mem1BrowseWinSize[%i]", (unsigned int)i);
2129 size = settings.value(mem1Name, QSize(400, 400)).toSize();
2130 mem1BrowseWin[i]->resize(size);
2131 }
2132 }
2133
2134 settings.endGroup();
2135
2136 WriteLog("Read UI setting = Done\n");
2137 }
2138
2139
2140 // Save the settings
2141 void MainWin::WriteSettings(void)
2142 {
2143 size_t i;
2144
2145 // Point on the emulator settings
2146 QSettings settings("Underground Software", "Virtual Jaguar");
2147 //settings.setValue("pos", pos());
2148 //settings.setValue("size", size());
2149 //settings.setValue("cartLoadPos", filePickWin->pos());
2150
2151 //settings.setValue("zoom", zoomLevel);
2152 settings.setValue("showUnknownSoftware", allowUnknownSoftware);
2153 settings.setValue("lastEditedProfile", lastEditedProfile);
2154
2155 settings.setValue("useJoystick", vjs.useJoystick);
2156 settings.setValue("joyport", vjs.joyport);
2157 settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
2158 settings.setValue("frameSkip", vjs.frameSkip);
2159 settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
2160 settings.setValue("useRetailBIOS", vjs.useRetailBIOS);
2161 settings.setValue("useDevBIOS", vjs.useDevBIOS);
2162 settings.setValue("GPUEnabled", vjs.GPUEnabled);
2163 settings.setValue("DSPEnabled", vjs.DSPEnabled);
2164 settings.setValue("audioEnabled", vjs.audioEnabled);
2165 settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
2166 settings.setValue("fullscreen", vjs.fullscreen);
2167 settings.setValue("useOpenGL", vjs.useOpenGL);
2168 settings.setValue("glFilterType", vjs.glFilter);
2169 settings.setValue("renderType", vjs.renderType);
2170 settings.setValue("jaguarModel", vjs.jaguarModel);
2171 settings.setValue("biosType", vjs.biosType);
2172 settings.setValue("useFastBlitter", vjs.useFastBlitter);
2173 //settings.setValue("JagBootROM", vjs.jagBootPath);
2174 //settings.setValue("CDBootROM", vjs.CDBootPath);
2175 settings.setValue("EEPROMs", vjs.EEPROMPath);
2176 settings.setValue("ROMs", vjs.ROMPath);
2177 settings.setValue("Screenshots", vjs.screenshotPath);
2178
2179 // Write settings from the Alpine mode
2180 settings.beginGroup("alpine");
2181 settings.setValue("refresh", vjs.refresh);
2182 settings.setValue("DefaultROM", vjs.alpineROMPath);
2183 settings.setValue("DefaultABS", vjs.absROMPath);
2184 settings.setValue("writeROM", vjs.allowWritesToROM);
2185 settings.endGroup();
2186
2187 // Write settings from the Debugger mode
2188 settings.beginGroup("debugger");
2189 settings.setValue("DisplayHWLabels", vjs.displayHWlabels);
2190 settings.setValue("NbrDisasmLines", vjs.nbrdisasmlines);
2191 settings.setValue("DisasmOpcodes", vjs.disasmopcodes);
2192 settings.setValue("displayFullSourceFilename", vjs.displayFullSourceFilename);
2193 settings.setValue("ELFSectionsCheck", vjs.ELFSectionsCheck);
2194 settings.setValue("NbrMemory1BrowserWindow", (unsigned int)vjs.nbrmemory1browserwindow);
2195 settings.setValue("DefaultROM", vjs.debuggerROMPath);
2196 settings.setValue("SourceFileSearchPaths", vjs.sourcefilesearchPaths);
2197 settings.endGroup();
2198
2199 // Write settings from the Keybindings
2200 settings.beginGroup("keybindings");
2201 for (i = 0; i < KB_END; i++)
2202 {
2203 settings.setValue(KeyBindingsTable[i].KBNameSetting, vjs.KBContent[i].KBSettingValue);
2204 }
2205 settings.endGroup();
2206
2207 #if 0
2208 settings.setValue("p1k_up", vjs.p1KeyBindings[BUTTON_U]);
2209 settings.setValue("p1k_down", vjs.p1KeyBindings[BUTTON_D]);
2210 settings.setValue("p1k_left", vjs.p1KeyBindings[BUTTON_L]);
2211 settings.setValue("p1k_right", vjs.p1KeyBindings[BUTTON_R]);
2212 settings.setValue("p1k_c", vjs.p1KeyBindings[BUTTON_C]);
2213 settings.setValue("p1k_b", vjs.p1KeyBindings[BUTTON_B]);
2214 settings.setValue("p1k_a", vjs.p1KeyBindings[BUTTON_A]);
2215 settings.setValue("p1k_option", vjs.p1KeyBindings[BUTTON_OPTION]);
2216 settings.setValue("p1k_pause", vjs.p1KeyBindings[BUTTON_PAUSE]);
2217 settings.setValue("p1k_0", vjs.p1KeyBindings[BUTTON_0]);
2218 settings.setValue("p1k_1", vjs.p1KeyBindings[BUTTON_1]);
2219 settings.setValue("p1k_2", vjs.p1KeyBindings[BUTTON_2]);
2220 settings.setValue("p1k_3", vjs.p1KeyBindings[BUTTON_3]);
2221 settings.setValue("p1k_4", vjs.p1KeyBindings[BUTTON_4]);
2222 settings.setValue("p1k_5", vjs.p1KeyBindings[BUTTON_5]);
2223 settings.setValue("p1k_6", vjs.p1KeyBindings[BUTTON_6]);
2224 settings.setValue("p1k_7", vjs.p1KeyBindings[BUTTON_7]);
2225 settings.setValue("p1k_8", vjs.p1KeyBindings[BUTTON_8]);
2226 settings.setValue("p1k_9", vjs.p1KeyBindings[BUTTON_9]);
2227 settings.setValue("p1k_pound", vjs.p1KeyBindings[BUTTON_d]);
2228 settings.setValue("p1k_star", vjs.p1KeyBindings[BUTTON_s]);
2229
2230 settings.setValue("p2k_up", vjs.p2KeyBindings[BUTTON_U]);
2231 settings.setValue("p2k_down", vjs.p2KeyBindings[BUTTON_D]);
2232 settings.setValue("p2k_left", vjs.p2KeyBindings[BUTTON_L]);
2233 settings.setValue("p2k_right", vjs.p2KeyBindings[BUTTON_R]);
2234 settings.setValue("p2k_c", vjs.p2KeyBindings[BUTTON_C]);
2235 settings.setValue("p2k_b", vjs.p2KeyBindings[BUTTON_B]);
2236 settings.setValue("p2k_a", vjs.p2KeyBindings[BUTTON_A]);
2237 settings.setValue("p2k_option", vjs.p2KeyBindings[BUTTON_OPTION]);
2238 settings.setValue("p2k_pause", vjs.p2KeyBindings[BUTTON_PAUSE]);
2239 settings.setValue("p2k_0", vjs.p2KeyBindings[BUTTON_0]);
2240 settings.setValue("p2k_1", vjs.p2KeyBindings[BUTTON_1]);
2241 settings.setValue("p2k_2", vjs.p2KeyBindings[BUTTON_2]);
2242 settings.setValue("p2k_3", vjs.p2KeyBindings[BUTTON_3]);
2243 settings.setValue("p2k_4", vjs.p2KeyBindings[BUTTON_4]);
2244 settings.setValue("p2k_5", vjs.p2KeyBindings[BUTTON_5]);
2245 settings.setValue("p2k_6", vjs.p2KeyBindings[BUTTON_6]);
2246 settings.setValue("p2k_7", vjs.p2KeyBindings[BUTTON_7]);
2247 settings.setValue("p2k_8", vjs.p2KeyBindings[BUTTON_8]);
2248 settings.setValue("p2k_9", vjs.p2KeyBindings[BUTTON_9]);
2249 settings.setValue("p2k_pound", vjs.p2KeyBindings[BUTTON_d]);
2250 settings.setValue("p2k_star", vjs.p2KeyBindings[BUTTON_s]);
2251 #endif
2252
2253 WriteProfiles(&settings);
2254 DBGManager_SourceFileSearchPathsSet(vjs.sourcefilesearchPaths);
2255 }
2256
2257
2258 // Save the UI settings
2259 void MainWin::WriteUISettings(void)
2260 {
2261 char mem1Name[100];
2262 size_t i;
2263
2264 // Point on the emulator settings
2265 QSettings settings("Underground Software", "Virtual Jaguar");
2266 settings.beginGroup("ui");
2267
2268 // Emulator UI information
2269 settings.setValue("pos", pos());
2270 settings.setValue("size", size());
2271 settings.setValue("cartLoadPos", filePickWin->pos());
2272
2273 // Video output information
2274 settings.setValue("zoom", zoomLevel);
2275
2276 // Common UI information
2277 settings.setValue("emuStatusWinPos", emuStatusWin->pos());
2278 settings.setValue("emuStatusWinIsVisible", emuStatusWin->isVisible());
2279
2280 // Alpine debug UI information (also needed by the Debugger)
2281 if (vjs.hardwareTypeAlpine || vjs.softTypeDebugger)
2282 {
2283 settings.setValue("cpuBrowseWinPos", cpuBrowseWin->pos());
2284 settings.setValue("cpuBrowseWinIsVisible", cpuBrowseWin->isVisible());
2285 settings.setValue("memBrowseWinPos", memBrowseWin->pos());
2286 settings.setValue("memBrowseWinIsVisible", memBrowseWin->isVisible());
2287 settings.setValue("stackBrowseWinPos", stackBrowseWin->pos());
2288 settings.setValue("stackBrowseWinIsVisible", stackBrowseWin->isVisible());
2289 settings.setValue("stackBrowseWinSize", stackBrowseWin->size());
2290 settings.setValue("opBrowseWinPos", opBrowseWin->pos());
2291 settings.setValue("opBrowseWinIsVisible", opBrowseWin->isVisible());
2292 settings.setValue("opBrowseWinSize", opBrowseWin->size());
2293 settings.setValue("riscDasmBrowseWinPos", riscDasmBrowseWin->pos());
2294 settings.setValue("riscDasmBrowseWinIsVisible", riscDasmBrowseWin->isVisible());
2295 settings.setValue("m68kDasmBrowseWinPos", m68kDasmBrowseWin->pos());
2296 settings.setValue("m68kDasmBrowseWinIsVisible", m68kDasmBrowseWin->isVisible());
2297 }
2298
2299 // Debugger UI information
2300 if (vjs.softTypeDebugger)
2301 {
2302 #if 0
2303 settings.setValue("m68kDasmWinPos", m68kDasmWin->pos());
2304 //settings.setValue("m68kDasmWinIsVisible", m68kDasmWin->isVisible());
2305 settings.setValue("GPUDasmWinPos", GPUDasmWin->pos());
2306 settings.setValue("DSPDasmWinPos", DSPDasmWin->pos());
2307 #endif
2308 settings.setValue("allWatchBrowseWinPos", allWatchBrowseWin->pos());
2309 settings.setValue("allWatchBrowseWinIsVisible", allWatchBrowseWin->isVisible());
2310 settings.setValue("allWatchBrowseWinSize", allWatchBrowseWin->size());
2311 settings.setValue("LocalBrowseWinPos", LocalBrowseWin->pos());
2312 settings.setValue("LocalBrowseWinIsVisible", LocalBrowseWin->isVisible());
2313 settings.setValue("LocalBrowseWinSize", LocalBrowseWin->size());
2314 settings.setValue("heapallocatorBrowseWinPos", heapallocatorBrowseWin->pos());
2315 settings.setValue("heapallocatorBrowseWinIsVisible", heapallocatorBrowseWin->isVisible());
2316 settings.setValue("heapallocatorBrowseWinSize", heapallocatorBrowseWin->size());
2317 settings.setValue("exceptionVectorTableBrowseWinPos", exceptionvectortableBrowseWin->pos());
2318 settings.setValue("exceptionVectorTableBrowseWinIsVisible", exceptionvectortableBrowseWin->isVisible());
2319 settings.setValue("exceptionVectorTableBrowseWinSize", exceptionvectortableBrowseWin->size());
2320 settings.setValue("CallStackBrowseWinPos", CallStackBrowseWin->pos());
2321 settings.setValue("CallStackBrowseWinIsVisible", CallStackBrowseWin->isVisible());
2322 settings.setValue("CallStackBrowseWinSize", CallStackBrowseWin->size());
2323 settings.setValue("BreakpointsWinPos", BreakpointsWin->pos());
2324 settings.setValue("BreakpointsWinIsVisible", BreakpointsWin->isVisible());
2325 settings.setValue("BreakpointsWinSize", BreakpointsWin->size());
2326 settings.setValue("NewFunctionBreakpointWinPos", NewFunctionBreakpointWin->pos());
2327 settings.setValue("NewFunctionBreakpointWinIsVisible", NewFunctionBreakpointWin->isVisible());
2328 settings.setValue("NewFunctionBreakpointWinSize", NewFunctionBreakpointWin->size());
2329 settings.setValue("CartFilesListWinPos", CartFilesListWin->pos());
2330 settings.setValue("CartFilesListWinIsVisible", CartFilesListWin->isVisible());
2331 settings.setValue("CartFilesListWinSize", CartFilesListWin->size());
2332 settings.setValue("SaveDumpAsWinPos", SaveDumpAsWin->pos());
2333 settings.setValue("SaveDumpAsWinIsVisible", SaveDumpAsWin->isVisible());
2334 settings.setValue("SaveDumpAsWinSize", SaveDumpAsWin->size());
2335
2336 for (i = 0; i < vjs.nbrmemory1browserwindow; i++)
2337 {
2338 sprintf(mem1Name, "mem1BrowseWinPos[%i]", (unsigned int)i);
2339 settings.setValue(mem1Name, mem1BrowseWin[i]->pos());
2340 sprintf(mem1Name, "mem1BrowseWinIsVisible[%i]", (unsigned int)i);
2341 settings.setValue(mem1Name, mem1BrowseWin[i]->isVisible());
2342 sprintf(mem1Name, "mem1BrowseWinSize[%i]", (unsigned int)i);
2343 settings.setValue(mem1Name, mem1BrowseWin[i]->size());
2344 }
2345 }
2346
2347 settings.endGroup();
2348 }
2349
2350
2351 // Refresh alpine debug windows
2352 void MainWin::AlpineRefreshWindows(void)
2353 {
2354 cpuBrowseWin->RefreshContents();
2355 memBrowseWin->RefreshContents();
2356 stackBrowseWin->RefreshContents();
2357 opBrowseWin->RefreshContents();
2358 riscDasmBrowseWin->RefreshContents();
2359 m68kDasmBrowseWin->RefreshContents();
2360 }
2361
2362
2363 //
2364 void MainWin::CommonResetWindows(void)
2365 {
2366 }
2367
2368
2369 // Reset common
2370 void MainWin::CommonReset(void)
2371 {
2372 }
2373
2374
2375 // Reset soft debugger
2376 void MainWin::DebuggerReset(void)
2377 {
2378 if (vjs.softTypeDebugger)
2379 {
2380 DeleteAllBreakpoints();
2381 }
2382 }
2383
2384
2385 // Reset soft debugger windows
2386 void MainWin::DebuggerResetWindows(void)
2387 {
2388 if (vjs.softTypeDebugger)
2389 {
2390 FilesrcListWin->Reset();
2391 allWatchBrowseWin->Reset();
2392 heapallocatorBrowseWin->Reset();
2393 BreakpointsWin->Reset();
2394 CartFilesListWin->Reset();
2395 //ResetAlpineWindows();
2396 }
2397 }
2398
2399
2400 // Refresh common windows
2401 void MainWin::CommonRefreshWindows(void)
2402 {
2403 emuStatusWin->RefreshContents();
2404 }
2405
2406
2407 // Refresh view windows
2408 void MainWin::ViewRefreshWindows(void)
2409 {
2410 CartFilesListWin->RefreshContents();
2411 }
2412
2413
2414 //
2415 void MainWin::RefreshWindows(void)
2416 {
2417 DebuggerRefreshWindows();
2418 CommonRefreshWindows();
2419 }
2420
2421
2422 // Refresh soft debugger & alpine debug windows
2423 void MainWin::DebuggerRefreshWindows(void)
2424 {
2425 if (vjs.softTypeDebugger)
2426 {
2427 FilesrcListWin->RefreshContents();
2428 m68kDasmWin->RefreshContents();
2429 GPUDasmWin->RefreshContents();
2430 DSPDasmWin->RefreshContents();
2431 allWatchBrowseWin->RefreshContents();
2432 LocalBrowseWin->RefreshContents();
2433 CallStackBrowseWin->RefreshContents();
2434 heapallocatorBrowseWin->RefreshContents();
2435 BreakpointsWin->RefreshContents();
2436 for (size_t i = 0; i < vjs.nbrmemory1browserwindow; i++)
2437 {
2438 mem1BrowseWin[i]->RefreshContents(i);
2439 }
2440
2441 AlpineRefreshWindows();
2442 ViewRefreshWindows();
2443 }
2444 }
2445
2446
2447 // Create and save screenshot
2448 void MainWin::MakeScreenshot(void)
2449 {
2450 char Text[256];
2451 QImage screenshot;
2452 time_t now = time(0);
2453 struct tm tstruct;
2454
2455 // Create filename
2456 tstruct = *localtime(&now);
2457 sprintf(Text, "%svj_%i%i%i_%i%i%i.jpg", vjs.screenshotPath, tstruct.tm_year, tstruct.tm_mon, tstruct.tm_mday, tstruct.tm_hour, tstruct.tm_min, tstruct.tm_sec);
2458
2459 // Create screenshot
2460 screenshot = videoWidget->grabFrameBuffer();
2461 screenshot.save((char *)Text, "JPG", 100);
2462 }
2463