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