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