rewindCount = 0; rewindCounter = 0; rewindSaveNeeded = false;
BOOL fileOpen(){  // save battery file before we change the filename...  if(rom != NULL || gbRom != NULL) {    if(autoSaveLoadCheatList)      winSaveCheatListDefault();    writeBatteryFile();    emuCleanUp();    remoteCleanUp();      }  char tempName[2048];    utilGetBaseName(szFile, tempName);    _fullpath(filename, tempName, 1024);  char *p = strrchr(filename, '.');  if(p != NULL)    *p = 0;  sprintf(ipsname, "%s.ips", filename);    if(!dir[0]) {    p = strrchr(filename, '\\');    if(p) {      strncpy(dir, filename, p-filename);      dir[p-filename] = 0;    }  }  IMAGE_TYPE type = utilFindType(szFile);  if(type == IMAGE_UNKNOWN) {    systemMessage(IDS_UNSUPPORTED_FILE_TYPE,                  "Unsupported file type: %s", szFile);    return FALSE;  }  cartridgeType = (int)type;  if(type == IMAGE_GB) {    if(!gbLoadRom(szFile))      return FALSE;    emuWriteState = gbWriteSaveState;    emuWriteMemState = gbWriteMemSaveState;    emuReadState = gbReadSaveState;    emuReadMemState = gbReadMemSaveState;    emuWriteBattery = gbWriteBatteryFile;    emuReadBattery = gbReadBatteryFile;    emuReset = gbReset;    emuCleanUp = gbCleanUp;    emuWritePNG = gbWritePNGFile;    emuWriteBMP = gbWriteBMPFile;    emuMain = gbEmulate;#ifdef FINAL_VERSION    emuCount = 70000/4;#else    emuCount = 1000;#endif    gbBorderOn = winGbBorderOn;    if(autoIPS) {      int size = gbRomSize;      utilApplyIPS(ipsname, &gbRom, &size);      if(size != gbRomSize) {        extern bool gbUpdateSizes();        gbUpdateSizes();        gbReset();      }    }  } else {    if(!CPULoadRom(szFile))      return FALSE;        flashSetSize(winFlashSize);    rtcEnable(winRtcEnable);    cpuSaveType = winSaveType;    GetModuleFileName(NULL, winBuffer, 2048);    char *p = strrchr(winBuffer, '\\');    if(p)      *p = 0;        char buffer[5];    strncpy(buffer, (const char *)&rom[0xac], 4);    buffer[4] = 0;    strcat(winBuffer, "\\vba-over.ini");        UINT i = GetPrivateProfileInt(buffer,                                  "rtcEnabled",                                  -1,                                  winBuffer);    if(i != (UINT)-1)      rtcEnable(i == 0 ? false : true);    i = GetPrivateProfileInt(buffer,                             "flashSize",                             -1,                             winBuffer);    if(i != (UINT)-1 && (i == 0x10000 || i == 0x20000))      flashSetSize((int)i);    i = GetPrivateProfileInt(buffer,                             "saveType",                             -1,                             winBuffer);    if(i != (UINT)-1 && (i < 5))      cpuSaveType = (int)i;        emuWriteState = CPUWriteState;    emuWriteMemState = CPUWriteMemState;    emuReadState = CPUReadState;    emuReadMemState = CPUReadMemState;    emuWriteBattery = CPUWriteBatteryFile;    emuReadBattery = CPUReadBatteryFile;    emuReset = CPUReset;    emuCleanUp = CPUCleanUp;    emuWritePNG = CPUWritePNGFile;    emuWriteBMP = CPUWriteBMPFile;    emuMain = CPULoop;#ifdef FINAL_VERSION    emuCount = 250000;#else    emuCount = 5000;#endif    if(removeIntros && rom != NULL) {      *((u32 *)rom)= 0xea00002e;    }    if(autoIPS) {      int size = 0x2000000;      utilApplyIPS(ipsname, &rom, &size);      if(size != 0x2000000) {        CPUReset();      }    }  }      if(soundInitialized) {    if(cartridgeType == 1)      gbSoundReset();    else      soundReset();  } else {    if(!soundOffFlag)      soundInit();    soundInitialized = TRUE;  }  if(type == IMAGE_GBA) {    skipBios = skipBiosFile ? true : false;    CPUInit(biosFileName, useBiosFile ? true : false);    CPUReset();  }    readBatteryFile();  if(autoSaveLoadCheatList)    winLoadCheatListDefault();    addRecentFile(szFile);  updateWindowSize(videoOption);  updateFrameSkip();  if(autoHideMenu && videoOption > VIDEO_4X && menuToggle)    fileToggleMenu();    emulating = TRUE;  frameskipadjust = 0;  renderedFrames = 0;  autoFrameSkipLastTime = throttleLastTime = systemGetClock();  if(screenSaverState)    setScreenSaverEnable(FALSE);    return TRUE;}