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