frameSkip = 2;
systemFrameSkip = frameSkip = 2;
int main(int argc, char **argv){  fprintf(stderr,"VisualBoyAdvance-Test version %s\n", VERSION);#ifdef __GNUC__  fprintf(stderr,"Linux version\n");#else  fprintf(stderr,"Windows version\n");#endif  captureDir[0] = 0;  saveDir[0] = 0;  batteryDir[0] = 0;    char buffer[1024];  int op = -1;  frameSkip = 2;  gbBorderOn = 0;  parseDebug = true;  if(!debuggerStub) {    if(argc <= 1) {      systemMessage(0,"Missing image name");      usage(argv[0]);      exit(-1);    }  }  for(int i = 0; i < 24;) {    systemGbPalette[i++] = (0x1f) | (0x1f << 5) | (0x1f << 10);    systemGbPalette[i++] = (0x15) | (0x15 << 5) | (0x15 << 10);    systemGbPalette[i++] = (0x0c) | (0x0c << 5) | (0x0c << 10);    systemGbPalette[i++] = 0;  }  if(argc == 2) {    char *szFile = argv[optind];    bool failed = false;    if(CPUIsZipFile(szFile)) {      unzFile unz = unzOpen(szFile);            if(unz == NULL) {        systemMessage(0, "Cannot open file %s", szFile);        exit(-1);      }      int r = unzGoToFirstFile(unz);            if(r != UNZ_OK) {        unzClose(unz);        systemMessage(0, "Bad ZIP file %s", szFile);        exit(-1);      }            bool found = false;            unz_file_info info;            while(true) {        r = unzGetCurrentFileInfo(unz,                                  &info,                                  buffer,                                  sizeof(buffer),                                  NULL,                                  0,                                  NULL,                                  0);                if(r != UNZ_OK) {          unzClose(unz);          systemMessage(0,"Bad ZIP file %s", szFile);          exit(-1);        }                if(gbIsGameboyRom(buffer)) {          found = true;          cartridgeType = 1;          break;        }        if(CPUIsGBAImage(buffer)) {          found = true;          cartridgeType = 0;          break;        }                r = unzGoToNextFile(unz);                if(r != UNZ_OK)          break;      }            if(!found) {        unzClose(unz);        systemMessage(0, "No image found on ZIP file %s", szFile);        exit(-1);      }            unzClose(unz);    }        if(gbIsGameboyRom(szFile) || cartridgeType == 1) {      failed = !gbLoadRom(szFile);      cartridgeType = 1;      emuWriteState = gbWriteSaveState;      emuReadState = gbReadSaveState;      emuWriteBattery = gbWriteBatteryFile;      emuReadBattery = gbReadBatteryFile;      emuReset = gbReset;      emuCleanUp = gbCleanUp;      emuWritePNG = gbWritePNGFile;      emuWriteBMP = gbWriteBMPFile;      emuMain = gbEmulate;      emuUpdateCPSR = NULL;      emuHasDebugger = false;      emuCount = 70000/4;    } else if(CPUIsGBAImage(szFile) || cartridgeType == 0) {      failed = !CPULoadRom(szFile);      cartridgeType = 0;      emuWriteState = CPUWriteState;      emuReadState = CPUReadState;      emuWriteBattery = CPUWriteBatteryFile;      emuReadBattery = CPUReadBatteryFile;      emuReset = CPUReset;      emuCleanUp = CPUCleanUp;      emuWritePNG = CPUWritePNGFile;      emuWriteBMP = CPUWriteBMPFile;      emuMain = CPULoop;      emuUpdateCPSR = CPUUpdateCPSR;      emuHasDebugger = true;      emuCount = 50000;      CPUInit(biosFileName, useBios);      CPUReset();#ifdef GP_EMULATION    } else if(GPIsGPImage(szFile) || cartridgeType == 2) {      failed = !GPLoadRom(szFile);      cartridgeType = 2;      emuWriteState = GPWriteState;      emuReadState = GPReadState;      emuWriteBattery = GPWriteBatteryFile;      emuReadBattery = GPReadBatteryFile;      emuReset = GPReset;      emuCleanUp = GPCleanUp;      emuWritePNG = GPWritePNGFile;      emuWriteBMP = GPWriteBMPFile;      emuMain = GPLoop;      emuUpdateCPSR = GPUpdateCPSR;      emuHasDebugger = true;      emuCount = 50000;      GPInit();      GPReset();#endif    } else {      systemMessage(0, "Unknown file type %s", szFile);      exit(-1);    }        if(failed) {      systemMessage(0, "Failed to load file %s", szFile);      exit(-1);    }    strcpy(filename, szFile);    char *p = strrchr(filename, '.');        if(p)      *p = 0;  } else {    cartridgeType = 0;    strcpy(filename, "gnu_stub");    rom = (u8 *)malloc(0x2000000);    workRAM = (u8 *)calloc(1, 0x40000);    bios = (u8 *)calloc(1,0x4000);    internalRAM = (u8 *)calloc(1,0x8000);    paletteRAM = (u8 *)calloc(1,0x400);    vram = (u8 *)calloc(1, 0x20000);    oam = (u8 *)calloc(1, 0x400);    pix = (u8 *)calloc(1, 4 * 240 * 160);    ioMem = (u8 *)calloc(1, 0x400);    emuWriteState = CPUWriteState;    emuReadState = CPUReadState;    emuWriteBattery = CPUWriteBatteryFile;    emuReadBattery = CPUReadBatteryFile;    emuReset = CPUReset;    emuCleanUp = CPUCleanUp;    emuWritePNG = CPUWritePNGFile;    emuWriteBMP = CPUWriteBMPFile;    emuMain = CPULoop;    emuUpdateCPSR = CPUUpdateCPSR;    emuHasDebugger = true;    emuCount = 50000;            CPUInit(biosFileName, useBios);    CPUReset();      }    if(debuggerStub)     remoteInit();    if(cartridgeType == 0) {  } else if (cartridgeType == 1) {    if(gbBorderOn) {      gbBorderLineSkip = 256;      gbBorderColumnSkip = 48;      gbBorderRowSkip = 40;    } else {            gbBorderLineSkip = 160;      gbBorderColumnSkip = 0;      gbBorderRowSkip = 0;    }        } else {  }  for(int i = 0; i < 0x10000; i++) {    systemColorMap32[i] = ((i & 0x1f) << systemRedShift) |      (((i & 0x3e0) >> 5) << systemGreenShift) |      (((i & 0x7c00) >> 10) << systemBlueShift);    }  emulating = 1;  soundInit();    while(emulating) {    if(!paused) {      if(debugger && emuHasDebugger)        dbgMain();      else        emuMain(emuCount);    }  }  emulating = 0;  fprintf(stderr,"Shutting down\n");  remoteCleanUp();  soundShutdown();  if(gbRom != NULL || rom != NULL) {    emuCleanUp();  }  return 0;}