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