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