]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/mainwin.cpp
c0f215ee865dde2e77a85284c233851ccace9b73
[virtualjaguar] / src / gui / mainwin.cpp
1 //
2 // mainwin.cpp - Qt-based GUI for Virtual Jaguar: Main Application Window
3 // by James L. Hammons
4 // (C) 2009 Underground Software
5 //
6 // JLH = James L. Hammons <jlhamm@acm.org>
7 //
8 // Who  When        What
9 // ---  ----------  -------------------------------------------------------------
10 // JLH  12/23/2009  Created this file
11 // JLH  12/20/2010  Added settings, menus & toolbars
12 //
13
14 // FIXED:
15 //
16 //
17 // STILL TO BE DONE:
18 //
19 //
20
21 // Uncomment this for debugging...
22 //#define DEBUG
23 //#define DEBUGFOO                      // Various tool debugging...
24 //#define DEBUGTP                               // Toolpalette debugging...
25
26 #include "mainwin.h"
27
28 //#include <QtGui>
29 //#include <QtOpenGL>
30 #include "glwidget.h"
31 #include "about.h"
32 #include "settings.h"
33 #include "filepicker.h"
34
35 #include "jaguar.h"
36 #include "video.h"
37 #include "tom.h"
38 #include "log.h"
39 #include "file.h"
40
41 // Uncomment this to use built-in BIOS/CD-ROM BIOS
42 // You'll need a copy of jagboot.h & jagcd.h for this to work...!
43 //#define USE_BUILT_IN_BIOS
44
45 // Uncomment this for an official Virtual Jaguar release
46 //#define VJ_RELEASE_VERSION "2.0.0"
47 #warning !!! FIX !!! Figure out how to use this in GUI.CPP as well!
48
49 #ifdef USE_BUILT_IN_BIOS
50 #include "jagboot.h"
51 #include "jagcd.h"
52 #endif
53
54 // The way BSNES controls things is by setting a timer with a zero
55 // timeout, sleeping if not emulating anything. Seems there has to be a
56 // better way.
57
58 // It has a novel approach to plugging-in/using different video/audio/input
59 // methods, can we do something similar or should we just use the built-in
60 // QOpenGL?
61
62 // We're going to try to use the built-in OpenGL support and see how it goes.
63 // We'll make the VJ core modular so that it doesn't matter what GUI is in
64 // use, we can drop it in anywhere and use it as-is.
65
66 MainWin::MainWin(): running(false), powerButtonOn(false), showUntunedTankCircuit(true),
67         cartridgeLoaded(false)
68 {
69         videoWidget = new GLWidget(this);
70         setCentralWidget(videoWidget);
71         setWindowIcon(QIcon(":/res/vj-icon.png"));
72         setWindowTitle("Virtual Jaguar v2.0.0");
73
74         ReadSettings();
75         setUnifiedTitleAndToolBarOnMac(true);
76
77 #warning "!!! Save/Restore window location for FilePickerWindow !!!"
78         aboutWin = new AboutWindow(this);
79         filePickWin = new FilePickerWindow(this);
80
81     videoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
82     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
83
84         // Create actions
85
86         quitAppAct = new QAction(tr("E&xit"), this);
87         quitAppAct->setShortcuts(QKeySequence::Quit);
88         quitAppAct->setStatusTip(tr("Quit Virtual Jaguar"));
89         connect(quitAppAct, SIGNAL(triggered()), this, SLOT(close()));
90
91         powerAct = new QAction(QIcon(":/res/power.png"), tr("&Power"), this);
92         powerAct->setStatusTip(tr("Powers Jaguar on/off"));
93         powerAct->setCheckable(true);
94         powerAct->setChecked(false);
95         powerAct->setDisabled(true);
96         connect(powerAct, SIGNAL(triggered()), this, SLOT(TogglePowerState()));
97
98         pauseAct = new QAction(QIcon(":/res/pause.png"), tr("Pause"), this);
99         pauseAct->setStatusTip(tr("Toggles the running state"));
100         pauseAct->setCheckable(true);
101         pauseAct->setDisabled(true);
102         connect(pauseAct, SIGNAL(triggered()), this, SLOT(ToggleRunState()));
103
104         zoomActs = new QActionGroup(this);
105
106         x1Act = new QAction(QIcon(":/res/zoom100.png"), tr("Zoom 100%"), zoomActs);
107         x1Act->setStatusTip(tr("Set window zoom to 100%"));
108         x1Act->setCheckable(true);
109         connect(x1Act, SIGNAL(triggered()), this, SLOT(SetZoom100()));
110
111         x2Act = new QAction(QIcon(":/res/zoom200.png"), tr("Zoom 200%"), zoomActs);
112         x2Act->setStatusTip(tr("Set window zoom to 200%"));
113         x2Act->setCheckable(true);
114         connect(x2Act, SIGNAL(triggered()), this, SLOT(SetZoom200()));
115
116         x3Act = new QAction(QIcon(":/res/zoom300.png"), tr("Zoom 300%"), zoomActs);
117         x3Act->setStatusTip(tr("Set window zoom to 300%"));
118         x3Act->setCheckable(true);
119         connect(x3Act, SIGNAL(triggered()), this, SLOT(SetZoom300()));
120
121         tvTypeActs = new QActionGroup(this);
122
123         ntscAct = new QAction(QIcon(":/res/generic.png"), tr("NTSC"), tvTypeActs);
124         ntscAct->setStatusTip(tr("Sets Jaguar to NTSC mode"));
125         ntscAct->setCheckable(true);
126         connect(ntscAct, SIGNAL(triggered()), this, SLOT(SetNTSC()));
127
128         palAct = new QAction(QIcon(":/res/generic.png"), tr("PAL"), tvTypeActs);
129         palAct->setStatusTip(tr("Sets Jaguar to PAL mode"));
130         palAct->setCheckable(true);
131         connect(palAct, SIGNAL(triggered()), this, SLOT(SetPAL()));
132
133         blurAct = new QAction(QIcon(":/res/generic.png"), tr("Blur"), this);
134         blurAct->setStatusTip(tr("Sets OpenGL rendering to GL_NEAREST"));
135         blurAct->setCheckable(true);
136         connect(blurAct, SIGNAL(triggered()), this, SLOT(ToggleBlur()));
137
138         aboutAct = new QAction(QIcon(":/res/generic.png"), tr("&About..."), this);
139         aboutAct->setStatusTip(tr("Blatant self-promotion"));
140         connect(aboutAct, SIGNAL(triggered()), this, SLOT(ShowAboutWin()));
141
142 #warning "!!! Set up a decent keyboard shortcut for Insert Cartridge !!!"
143         filePickAct = new QAction(QIcon(":/res/software.png"), tr("&Insert Cartridge..."), this);
144         filePickAct->setStatusTip(tr("Insert a cartridge into Virtual Jaguar"));
145         connect(filePickAct, SIGNAL(triggered()), this, SLOT(InsertCart()));
146
147         // Misc. connections...
148         connect(filePickWin, SIGNAL(RequestLoad(QString)), this, SLOT(LoadSoftware(QString)));
149
150         // Create menus & toolbars
151
152         fileMenu = menuBar()->addMenu(tr("&File"));
153         fileMenu->addAction(filePickAct);
154         fileMenu->addAction(powerAct);
155         fileMenu->addAction(pauseAct);
156         fileMenu->addAction(quitAppAct);
157
158         helpMenu = menuBar()->addMenu(tr("&Help"));
159         helpMenu->addAction(aboutAct);
160
161         toolbar = addToolBar(tr("Stuff"));
162         toolbar->addAction(powerAct);
163         toolbar->addAction(pauseAct);
164         toolbar->addAction(filePickAct);
165         toolbar->addSeparator();
166         toolbar->addAction(x1Act);
167         toolbar->addAction(x2Act);
168         toolbar->addAction(x3Act);
169         toolbar->addSeparator();
170         toolbar->addAction(ntscAct);
171         toolbar->addAction(palAct);
172         toolbar->addSeparator();
173         toolbar->addAction(blurAct);
174
175         //      Create status bar
176         statusBar()->showMessage(tr("Ready"));
177
178         // Set toolbar buttons/menus based on settings read in (sync the UI)...
179         blurAct->setChecked(vjs.glFilter);
180         x1Act->setChecked(zoomLevel == 1);
181         x2Act->setChecked(zoomLevel == 2);
182         x3Act->setChecked(zoomLevel == 3);
183         running = powerAct->isChecked();
184         ntscAct->setChecked(vjs.hardwareTypeNTSC);
185         palAct->setChecked(!vjs.hardwareTypeNTSC);
186
187         // Do this in case original size isn't correct (mostly for the first-run case)
188         ResizeMainWindow();
189
190         // Set up timer based loop for animation...
191         timer = new QTimer(this);
192         connect(timer, SIGNAL(timeout()), this, SLOT(Timer()));
193         timer->start(20);
194
195         // NOTE: Keyboards/joysticks will *not* work until SDL is brought back in, or
196         //       the key handling is improved in Qt...
197         // Wait a minute... it seems they already are... So why no keyboard love?
198
199 #ifdef VJ_RELEASE_VERSION
200         WriteLog("Virtual Jaguar %s (Last full build was on %s %s)\n", VJ_RELEASE_VERSION, __DATE__, __TIME__);
201 #else
202         WriteLog("Virtual Jaguar SVN %s (Last full build was on %s %s)\n", __DATE__, __DATE__, __TIME__);
203 #endif
204         WriteLog("Initializing jaguar subsystem...\n");
205         JaguarInit();
206
207         // Get the BIOS ROM
208 #ifdef USE_BUILT_IN_BIOS
209         WriteLog("VJ: Using built in BIOS/CD BIOS...\n");
210         memcpy(jaguarBootROM, jagBootROM, 0x20000);
211         memcpy(jaguarCDBootROM, jagCDROM, 0x40000);
212         BIOSLoaded = CDBIOSLoaded = true;
213 #else
214 // What would be nice here would be a way to check if the BIOS was loaded so that we
215 // could disable the pushbutton on the Misc Options menu... !!! FIX !!! [DONE here, but needs to be fixed in GUI as well!]
216 WriteLog("About to attempt to load BIOSes...\n");
217 #if 1
218 //This is short-circuiting the file finding thread... ??? WHY ???
219         BIOSLoaded = (JaguarLoadROM(jaguarBootROM, vjs.jagBootPath) == 0x20000 ? true : false);
220 #else
221         BIOSLoaded = false;
222 #endif
223         WriteLog("VJ: BIOS is %savailable...\n", (BIOSLoaded ? "" : "not "));
224         CDBIOSLoaded = (JaguarLoadROM(jaguarCDBootROM, vjs.CDBootPath) == 0x40000 ? true : false);
225         WriteLog("VJ: CD BIOS is %savailable...\n", (CDBIOSLoaded ? "" : "not "));
226 #endif
227
228         SET32(jaguarMainRAM, 0, 0x00200000);                    // Set top of stack...
229
230 //Let's try this...
231 //      JaguarLoadFile("./software/Rayman (World).j64");
232 //      JaguarLoadFile("./software/I-War (World).j64");
233 //      JaguarLoadFile("./software/Alien vs Predator (World).j64");
234 //no    JaguarLoadFile("./software/battlesphere.bin");
235 //      JaguarLoadFile("./software/Battle Sphere Gold (World).j64");
236 //      JaguarLoadFile("./software/Rayman (USA, Europe).zip");
237 //This is crappy!!! !!! FIX !!!
238 //Is this even needed any more? Hmm. Maybe. Dunno.
239 //Seems like it is... But then again, maybe not. Have to test it to see.
240 //WriteLog("GUI: Resetting Jaguar...\n");
241 //      JaguarReset();
242 }
243
244 void MainWin::closeEvent(QCloseEvent * event)
245 {
246         WriteSettings();
247         event->accept(); // ignore() if can't close for some reason
248 }
249
250 void MainWin::Open(void)
251 {
252 }
253
254 //
255 // Here's the main emulator loop
256 //
257 void MainWin::Timer(void)
258 {
259         if (!running)
260                 return;
261
262         if (showUntunedTankCircuit)
263         {
264                 // Random hash & trash
265                 // We try to simulate an untuned tank circuit here... :-)
266                 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
267                 {
268                         for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
269                         {
270                                 videoWidget->buffer[(y * videoWidget->textureWidth) + x] = (rand() & 0xFF) << 8 | (rand() & 0xFF) << 16 | (rand() & 0xFF) << 24;// | (rand() & 0xFF);//0x000000FF;
271         //                      buffer[(y * textureWidth) + x] = x*y;
272                         }
273                 }
274         }
275         else
276         {
277                 // Otherwise, run the Jaguar simulation
278                 JaguarExecuteNew();
279 //              memcpy(videoWidget->buffer, backbuffer, videoWidget->rasterHeight * videoWidget->rasterWidth);
280                 memcpy(videoWidget->buffer, backbuffer, videoWidget->rasterHeight * videoWidget->textureWidth * sizeof(uint32_t));
281 //              memcpy(surface->pixels, backbuffer, TOMGetVideoModeWidth() * TOMGetVideoModeHeight() * 4);
282         }
283
284         videoWidget->updateGL();
285 }
286
287 #if 0
288 Window * RunEmu(void)
289 {
290 //      extern uint32 * backbuffer;
291         uint32 * overlayPixels = (uint32 *)sdlemuGetOverlayPixels();
292         memset(overlayPixels, 0x00, 640 * 480 * 4);                     // Clear out overlay...
293
294 //This is crappy... !!! FIX !!!
295 //      extern bool finished, showGUI;
296
297         sdlemuDisableOverlay();
298
299 //      uint32 nFrame = 0, nFrameskip = 0;
300         uint32 totalFrames = 0;
301         finished = false;
302         bool showMessage = true;
303         uint32 showMsgFrames = 120;
304         uint8 transparency = 0xFF;
305         // Pass a message to the "joystick" code to debounce the ESC key...
306         debounceRunKey = true;
307
308         uint32 cartType = 4;
309         if (jaguarRomSize == 0x200000)
310                 cartType = 0;
311         else if (jaguarRomSize == 0x400000)
312                 cartType = 1;
313         else if (jaguarMainRomCRC32 == 0x687068D5)
314                 cartType = 2;
315         else if (jaguarMainRomCRC32 == 0x55A0669C)
316                 cartType = 3;
317
318         const char * cartTypeName[5] = { "2M Cartridge", "4M Cartridge", "CD BIOS", "CD Dev BIOS", "Homebrew" };
319         uint32 elapsedTicks = SDL_GetTicks(), frameCount = 0, framesPerSecond = 0;
320
321         while (!finished)
322         {
323                 // Set up new backbuffer with new pixels and data
324                 JaguarExecuteNew();
325                 totalFrames++;
326 //WriteLog("Frame #%u...\n", totalFrames);
327 //extern bool doDSPDis;
328 //if (totalFrames == 373)
329 //      doDSPDis = true;
330
331 //Problem: Need to do this *only* when the state changes from visible to not...
332 //Also, need to clear out the GUI when not on (when showMessage is active...)
333 if (showGUI || showMessage)
334         sdlemuEnableOverlay();
335 else
336         sdlemuDisableOverlay();
337
338 //Add in a new function for clearing patches of screen (ClearOverlayRect)
339
340 // Also: Take frame rate into account when calculating fade time...
341
342                 // Some QnD GUI stuff here...
343                 if (showGUI)
344                 {
345                         FillScreenRectangle(overlayPixels, 8, 1*FONT_HEIGHT, 128, 4*FONT_HEIGHT, 0x00000000);
346                         extern uint32 gpu_pc, dsp_pc;
347                         DrawString(overlayPixels, 8, 1*FONT_HEIGHT, false, "GPU PC: %08X", gpu_pc);
348                         DrawString(overlayPixels, 8, 2*FONT_HEIGHT, false, "DSP PC: %08X", dsp_pc);
349                         DrawString(overlayPixels, 8, 4*FONT_HEIGHT, false, "%u FPS", framesPerSecond);
350                 }
351
352                 if (showMessage)
353                 {
354                         DrawString2(overlayPixels, 8, 24*FONT_HEIGHT, 0x007F63FF, transparency, "Running...");
355                         DrawString2(overlayPixels, 8, 26*FONT_HEIGHT, 0x001FFF3F, transparency, "%s, run address: %06X", cartTypeName[cartType], jaguarRunAddress);
356                         DrawString2(overlayPixels, 8, 27*FONT_HEIGHT, 0x001FFF3F, transparency, "CRC: %08X", jaguarMainRomCRC32);
357
358                         if (showMsgFrames == 0)
359                         {
360                                 transparency--;
361
362                                 if (transparency == 0)
363 {
364                                         showMessage = false;
365 /*extern bool doGPUDis;
366 doGPUDis = true;//*/
367 }
368
369                         }
370                         else
371                                 showMsgFrames--;
372                 }
373
374                 frameCount++;
375
376                 if (SDL_GetTicks() - elapsedTicks > 250)
377                         elapsedTicks += 250, framesPerSecond = frameCount * 4, frameCount = 0;
378         }
379
380         // Save the background for the GUI...
381         // In this case, we squash the color to monochrome, then force it to blue + green...
382         for(uint32 i=0; i<TOMGetVideoModeWidth() * 256; i++)
383         {
384                 uint32 pixel = backbuffer[i];
385                 uint8 b = (pixel >> 16) & 0xFF, g = (pixel >> 8) & 0xFF, r = pixel & 0xFF;
386                 pixel = ((r + g + b) / 3) & 0x00FF;
387                 backbuffer[i] = 0xFF000000 | (pixel << 16) | (pixel << 8);
388         }
389
390         sdlemuEnableOverlay();
391
392         return NULL;
393 }
394 #endif
395
396 void MainWin::TogglePowerState(void)
397 {
398         powerButtonOn = !powerButtonOn;
399
400         if (!powerButtonOn)
401         {
402                 pauseAct->setChecked(false);
403                 pauseAct->setDisabled(true);
404                 showUntunedTankCircuit = true;
405                 running = true;
406         }
407         else
408         {
409                 showUntunedTankCircuit = (cartridgeLoaded ? false : true);
410                 pauseAct->setDisabled(!cartridgeLoaded);
411 //This is crappy!!! !!! FIX !!!
412 //Is this even needed any more? Hmm. Maybe. Dunno.
413 //Seems like it is... But then again, maybe not. Have to test it to see.
414                 WriteLog("GUI: Resetting Jaguar...\n");
415                 JaguarReset();
416                 running = true;
417         }
418 }
419
420 void MainWin::ToggleRunState(void)
421 {
422         running = !running;
423
424         if (!running)
425         {
426 #if 0
427                 for(uint32_t x=0; x<videoWidget->rasterWidth; x++)
428                         for(uint32_t y=0; y<videoWidget->rasterHeight; y++)
429                                 videoWidget->buffer[(y * videoWidget->textureWidth) + x] = 0x00000000;
430 #else
431 //              for(uint32_t i=0; i<TOMGetVideoModeWidth() * 256; i++)
432                 for(uint32_t i=0; i<videoWidget->textureWidth * 256; i++)
433                 {
434                         uint32_t pixel = backbuffer[i];
435 //                      uint8_t b = (pixel >> 16) & 0xFF, g = (pixel >> 8) & 0xFF, r = pixel & 0xFF;
436                         uint8_t r = (pixel >> 24) & 0xFF, g = (pixel >> 16) & 0xFF, b = (pixel >> 8) & 0xFF;
437                         pixel = ((r + g + b) / 3) & 0x00FF;
438 //                      backbuffer[i] = 0xFF000000 | (pixel << 16) | (pixel << 8);
439                         backbuffer[i] = 0x000000FF | (pixel << 16) | (pixel << 8);
440                 }
441
442 //              memcpy(videoWidget->buffer, backbuffer, videoWidget->rasterHeight * videoWidget->rasterWidth);
443                 memcpy(videoWidget->buffer, backbuffer, videoWidget->rasterHeight * videoWidget->textureWidth * sizeof(uint32_t));
444 #endif
445
446                 videoWidget->updateGL();
447         }
448 }
449
450 void MainWin::SetZoom100(void)
451 {
452         zoomLevel = 1;
453         ResizeMainWindow();
454 }
455
456 void MainWin::SetZoom200(void)
457 {
458         zoomLevel = 2;
459         ResizeMainWindow();
460 }
461
462 void MainWin::SetZoom300(void)
463 {
464         zoomLevel = 3;
465         ResizeMainWindow();
466 }
467
468 void MainWin::SetNTSC(void)
469 {
470         vjs.hardwareTypeNTSC = true;
471         ResizeMainWindow();
472 }
473
474 void MainWin::SetPAL(void)
475 {
476         vjs.hardwareTypeNTSC = false;
477         ResizeMainWindow();
478 }
479
480 void MainWin::ToggleBlur(void)
481 {
482         vjs.glFilter = !vjs.glFilter;
483 }
484
485 void MainWin::ShowAboutWin(void)
486 {
487         aboutWin->show();
488 }
489
490 void MainWin::InsertCart(void)
491 {
492         filePickWin->show();
493 }
494
495 void MainWin::LoadSoftware(QString file)
496 {
497         running = false;                                                        //  Prevent bad things(TM) from happening...
498         SET32(jaguarMainRAM, 0, 0x00200000);                    // Set top of stack...
499         cartridgeLoaded = (JaguarLoadFile(file.toAscii().data()) ? true : false);
500
501 #if 0
502         showUntunedTankCircuit = !cartridgeLoaded;
503 //This is crappy!!! !!! FIX !!!
504 //Is this even needed any more? Hmm. Maybe. Dunno.
505 //Seems like it is... But then again, maybe not. Have to test it to see.
506         WriteLog("GUI: Resetting Jaguar...\n");
507         JaguarReset();
508         running = true;
509 #else
510         powerAct->setDisabled(false);
511         powerAct->setChecked(true);
512         powerButtonOn = false;
513         TogglePowerState();
514 #endif
515
516         QString newTitle = QString("Virtual Jaguar 2.0.0 - Now playing: %1")
517                 .arg(filePickWin->GetSelectedPrettyName());
518         setWindowTitle(newTitle);
519 }
520
521 void MainWin::ResizeMainWindow(void)
522 {
523         videoWidget->setFixedSize(zoomLevel * 320, zoomLevel * (vjs.hardwareTypeNTSC ? 240 : 256));
524         show();
525
526         for(int i=0; i<2; i++)
527         {
528                 resize(0, 0);
529                 usleep(2000);
530                 QApplication::processEvents();
531         }
532 }
533
534 void MainWin::ReadSettings(void)
535 {
536         QSettings settings("Underground Software", "Virtual Jaguar");
537         QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
538         QSize size = settings.value("size", QSize(400, 400)).toSize();
539         resize(size);
540         move(pos);
541
542         zoomLevel = settings.value("zoom", 1).toInt();
543
544         vjs.useJoystick      = settings.value("useJoystick", false).toBool();
545         vjs.joyport          = settings.value("joyport", 0).toInt();
546         vjs.hardwareTypeNTSC = settings.value("hardwareTypeNTSC", true).toBool();
547         vjs.frameSkip        = settings.value("frameSkip", 0).toInt();
548         vjs.useJaguarBIOS    = settings.value("useJaguarBIOS", false).toBool();
549         vjs.DSPEnabled       = settings.value("DSPEnabled", false).toBool();
550         vjs.usePipelinedDSP  = settings.value("usePipelinedDSP", false).toBool();
551         vjs.fullscreen       = settings.value("fullscreen", false).toBool();
552         vjs.useOpenGL        = settings.value("useOpenGL", true).toBool();
553         vjs.glFilter         = settings.value("glFilterType", 0).toInt();
554         vjs.renderType       = settings.value("renderType", 0).toInt();
555         strcpy(vjs.jagBootPath, settings.value("JagBootROM", "./bios/[BIOS] Atari Jaguar (USA, Europe).zip").toString().toAscii().data());
556         strcpy(vjs.CDBootPath, settings.value("CDBootROM", "./bios/jagcd.rom").toString().toAscii().data());
557         strcpy(vjs.EEPROMPath, settings.value("EEPROMs", "./eeproms").toString().toAscii().data());
558         strcpy(vjs.ROMPath, settings.value("ROMs", "./software").toString().toAscii().data());
559 WriteLog("MainWin: Paths\n");
560 WriteLog("    jagBootPath = \"%s\"\n", vjs.jagBootPath);
561 WriteLog("    CDBootPath  = \"%s\"\n", vjs.CDBootPath);
562 WriteLog("    EEPROMPath  = \"%s\"\n", vjs.EEPROMPath);
563 WriteLog("    ROMPath     = \"%s\"\n", vjs.ROMPath);
564 }
565
566 void MainWin::WriteSettings(void)
567 {
568         QSettings settings("Underground Software", "Virtual Jaguar");
569         settings.setValue("pos", pos());
570         settings.setValue("size", size());
571
572         settings.setValue("zoom", zoomLevel);
573
574         settings.setValue("useJoystick", vjs.useJoystick);
575         settings.setValue("joyport", vjs.joyport);
576         settings.setValue("hardwareTypeNTSC", vjs.hardwareTypeNTSC);
577         settings.setValue("frameSkip", vjs.frameSkip);
578         settings.setValue("useJaguarBIOS", vjs.useJaguarBIOS);
579         settings.setValue("DSPEnabled", vjs.DSPEnabled);
580         settings.setValue("usePipelinedDSP", vjs.usePipelinedDSP);
581         settings.setValue("fullscreen", vjs.fullscreen);
582         settings.setValue("useOpenGL", vjs.useOpenGL);
583         settings.setValue("glFilterType", vjs.glFilter);
584         settings.setValue("renderType", vjs.renderType);
585         settings.setValue("JagBootROM", vjs.jagBootPath);
586         settings.setValue("CDBootROM", vjs.CDBootPath);
587         settings.setValue("EEPROMs", vjs.EEPROMPath);
588         settings.setValue("ROMs", vjs.ROMPath);
589 }
590
591 // Here's how Byuu does it...
592 // I think I have it working now... :-)
593 #if 0
594 void Utility::resizeMainWindow()
595 {
596   unsigned region = config().video.context->region;
597   unsigned multiplier = config().video.context->multiplier;
598   unsigned width = 256 * multiplier;
599   unsigned height = (region == 0 ? 224 : 239) * multiplier;
600
601   if(config().video.context->correctAspectRatio)
602   {
603     if(region == 0)
604         {
605       width = (double)width * config().video.ntscAspectRatio + 0.5;  //NTSC adjust
606     }
607         else
608         {
609       width = (double)width * config().video.palAspectRatio  + 0.5;  //PAL adjust
610     }
611   }
612
613   if(config().video.isFullscreen == false)
614   {
615     //get effective desktop work area region (ignore Windows taskbar, OS X dock, etc.)
616     QRect deskRect = QApplication::desktop()->availableGeometry(mainWindow);
617
618     //ensure window size will not be larger than viewable desktop area
619     constrainSize(height, width, deskRect.height()); //- frameHeight);
620     constrainSize(width, height, deskRect.width());  //- frameWidth );
621
622     mainWindow->canvas->setFixedSize(width, height);
623     mainWindow->show();
624   }
625   else
626   {
627     for(unsigned i = 0; i < 2; i++)
628         {
629       unsigned iWidth = width, iHeight = height;
630
631       constrainSize(iHeight, iWidth, mainWindow->canvasContainer->size().height());
632       constrainSize(iWidth, iHeight, mainWindow->canvasContainer->size().width());
633
634       //center canvas onscreen; ensure it is not larger than viewable area
635       mainWindow->canvas->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
636       mainWindow->canvas->setFixedSize(iWidth, iHeight);
637       mainWindow->canvas->setMinimumSize(0, 0);
638
639       usleep(2000);
640       QApplication::processEvents();
641     }
642   }
643
644   //workaround for Qt/Xlib bug:
645   //if window resize occurs with cursor over it, Qt shows Qt::Size*DiagCursor;
646   //so force it to show Qt::ArrowCursor, as expected
647   mainWindow->setCursor(Qt::ArrowCursor);
648   mainWindow->canvasContainer->setCursor(Qt::ArrowCursor);
649   mainWindow->canvas->setCursor(Qt::ArrowCursor);
650
651   //workaround for DirectSound(?) bug:
652   //window resizing sometimes breaks audio sync, this call re-initializes it
653   updateAvSync();
654 }
655
656 void Utility::setScale(unsigned scale)
657 {
658   config().video.context->multiplier = scale;
659   resizeMainWindow();
660   mainWindow->shrink();
661   mainWindow->syncUi();
662 }
663
664 void QbWindow::shrink()
665 {
666   if(config().video.isFullscreen == false)
667   {
668     for(unsigned i = 0; i < 2; i++)
669         {
670       resize(0, 0);
671       usleep(2000);
672       QApplication::processEvents();
673     }
674   }
675 }
676 #endif