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