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