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