annotate src/win32/VBA.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
rev   line source
rlm@1 1 // VBA.cpp : Defines the class behaviors for the application.
rlm@1 2 //
rlm@1 3 #include "stdafx.h"
rlm@1 4 #include <mmsystem.h>
rlm@1 5 #include <cassert>
rlm@1 6
rlm@1 7 #include "resource.h"
rlm@1 8 #include "VBA.h"
rlm@1 9 #include "AVIWrite.h"
rlm@1 10 #include "Input.h"
rlm@1 11 #include "IUpdate.h"
rlm@1 12 #include "LangSelect.h"
rlm@1 13 #include "MainWnd.h"
rlm@1 14 #include "Reg.h"
rlm@1 15 #include "WavWriter.h"
rlm@1 16 #include "WinResUtil.h"
rlm@1 17 #include "WinMiscUtil.h"
rlm@1 18 #include "ramwatch.h"
rlm@1 19
rlm@1 20 #include "../gba/GBA.h"
rlm@1 21 #include "../gba/GBAGlobals.h"
rlm@1 22 #include "../gba/agbprint.h"
rlm@1 23 #include "../gb/GB.h"
rlm@1 24 #include "../gb/gbGlobals.h"
rlm@1 25 #include "../gb/gbPrinter.h"
rlm@1 26 #include "../common/CheatSearch.h"
rlm@1 27 #include "../gba/RTC.h"
rlm@1 28 #include "../gba/GBASound.h"
rlm@1 29 #include "../common/Util.h"
rlm@1 30 #include "../common/Text.h"
rlm@1 31 #include "../common/movie.h"
rlm@1 32 #include "../common/nesvideos-piece.h"
rlm@1 33 #include "../common/vbalua.h"
rlm@1 34 #include "../filters/filters.h"
rlm@1 35 #include "../version.h"
rlm@1 36
rlm@1 37 extern IDisplay *newGDIDisplay();
rlm@1 38 extern IDisplay *newDirectDrawDisplay();
rlm@1 39 extern IDisplay *newDirect3DDisplay();
rlm@1 40 extern IDisplay *newOpenGLDisplay();
rlm@1 41
rlm@1 42 extern Input *newDirectInput();
rlm@1 43
rlm@1 44 extern void remoteStubSignal(int, int);
rlm@1 45 extern void remoteOutput(char *, u32);
rlm@1 46 extern void remoteStubMain();
rlm@1 47 extern void remoteSetProtocol(int);
rlm@1 48 extern void remoteCleanUp();
rlm@1 49 extern int remoteSocket;
rlm@1 50
rlm@1 51 void winlog(const char *msg, ...);
rlm@1 52
rlm@1 53 bool debugger = false;
rlm@1 54
rlm@1 55 char movieFileToPlay[1024];
rlm@1 56 bool playMovieFile = false;
rlm@1 57 bool playMovieFileReadOnly = false;
rlm@1 58 char wavFileToOutput [1024];
rlm@1 59 bool outputWavFile = false;
rlm@1 60 bool outputAVIFile = false;
rlm@1 61 bool flagHideMenu = false;
rlm@1 62 int quitAfterTime = -1;
rlm@1 63 int pauseAfterTime = -1;
rlm@1 64
rlm@1 65 void winSignal(int, int);
rlm@1 66 void winOutput(char *, u32);
rlm@1 67
rlm@1 68 void (*dbgSignal)(int, int) = winSignal;
rlm@1 69 void (*dbgOutput)(char *, u32) = winOutput;
rlm@1 70
rlm@1 71 #ifdef MMX
rlm@1 72 extern "C" bool cpu_mmx;
rlm@1 73 #endif
rlm@1 74
rlm@1 75 // nowhere good to put them to
rlm@1 76
rlm@1 77 void DrawTextMessages(u8 *dest, int pitch, int left, int bottom)
rlm@1 78 {
rlm@1 79 for (int slot = 0; slot < SCREEN_MESSAGE_SLOTS; slot++)
rlm@1 80 {
rlm@1 81 if (theApp.screenMessage[slot])
rlm@1 82 {
rlm@1 83 if ((theApp.screenMessageDuration[slot] < 0 ||
rlm@1 84 (int)(GetTickCount() - theApp.screenMessageTime[slot]) < theApp.screenMessageDuration[slot]) &&
rlm@1 85 (!theApp.disableStatusMessage || slot == 1 || slot == 2))
rlm@1 86 {
rlm@1 87 drawText(dest,
rlm@1 88 pitch,
rlm@1 89 left,
rlm@1 90 bottom - 10 * (slot + 1),
rlm@1 91 theApp.screenMessageBuffer[slot],
rlm@1 92 theApp.screenMessageColorBuffer[slot]);
rlm@1 93 }
rlm@1 94 else
rlm@1 95 {
rlm@1 96 theApp.screenMessage[slot] = false;
rlm@1 97 }
rlm@1 98 }
rlm@1 99 }
rlm@1 100 }
rlm@1 101
rlm@1 102 // draw Lua graphics in game screen
rlm@1 103 void DrawLuaGui()
rlm@1 104 {
rlm@1 105 int copyX = 240, copyY = 160;
rlm@1 106 int screenX = 240, screenY = 160;
rlm@1 107 int copyOffsetX = 0, copyOffsetY = 0;
rlm@1 108 if (systemCartridgeType == 1)
rlm@1 109 {
rlm@1 110 if (gbBorderOn)
rlm@1 111 {
rlm@1 112 copyX = 256, copyY = 224;
rlm@1 113 screenX = 256, screenY = 224;
rlm@1 114 }
rlm@1 115 else
rlm@1 116 {
rlm@1 117 copyX = 160, copyY = 144;
rlm@1 118 screenX = 160, screenY = 144;
rlm@1 119 }
rlm@1 120 }
rlm@1 121 int pitch = copyX * (systemColorDepth / 8) + (systemColorDepth == 24 ? 0 : 4);
rlm@1 122
rlm@1 123 ++copyOffsetY; // don't know why it's needed
rlm@1 124
rlm@1 125 VBALuaGui(&pix[copyOffsetY * pitch + copyOffsetX * (systemColorDepth / 8)], copyX, screenX, screenY);
rlm@1 126 VBALuaClearGui();
rlm@1 127 }
rlm@1 128
rlm@1 129 void directXMessage(const char *msg)
rlm@1 130 {
rlm@1 131 systemMessage(
rlm@1 132 IDS_DIRECTX_7_REQUIRED,
rlm@1 133 "DirectX 7.0 or greater is required to run.\nDownload at http://www.microsoft.com/directx.\n\nError found at: %s",
rlm@1 134 msg);
rlm@1 135 }
rlm@1 136
rlm@1 137 void winlog(const char *msg, ...)
rlm@1 138 {
rlm@1 139 CString buffer;
rlm@1 140 va_list valist;
rlm@1 141
rlm@1 142 va_start(valist, msg);
rlm@1 143 buffer.FormatV(msg, valist);
rlm@1 144
rlm@1 145 FILE *winout = fopen("vba-trace.log", "w");
rlm@1 146
rlm@1 147 fputs(buffer, winout);
rlm@1 148
rlm@1 149 fclose(winout);
rlm@1 150
rlm@1 151 va_end(valist);
rlm@1 152 }
rlm@1 153
rlm@1 154 // code from SDL_main.c for Windows
rlm@1 155 /* Parse a command line buffer into arguments */
rlm@1 156
rlm@1 157 static int parseCommandLine(char *cmdline, char * *argv)
rlm@1 158 {
rlm@1 159 char *bufp;
rlm@1 160 int argc;
rlm@1 161
rlm@1 162 argc = 0;
rlm@1 163 for (bufp = cmdline; *bufp; )
rlm@1 164 {
rlm@1 165 /* Skip leading whitespace */
rlm@1 166 while (isspace(*bufp))
rlm@1 167 {
rlm@1 168 ++bufp;
rlm@1 169 }
rlm@1 170 /* Skip over argument */
rlm@1 171 if (*bufp == '"')
rlm@1 172 {
rlm@1 173 ++bufp;
rlm@1 174 if (*bufp)
rlm@1 175 {
rlm@1 176 if (argv)
rlm@1 177 {
rlm@1 178 argv[argc] = bufp;
rlm@1 179 }
rlm@1 180 ++argc;
rlm@1 181 }
rlm@1 182 /* Skip over word */
rlm@1 183 while (*bufp && (*bufp != '"'))
rlm@1 184 {
rlm@1 185 ++bufp;
rlm@1 186 }
rlm@1 187 }
rlm@1 188 else
rlm@1 189 {
rlm@1 190 if (*bufp)
rlm@1 191 {
rlm@1 192 if (argv)
rlm@1 193 {
rlm@1 194 argv[argc] = bufp;
rlm@1 195 }
rlm@1 196 ++argc;
rlm@1 197 }
rlm@1 198 /* Skip over word */
rlm@1 199 while (*bufp && !isspace(*bufp))
rlm@1 200 {
rlm@1 201 ++bufp;
rlm@1 202 }
rlm@1 203 }
rlm@1 204 if (*bufp)
rlm@1 205 {
rlm@1 206 if (argv)
rlm@1 207 {
rlm@1 208 *bufp = '\0';
rlm@1 209 }
rlm@1 210 ++bufp;
rlm@1 211 }
rlm@1 212 }
rlm@1 213 if (argv)
rlm@1 214 {
rlm@1 215 argv[argc] = NULL;
rlm@1 216 }
rlm@1 217 return(argc);
rlm@1 218 }
rlm@1 219
rlm@1 220 static void debugSystemScreenMessage1(const char *msg)
rlm@1 221 {
rlm@1 222 systemScreenMessage(msg, 3);
rlm@1 223 }
rlm@1 224
rlm@1 225 static void debugSystemScreenMessage2(const char *msg)
rlm@1 226 {
rlm@1 227 systemScreenMessage(msg, 4);
rlm@1 228 }
rlm@1 229
rlm@1 230 static void winSignal(int, int)
rlm@1 231 {}
rlm@1 232
rlm@1 233 #define CPUReadByteQuick(addr) \
rlm@1 234 map[(addr) >> 24].address[(addr) & map[(addr) >> 24].mask]
rlm@1 235
rlm@1 236 static void winOutput(char *s, u32 addr)
rlm@1 237 {
rlm@1 238 if (s)
rlm@1 239 {
rlm@1 240 log(s);
rlm@1 241 }
rlm@1 242 else
rlm@1 243 {
rlm@1 244 CString str;
rlm@1 245 char c;
rlm@1 246
rlm@1 247 c = CPUReadByteQuick(addr);
rlm@1 248 addr++;
rlm@1 249 while (c)
rlm@1 250 {
rlm@1 251 str += c;
rlm@1 252 c = CPUReadByteQuick(addr);
rlm@1 253 addr++;
rlm@1 254 }
rlm@1 255 log(str);
rlm@1 256 }
rlm@1 257 }
rlm@1 258
rlm@1 259 typedef BOOL (WINAPI * GETMENUBARINFO)(HWND, LONG, LONG, PMENUBARINFO);
rlm@1 260
rlm@1 261 static int winGetMenuBarHeight()
rlm@1 262 {
rlm@1 263 HINSTANCE hinstDll = /**/ ::LoadLibrary("USER32.DLL");
rlm@1 264
rlm@1 265 if (hinstDll)
rlm@1 266 {
rlm@1 267 GETMENUBARINFO func = (GETMENUBARINFO)GetProcAddress(hinstDll, "GetMenuBarInfo");
rlm@1 268
rlm@1 269 if (func)
rlm@1 270 {
rlm@1 271 MENUBARINFO info;
rlm@1 272 info.cbSize = sizeof(info);
rlm@1 273
rlm@1 274 func(AfxGetMainWnd()->GetSafeHwnd(), OBJID_MENU, 0, &info);
rlm@1 275
rlm@1 276 /**/ ::FreeLibrary(hinstDll);
rlm@1 277
rlm@1 278 return info.rcBar.bottom - info.rcBar.top + 1;
rlm@1 279 }
rlm@1 280 }
rlm@1 281
rlm@1 282 return GetSystemMetrics(SM_CYMENU);
rlm@1 283 }
rlm@1 284
rlm@1 285 /////////////////////////////////////////////////////////////////////////////
rlm@1 286 // VBA
rlm@1 287
rlm@1 288 BEGIN_MESSAGE_MAP(VBA, CWinApp)
rlm@1 289 //{{AFX_MSG_MAP(VBA)
rlm@1 290 // NOTE - the ClassWizard will add and remove mapping macros here.
rlm@1 291 // DO NOT EDIT what you see in these blocks of generated code!
rlm@1 292 //}}AFX_MSG_MAP
rlm@1 293 END_MESSAGE_MAP()
rlm@1 294
rlm@1 295 /////////////////////////////////////////////////////////////////////////////
rlm@1 296 // The one and only VBA object
rlm@1 297
rlm@1 298 VBA theApp;
rlm@1 299
rlm@1 300 /////////////////////////////////////////////////////////////////////////////
rlm@1 301 // VBA construction
rlm@1 302
rlm@1 303 VBA::VBA() : emulator(::theEmulator)
rlm@1 304 {
rlm@1 305 // important
rlm@1 306 {
rlm@1 307 #ifdef MULTITHREAD_STDLOCALE_WORKAROUND
rlm@1 308 // Note: there's a known threading bug regarding std::locale with MSVC according to
rlm@1 309 // http://connect.microsoft.com/VisualStudio/feedback/details/492128/std-locale-constructor-modifies-global-locale-via-setlocale
rlm@1 310 int iPreviousFlag = ::_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
rlm@1 311 #endif
rlm@1 312 using std::locale;
rlm@1 313 locale::global(locale(locale::classic(), "", locale::collate | locale::ctype));
rlm@1 314
rlm@1 315 #ifdef MULTITHREAD_STDLOCALE_WORKAROUND
rlm@1 316 if (iPreviousFlag > 0 )
rlm@1 317 ::_configthreadlocale(iPreviousFlag);
rlm@1 318 #endif
rlm@1 319 }
rlm@1 320
rlm@1 321 mode320Available = false;
rlm@1 322 mode640Available = false;
rlm@1 323 mode800Available = false;
rlm@1 324 windowPositionX = 0;
rlm@1 325 windowPositionY = 0;
rlm@1 326 filterFunction = NULL;
rlm@1 327 ifbFunction = NULL;
rlm@1 328 ifbType = 0;
rlm@1 329 filterType = 0;
rlm@1 330 filterWidth = 0;
rlm@1 331 filterHeight = 0;
rlm@1 332 fsWidth = 0;
rlm@1 333 fsHeight = 0;
rlm@1 334 fsColorDepth = 0;
rlm@1 335 fsForceChange = false;
rlm@1 336 surfaceSizeX = 0;
rlm@1 337 surfaceSizeY = 0;
rlm@1 338 sizeX = 0;
rlm@1 339 sizeY = 0;
rlm@1 340 videoOption = 0;
rlm@1 341 fullScreenStretch = false;
rlm@1 342 disableStatusMessage = false;
rlm@1 343 showSpeed = 1;
rlm@1 344 showSpeedTransparent = true;
rlm@1 345 showRenderedFrames = 0;
rlm@1 346 for (int j = 0; j < SCREEN_MESSAGE_SLOTS; j++)
rlm@1 347 {
rlm@1 348 screenMessage[j] = false;
rlm@1 349 screenMessageTime[j] = 0;
rlm@1 350 screenMessageDuration[j] = 0;
rlm@1 351 }
rlm@1 352 menuToggle = true;
rlm@1 353 display = NULL;
rlm@1 354 menu = NULL;
rlm@1 355 popup = NULL;
rlm@1 356 soundInitialized = false;
rlm@1 357 useBiosFile = false;
rlm@1 358 skipBiosFile = false;
rlm@1 359 active = true;
rlm@1 360 paused = false;
rlm@1 361 recentFreeze = false;
rlm@1 362 autoSaveLoadCheatList = false;
rlm@1 363 pauseDuringCheatSearch = false;
rlm@1 364 modelessCheatDialogIsOpen = false;
rlm@1 365 // winout = NULL;
rlm@1 366 // removeIntros = false;
rlm@1 367 autoIPS = true;
rlm@1 368 winGbBorderOn = 0;
rlm@1 369 hideMovieBorder = false;
rlm@1 370 winFlashSize = 0x10000;
rlm@1 371 winRtcEnable = false;
rlm@1 372 winSaveType = 0;
rlm@1 373 rewindMemory = NULL;
rlm@1 374 frameSearchMemory = NULL;
rlm@1 375 rewindPos = 0;
rlm@1 376 rewindTopPos = 0;
rlm@1 377 rewindCounter = 0;
rlm@1 378 rewindCount = 0;
rlm@1 379 rewindSaveNeeded = false;
rlm@1 380 rewindTimer = 0;
rlm@1 381 captureFormat = 0;
rlm@1 382 tripleBuffering = true;
rlm@1 383 autoHideMenu = false;
rlm@1 384 throttle = 100;
rlm@1 385 throttleLastTime = 0;
rlm@1 386 /// autoFrameSkipLastTime = 0;
rlm@1 387 /// autoFrameSkip = false;
rlm@1 388 vsync = false;
rlm@1 389 changingVideoSize = false;
rlm@1 390 pVideoDriverGUID = NULL;
rlm@1 391 renderMethod = DIRECT_DRAW;
rlm@1 392 iconic = false;
rlm@1 393 ddrawEmulationOnly = false;
rlm@1 394 ddrawUsingEmulationOnly = false;
rlm@1 395 ddrawDebug = false;
rlm@1 396 ddrawUseVideoMemory = false;
rlm@1 397 d3dFilter = 0;
rlm@1 398 glFilter = 0;
rlm@1 399 glType = 0;
rlm@1 400 regEnabled = false;
rlm@1 401 pauseWhenInactive = true;
rlm@1 402 muteWhenInactive = true;
rlm@1 403 enableBackgroundInput = false;
rlm@1 404 alwaysOnTop = false;
rlm@1 405 filenamePreference = true;
rlm@1 406 frameCounter = false;
rlm@1 407 lagCounter = false;
rlm@1 408 extraCounter = false;
rlm@1 409 inputDisplay = false;
rlm@1 410 speedupToggle = false;
rlm@1 411 useOldSync = false;
rlm@1 412 allowLeftRight = false;
rlm@1 413 autofireAccountForLag = false;
rlm@1 414 nextframeAccountForLag = false;
rlm@1 415 muteFrameAdvance = false;
rlm@1 416 muteWhenInactive = false;
rlm@1 417 winMuteForNow = false;
rlm@1 418 winGbPrinterEnabled = false;
rlm@1 419 threadPriority = 2;
rlm@1 420 disableMMX = false;
rlm@1 421 languageOption = 0;
rlm@1 422 languageModule = NULL;
rlm@1 423 languageName = "";
rlm@1 424 renderedFrames = 0;
rlm@1 425 input = NULL;
rlm@1 426 joypadDefault = 0;
rlm@1 427 autoFire = 0;
rlm@1 428 autoFire2 = 0;
rlm@1 429 autoHold = 0;
rlm@1 430 autoFireToggle = false;
rlm@1 431 winPauseNextFrame = false;
rlm@1 432 soundRecording = false;
rlm@1 433 soundRecorder = NULL;
rlm@1 434 sound = NULL;
rlm@1 435 aviRecording = false;
rlm@1 436 aviRecorder = NULL;
rlm@1 437 painting = false;
rlm@1 438 mouseCounter = 0;
rlm@1 439 movieReadOnly = true;
rlm@1 440 movieOnEndPause = false;
rlm@1 441 movieOnEndBehavior = 0;
rlm@1 442 wasPaused = false;
rlm@1 443 fsMaxScale = 0;
rlm@1 444 romSize = 0;
rlm@1 445 autoLoadMostRecent = false;
rlm@1 446 loadMakesRecent = false;
rlm@1 447 loadMakesCurrent = false;
rlm@1 448 saveMakesCurrent = false;
rlm@1 449 currentSlot = 0;
rlm@1 450 showSlotTime = false;
rlm@1 451 frameSearchLoadValid = false;
rlm@1 452 frameSearching = false;
rlm@1 453 frameSearchSkipping = false;
rlm@1 454 nvVideoLog = false;
rlm@1 455 nvAudioLog = false;
rlm@1 456 LoggingEnabled = 0;
rlm@1 457 /// FPS = 60;
rlm@1 458
rlm@1 459 updateCount = 0;
rlm@1 460
rlm@1 461 systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
rlm@1 462
rlm@1 463 ZeroMemory(&emulator, sizeof(emulator));
rlm@1 464
rlm@1 465 hAccel = NULL;
rlm@1 466
rlm@1 467 for (int i = 0; i < 24; )
rlm@1 468 {
rlm@1 469 systemGbPalette[i++] = (0x1f) | (0x1f << 5) | (0x1f << 10);
rlm@1 470 systemGbPalette[i++] = (0x15) | (0x15 << 5) | (0x15 << 10);
rlm@1 471 systemGbPalette[i++] = (0x0c) | (0x0c << 5) | (0x0c << 10);
rlm@1 472 systemGbPalette[i++] = 0;
rlm@1 473 }
rlm@1 474
rlm@1 475 VBAMovieInit();
rlm@1 476
rlm@1 477 TIMECAPS tc;
rlm@1 478 if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) == TIMERR_NOERROR)
rlm@1 479 {
rlm@1 480 wmTimerRes = min(max(tc.wPeriodMin, 1), tc.wPeriodMax);
rlm@1 481 timeBeginPeriod(wmTimerRes);
rlm@1 482 }
rlm@1 483 else
rlm@1 484 {
rlm@1 485 wmTimerRes = 5;
rlm@1 486 timeBeginPeriod(wmTimerRes);
rlm@1 487 }
rlm@1 488 }
rlm@1 489
rlm@1 490 VBA::~VBA()
rlm@1 491 {
rlm@1 492 if (VBAMovieActive())
rlm@1 493 VBAMovieStop(true);
rlm@1 494
rlm@1 495 saveSettings();
rlm@1 496
rlm@1 497 InterframeCleanup();
rlm@1 498
rlm@1 499 if (aviRecorder)
rlm@1 500 {
rlm@1 501 delete aviRecorder;
rlm@1 502 aviRecorder = NULL;
rlm@1 503 aviRecording = false;
rlm@1 504 }
rlm@1 505
rlm@1 506 if (soundRecorder)
rlm@1 507 {
rlm@1 508 delete soundRecorder;
rlm@1 509 soundRecorder = NULL;
rlm@1 510 }
rlm@1 511 soundRecording = false;
rlm@1 512 soundPause();
rlm@1 513 soundShutdown();
rlm@1 514
rlm@1 515 ((MainWnd *)(m_pMainWnd))->winFileClose();
rlm@1 516
rlm@1 517 if (input)
rlm@1 518 delete input;
rlm@1 519
rlm@1 520 shutdownDisplay();
rlm@1 521
rlm@1 522 if (rewindMemory)
rlm@1 523 free(rewindMemory);
rlm@1 524
rlm@1 525 if (frameSearchMemory)
rlm@1 526 free(frameSearchMemory);
rlm@1 527
rlm@1 528 timeEndPeriod(wmTimerRes);
rlm@1 529 }
rlm@1 530
rlm@1 531 /////////////////////////////////////////////////////////////////////////////
rlm@1 532 // VBA initialization
rlm@1 533
rlm@1 534 #include <afxdisp.h>
rlm@1 535
rlm@1 536 BOOL VBA::InitInstance()
rlm@1 537 {
rlm@1 538 AfxEnableControlContainer();
rlm@1 539 // Standard initialization
rlm@1 540 // If you are not using these features and wish to reduce the size
rlm@1 541 // of your final executable, you should remove from the following
rlm@1 542 // the specific initialization routines you do not need.
rlm@1 543
rlm@1 544 //#ifdef _AFXDLL
rlm@1 545 // Enable3dControls(); // Call this when using MFC in a shared DLL
rlm@1 546 //#else
rlm@1 547 // Enable3dControlsStatic(); // Call this when linking to MFC statically
rlm@1 548 //#endif
rlm@1 549
rlm@1 550 SetRegistryKey(_T("VBA"));
rlm@1 551
rlm@1 552 remoteSetProtocol(0);
rlm@1 553
rlm@1 554 systemVerbose = GetPrivateProfileInt("config", "verbose", 0, "VBA.ini");
rlm@1 555 systemDebug = GetPrivateProfileInt("config", "debug", 0, "VBA.ini");
rlm@1 556 ddrawDebug = GetPrivateProfileInt("config", "ddrawDebug", 0, "VBA.ini") ? true : false;
rlm@1 557
rlm@1 558 wndClass = AfxRegisterWndClass(0, LoadCursor(IDC_ARROW), (HBRUSH)GetStockObject(BLACK_BRUSH), LoadIcon(IDI_ICON));
rlm@1 559
rlm@1 560 char winBuffer[2048];
rlm@1 561 GetModuleFileName(NULL, winBuffer, 2048);
rlm@1 562 char *p = strrchr(winBuffer, '\\');
rlm@1 563 if (p)
rlm@1 564 *p = 0;
rlm@1 565 exeDir = winBuffer;
rlm@1 566
rlm@1 567 regInit(winBuffer);
rlm@1 568
rlm@1 569 loadSettings();
rlm@1 570 theApp.LuaFastForward = -1;
rlm@1 571 if (!initInput())
rlm@1 572 return FALSE;
rlm@1 573
rlm@1 574 if (!initDisplay())
rlm@1 575 {
rlm@1 576 if (videoOption >= VIDEO_320x240)
rlm@1 577 {
rlm@1 578 regSetDwordValue("video", VIDEO_1X);
rlm@1 579 if (pVideoDriverGUID)
rlm@1 580 regSetDwordValue("defaultVideoDriver", TRUE);
rlm@1 581 }
rlm@1 582 return FALSE;
rlm@1 583 }
rlm@1 584
rlm@1 585 hAccel = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR));
rlm@1 586
rlm@1 587 winAccelMgr.Connect((MainWnd *)m_pMainWnd);
rlm@1 588
rlm@1 589 extern void winAccelAddCommandsFromMenu(CAcceleratorManager & mgr, CMenu * pMenu, const CString &parentStr);
rlm@1 590 extern void winAccelAddCommandsFromTable(CAcceleratorManager & mgr);
rlm@1 591
rlm@1 592 winAccelAddCommandsFromMenu(winAccelMgr, &m_menu, CString());
rlm@1 593 winAccelAddCommandsFromTable(winAccelMgr);
rlm@1 594
rlm@1 595 winAccelMgr.CreateDefaultTable();
rlm@1 596 winAccelMgr.Load();
rlm@1 597 winAccelMgr.UpdateWndTable();
rlm@1 598 winAccelMgr.UpdateMenu(menu);
rlm@1 599
rlm@1 600 if (m_lpCmdLine[0])
rlm@1 601 {
rlm@1 602 int argc = parseCommandLine(m_lpCmdLine, NULL);
rlm@1 603 char * *argv = (char * *)malloc((argc + 1) * sizeof(char *));
rlm@1 604 parseCommandLine(m_lpCmdLine, argv);
rlm@1 605
rlm@1 606 bool gotFlag = false, enoughArgs = false;
rlm@1 607 for (int i = 0; i < argc; i++)
rlm@1 608 {
rlm@1 609 if (argv[i][0] == '-' || gotFlag)
rlm@1 610 {
rlm@1 611 if (!gotFlag)
rlm@1 612 loadSettings();
rlm@1 613 gotFlag = true;
rlm@1 614 if (_stricmp(argv[i], "-rom") == 0)
rlm@1 615 {
rlm@1 616 if (i + 1 >= argc || argv[i + 1][0] == '-')
rlm@1 617 goto invalidArgument;
rlm@1 618 romFilename = argv[++i];
rlm@1 619 winCorrectPath(romFilename);
rlm@1 620 gameFilename = romFilename;
rlm@1 621 }
rlm@1 622 else if (_stricmp(argv[i], "-bios") == 0)
rlm@1 623 {
rlm@1 624 if (i + 1 >= argc || argv[i + 1][0] == '-')
rlm@1 625 goto invalidArgument;
rlm@1 626 biosFileName = argv[++i];
rlm@1 627 winCorrectPath(biosFileName);
rlm@1 628
rlm@1 629 //systemLoadBIOS();
rlm@1 630 }
rlm@1 631 else if (_stricmp(argv[i], "-frameskip") == 0)
rlm@1 632 {
rlm@1 633 if (i + 1 >= argc || argv[i + 1][0] == '-')
rlm@1 634 goto invalidArgument;
rlm@1 635 frameSkip = atoi(argv[++i]);
rlm@1 636 if (frameSkip < 0)
rlm@1 637 frameSkip = 0;
rlm@1 638 if (frameSkip > 9)
rlm@1 639 frameSkip = 9;
rlm@1 640 gbFrameSkip = frameSkip;
rlm@1 641 }
rlm@1 642 else if (_stricmp(argv[i], "-throttle") == 0)
rlm@1 643 {
rlm@1 644 if (i + 1 >= argc || argv[i + 1][0] == '-')
rlm@1 645 goto invalidArgument;
rlm@1 646 throttle = atoi(argv[++i]);
rlm@1 647 if (throttle < 5)
rlm@1 648 throttle = 5;
rlm@1 649 if (throttle > 1000)
rlm@1 650 throttle = 1000;
rlm@1 651 }
rlm@1 652 else if (_stricmp(argv[i], "-throttleKeepPitch") == 0)
rlm@1 653 {
rlm@1 654 if (i + 1 >= argc || argv[i + 1][0] == '-')
rlm@1 655 goto invalidArgument;
rlm@1 656 accuratePitchThrottle = atoi(argv[++i]) != 0;
rlm@1 657 }
rlm@1 658 else if (_stricmp(argv[i], "-synchronize") == 0)
rlm@1 659 {
rlm@1 660 if (i + 1 >= argc || argv[i + 1][0] == '-')
rlm@1 661 goto invalidArgument;
rlm@1 662 synchronize = atoi(argv[++i]) != 0;
rlm@1 663 }
rlm@1 664 else if (_stricmp(argv[i], "-hideborder") == 0)
rlm@1 665 {
rlm@1 666 if (i + 1 >= argc || argv[i + 1][0] == '-')
rlm@1 667 goto invalidArgument;
rlm@1 668 hideMovieBorder = atoi(argv[++i]) != 0;
rlm@1 669 }
rlm@1 670 else if (_stricmp(argv[i], "-play") == 0)
rlm@1 671 {
rlm@1 672 playMovieFile = true;
rlm@1 673 if (i + 1 >= argc || argv[i + 1][0] == '-')
rlm@1 674 goto invalidArgument;
rlm@1 675 strcpy(movieFileToPlay, argv[++i]);
rlm@1 676 winCorrectPath(movieFileToPlay);
rlm@1 677 if (i + 1 >= argc || argv[i + 1][0] == '-') { --i; goto invalidArgument; }
rlm@1 678 playMovieFileReadOnly = atoi(argv[++i]) != 0;
rlm@1 679 }
rlm@1 680 else if (_stricmp(argv[i], "-videoLog") == 0)
rlm@1 681 {
rlm@1 682 nvVideoLog = true;
rlm@1 683 nvAudioLog = true;
rlm@1 684 LoggingEnabled = 2;
rlm@1 685 if (i + 1 >= argc || argv[i + 1][0] == '-') {}
rlm@1 686 else
rlm@1 687 NESVideoSetVideoCmd(argv[++i]);
rlm@1 688 }
rlm@1 689 else if (_stricmp(argv[i], "-logDebug") == 0)
rlm@1 690 {
rlm@1 691 NESVideoEnableDebugging(debugSystemScreenMessage1, debugSystemScreenMessage2);
rlm@1 692 }
rlm@1 693 else if (_stricmp(argv[i], "-logToFile") == 0)
rlm@1 694 {
rlm@1 695 NESVideoSetFileFuncs(fopen, fclose);
rlm@1 696 }
rlm@1 697 else if (_stricmp(argv[i], "-outputWAV") == 0)
rlm@1 698 {
rlm@1 699 outputWavFile = true;
rlm@1 700 if (i + 1 >= argc || argv[i + 1][0] == '-')
rlm@1 701 goto invalidArgument;
rlm@1 702 strcpy(wavFileToOutput, argv[++i]);
rlm@1 703 }
rlm@1 704 else if (_stricmp(argv[i], "-outputAVI") == 0)
rlm@1 705 {
rlm@1 706 outputAVIFile = true;
rlm@1 707 }
rlm@1 708 else if (_stricmp(argv[i], "-quitAfter") == 0)
rlm@1 709 {
rlm@1 710 if (i + 1 >= argc || argv[i + 1][0] == '-')
rlm@1 711 goto invalidArgument;
rlm@1 712 quitAfterTime = atoi(argv[++i]);
rlm@1 713 }
rlm@1 714 else if (_stricmp(argv[i], "-pauseAt") == 0)
rlm@1 715 {
rlm@1 716 if (i + 1 >= argc || argv[i + 1][0] == '-')
rlm@1 717 goto invalidArgument;
rlm@1 718 pauseAfterTime = atoi(argv[++i]);
rlm@1 719 }
rlm@1 720 else if (_stricmp(argv[i], "-videoScale") == 0)
rlm@1 721 {
rlm@1 722 if (i + 1 >= argc || argv[i + 1][0] == '-')
rlm@1 723 goto invalidArgument;
rlm@1 724 int size = atoi(argv[++i]);
rlm@1 725 if (size < 1)
rlm@1 726 size = 1;
rlm@1 727 if (size > 4)
rlm@1 728 size = 4;
rlm@1 729 switch (size)
rlm@1 730 {
rlm@1 731 case 1:
rlm@1 732 videoOption = VIDEO_1X; break;
rlm@1 733 case 2:
rlm@1 734 videoOption = VIDEO_2X; break;
rlm@1 735 case 3:
rlm@1 736 videoOption = VIDEO_3X; break;
rlm@1 737 case 4:
rlm@1 738 videoOption = VIDEO_4X; break;
rlm@1 739 }
rlm@1 740 }
rlm@1 741 else if (_stricmp(argv[i], "-hideMenu") == 0)
rlm@1 742 {
rlm@1 743 flagHideMenu = true;
rlm@1 744 }
rlm@1 745 else
rlm@1 746 {
rlm@1 747 enoughArgs = true;
rlm@1 748 invalidArgument:
rlm@1 749 char str [2048]; // the string is larger than 1024 bytes
rlm@1 750 strcpy(str, "");
rlm@1 751 if (_stricmp(argv[i], "-h") != 0)
rlm@1 752 if (enoughArgs)
rlm@1 753 sprintf(str, "Invalid commandline argument %d: %s\n", i, argv[i]);
rlm@1 754 else
rlm@1 755 sprintf(str, "Not enough arguments for arg %d: %s\n", i, argv[i]);
rlm@1 756 strcat(str, "Valid commands:\n"
rlm@1 757 "-h \t\t\t displays this help\n"
rlm@1 758 "-rom filename \t\t opens the given ROM\n"
rlm@1 759 "-bios filename \t\t use the given GBA BIOS\n"
rlm@1 760 "-play filename val \t\t plays the given VBM movie (val: 1 = read-only, 0 = editable)\n"
rlm@1 761 "-outputWAV filename \t outputs WAV audio to the given file\n"
rlm@1 762 "-outputAVI \t\t outputs an AVI (you are prompted for location and codec)\n"
rlm@1 763 "-frameskip val \t\t sets the frameskip amount to the given value\n"
rlm@1 764 "-synchronize val \t\t limits running speed to sound playing speed, (0 = off, 1 = on)\n"
rlm@1 765 "-throttle val \t\t sets the throttle speed to the given percentage\n"
rlm@1 766 "-hideborder val \t\t hides SGB border, if any (0 = show, 1 = hide)\n"
rlm@1 767 "-throttleKeepPitch val \t if throttle and synch, don't change sound freq (0 = off, 1 = on)\n"
rlm@1 768 "-quitAfter val \t\t close program when frame counter == val\n"
rlm@1 769 "-pauseAt val \t\t pause (movie) once when frame counter == val\n"
rlm@1 770 "-videoScale val \t\t sets the video size (val = 1 for 1X, 2 for 2X, 3 for 3X, or 4 for 4X)\n"
rlm@1 771 "-hideMenu \t\t hides the menu until program exit\n"
rlm@1 772 "\n"
rlm@1 773 "-videoLog args \t does (nesvideos) video+audio logging with the given arguments\n"
rlm@1 774 "-logToFile \t tells logging to use fopen/fclose of args, if logging is enabled\n"
rlm@1 775 "-logDebug \t tells logging to output debug info to screen, if logging is enabled\n"
rlm@1 776 );
rlm@1 777 theApp.winCheckFullscreen();
rlm@1 778 AfxGetApp()->m_pMainWnd->MessageBox(str, "Commandline Help", MB_OK | MB_ICONINFORMATION);
rlm@1 779 exit(0);
rlm@1 780 }
rlm@1 781 }
rlm@1 782 else
rlm@1 783 {
rlm@1 784 // assume anything else is a ROM, for backward compatibility
rlm@1 785 romFilename = argv[i++];
rlm@1 786 gameFilename = romFilename;
rlm@1 787 loadSettings();
rlm@1 788 }
rlm@1 789 }
rlm@1 790
rlm@1 791 /*
rlm@1 792 int index = filename.ReverseFind('.');
rlm@1 793
rlm@1 794 if (index != -1)
rlm@1 795 filename = filename.Left(index);
rlm@1 796 */
rlm@1 797 if (romFilename.GetLength() > 0)
rlm@1 798 {
rlm@1 799 ((MainWnd *)theApp.m_pMainWnd)->winFileRun();
rlm@1 800 }
rlm@1 801 free(argv);
rlm@1 802 }
rlm@1 803
rlm@1 804 return TRUE;
rlm@1 805 }
rlm@1 806
rlm@1 807 void VBA::adjustDestRect()
rlm@1 808 {
rlm@1 809 POINT point;
rlm@1 810
rlm@1 811 point.x = 0;
rlm@1 812 point.y = 0;
rlm@1 813
rlm@1 814 m_pMainWnd->ClientToScreen(&point);
rlm@1 815 dest.top = point.y;
rlm@1 816 dest.left = point.x;
rlm@1 817
rlm@1 818 point.x = surfaceSizeX;
rlm@1 819 point.y = surfaceSizeY;
rlm@1 820
rlm@1 821 m_pMainWnd->ClientToScreen(&point);
rlm@1 822 dest.bottom = point.y;
rlm@1 823 dest.right = point.x;
rlm@1 824
rlm@1 825 if (videoOption > VIDEO_4X)
rlm@1 826 {
rlm@1 827 int menuSkip = 0;
rlm@1 828 if (menuToggle)
rlm@1 829 {
rlm@1 830 menuSkip = winGetMenuBarHeight();
rlm@1 831 }
rlm@1 832
rlm@1 833 if (fullScreenStretch)
rlm@1 834 {
rlm@1 835 dest.top = menuSkip;
rlm@1 836 dest.left = 0;
rlm@1 837 dest.right = fsWidth;
rlm@1 838 dest.bottom = fsHeight;
rlm@1 839 }
rlm@1 840 else
rlm@1 841 {
rlm@1 842 int top = (fsHeight - surfaceSizeY) / 2;
rlm@1 843 int left = (fsWidth - surfaceSizeX) / 2;
rlm@1 844 dest.top += top - menuSkip * 2;
rlm@1 845 dest.bottom += top;
rlm@1 846 dest.left += left;
rlm@1 847 dest.right += left;
rlm@1 848 }
rlm@1 849 }
rlm@1 850 }
rlm@1 851
rlm@1 852 void VBA::updateIFB()
rlm@1 853 {
rlm@1 854 if (systemColorDepth == 16)
rlm@1 855 {
rlm@1 856 switch (ifbType)
rlm@1 857 {
rlm@1 858 case 0:
rlm@1 859 default:
rlm@1 860 ifbFunction = NULL;
rlm@1 861 break;
rlm@1 862 case 1:
rlm@1 863 ifbFunction = MotionBlurIB;
rlm@1 864 break;
rlm@1 865 case 2:
rlm@1 866 ifbFunction = SmartIB;
rlm@1 867 break;
rlm@1 868 }
rlm@1 869 }
rlm@1 870 else if (systemColorDepth == 32)
rlm@1 871 {
rlm@1 872 switch (ifbType)
rlm@1 873 {
rlm@1 874 case 0:
rlm@1 875 default:
rlm@1 876 ifbFunction = NULL;
rlm@1 877 break;
rlm@1 878 case 1:
rlm@1 879 ifbFunction = MotionBlurIB32;
rlm@1 880 break;
rlm@1 881 case 2:
rlm@1 882 ifbFunction = SmartIB32;
rlm@1 883 break;
rlm@1 884 }
rlm@1 885 }
rlm@1 886 else
rlm@1 887 ifbFunction = NULL;
rlm@1 888 }
rlm@1 889
rlm@1 890 void VBA::updateFilter()
rlm@1 891 {
rlm@1 892 filterWidth = sizeX;
rlm@1 893 filterHeight = sizeY;
rlm@1 894
rlm@1 895 if (systemColorDepth == 16 && (videoOption > VIDEO_1X &&
rlm@1 896 videoOption != VIDEO_320x240))
rlm@1 897 {
rlm@1 898 switch (filterType)
rlm@1 899 {
rlm@1 900 default:
rlm@1 901 case 0:
rlm@1 902 filterFunction = NULL;
rlm@1 903 break;
rlm@1 904 case 1:
rlm@1 905 filterFunction = ScanlinesTV;
rlm@1 906 break;
rlm@1 907 case 2:
rlm@1 908 filterFunction = _2xSaI;
rlm@1 909 break;
rlm@1 910 case 3:
rlm@1 911 filterFunction = Super2xSaI;
rlm@1 912 break;
rlm@1 913 case 4:
rlm@1 914 filterFunction = SuperEagle;
rlm@1 915 break;
rlm@1 916 case 5:
rlm@1 917 filterFunction = Pixelate2x16;
rlm@1 918 break;
rlm@1 919 case 6:
rlm@1 920 filterFunction = MotionBlur;
rlm@1 921 break;
rlm@1 922 case 7:
rlm@1 923 filterFunction = AdMame2x;
rlm@1 924 break;
rlm@1 925 case 8:
rlm@1 926 filterFunction = Simple2x16;
rlm@1 927 break;
rlm@1 928 case 9:
rlm@1 929 filterFunction = Bilinear;
rlm@1 930 break;
rlm@1 931 case 10:
rlm@1 932 filterFunction = BilinearPlus;
rlm@1 933 break;
rlm@1 934 case 11:
rlm@1 935 filterFunction = Scanlines;
rlm@1 936 break;
rlm@1 937 case 12:
rlm@1 938 filterFunction = hq2xS;
rlm@1 939 break;
rlm@1 940 case 13:
rlm@1 941 filterFunction = hq2x;
rlm@1 942 break;
rlm@1 943 case 14:
rlm@1 944 filterFunction = lq2x;
rlm@1 945 break;
rlm@1 946 case 15:
rlm@1 947 filterFunction = hq3xS;
rlm@1 948 break;
rlm@1 949 case 16:
rlm@1 950 filterFunction = hq3x;
rlm@1 951 break;
rlm@1 952 case 17:
rlm@1 953 filterFunction = Simple3x16;
rlm@1 954 break;
rlm@1 955 case 18:
rlm@1 956 filterFunction = Simple4x16;
rlm@1 957 break;
rlm@1 958 case 19:
rlm@1 959 filterFunction = Pixelate3x16;
rlm@1 960 break;
rlm@1 961 case 20:
rlm@1 962 filterFunction = Pixelate4x16;
rlm@1 963 break;
rlm@1 964 }
rlm@1 965 switch (filterType)
rlm@1 966 {
rlm@1 967 case 0: // normal -> 1x texture
rlm@1 968 rect.right = sizeX;
rlm@1 969 rect.bottom = sizeY;
rlm@1 970 break;
rlm@1 971 default: // other -> 2x texture
rlm@1 972 rect.right = sizeX * 2;
rlm@1 973 rect.bottom = sizeY * 2;
rlm@1 974 memset(delta, 255, sizeof(delta));
rlm@1 975 break;
rlm@1 976 case 15: // hq3x -> 3x texture
rlm@1 977 case 16:
rlm@1 978 case 17:
rlm@1 979 case 19:
rlm@1 980 rect.right = sizeX * 3;
rlm@1 981 rect.bottom = sizeY * 3;
rlm@1 982 memset(delta, 255, sizeof(delta));
rlm@1 983 break;
rlm@1 984 case 18: // Simple4x -> 4x texture
rlm@1 985 case 20:
rlm@1 986 rect.right = sizeX * 4;
rlm@1 987 rect.bottom = sizeY * 4;
rlm@1 988 memset(delta, 255, sizeof(delta));
rlm@1 989 break;
rlm@1 990 }
rlm@1 991 }
rlm@1 992 else
rlm@1 993 {
rlm@1 994 if (systemColorDepth == 32 && videoOption > VIDEO_1X &&
rlm@1 995 videoOption != VIDEO_320x240)
rlm@1 996 {
rlm@1 997 switch (filterType)
rlm@1 998 {
rlm@1 999 default:
rlm@1 1000 case 0:
rlm@1 1001 filterFunction = NULL;
rlm@1 1002 break;
rlm@1 1003 case 1:
rlm@1 1004 filterFunction = ScanlinesTV32;
rlm@1 1005 break;
rlm@1 1006 case 2:
rlm@1 1007 filterFunction = _2xSaI32;
rlm@1 1008 break;
rlm@1 1009 case 3:
rlm@1 1010 filterFunction = Super2xSaI32;
rlm@1 1011 break;
rlm@1 1012 case 4:
rlm@1 1013 filterFunction = SuperEagle32;
rlm@1 1014 break;
rlm@1 1015 case 5:
rlm@1 1016 filterFunction = Pixelate2x32;
rlm@1 1017 break;
rlm@1 1018 case 6:
rlm@1 1019 filterFunction = MotionBlur32;
rlm@1 1020 break;
rlm@1 1021 case 7:
rlm@1 1022 filterFunction = AdMame2x32;
rlm@1 1023 break;
rlm@1 1024 case 8:
rlm@1 1025 filterFunction = Simple2x32;
rlm@1 1026 break;
rlm@1 1027 case 9:
rlm@1 1028 filterFunction = Bilinear32;
rlm@1 1029 break;
rlm@1 1030 case 10:
rlm@1 1031 filterFunction = BilinearPlus32;
rlm@1 1032 break;
rlm@1 1033 case 11:
rlm@1 1034 filterFunction = Scanlines32;
rlm@1 1035 break;
rlm@1 1036 case 12:
rlm@1 1037 filterFunction = hq2xS32;
rlm@1 1038 break;
rlm@1 1039 case 13:
rlm@1 1040 filterFunction = hq2x32;
rlm@1 1041 break;
rlm@1 1042 case 14:
rlm@1 1043 filterFunction = lq2x32;
rlm@1 1044 break;
rlm@1 1045 case 15:
rlm@1 1046 filterFunction = hq3xS32;
rlm@1 1047 break;
rlm@1 1048 case 16:
rlm@1 1049 filterFunction = hq3x32;
rlm@1 1050 break;
rlm@1 1051 case 17:
rlm@1 1052 filterFunction = Simple3x32;
rlm@1 1053 break;
rlm@1 1054 case 18:
rlm@1 1055 filterFunction = Simple4x32;
rlm@1 1056 break;
rlm@1 1057 case 19:
rlm@1 1058 filterFunction = Pixelate3x32;
rlm@1 1059 break;
rlm@1 1060 case 20:
rlm@1 1061 filterFunction = Pixelate4x32;
rlm@1 1062 break;
rlm@1 1063 }
rlm@1 1064 switch (filterType)
rlm@1 1065 {
rlm@1 1066 case 0: // normal -> 1x texture
rlm@1 1067 rect.right = sizeX;
rlm@1 1068 rect.bottom = sizeY;
rlm@1 1069 break;
rlm@1 1070 default: // other -> 2x texture
rlm@1 1071 rect.right = sizeX * 2;
rlm@1 1072 rect.bottom = sizeY * 2;
rlm@1 1073 memset(delta, 255, sizeof(delta));
rlm@1 1074 break;
rlm@1 1075 case 15: // hq3x -> 3x texture
rlm@1 1076 case 16:
rlm@1 1077 case 17:
rlm@1 1078 case 19:
rlm@1 1079 rect.right = sizeX * 3;
rlm@1 1080 rect.bottom = sizeY * 3;
rlm@1 1081 memset(delta, 255, sizeof(delta));
rlm@1 1082 break;
rlm@1 1083 case 18: // Simple4x -> 4x texture
rlm@1 1084 case 20:
rlm@1 1085 rect.right = sizeX * 4;
rlm@1 1086 rect.bottom = sizeY * 4;
rlm@1 1087 memset(delta, 255, sizeof(delta));
rlm@1 1088 break;
rlm@1 1089 }
rlm@1 1090 }
rlm@1 1091 else
rlm@1 1092 filterFunction = NULL;
rlm@1 1093 }
rlm@1 1094
rlm@1 1095 if (display)
rlm@1 1096 display->changeRenderSize(rect.right, rect.bottom);
rlm@1 1097 }
rlm@1 1098
rlm@1 1099 void VBA::recreateMenuBar()
rlm@1 1100 {
rlm@1 1101 m_menu.Detach();
rlm@1 1102 m_menu.Attach(winResLoadMenu(MAKEINTRESOURCE(IDR_MENU)));
rlm@1 1103
rlm@1 1104 if (m_pMainWnd && menuToggle) // assuming that whether the menu has been set is always kept tracked
rlm@1 1105 {
rlm@1 1106 m_pMainWnd->SetMenu(&m_menu);
rlm@1 1107 }
rlm@1 1108
rlm@1 1109 if (menu != NULL)
rlm@1 1110 {
rlm@1 1111 DestroyMenu(menu);
rlm@1 1112 }
rlm@1 1113
rlm@1 1114 menu = m_menu.GetSafeHmenu();
rlm@1 1115 }
rlm@1 1116
rlm@1 1117 void VBA::updateMenuBar()
rlm@1 1118 {
rlm@1 1119 if (flagHideMenu)
rlm@1 1120 return;
rlm@1 1121
rlm@1 1122 recreateMenuBar();
rlm@1 1123
rlm@1 1124 if (popup != NULL)
rlm@1 1125 {
rlm@1 1126 // force popup recreation if language changed
rlm@1 1127 DestroyMenu(popup);
rlm@1 1128 popup = NULL;
rlm@1 1129 }
rlm@1 1130 }
rlm@1 1131
rlm@1 1132 void VBA::saveRewindStateIfNecessary()
rlm@1 1133 {
rlm@1 1134 if (rewindSaveNeeded && rewindMemory && emulator.emuWriteMemState)
rlm@1 1135 {
rlm@1 1136 rewindCount++;
rlm@1 1137 if (rewindCount > rewindSlots)
rlm@1 1138 rewindCount = rewindSlots;
rlm@1 1139 assert(rewindPos >= 0 && rewindPos < rewindSlots);
rlm@1 1140 if (emulator.emuWriteMemState(&rewindMemory[rewindPos * REWIND_SIZE], REWIND_SIZE))
rlm@1 1141 {
rlm@1 1142 rewindPos = ++rewindPos % rewindSlots;
rlm@1 1143 assert(rewindPos >= 0 && rewindPos < rewindSlots);
rlm@1 1144 if (rewindCount == rewindSlots)
rlm@1 1145 rewindTopPos = ++rewindTopPos % rewindSlots;
rlm@1 1146 }
rlm@1 1147 }
rlm@1 1148
rlm@1 1149 // also update/cache some frame search stuff
rlm@1 1150 if (frameSearching)
rlm@1 1151 {
rlm@1 1152 extern SMovie Movie;
rlm@1 1153 int curFrame = (Movie.state == MOVIE_STATE_NONE) ? systemCounters.frameCount : Movie.currentFrame;
rlm@1 1154 int endFrame = theApp.frameSearchStart + theApp.frameSearchLength;
rlm@1 1155 frameSearchSkipping = (curFrame < endFrame);
rlm@1 1156 frameSearchFirstStep = false;
rlm@1 1157
rlm@1 1158 if (curFrame == endFrame)
rlm@1 1159 {
rlm@1 1160 // cache intermediate state to speed up searching forward
rlm@1 1161 emulator.emuWriteMemState(&frameSearchMemory[REWIND_SIZE * 1], REWIND_SIZE);
rlm@1 1162 }
rlm@1 1163
rlm@1 1164 if (curFrame == endFrame + 1)
rlm@1 1165 {
rlm@1 1166 emulator.emuWriteMemState(&frameSearchMemory[REWIND_SIZE * 2], REWIND_SIZE);
rlm@1 1167 frameSearchLoadValid = true;
rlm@1 1168 }
rlm@1 1169 }
rlm@1 1170 else
rlm@1 1171 {
rlm@1 1172 frameSearchFirstStep = false;
rlm@1 1173
rlm@1 1174 assert(!frameSearchSkipping);
rlm@1 1175 // just in case
rlm@1 1176 frameSearchSkipping = false;
rlm@1 1177 }
rlm@1 1178 }
rlm@1 1179
rlm@1 1180 BOOL VBA::OnIdle(LONG lCount)
rlm@1 1181 {
rlm@1 1182 if (emulating && debugger)
rlm@1 1183 {
rlm@1 1184 MSG msg;
rlm@1 1185 remoteStubMain();
rlm@1 1186 if (debugger)
rlm@1 1187 return TRUE; // continue loop
rlm@1 1188 return !::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE);
rlm@1 1189 }
rlm@1 1190 else if (emulating && active && !paused)
rlm@1 1191 {
rlm@1 1192 /// for(int i = 0; i < 2; i++)
rlm@1 1193 {
rlm@1 1194 emulator.emuMain(emulator.emuCount);
rlm@1 1195
rlm@1 1196 // save the state for rewinding, if necessary
rlm@1 1197 saveRewindStateIfNecessary();
rlm@1 1198
rlm@1 1199 rewindSaveNeeded = false;
rlm@1 1200 }
rlm@1 1201
rlm@1 1202 if (mouseCounter)
rlm@1 1203 {
rlm@1 1204 if (--mouseCounter == 0)
rlm@1 1205 {
rlm@1 1206 SetCursor(NULL);
rlm@1 1207 }
rlm@1 1208 }
rlm@1 1209 return TRUE;
rlm@1 1210 }
rlm@1 1211 else if (emulating) // this fixes display if resetting while paused
rlm@1 1212 {
rlm@1 1213 // VBAUpdateButtonPressDisplay();
rlm@1 1214 VBAUpdateFrameCountDisplay();
rlm@1 1215 systemRefreshScreen();
rlm@1 1216 }
rlm@1 1217
rlm@1 1218 return FALSE;
rlm@1 1219
rlm@1 1220 // return CWinApp::OnIdle(lCount);
rlm@1 1221 }
rlm@1 1222
rlm@1 1223 void VBA::addRecentFile(const CString &file)
rlm@1 1224 {
rlm@1 1225 // Do not change recent list if frozen
rlm@1 1226 if (recentFreeze)
rlm@1 1227 return;
rlm@1 1228 int i = 0;
rlm@1 1229 for (i = 0; i < 10; ++i)
rlm@1 1230 {
rlm@1 1231 if (recentFiles[i].GetLength() == 0)
rlm@1 1232 break;
rlm@1 1233
rlm@1 1234 if (recentFiles[i].Compare(file) == 0)
rlm@1 1235 {
rlm@1 1236 if (i == 0)
rlm@1 1237 return;
rlm@1 1238 CString p = recentFiles[i];
rlm@1 1239 for (int j = i; j > 0; --j)
rlm@1 1240 {
rlm@1 1241 recentFiles[j] = recentFiles[j - 1];
rlm@1 1242 }
rlm@1 1243 recentFiles[0] = p;
rlm@1 1244 return;
rlm@1 1245 }
rlm@1 1246 }
rlm@1 1247 int num = 0;
rlm@1 1248 for (i = 0; i < 10; ++i)
rlm@1 1249 {
rlm@1 1250 if (recentFiles[i].GetLength() != 0)
rlm@1 1251 ++num;
rlm@1 1252 }
rlm@1 1253 if (num == 10)
rlm@1 1254 {
rlm@1 1255 --num;
rlm@1 1256 }
rlm@1 1257
rlm@1 1258 for (i = num; i >= 1; --i)
rlm@1 1259 {
rlm@1 1260 recentFiles[i] = recentFiles[i - 1];
rlm@1 1261 }
rlm@1 1262 recentFiles[0] = file;
rlm@1 1263 }
rlm@1 1264
rlm@1 1265 void VBA::updateFrameSkip()
rlm@1 1266 {
rlm@1 1267 switch (systemCartridgeType)
rlm@1 1268 {
rlm@1 1269 case 0:
rlm@1 1270 systemFrameSkip = frameSkip;
rlm@1 1271 break;
rlm@1 1272 case 1:
rlm@1 1273 systemFrameSkip = gbFrameSkip;
rlm@1 1274 break;
rlm@1 1275 }
rlm@1 1276 }
rlm@1 1277
rlm@1 1278 void VBA::updateVideoSize(UINT id)
rlm@1 1279 {
rlm@1 1280 int value = 0;
rlm@1 1281 bool forceUpdate = false;
rlm@1 1282
rlm@1 1283 switch (id)
rlm@1 1284 {
rlm@1 1285 case ID_OPTIONS_VIDEO_X1:
rlm@1 1286 value = VIDEO_1X;
rlm@1 1287 forceUpdate = true;
rlm@1 1288 break;
rlm@1 1289 case ID_OPTIONS_VIDEO_X2:
rlm@1 1290 value = VIDEO_2X;
rlm@1 1291 forceUpdate = true;
rlm@1 1292 break;
rlm@1 1293 case ID_OPTIONS_VIDEO_X3:
rlm@1 1294 value = VIDEO_3X;
rlm@1 1295 forceUpdate = true;
rlm@1 1296 break;
rlm@1 1297 case ID_OPTIONS_VIDEO_X4:
rlm@1 1298 value = VIDEO_4X;
rlm@1 1299 forceUpdate = true;
rlm@1 1300 break;
rlm@1 1301 case ID_OPTIONS_VIDEO_FULLSCREEN320X240:
rlm@1 1302 value = VIDEO_320x240;
rlm@1 1303 fsWidth = 320;
rlm@1 1304 fsHeight = 240;
rlm@1 1305 fsColorDepth = 16;
rlm@1 1306 break;
rlm@1 1307 case ID_OPTIONS_VIDEO_FULLSCREEN640X480:
rlm@1 1308 value = VIDEO_640x480;
rlm@1 1309 fsWidth = 640;
rlm@1 1310 fsHeight = 480;
rlm@1 1311 fsColorDepth = 16;
rlm@1 1312 break;
rlm@1 1313 case ID_OPTIONS_VIDEO_FULLSCREEN800X600:
rlm@1 1314 value = VIDEO_800x600;
rlm@1 1315 fsWidth = 800;
rlm@1 1316 fsHeight = 600;
rlm@1 1317 fsColorDepth = 16;
rlm@1 1318 break;
rlm@1 1319 case ID_OPTIONS_VIDEO_FULLSCREEN:
rlm@1 1320 value = VIDEO_OTHER;
rlm@1 1321 forceUpdate = true;
rlm@1 1322 break;
rlm@1 1323 }
rlm@1 1324
rlm@1 1325 if (videoOption != value || forceUpdate)
rlm@1 1326 updateWindowSize(value);
rlm@1 1327 }
rlm@1 1328
rlm@1 1329 void VBA::updateWindowSize(int value)
rlm@1 1330 {
rlm@1 1331 regSetDwordValue("video", value);
rlm@1 1332
rlm@1 1333 if (value == VIDEO_OTHER)
rlm@1 1334 {
rlm@1 1335 regSetDwordValue("fsWidth", fsWidth);
rlm@1 1336 regSetDwordValue("fsHeight", fsHeight);
rlm@1 1337 regSetDwordValue("fsColorDepth", fsColorDepth);
rlm@1 1338 }
rlm@1 1339
rlm@1 1340 if (display &&
rlm@1 1341 (((value >= VIDEO_320x240 || videoOption >= VIDEO_320x240) && videoOption != value) ||
rlm@1 1342 fsForceChange))
rlm@1 1343 {
rlm@1 1344 fsForceChange = false;
rlm@1 1345 videoOption = value;
rlm@1 1346 initDisplay();
rlm@1 1347 }
rlm@1 1348
rlm@1 1349 videoOption = value;
rlm@1 1350
rlm@1 1351 if (systemCartridgeType == 1)
rlm@1 1352 {
rlm@1 1353 if (gbBorderOn)
rlm@1 1354 {
rlm@1 1355 sizeX = 256;
rlm@1 1356 sizeY = 224;
rlm@1 1357 gbBorderLineSkip = 256;
rlm@1 1358 gbBorderColumnSkip = 48;
rlm@1 1359 gbBorderRowSkip = 40;
rlm@1 1360 }
rlm@1 1361 else
rlm@1 1362 {
rlm@1 1363 sizeX = 160;
rlm@1 1364 sizeY = 144;
rlm@1 1365 gbBorderLineSkip = 160;
rlm@1 1366 gbBorderColumnSkip = 0;
rlm@1 1367 gbBorderRowSkip = 0;
rlm@1 1368 }
rlm@1 1369 }
rlm@1 1370 else
rlm@1 1371 {
rlm@1 1372 sizeX = 240;
rlm@1 1373 sizeY = 160;
rlm@1 1374 }
rlm@1 1375
rlm@1 1376 switch (videoOption)
rlm@1 1377 {
rlm@1 1378 case VIDEO_1X:
rlm@1 1379 surfaceSizeX = sizeX;
rlm@1 1380 surfaceSizeY = sizeY;
rlm@1 1381 break;
rlm@1 1382 case VIDEO_2X:
rlm@1 1383 surfaceSizeX = sizeX * 2;
rlm@1 1384 surfaceSizeY = sizeY * 2;
rlm@1 1385 break;
rlm@1 1386 case VIDEO_3X:
rlm@1 1387 surfaceSizeX = sizeX * 3;
rlm@1 1388 surfaceSizeY = sizeY * 3;
rlm@1 1389 break;
rlm@1 1390 case VIDEO_4X:
rlm@1 1391 surfaceSizeX = sizeX * 4;
rlm@1 1392 surfaceSizeY = sizeY * 4;
rlm@1 1393 break;
rlm@1 1394 case VIDEO_320x240:
rlm@1 1395 case VIDEO_640x480:
rlm@1 1396 case VIDEO_800x600:
rlm@1 1397 case VIDEO_OTHER:
rlm@1 1398 // Need to fix this code later. For now, Fullscreen takes the whole screen.
rlm@1 1399 if (fullScreenStretch)
rlm@1 1400 {
rlm@1 1401 surfaceSizeX = fsWidth;
rlm@1 1402 surfaceSizeY = fsHeight;
rlm@1 1403 }
rlm@1 1404 else
rlm@1 1405 {
rlm@1 1406 double scaleX = (double)fsWidth / (double)sizeX;
rlm@1 1407 double scaleY = (double)fsHeight / (double)sizeY;
rlm@1 1408 double scaleMin = scaleX < scaleY ? scaleX : scaleY;
rlm@1 1409 if (fsMaxScale)
rlm@1 1410 scaleMin = scaleMin > fsMaxScale ? fsMaxScale : scaleMin;
rlm@1 1411 surfaceSizeX = (int)(scaleMin * sizeX);
rlm@1 1412 surfaceSizeY = (int)(scaleMin * sizeY);
rlm@1 1413 }
rlm@1 1414 break;
rlm@1 1415 }
rlm@1 1416
rlm@1 1417 rect.left = 0;
rlm@1 1418 rect.top = 0;
rlm@1 1419 rect.right = sizeX;
rlm@1 1420 rect.bottom = sizeY;
rlm@1 1421
rlm@1 1422 int winSizeX = 0;
rlm@1 1423 int winSizeY = 0;
rlm@1 1424 int x = 0;
rlm@1 1425 int y = 0;
rlm@1 1426
rlm@1 1427 DWORD style = WS_POPUP | WS_VISIBLE;
rlm@1 1428 DWORD styleEx = alwaysOnTop ? WS_EX_TOPMOST : 0;
rlm@1 1429
rlm@1 1430 if (videoOption <= VIDEO_4X)
rlm@1 1431 {
rlm@1 1432 style |= WS_OVERLAPPEDWINDOW;
rlm@1 1433
rlm@1 1434 dest.left = 0;
rlm@1 1435 dest.top = 0;
rlm@1 1436 dest.right = surfaceSizeX;
rlm@1 1437 dest.bottom = surfaceSizeY;
rlm@1 1438
rlm@1 1439 x = windowPositionX;
rlm@1 1440 y = windowPositionY;
rlm@1 1441 }
rlm@1 1442 else
rlm@1 1443 {
rlm@1 1444 dest.left = 0;
rlm@1 1445 dest.top = 0;
rlm@1 1446 dest.right = fsWidth;
rlm@1 1447 dest.bottom = fsHeight;
rlm@1 1448 }
rlm@1 1449
rlm@1 1450 AdjustWindowRectEx(&dest, style, flagHideMenu ? FALSE : TRUE, styleEx);
rlm@1 1451 winSizeX = dest.right - dest.left;
rlm@1 1452 winSizeY = dest.bottom - dest.top;
rlm@1 1453
rlm@1 1454 if (m_pMainWnd == NULL)
rlm@1 1455 {
rlm@1 1456 // Create a new window
rlm@1 1457 m_pMainWnd = new MainWnd;
rlm@1 1458 m_pMainWnd->CreateEx(styleEx,
rlm@1 1459 theApp.wndClass,
rlm@1 1460 VBA_NAME_AND_VERSION,
rlm@1 1461 style,
rlm@1 1462 x, y, winSizeX, winSizeY,
rlm@1 1463 NULL,
rlm@1 1464 0);
rlm@1 1465
rlm@1 1466 if (!(HWND)*m_pMainWnd)
rlm@1 1467 {
rlm@1 1468 winlog("Error creating Window %08x\n", GetLastError());
rlm@1 1469 AfxPostQuitMessage(0);
rlm@1 1470 return;
rlm@1 1471 }
rlm@1 1472 }
rlm@1 1473 else
rlm@1 1474 {
rlm@1 1475 m_pMainWnd->SetWindowPos(0, //HWND_TOPMOST,
rlm@1 1476 x,
rlm@1 1477 y,
rlm@1 1478 winSizeX,
rlm@1 1479 winSizeY,
rlm@1 1480 SWP_NOMOVE | SWP_SHOWWINDOW);
rlm@1 1481 }
rlm@1 1482
rlm@1 1483 updateMenuBar(); // add menubar first of all, or winGetMenuBarHeight() will get random height.
rlm@1 1484 winAccelMgr.UpdateMenu(menu);
rlm@1 1485 adjustDestRect();
rlm@1 1486
rlm@1 1487 updateIFB();
rlm@1 1488 updateFilter();
rlm@1 1489
rlm@1 1490 m_pMainWnd->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN);
rlm@1 1491 }
rlm@1 1492
rlm@1 1493 bool VBA::initDisplay()
rlm@1 1494 {
rlm@1 1495 if (display)
rlm@1 1496 {
rlm@1 1497 changingVideoSize = true;
rlm@1 1498 shutdownDisplay();
rlm@1 1499 if (input)
rlm@1 1500 {
rlm@1 1501 delete input;
rlm@1 1502 input = NULL;
rlm@1 1503 }
rlm@1 1504 CWnd *pWnd = m_pMainWnd;
rlm@1 1505
rlm@1 1506 m_pMainWnd = NULL;
rlm@1 1507 pWnd->DragAcceptFiles(FALSE);
rlm@1 1508 pWnd->DestroyWindow();
rlm@1 1509 delete pWnd;
rlm@1 1510
rlm@1 1511 display = NULL;
rlm@1 1512 }
rlm@1 1513
rlm@1 1514 if (display == NULL)
rlm@1 1515 {
rlm@1 1516 updateWindowSize(videoOption);
rlm@1 1517
rlm@1 1518 switch (renderMethod)
rlm@1 1519 {
rlm@1 1520 case GDI:
rlm@1 1521 display = newGDIDisplay();
rlm@1 1522 break;
rlm@1 1523 case DIRECT_DRAW:
rlm@1 1524 display = newDirectDrawDisplay();
rlm@1 1525 break;
rlm@1 1526 case DIRECT_3D:
rlm@1 1527 display = newDirect3DDisplay();
rlm@1 1528 break;
rlm@1 1529 case OPENGL:
rlm@1 1530 display = newOpenGLDisplay();
rlm@1 1531 break;
rlm@1 1532 }
rlm@1 1533
rlm@1 1534 if (display->initialize())
rlm@1 1535 {
rlm@1 1536 if (input == NULL)
rlm@1 1537 {
rlm@1 1538 if (!initInput())
rlm@1 1539 {
rlm@1 1540 changingVideoSize = false;
rlm@1 1541 AfxPostQuitMessage(0);
rlm@1 1542 return false;
rlm@1 1543 }
rlm@1 1544 }
rlm@1 1545
rlm@1 1546 input->checkKeys();
rlm@1 1547
rlm@1 1548 changingVideoSize = false;
rlm@1 1549 }
rlm@1 1550 else
rlm@1 1551 {
rlm@1 1552 if (videoOption == VIDEO_320x240 ||
rlm@1 1553 videoOption == VIDEO_640x480 ||
rlm@1 1554 videoOption == VIDEO_800x600 ||
rlm@1 1555 videoOption == VIDEO_OTHER)
rlm@1 1556 {
rlm@1 1557 regSetDwordValue("video", VIDEO_1X);
rlm@1 1558 if (pVideoDriverGUID)
rlm@1 1559 regSetDwordValue("defaultVideoDriver", TRUE);
rlm@1 1560 }
rlm@1 1561 changingVideoSize = false;
rlm@1 1562 return false;
rlm@1 1563 }
rlm@1 1564 }
rlm@1 1565 changingVideoSize = false;
rlm@1 1566 return true;
rlm@1 1567 }
rlm@1 1568
rlm@1 1569 bool VBA::updateRenderMethod(bool force)
rlm@1 1570 {
rlm@1 1571 bool res = true;
rlm@1 1572 if (force || (display && display->getType() != renderMethod))
rlm@1 1573 {
rlm@1 1574 res = initDisplay();
rlm@1 1575
rlm@1 1576 while (!res && renderMethod > 0)
rlm@1 1577 {
rlm@1 1578 if (renderMethod == OPENGL)
rlm@1 1579 renderMethod = DIRECT_3D;
rlm@1 1580 else if (renderMethod == DIRECT_3D)
rlm@1 1581 renderMethod = DIRECT_DRAW;
rlm@1 1582 else if (renderMethod == DIRECT_DRAW)
rlm@1 1583 renderMethod = GDI;
rlm@1 1584
rlm@1 1585 res = initDisplay();
rlm@1 1586 }
rlm@1 1587 }
rlm@1 1588
rlm@1 1589 updateIFB();
rlm@1 1590 updateFilter();
rlm@1 1591
rlm@1 1592 m_pMainWnd->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN);
rlm@1 1593
rlm@1 1594 regSetDwordValue("renderMethod", renderMethod);
rlm@1 1595
rlm@1 1596 return res;
rlm@1 1597 }
rlm@1 1598
rlm@1 1599 void VBA::winCheckFullscreen()
rlm@1 1600 {
rlm@1 1601 if (videoOption > VIDEO_4X && tripleBuffering)
rlm@1 1602 {
rlm@1 1603 if (display)
rlm@1 1604 display->checkFullScreen();
rlm@1 1605 }
rlm@1 1606 }
rlm@1 1607
rlm@1 1608 void VBA::shutdownDisplay()
rlm@1 1609 {
rlm@1 1610 if (display != NULL)
rlm@1 1611 {
rlm@1 1612 display->cleanup();
rlm@1 1613 delete display;
rlm@1 1614 display = NULL;
rlm@1 1615 }
rlm@1 1616 }
rlm@1 1617
rlm@1 1618 void VBA::updatePriority()
rlm@1 1619 {
rlm@1 1620 switch (threadPriority)
rlm@1 1621 {
rlm@1 1622 case 0:
rlm@1 1623 SetThreadPriority(THREAD_PRIORITY_HIGHEST);
rlm@1 1624 break;
rlm@1 1625 case 1:
rlm@1 1626 SetThreadPriority(THREAD_PRIORITY_ABOVE_NORMAL);
rlm@1 1627 break;
rlm@1 1628 case 3:
rlm@1 1629 SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL);
rlm@1 1630 break;
rlm@1 1631 default:
rlm@1 1632 SetThreadPriority(THREAD_PRIORITY_NORMAL);
rlm@1 1633 }
rlm@1 1634 }
rlm@1 1635
rlm@1 1636 #ifdef MMX
rlm@1 1637 bool VBA::detectMMX()
rlm@1 1638 {
rlm@1 1639 bool support = false;
rlm@1 1640 char brand[13];
rlm@1 1641
rlm@1 1642 // check for Intel chip
rlm@1 1643 __try {
rlm@1 1644 __asm {
rlm@1 1645 mov eax, 0;
rlm@1 1646 cpuid;
rlm@1 1647 mov [dword ptr brand + 0], ebx;
rlm@1 1648 mov [dword ptr brand + 4], edx;
rlm@1 1649 mov [dword ptr brand + 8], ecx;
rlm@1 1650 }
rlm@1 1651 }
rlm@1 1652 __except(EXCEPTION_EXECUTE_HANDLER) {
rlm@1 1653 if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
rlm@1 1654 {
rlm@1 1655 return false;
rlm@1 1656 }
rlm@1 1657 return false;
rlm@1 1658 }
rlm@1 1659 // Check for Intel or AMD CPUs
rlm@1 1660 if (strncmp(brand, "GenuineIntel", 12))
rlm@1 1661 {
rlm@1 1662 if (strncmp(brand, "AuthenticAMD", 12))
rlm@1 1663 {
rlm@1 1664 return false;
rlm@1 1665 }
rlm@1 1666 }
rlm@1 1667
rlm@1 1668 __asm {
rlm@1 1669 mov eax, 1;
rlm@1 1670 cpuid;
rlm@1 1671 test edx, 00800000h;
rlm@1 1672 jz NotFound;
rlm@1 1673 mov [support], 1;
rlm@1 1674 NotFound:
rlm@1 1675 }
rlm@1 1676 return support;
rlm@1 1677 }
rlm@1 1678
rlm@1 1679 #endif
rlm@1 1680
rlm@1 1681 void VBA::winSetLanguageOption(int option, bool force)
rlm@1 1682 {
rlm@1 1683 if (((option == languageOption) && option != 2) && !force)
rlm@1 1684 return;
rlm@1 1685 switch (option)
rlm@1 1686 {
rlm@1 1687 case 0:
rlm@1 1688 {
rlm@1 1689 char lbuffer[10];
rlm@1 1690
rlm@1 1691 if (GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SABBREVLANGNAME,
rlm@1 1692 lbuffer, 10))
rlm@1 1693 {
rlm@1 1694 HINSTANCE l = winLoadLanguage(lbuffer);
rlm@1 1695 if (l == NULL)
rlm@1 1696 {
rlm@1 1697 LCID locIdBase = MAKELCID(MAKELANGID(PRIMARYLANGID(GetSystemDefaultLangID()), SUBLANG_NEUTRAL), SORT_DEFAULT);
rlm@1 1698 if (GetLocaleInfo(locIdBase, LOCALE_SABBREVLANGNAME,
rlm@1 1699 lbuffer, 10))
rlm@1 1700 {
rlm@1 1701 l = winLoadLanguage(lbuffer);
rlm@1 1702 if (l == NULL)
rlm@1 1703 {
rlm@1 1704 systemMessage(IDS_FAILED_TO_LOAD_LIBRARY,
rlm@1 1705 "Failed to load library %s",
rlm@1 1706 lbuffer);
rlm@1 1707 return;
rlm@1 1708 }
rlm@1 1709 }
rlm@1 1710 }
rlm@1 1711 AfxSetResourceHandle(l);
rlm@1 1712 if (languageModule != NULL)
rlm@1 1713 /**/ ::FreeLibrary(languageModule);
rlm@1 1714 languageModule = l;
rlm@1 1715 }
rlm@1 1716 else
rlm@1 1717 {
rlm@1 1718 systemMessage(IDS_FAILED_TO_GET_LOCINFO,
rlm@1 1719 "Failed to get locale information");
rlm@1 1720 return;
rlm@1 1721 }
rlm@1 1722 break;
rlm@1 1723 }
rlm@1 1724 case 1:
rlm@1 1725 if (languageModule != NULL)
rlm@1 1726 /**/ ::FreeLibrary(languageModule);
rlm@1 1727 languageModule = NULL;
rlm@1 1728 AfxSetResourceHandle(AfxGetInstanceHandle());
rlm@1 1729 break;
rlm@1 1730 case 2:
rlm@1 1731 {
rlm@1 1732 if (!force)
rlm@1 1733 {
rlm@1 1734 LangSelect dlg;
rlm@1 1735 if (dlg.DoModal())
rlm@1 1736 {
rlm@1 1737 HINSTANCE l = winLoadLanguage(languageName);
rlm@1 1738 if (l == NULL)
rlm@1 1739 {
rlm@1 1740 systemMessage(IDS_FAILED_TO_LOAD_LIBRARY,
rlm@1 1741 "Failed to load library %s",
rlm@1 1742 languageName);
rlm@1 1743 return;
rlm@1 1744 }
rlm@1 1745 AfxSetResourceHandle(l);
rlm@1 1746 if (languageModule != NULL)
rlm@1 1747 /**/ ::FreeLibrary(languageModule);
rlm@1 1748 languageModule = l;
rlm@1 1749 }
rlm@1 1750 }
rlm@1 1751 else
rlm@1 1752 {
rlm@1 1753 if (languageName.IsEmpty())
rlm@1 1754 return;
rlm@1 1755 HINSTANCE l = winLoadLanguage(languageName);
rlm@1 1756 if (l == NULL)
rlm@1 1757 {
rlm@1 1758 systemMessage(IDS_FAILED_TO_LOAD_LIBRARY,
rlm@1 1759 "Failed to load library %s",
rlm@1 1760 languageName);
rlm@1 1761 return;
rlm@1 1762 }
rlm@1 1763 AfxSetResourceHandle(l);
rlm@1 1764 if (languageModule != NULL)
rlm@1 1765 FreeLibrary(languageModule);
rlm@1 1766 languageModule = l;
rlm@1 1767 }
rlm@1 1768 break;
rlm@1 1769 }
rlm@1 1770 }
rlm@1 1771 languageOption = option;
rlm@1 1772 updateMenuBar();
rlm@1 1773 theApp.winAccelMgr.UpdateMenu(theApp.menu);
rlm@1 1774 }
rlm@1 1775
rlm@1 1776 HINSTANCE VBA::winLoadLanguage(const char *name)
rlm@1 1777 {
rlm@1 1778 CString buffer;
rlm@1 1779
rlm@1 1780 buffer.Format("vba_%s.dll", name);
rlm@1 1781
rlm@1 1782 HINSTANCE l = /**/ ::LoadLibrary(buffer);
rlm@1 1783
rlm@1 1784 if (l == NULL)
rlm@1 1785 {
rlm@1 1786 if (strlen(name) == 3)
rlm@1 1787 {
rlm@1 1788 char buffer2[3];
rlm@1 1789 buffer2[0] = name[0];
rlm@1 1790 buffer2[1] = name[1];
rlm@1 1791 buffer2[2] = 0;
rlm@1 1792 buffer.Format("vba_%s.dll", buffer2);
rlm@1 1793
rlm@1 1794 return /**/ ::LoadLibrary(buffer);
rlm@1 1795 }
rlm@1 1796 }
rlm@1 1797 return l;
rlm@1 1798 }
rlm@1 1799
rlm@1 1800 bool VBA::initInput()
rlm@1 1801 {
rlm@1 1802 if (input)
rlm@1 1803 delete input;
rlm@1 1804 input = newDirectInput();
rlm@1 1805 if (input->initialize())
rlm@1 1806 {
rlm@1 1807 input->loadSettings();
rlm@1 1808 input->checkKeys();
rlm@1 1809 return true;
rlm@1 1810 }
rlm@1 1811 delete input;
rlm@1 1812 return false;
rlm@1 1813 }
rlm@1 1814
rlm@1 1815 void VBA::winAddUpdateListener(IUpdateListener *l)
rlm@1 1816 {
rlm@1 1817 updateList.AddTail(l);
rlm@1 1818 updateCount++;
rlm@1 1819 }
rlm@1 1820
rlm@1 1821 void VBA::winRemoveUpdateListener(IUpdateListener *l)
rlm@1 1822 {
rlm@1 1823 POSITION pos = updateList.Find(l);
rlm@1 1824 if (pos)
rlm@1 1825 {
rlm@1 1826 updateList.RemoveAt(pos);
rlm@1 1827 updateCount--;
rlm@1 1828 if (updateCount < 0)
rlm@1 1829 updateCount = 0;
rlm@1 1830 }
rlm@1 1831 }
rlm@1 1832
rlm@1 1833 void VBA::loadSettings()
rlm@1 1834 {
rlm@1 1835 CString buffer;
rlm@1 1836 // video
rlm@1 1837 bool defaultVideoDriver = regQueryDwordValue("defaultVideoDriver", true) ? true : false;
rlm@1 1838 if (!regQueryBinaryValue("videoDriverGUID", (char *)&videoDriverGUID, sizeof(GUID)))
rlm@1 1839 {
rlm@1 1840 defaultVideoDriver = TRUE;
rlm@1 1841 }
rlm@1 1842 if (defaultVideoDriver)
rlm@1 1843 pVideoDriverGUID = NULL;
rlm@1 1844 else
rlm@1 1845 pVideoDriverGUID = &videoDriverGUID;
rlm@1 1846
rlm@1 1847 videoOption = regQueryDwordValue("video", 0);
rlm@1 1848 if (videoOption < 0 || videoOption > VIDEO_OTHER)
rlm@1 1849 videoOption = 0;
rlm@1 1850 switch (videoOption)
rlm@1 1851 {
rlm@1 1852 case VIDEO_320x240:
rlm@1 1853 fsWidth = 320;
rlm@1 1854 fsHeight = 240;
rlm@1 1855 fsColorDepth = 16;
rlm@1 1856 break;
rlm@1 1857 case VIDEO_640x480:
rlm@1 1858 fsWidth = 640;
rlm@1 1859 fsHeight = 480;
rlm@1 1860 fsColorDepth = 16;
rlm@1 1861 break;
rlm@1 1862 case VIDEO_800x600:
rlm@1 1863 fsWidth = 800;
rlm@1 1864 fsHeight = 600;
rlm@1 1865 fsColorDepth = 16;
rlm@1 1866 break;
rlm@1 1867 }
rlm@1 1868 if (videoOption == VIDEO_OTHER)
rlm@1 1869 {
rlm@1 1870 if (fsWidth < 0 || fsWidth > 4095 || fsHeight < 0 || fsHeight > 4095)
rlm@1 1871 videoOption = 0;
rlm@1 1872 if (fsColorDepth != 16 && fsColorDepth != 24 && fsColorDepth != 32)
rlm@1 1873 videoOption = 0;
rlm@1 1874 }
rlm@1 1875
rlm@1 1876 fsWidth = regQueryDwordValue("fsWidth", 0);
rlm@1 1877 fsHeight = regQueryDwordValue("fsHeight", 0);
rlm@1 1878 fsColorDepth = regQueryDwordValue("fsColorDepth", 0);
rlm@1 1879 fsMaxScale = regQueryDwordValue("fsMaxScale", 0);
rlm@1 1880 fullScreenStretch = regQueryDwordValue("stretch", 0) ? true : false;
rlm@1 1881
rlm@1 1882 renderMethod = (DISPLAY_TYPE)regQueryDwordValue("renderMethod", DIRECT_DRAW);
rlm@1 1883 if (renderMethod < GDI || renderMethod > OPENGL)
rlm@1 1884 renderMethod = DIRECT_DRAW;
rlm@1 1885
rlm@1 1886 ddrawEmulationOnly = regQueryDwordValue("ddrawEmulationOnly", false) ? true : false;
rlm@1 1887 ddrawUseVideoMemory = regQueryDwordValue("ddrawUseVideoMemory", false) ? true : false;
rlm@1 1888 tripleBuffering = regQueryDwordValue("tripleBuffering", true) ? true : false;
rlm@1 1889 vsync = regQueryDwordValue("vsync", false) ? true : false;
rlm@1 1890
rlm@1 1891 d3dFilter = regQueryDwordValue("d3dFilter", 0);
rlm@1 1892 if (d3dFilter < 0 || d3dFilter > 1)
rlm@1 1893 d3dFilter = 0;
rlm@1 1894 glFilter = regQueryDwordValue("glFilter", 0);
rlm@1 1895 if (glFilter < 0 || glFilter > 1)
rlm@1 1896 glFilter = 0;
rlm@1 1897 glType = regQueryDwordValue("glType", 0);
rlm@1 1898 if (glType < 0 || glType > 1)
rlm@1 1899 glType = 0;
rlm@1 1900
rlm@1 1901 // pixel filter & ifb
rlm@1 1902 filterType = regQueryDwordValue("filter", 0);
rlm@1 1903 if (filterType < 0 || filterType > 20)
rlm@1 1904 filterType = 0;
rlm@1 1905 disableMMX = regQueryDwordValue("disableMMX", 0) ? true : false;
rlm@1 1906 ifbType = regQueryDwordValue("ifbType", 0);
rlm@1 1907 if (ifbType < 0 || ifbType > 2)
rlm@1 1908 ifbType = 0;
rlm@1 1909
rlm@1 1910 // frame skipping
rlm@1 1911 frameSkip = regQueryDwordValue("frameSkip", /*2*/ 0);
rlm@1 1912 if (frameSkip < 0 || frameSkip > 9)
rlm@1 1913 frameSkip = 1;
rlm@1 1914 gbFrameSkip = regQueryDwordValue("gbFrameSkip", 0);
rlm@1 1915 if (gbFrameSkip < 0 || gbFrameSkip > 9)
rlm@1 1916 gbFrameSkip = 0;
rlm@1 1917 /// autoFrameSkip = regQueryDwordValue("autoFrameSkip", FALSE) ? TRUE : FALSE;
rlm@1 1918
rlm@1 1919 // input
rlm@1 1920 joypadDefault = regQueryDwordValue("joypadDefault", 0);
rlm@1 1921 if (joypadDefault < 0 || joypadDefault > 3)
rlm@1 1922 joypadDefault = 0;
rlm@1 1923 allowLeftRight = regQueryDwordValue("allowLeftRight", false) ? true : false;
rlm@1 1924 autofireAccountForLag = regQueryDwordValue("autofireAccountForLag", false) ? true : false;
rlm@1 1925 nextframeAccountForLag = regQueryDwordValue("nextframeAccountForLag", false) ? true : false;
rlm@1 1926 theApp.AsscWithSaveState = regQueryDwordValue("AsscWithSaveState", false) ? true : false;
rlm@1 1927
rlm@1 1928 // speed
rlm@1 1929 throttle = regQueryDwordValue("throttle", 0);
rlm@1 1930 if (throttle < 5 || throttle > 1000)
rlm@1 1931 throttle = 100;
rlm@1 1932
rlm@1 1933 synchronize = regQueryDwordValue("synchronize", 1) ? true : false;
rlm@1 1934 accuratePitchThrottle = regQueryDwordValue("accuratePitchThrottle", FALSE) ? TRUE : FALSE;
rlm@1 1935
rlm@1 1936 // sound
rlm@1 1937 int resChannels = regQueryDwordValue("soundEnable", 0x30f);
rlm@1 1938 soundEnableChannels(resChannels);
rlm@1 1939 soundDisableChannels(~resChannels);
rlm@1 1940 soundOffFlag = (regQueryDwordValue("soundOff", 0)) ? true : false;
rlm@1 1941 soundQuality = regQueryDwordValue("soundQuality", 2);
rlm@1 1942 soundEcho = regQueryDwordValue("soundEcho", 0) ? true : false;
rlm@1 1943 soundLowPass = regQueryDwordValue("soundLowPass", 0) ? true : false;
rlm@1 1944 soundReverse = regQueryDwordValue("soundReverse", 0) ? true : false;
rlm@1 1945 soundVolume = regQueryDwordValue("soundVolume", 0);
rlm@1 1946 if (soundVolume < 0 || soundVolume > 5)
rlm@1 1947 soundVolume = 0;
rlm@1 1948 muteFrameAdvance = regQueryDwordValue("muteFrameAdvance", 0) ? TRUE : FALSE;
rlm@1 1949 muteWhenInactive = regQueryDwordValue("muteWhenInactive", 0) ? TRUE : FALSE;
rlm@1 1950
rlm@1 1951 // emulation
rlm@1 1952 memLagEnabled = regQueryDwordValue("memLagEnabled", false) ? true : false;
rlm@1 1953 memLagTempEnabled = memLagEnabled;
rlm@1 1954 gbNullInputHackEnabled = regQueryDwordValue("gbNullInputHackEnabled", false) ? true : false;
rlm@1 1955 gbNullInputHackTempEnabled = gbNullInputHackEnabled;
rlm@1 1956 useOldSync = regQueryDwordValue("useOldSync", 0) ? TRUE : FALSE;
rlm@1 1957 useOldFrameTiming = regQueryDwordValue("useOldGBTiming", false) ? true : false;
rlm@1 1958
rlm@1 1959 useBiosFile = regQueryDwordValue("useBios", 0) ? true : false;
rlm@1 1960 skipBiosFile = regQueryDwordValue("skipBios", 0) ? true : false;
rlm@1 1961 buffer = regQueryStringValue("biosFile", "");
rlm@1 1962 if (!buffer.IsEmpty())
rlm@1 1963 {
rlm@1 1964 biosFileName = buffer;
rlm@1 1965 }
rlm@1 1966 // removeIntros = regQueryDwordValue("removeIntros", false) ? true : false;
rlm@1 1967
rlm@1 1968 autoIPS = regQueryDwordValue("autoIPS", true) ? true : false;
rlm@1 1969
rlm@1 1970 agbPrintEnable(regQueryDwordValue("agbPrint", 0) ? true : false);
rlm@1 1971 winRtcEnable = regQueryDwordValue("rtcEnabled", 0) ? true : false;
rlm@1 1972 rtcEnable(winRtcEnable);
rlm@1 1973
rlm@1 1974 winSaveType = regQueryDwordValue("saveType", 0);
rlm@1 1975 if (winSaveType < 0 || winSaveType > 5)
rlm@1 1976 winSaveType = 0;
rlm@1 1977 cpuEnhancedDetection = regQueryDwordValue("enhancedDetection", 1) ? true : false;
rlm@1 1978 winFlashSize = regQueryDwordValue("flashSize", 0x10000);
rlm@1 1979 if (winFlashSize != 0x10000 && winFlashSize != 0x20000)
rlm@1 1980 winFlashSize = 0x10000;
rlm@1 1981
rlm@1 1982 cpuDisableSfx = regQueryDwordValue("disableSfx", 0) ? true : false;
rlm@1 1983
rlm@1 1984 // GBx
rlm@1 1985 winGbPrinterEnabled = regQueryDwordValue("gbPrinter", false) ? true : false;
rlm@1 1986 if (winGbPrinterEnabled)
rlm@1 1987 gbSerialFunction = gbPrinterSend;
rlm@1 1988 else
rlm@1 1989 gbSerialFunction = NULL;
rlm@1 1990 gbEmulatorType = regQueryDwordValue("emulatorType", 0);
rlm@1 1991 if (gbEmulatorType < 0 || gbEmulatorType > 5)
rlm@1 1992 gbEmulatorType = 1;
rlm@1 1993 winGbBorderOn = regQueryDwordValue("borderOn", 0);
rlm@1 1994 gbBorderAutomatic = regQueryDwordValue("borderAutomatic", 0);
rlm@1 1995
rlm@1 1996 gbColorOption = regQueryDwordValue("colorOption", 0);
rlm@1 1997 gbPaletteOption = regQueryDwordValue("gbPaletteOption", 0);
rlm@1 1998 if (gbPaletteOption < 0)
rlm@1 1999 gbPaletteOption = 0;
rlm@1 2000 if (gbPaletteOption > 2)
rlm@1 2001 gbPaletteOption = 2;
rlm@1 2002 regQueryBinaryValue("gbPalette", (char *)systemGbPalette, 24 * sizeof(u16));
rlm@1 2003
rlm@1 2004 // head-up display
rlm@1 2005 showSpeed = regQueryDwordValue("showSpeed", 1);
rlm@1 2006 if (showSpeed < 0 || showSpeed > 2)
rlm@1 2007 showSpeed = 1;
rlm@1 2008 showSpeedTransparent = regQueryDwordValue("showSpeedTransparent", TRUE) ? TRUE : FALSE;
rlm@1 2009 outlinedText = regQueryDwordValue("outlinedText", TRUE) != 0;
rlm@1 2010 transparentText = regQueryDwordValue("transparentText", FALSE) != 0;
rlm@1 2011 textColor = regQueryDwordValue("textColor", 0);
rlm@1 2012 textMethod = regQueryDwordValue("textMethod", 1);
rlm@1 2013 frameCounter = regQueryDwordValue("frameCounter", false) ? true : false;
rlm@1 2014 lagCounter = regQueryDwordValue("lagCounter", false) ? true : false;
rlm@1 2015 extraCounter = regQueryDwordValue("extraCounter", false) ? true : false;
rlm@1 2016 inputDisplay = regQueryDwordValue("inputDisplay", false) ? true : false;
rlm@1 2017 disableStatusMessage = regQueryDwordValue("disableStatus", 0) ? true : false;
rlm@1 2018
rlm@1 2019 // UI
rlm@1 2020 windowPositionX = regQueryDwordValue("windowX", 0);
rlm@1 2021 if (windowPositionX < 0)
rlm@1 2022 windowPositionX = 0;
rlm@1 2023 windowPositionY = regQueryDwordValue("windowY", 0);
rlm@1 2024 if (windowPositionY < 0)
rlm@1 2025 windowPositionY = 0;
rlm@1 2026
rlm@1 2027 autoHideMenu = regQueryDwordValue("autoHideMenu", 0) ? true : false;
rlm@1 2028
rlm@1 2029 languageOption = regQueryDwordValue("language", 1);
rlm@1 2030 if (languageOption < 0 || languageOption > 2)
rlm@1 2031 languageOption = 1;
rlm@1 2032 buffer = regQueryStringValue("languageName", "");
rlm@1 2033 if (!buffer.IsEmpty())
rlm@1 2034 {
rlm@1 2035 languageName = buffer.Left(3);
rlm@1 2036 }
rlm@1 2037 else
rlm@1 2038 languageName = "";
rlm@1 2039 winSetLanguageOption(languageOption, true);
rlm@1 2040
rlm@1 2041 // preferences
rlm@1 2042 alwaysOnTop = regQueryDwordValue("alwaysOnTop", false) ? true : false;
rlm@1 2043 pauseWhenInactive = regQueryDwordValue("pauseWhenInactive", 1) ? true : false;
rlm@1 2044 enableBackgroundInput = regQueryDwordValue("enableBackgroundInput", 0) ? true : false;
rlm@1 2045 threadPriority = regQueryDwordValue("priority", 2);
rlm@1 2046 if (threadPriority < 0 || threadPriority > 3)
rlm@1 2047 threadPriority = 2;
rlm@1 2048 updatePriority();
rlm@1 2049
rlm@1 2050 filenamePreference = regQueryDwordValue("filenamePreference", 0);
rlm@1 2051 altAviRecordMethod = regQueryDwordValue("altAviRecordMethod", false) ? true : false;
rlm@1 2052 captureFormat = regQueryDwordValue("captureFormat", 0);
rlm@1 2053
rlm@1 2054 rewindTimer = regQueryDwordValue("rewindTimer", 0);
rlm@1 2055 rewindSlots = regQueryDwordValue("rewindSlots", 64);
rlm@1 2056 if (rewindTimer < 0 || rewindTimer > 600)
rlm@1 2057 rewindTimer = 0;
rlm@1 2058 if (rewindSlots <= 0)
rlm@1 2059 rewindTimer = rewindSlots = 0;
rlm@1 2060 if (rewindSlots > MAX_REWIND_SLOTS)
rlm@1 2061 rewindSlots = MAX_REWIND_SLOTS;
rlm@1 2062 if (rewindTimer != 0)
rlm@1 2063 {
rlm@1 2064 if (rewindMemory == NULL)
rlm@1 2065 rewindMemory = (char *)malloc(rewindSlots * REWIND_SIZE);
rlm@1 2066 }
rlm@1 2067
rlm@1 2068 if (frameSearchMemory == NULL)
rlm@1 2069 frameSearchMemory = (char *)malloc(3 * REWIND_SIZE);
rlm@1 2070
rlm@1 2071 recentFreeze = regQueryDwordValue("recentFreeze", false) ? true : false;
rlm@1 2072 for (int i = 0, j = 0; i < 10; ++i)
rlm@1 2073 {
rlm@1 2074 buffer.Format("recent%d", i);
rlm@1 2075 const char *s = regQueryStringValue(buffer, NULL);
rlm@1 2076 if (s == NULL)
rlm@1 2077 continue;
rlm@1 2078 recentFiles[j] = s;
rlm@1 2079 ++j;
rlm@1 2080 }
rlm@1 2081
rlm@1 2082 autoLoadMostRecent = regQueryDwordValue("autoLoadMostRecent", false) ? true : false;
rlm@1 2083 loadMakesRecent = regQueryDwordValue("loadMakesRecent", false) ? true : false;
rlm@1 2084 loadMakesCurrent = regQueryDwordValue("loadMakesCurrent", false) ? true : false;
rlm@1 2085 saveMakesCurrent = regQueryDwordValue("saveMakesCurrent", false) ? true : false;
rlm@1 2086 currentSlot = regQueryDwordValue("currentSlot", 0);
rlm@1 2087 showSlotTime = regQueryDwordValue("showSlotTime", 0) ? true : false;
rlm@1 2088
rlm@1 2089 cheatsEnabled = regQueryDwordValue("cheatsEnabled", true) ? true : false;
rlm@1 2090 autoSaveLoadCheatList = regQueryDwordValue("autoSaveCheatList", 0) ? true : false;
rlm@1 2091 pauseDuringCheatSearch = regQueryDwordValue("pauseDuringCheatSearch2", 0) ? true : false;
rlm@1 2092
rlm@1 2093 movieOnEndBehavior = regQueryDwordValue("movieOnEndBehavior", 0);
rlm@1 2094 movieOnEndPause = regQueryDwordValue("movieOnEndPause", 0) ? true : false;
rlm@1 2095
rlm@1 2096 extern bool autoConvertMovieWhenPlaying; // from movie.cpp
rlm@1 2097 autoConvertMovieWhenPlaying = regQueryDwordValue("autoConvertMovieWhenPlaying", 0) ? true : false;
rlm@1 2098
rlm@1 2099 // RamWatch Settings
rlm@1 2100 AutoRWLoad = regQueryDwordValue(AUTORWLOAD, false);
rlm@1 2101 RWSaveWindowPos = regQueryDwordValue(RWSAVEPOS, false);
rlm@1 2102 ramw_x = regQueryDwordValue(RAMWX, 0);
rlm@1 2103 ramw_y = regQueryDwordValue(RAMWY, 0);
rlm@1 2104
rlm@1 2105 // this is FILO
rlm@1 2106 for (int i = MAX_RECENT_WATCHES; i > 0; --i)
rlm@1 2107 {
rlm@1 2108 buffer.Format("recentWatch%d", i);
rlm@1 2109 const char *s = regQueryStringValue(buffer, NULL);
rlm@1 2110 if (s == NULL)
rlm@1 2111 continue;
rlm@1 2112 RWAddRecentFile(s);
rlm@1 2113 }
rlm@1 2114 }
rlm@1 2115
rlm@1 2116 void VBA::saveSettings()
rlm@1 2117 {
rlm@1 2118 regSetDwordValue("defaultVideoDriver", pVideoDriverGUID == NULL);
rlm@1 2119 if (pVideoDriverGUID)
rlm@1 2120 {
rlm@1 2121 regSetBinaryValue("videoDriverGUID", (char *)&videoDriverGUID,
rlm@1 2122 sizeof(GUID));
rlm@1 2123 }
rlm@1 2124 regSetDwordValue("video", videoOption);
rlm@1 2125
rlm@1 2126 regSetDwordValue("fsWidth", fsWidth);
rlm@1 2127 regSetDwordValue("fsHeight", fsHeight);
rlm@1 2128 regSetDwordValue("fsColorDepth", fsColorDepth);
rlm@1 2129 regSetDwordValue("fsMaxScale", fsMaxScale);
rlm@1 2130
rlm@1 2131 regSetDwordValue("stretch", fullScreenStretch);
rlm@1 2132
rlm@1 2133 regSetDwordValue("renderMethod", renderMethod);
rlm@1 2134
rlm@1 2135 regSetDwordValue("ddrawEmulationOnly", ddrawEmulationOnly);
rlm@1 2136 regSetDwordValue("ddrawUseVideoMemory", ddrawUseVideoMemory);
rlm@1 2137 regSetDwordValue("tripleBuffering", tripleBuffering);
rlm@1 2138 regSetDwordValue("vsync", vsync);
rlm@1 2139
rlm@1 2140 regSetDwordValue("d3dFilter", d3dFilter);
rlm@1 2141 regSetDwordValue("glFilter", glFilter);
rlm@1 2142 regSetDwordValue("glType", glType);
rlm@1 2143
rlm@1 2144 // pixel filter & ifb
rlm@1 2145 regSetDwordValue("filter", filterType);
rlm@1 2146 regSetDwordValue("ifbType", ifbType);
rlm@1 2147 regSetDwordValue("disableMMX", disableMMX);
rlm@1 2148
rlm@1 2149 // frame skipping
rlm@1 2150 regSetDwordValue("frameSkip", frameSkip);
rlm@1 2151 regSetDwordValue("gbFrameSkip", gbFrameSkip);
rlm@1 2152 /// regSetDwordValue("autoFrameSkip", autoFrameSkip);
rlm@1 2153
rlm@1 2154 // input
rlm@1 2155 regSetDwordValue("joypadDefault", joypadDefault);
rlm@1 2156 regSetDwordValue("allowLeftRight", allowLeftRight);
rlm@1 2157 regSetDwordValue("autofireAccountforLag", autofireAccountForLag);
rlm@1 2158 regSetDwordValue("nextframeAccountforLag", nextframeAccountForLag);
rlm@1 2159 regSetDwordValue("AsscWithSaveState", theApp.AsscWithSaveState);
rlm@1 2160
rlm@1 2161
rlm@1 2162 // speed
rlm@1 2163 regSetDwordValue("throttle", throttle);
rlm@1 2164 regSetDwordValue("synchronize", synchronize);
rlm@1 2165 regSetDwordValue("accuratePitchThrottle", accuratePitchThrottle);
rlm@1 2166
rlm@1 2167 // sound
rlm@1 2168 regSetDwordValue("soundEnable", soundGetEnabledChannels() & 0x030f);
rlm@1 2169 regSetDwordValue("soundOff", soundOffFlag);
rlm@1 2170 regSetDwordValue("soundQuality", soundQuality);
rlm@1 2171 regSetDwordValue("soundEcho", soundEcho);
rlm@1 2172 regSetDwordValue("soundLowPass", soundLowPass);
rlm@1 2173 regSetDwordValue("soundReverse", soundReverse);
rlm@1 2174 regSetDwordValue("soundVolume", soundVolume);
rlm@1 2175 regSetDwordValue("muteFrameAdvance", muteFrameAdvance);
rlm@1 2176 regSetDwordValue("muteWhenInactive", muteWhenInactive);
rlm@1 2177
rlm@1 2178 // emulation
rlm@1 2179 regSetDwordValue("useBios", useBiosFile);
rlm@1 2180 regSetDwordValue("skipBios", skipBiosFile);
rlm@1 2181 if (!biosFileName.IsEmpty())
rlm@1 2182 regSetStringValue("biosFile", biosFileName);
rlm@1 2183 // regSetDwordValue("removeIntros", removeIntros);
rlm@1 2184
rlm@1 2185 regSetDwordValue("autoIPS", autoIPS);
rlm@1 2186
rlm@1 2187 regSetDwordValue("memLagEnabled", memLagEnabled);
rlm@1 2188 regSetDwordValue("gbNullInputHackEnabled", gbNullInputHackEnabled);
rlm@1 2189 regSetDwordValue("useOldGBTiming", useOldFrameTiming);
rlm@1 2190 regSetDwordValue("useOldSync", useOldSync);
rlm@1 2191
rlm@1 2192 regSetDwordValue("agbPrint", agbPrintIsEnabled());
rlm@1 2193 regSetDwordValue("rtcEnabled", winRtcEnable);
rlm@1 2194
rlm@1 2195 regSetDwordValue("saveType", winSaveType);
rlm@1 2196 regSetDwordValue("enhancedDetection", cpuEnhancedDetection);
rlm@1 2197 regSetDwordValue("flashSize", winFlashSize);
rlm@1 2198
rlm@1 2199 regSetDwordValue("disableSfx", cpuDisableSfx);
rlm@1 2200
rlm@1 2201 // GBx
rlm@1 2202 regSetDwordValue("emulatorType", gbEmulatorType);
rlm@1 2203 regSetDwordValue("gbPrinter", winGbPrinterEnabled);
rlm@1 2204 regSetDwordValue("borderOn", winGbBorderOn);
rlm@1 2205 regSetDwordValue("borderAutomatic", gbBorderAutomatic);
rlm@1 2206
rlm@1 2207 regSetDwordValue("colorOption", gbColorOption);
rlm@1 2208 regSetDwordValue("gbPaletteOption", gbPaletteOption);
rlm@1 2209 regSetBinaryValue("gbPalette", (char *)systemGbPalette, 24 * sizeof(u16));
rlm@1 2210
rlm@1 2211 // head-up display
rlm@1 2212 regSetDwordValue("showSpeed", showSpeed);
rlm@1 2213 regSetDwordValue("showSpeedTransparent", showSpeedTransparent);
rlm@1 2214
rlm@1 2215 regSetDwordValue("outlinedText", outlinedText);
rlm@1 2216 regSetDwordValue("transparentText", transparentText);
rlm@1 2217 regSetDwordValue("textColor", textColor);
rlm@1 2218 regSetDwordValue("textMethod", textMethod);
rlm@1 2219 regSetDwordValue("frameCounter", frameCounter);
rlm@1 2220 regSetDwordValue("lagCounter", lagCounter);
rlm@1 2221 regSetDwordValue("extraCounter", extraCounter);
rlm@1 2222 regSetDwordValue("inputDisplay", inputDisplay);
rlm@1 2223 regSetDwordValue("disableStatus", disableStatusMessage);
rlm@1 2224
rlm@1 2225 // UI
rlm@1 2226 regSetDwordValue("windowX", windowPositionX);
rlm@1 2227 regSetDwordValue("windowY", windowPositionY);
rlm@1 2228
rlm@1 2229 regSetDwordValue("autoHideMenu", autoHideMenu);
rlm@1 2230
rlm@1 2231 regSetDwordValue("language", languageOption);
rlm@1 2232 regSetStringValue("languageName", languageName);
rlm@1 2233
rlm@1 2234 // preferences
rlm@1 2235 regSetDwordValue("alwaysOnTop", alwaysOnTop);
rlm@1 2236 regSetDwordValue("pauseWhenInactive", pauseWhenInactive);
rlm@1 2237 regSetDwordValue("enableBackgroundInput", enableBackgroundInput);
rlm@1 2238 regSetDwordValue("priority", threadPriority);
rlm@1 2239
rlm@1 2240 regSetDwordValue("filenamePreference", filenamePreference);
rlm@1 2241 regSetDwordValue("altAviRecordMethod", altAviRecordMethod);
rlm@1 2242 regSetDwordValue("captureFormat", captureFormat);
rlm@1 2243
rlm@1 2244 regSetDwordValue("cheatsEnabled", cheatsEnabled);
rlm@1 2245 regSetDwordValue("autoSaveCheatList", autoSaveLoadCheatList);
rlm@1 2246 regSetDwordValue("pauseDuringCheatSearch2", pauseDuringCheatSearch);
rlm@1 2247
rlm@1 2248 regSetDwordValue("rewindTimer", rewindTimer);
rlm@1 2249 regSetDwordValue("rewindSlots", rewindSlots);
rlm@1 2250
rlm@1 2251 regSetDwordValue("recentFreeze", recentFreeze);
rlm@1 2252 CString buffer;
rlm@1 2253 for (int i = 0; i < 10; i++)
rlm@1 2254 {
rlm@1 2255 buffer.Format("recent%d", i);
rlm@1 2256 regSetStringValue(buffer, recentFiles[i]);
rlm@1 2257 }
rlm@1 2258
rlm@1 2259 regSetDwordValue("autoLoadMostRecent", autoLoadMostRecent);
rlm@1 2260 regSetDwordValue("loadMakesRecent", loadMakesRecent);
rlm@1 2261 regSetDwordValue("loadMakesCurrent", loadMakesCurrent);
rlm@1 2262 regSetDwordValue("saveMakesCurrent", saveMakesCurrent);
rlm@1 2263 regSetDwordValue("currentSlot", currentSlot);
rlm@1 2264 regSetDwordValue("showSlotTime", showSlotTime);
rlm@1 2265
rlm@1 2266 regSetDwordValue("movieOnEndBehavior", movieOnEndBehavior);
rlm@1 2267 regSetDwordValue("movieOnEndPause", movieOnEndPause);
rlm@1 2268
rlm@1 2269 extern bool autoConvertMovieWhenPlaying; // from movie.cpp
rlm@1 2270 regSetDwordValue("autoConvertMovieWhenPlaying", autoConvertMovieWhenPlaying);
rlm@1 2271 }
rlm@1 2272