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