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