Ejemplo n.º 1
0
int Application::main(int argc, char **argv) {
  app = new App(argc, argv);
  #if !defined(_WIN32)
  //Windows port uses 256x256 icon from resource file
  app->setWindowIcon(QIcon(":/bsnes.png"));
  #endif

  initargs(argc, argv);  //ensure argv[]s are in UTF-8 format
  initPaths(argv[0]);
  locateFile(configFilename = "bsnes.cfg", true);
  locateFile(styleSheetFilename = "style.qss", false);

  string customStylesheet;
  if(customStylesheet.readfile(styleSheetFilename) == true) {
    app->setStyleSheet((const char*)customStylesheet);
  } else {
    app->setStyleSheet(defaultStylesheet);
  }

  config.load(configFilename);
  init();
  snes.init();

  if(argc == 2) {
    //if valid file was specified on the command-line, attempt to load it now
    utility.loadCartridge(argv[1]);
  }

  while(terminate == false) {
    processEvents();
    utility.updateSystemState();
    inputManager.refresh();

    if(config.input.focusPolicy == Configuration::Input::FocusPolicyPauseEmulation) {
      bool inactive = (winMain->window->isActiveWindow() == false);
      if(!autopause && inactive) {
        autopause = true;
        audio.clear();
      } else if(autopause && !inactive) {
        autopause = false;
      }
    } else {
      autopause = false;
    }

    if(cartridge.loaded() && !pause && !autopause) {
      snes.runtoframe();
    } else {
      usleep(20 * 1000);
    }

    supressScreenSaver();
  }

  config.save(configFilename);
  return 0;
}
Ejemplo n.º 2
0
void Application::run() {
  if(terminate == true) {
    timer->stop();
    app->quit();
    return;
  }

  QApplication::processEvents();
  utility.updateSystemState();
  mapper().poll();

  if(config().input.focusPolicy == Configuration::Input::FocusPolicyPauseEmulation) {
    bool active = mainWindow->isActive();
    if(!autopause && !active) {
      autopause = true;
      audio.clear();
    } else if(autopause && active) {
      autopause = false;
    }
  } else {
    autopause = false;
  }

  if(SNES::cartridge.loaded() && !pause && !autopause && (!debug || debugrun)) {
    SNES::system.run();
    #if defined(DEBUGGER)
    if(SNES::debugger.break_event != SNES::Debugger::BreakEvent::None) {
      debug = true;
      debugrun = false;
      debugger->synchronize();
      debugger->event();
      SNES::debugger.break_event = SNES::Debugger::BreakEvent::None;
    }
    #endif
  } else {
    usleep(20 * 1000);
  }

  clock_t currentTime = clock();
  autosaveTime += currentTime - clockTime;
  screensaverTime += currentTime - clockTime;
  clockTime = currentTime;

  if(autosaveTime >= CLOCKS_PER_SEC * 60) {
    //auto-save RAM once per minute in case of emulator crash
    autosaveTime = 0;
    if(config().system.autoSaveMemory == true) cartridge.saveMemory();
  }

  if(screensaverTime >= CLOCKS_PER_SEC * 30) {
    //supress screen saver every 30 seconds so it will not trigger during gameplay
    screensaverTime = 0;
    supressScreenSaver();
  }
}