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