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