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