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