Beispiel #1
0
    void scc<F>::scc_do_elim()
    {
      const x_lib::configuration *config = graph_storage->get_config();
      scc_pcpu::current_step = step_elim_push;
      graph_storage->rewind_stream(edges_stream);
      for(unsigned long i=0;i<config->super_partitions;i++) {
	state_load(false, i);
	x_lib::do_stream< scc<F>, 
			  scc_edge_wrapper, 
			  scc_message_wrapper >
	  (graph_storage, i, edges_stream, messages_stream0, NULL);
	graph_storage->reset_stream(edges_stream, i);
	state_store(i);
      }
      graph_storage->rewind_stream(messages_stream0);
      scc_pcpu::current_step = step_elim_write;
      for(unsigned long i=0;i<config->super_partitions;i++) {
	state_load(false, i);
	x_lib::do_stream< scc<F>, 
			  scc_message_wrapper, 
			  scc_edge_wrapper >
	  (graph_storage, i, messages_stream0, edges_stream, NULL);
	graph_storage->reset_stream(messages_stream0, i);
	state_store(i);
      }
    }
void load_state(const char *dest) {
    FILE *f = fopen(dest, "rb");
    if (f) {
        fread(&state_buf, STATE_SIZE, 1, f);
        state_load(state_buf);
        fclose(f);
        SYSMenuDisplayString("Loaded state from %s", dest);
    }
}
Beispiel #3
0
bool
cmd_load ( char * const cmd , State * const state )
{
  /*
   * Try and pull a filename off the command.
   */
  char* filename = strtok ( NULL , " \n" );

  /*
   * Initialize the return value to false, for failure.
   */
  bool retval = false;
  
  if ( filename )
    {
      /*
       * If a filename was given, try and save to filename.
       */

      /*
       * Attempt to open the file. If successful, load the state from
       * the file. Close the file.
       */
      FILE* loadfile = fopen ( filename , "r" );
      retval = loadfile && state_load ( state , loadfile );
      fclose ( loadfile );
    }
  else
    {
      /*
       * If no filename was provided, load from stdin.
       */

      retval = state_load ( state , stdin );
    }

  /*
   * Return the retval.
   */
  return retval;
};
Beispiel #4
0
GPGX_EX int gpgx_state_load(void *src, int size)
{
	if (!size)
		return 0;

	if (state_load((unsigned char *) src) == size)
	{
		update_viewport();
		return 1;
	}
	else
		return 0;
}
Beispiel #5
0
    void scc<F>::operator() ()
    {
      unsigned long edges = pt.get<unsigned long>("graph.edges");
      scc_pcpu::current_step = step_split_edges;
      x_lib::do_stream< scc<F>, 
      			edge_wrapper<F>, 
			scc_edge_wrapper >
	(graph_storage, 0, init_stream, edges_stream, NULL); 
      graph_storage->close_stream(init_stream);
      // Main loop
      bool do_init = true;
      unsigned long total_elims;
      scc_pcpu::scc_iteration = 0;
      do {
	total_elims = 0;
	scc_do_cc(do_init);
	scc_pcpu::scc_iteration++;
	scc_do_elim();
	total_elims += scc_pcpu::elims_global;
	scc_pcpu::elims_global = 0;
	scc_do_cc(do_init);
	scc_pcpu::scc_iteration++;
	scc_do_elim();
	total_elims += scc_pcpu::elims_global;
	scc_pcpu::elims_global = 0;
	if(heartbeat) {
	  BOOST_LOG_TRIVIAL(info) << clock::timestamp() 
				  << " Heartbeat. "
				  << " edges_eliminated: "
				  << total_elims;
	}
	edges -= total_elims;
      } while(edges > 0);

      scc_pcpu::current_step = step_count_scc;
      for(unsigned long i=0;i<graph_storage->get_config()->super_partitions;i++) {
	state_load(do_init, i);
	do_init = false;
	x_lib::do_state_iter<scc<F> > (graph_storage, i);
      }
      scc_pcpu::current_step = step_terminate;
      x_lib::do_cpu< scc<F> >(graph_storage, ULONG_MAX);
      setup_time.start();
      graph_storage->terminate();
      setup_time.stop();
      wall_clock.stop();
      BOOST_LOG_TRIVIAL(info) << "ALGORITHM::SCC_COUNT " <<
	scc_pcpu::scc_global;
      setup_time.print("CORE::TIME::SETUP");
      wall_clock.print("CORE::TIME::WALL");
    }
Beispiel #6
0
//setup for playing data
int movie_play()
{
	if(nes->movie.state == 0) {
		log_printf("movie_play:  cannot play movie, no data loaded\n");
		return(1);
	}

	memfile_seek(nes->movie.state,0,SEEK_SET);
	state_load(nes->movie.state);
	nes->movie.mode &= ~7;
	nes->movie.mode |= MOVIE_PLAY;
	nes->movie.pos = 0;
	return(0);
}
Beispiel #7
0
static int gui_state_load(int slot)
{
	if (sshot_img) {
		free(sshot_img);
		sshot_img = NULL;
	}

	// Remember which saveslot was accessed last
	saveslot = slot;
	if (state_load(slot) < 0) {
		/* Load failure */
		return 0;
	}

	// Return -1 to gui_StateLoad() caller menu, so it knows
	//  to tell main menu to return back to main menu.
	return -1;
}
Beispiel #8
0
void Application::loadState(const int i)
{
     char path[MAX_PATH];
     makePath(_stateDir, path);
     sprintf(path, "%s%d.sav", path, i);

     LOGD("LoadState: %s", path);

     FILE *f = fopen(path,"rb");
     if (f)
     {
          uint8 *buf =(uint8 *)memalign(32,STATE_SIZE);
          fread(buf, STATE_SIZE, 1, f);
          state_load(buf, 1);
          fclose(f);
          free(buf);
     }
}
Beispiel #9
0
    void scc<F>::scc_do_cc(bool&do_init)
    {
      const x_lib::configuration *config = graph_storage->get_config();
      unsigned long PHASE = 0;
      unsigned long messages_in_stream;
      unsigned long messages_out_stream;
      scc_pcpu::wcc_iteration = 0;
      do {
	if(PHASE == 0) {
	  messages_in_stream  = messages_stream0;
	  messages_out_stream = messages_stream1;
	}
	else {
	  messages_in_stream  = messages_stream1;
	  messages_out_stream = messages_stream0;
	}
	graph_storage->rewind_stream(messages_in_stream);
	graph_storage->rewind_stream(edges_stream);
	for(unsigned long i=0;i<config->super_partitions;i++) {
	  state_load(do_init, i);
	  do_init = false;
	  scc_pcpu::current_step = step_wcc_in;
	  if(scc_pcpu::wcc_iteration == 0) {
	    x_lib::do_state_iter<scc<F> > (graph_storage, i);
	  }
	  x_lib::do_stream< scc<F>, 
			    scc_message_wrapper, 
			    scc_message_wrapper >
	    (graph_storage, i, messages_in_stream, ULONG_MAX, NULL);
	  graph_storage->reset_stream(messages_in_stream, i);
	  scc_pcpu::current_step = step_wcc_out;
	  x_lib::do_stream< scc<F>, 
			    scc_edge_wrapper, 
			    scc_message_wrapper >
	    (graph_storage, i, edges_stream, messages_out_stream, NULL);
	  state_store(i);
	}
	PHASE = 1 - PHASE;
	scc_pcpu::wcc_iteration++;
      } while(!graph_storage->stream_empty(messages_out_stream));
    }
 void LoadState()
 {
     LOG_DBG("LoadState()\n");
     char * currentsavestate;
     currentsavestate = new char [999];
     strcpy(currentsavestate, Settings.PS3PathSaveStates.c_str());
     LOG_DBG("Settings.PS3PathSaveStates.size() = %d\n", Settings.PS3PathSaveStates.size());
     LOG_DBG("Settings.PS3PathSaveStates = %s\n", Settings.PS3PathSaveStates.c_str());
     LOG_DBG("Savestate path: %s \n",currentsavestate);
     ChangePathAndExt(current_rom,".sav",currentsavestate);
     FILE *f = fopen(currentsavestate,"rb");
     if (f)
     {
         LOG_DBG("f: %s\n", currentsavestate);
         LOG_DBG("Enter in loadstate\n");
         uint8 *buf =(uint8 *)memalign(32,STATE_SIZE);
         fread(buf, STATE_SIZE, 1, f);
         state_load(buf);
         fclose(f);
         free(buf);
         LOG_DBG("Out from loadstate\n");
     }
 }
Beispiel #11
0
int slot_load(int slot, int device)
{
  char filename[MAXPATHLEN];
  int filesize, done = 0;
  int offset = 0;
  u8 *savebuffer;

  if (slot > 0)
  {
    GUI_MsgBoxOpen("Information","Loading State ...",1);
  }
  else
  {
    if (!sram.on)
    {
      GUI_WaitPrompt("Error","SRAM is disabled !");
      return 0;
    }

    GUI_MsgBoxOpen("Information","Loading SRAM ...",1);
  }

  if (!device)
  {
    /* FAT support */
    if (slot > 0)
      sprintf (filename,"%s/saves/%s.gp%d", DEFAULT_PATH, rom_filename, slot - 1);
    else
      sprintf (filename,"%s/saves/%s.srm", DEFAULT_PATH, rom_filename);

    /* Open file */
    FILE *fp = fopen(filename, "rb");
    if (!fp)
    {
      GUI_WaitPrompt("Error","Unable to open file !");
      return 0;
    }

    /* Read size */
    fseek(fp, 0, SEEK_END);
    filesize = ftell(fp);
    fseek(fp, 0, SEEK_SET);

    /* allocate buffer */
    savebuffer = (u8 *)memalign(32,filesize);
    if (!savebuffer)
    {
      GUI_WaitPrompt("Error","Unable to allocate memory !");
      fclose(fp);
      return 0;
    }

    /* Read into buffer (2k blocks) */
    while (filesize > FILECHUNK)
    {
      fread(savebuffer + done, FILECHUNK, 1, fp);
      done += FILECHUNK;
      filesize -= FILECHUNK;
    }

    /* Read remaining bytes */
    fread(savebuffer + done, filesize, 1, fp);
    done += filesize;
    fclose(fp);
  }  
  else
  {
    /* Memory Card support */
    if (slot > 0)
      sprintf(filename, "MD-%04X.gp%d", rominfo.realchecksum, slot - 1);
    else
      sprintf(filename, "MD-%04X.srm", rominfo.realchecksum);

    /* Initialise the CARD system */
    char action[64];
    memset(&SysArea, 0, CARD_WORKAREA);
    CARD_Init("GENP", "00");

    /* CARD slot */
    device--;

    /* Attempt to mount the card */
    if (!CardMount(device))
    {
      GUI_WaitPrompt("Error","Unable to mount memory card");
      return 0;
    }
    
    /* Retrieve the sector size */
    u32 SectorSize = 0;
    int CardError = CARD_GetSectorSize(device, &SectorSize);
    if (!SectorSize)
    {
      sprintf(action, "Invalid sector size (%d)", CardError);
      GUI_WaitPrompt("Error",action);
      CARD_Unmount(device);
      return 0;
    }

    /* Open file */
    card_file CardFile;
    CardError = CARD_Open(device, filename, &CardFile);
    if (CardError)
    {
      sprintf(action, "Unable to open file (%d)", CardError);
      GUI_WaitPrompt("Error",action);
      CARD_Unmount(device);
      return 0;
    }

    /* Retrieve file size */
    filesize = CardFile.len;
    if (filesize % SectorSize)
    filesize = ((filesize / SectorSize) + 1) * SectorSize;

    /* Allocate buffer */
    savebuffer = (u8 *)memalign(32,filesize);
    if (!savebuffer)
    {
      GUI_WaitPrompt("Error","Unable to allocate memory !");
      CARD_Close(&CardFile);
      CARD_Unmount(device);
      return 0;
    }

    /* Read file sectors */
    while (filesize > 0)
    {
      CARD_Read(&CardFile, &savebuffer[done], SectorSize, done);
      done += SectorSize;
      filesize -= SectorSize;
    }

    CARD_Close(&CardFile);
    CARD_Unmount(device);
    offset = 2112;
  }

  if (slot > 0)
  {
    /* Load state */
    if (!state_load(&savebuffer[offset]))
    {
      free(savebuffer);
      GUI_WaitPrompt("Error","Unable to load state !");
      return 0;
    }
  }
  else
  {
    /* Load SRAM & update CRC */
    memcpy(sram.sram, &savebuffer[offset], 0x10000);
    sram.crc = crc32(0, sram.sram, 0x10000);
  }

  free(savebuffer);
  GUI_MsgBoxClose();
  return 1;
}
Beispiel #12
0
static int cmd_loadstate(int argc, char **argv)
{
	state_load(argc > 1 ? atoi(argv[1]) : -1);
	return 0;
}
Beispiel #13
0
int
main ( int argc , char** argv )
{
  /*
   * Do initialization steps here.
   */

  /*
   * Set up list of player id's.
   */
  char* players [2] = { "r" , "b" };

  /*
   * Attempt to initialize the game state to the default.
   *
   * Add more error checking?
   */
  State* state = build_state ( );
  FILE* init_file = fopen ( INIT_FILENAME , "r" );
  bool initialized = init_file && state_load ( state , init_file );
  fclose ( init_file );
  if ( ! initialized )
    return 1;


  /*
   * The top level of program logic resides nested within this loop,
   * which runs until one of the players sends the termination signal.
   *
   * Note that this is an infinite loop. The actual control logic for
   * this loop is a single goto statment in the verb interpreter, set
   * to jump outside the loop if and only if the VERB_TERM is
   * encountered. DO NOT BE ALARMED. THIS IS A LEGITIMATE USE OF THE
   * GOTO STATEMENT!
   */
  while ( true )
    {
      /*
       * The logic inside this loop effectively handles a single
       * round, from the starting position to reseting the game.
       */


      /*
       * Initialize the player indexer and player.
       */
      unsigned short indexer = 0;
      char* player = players[0];


      /*
       * While a game is still in progress (i.e. while both players
       * have legal moves available), this loop alternates between
       * the red and black players, starting with the red player.
       *
       * The control statement for this loop determines whether the
       * player has any vaild moves. If the player does not have any
       * valid moves, the control logic of the interpreter loop is
       * modified to force the losing player to fix the situation.
       * This could change in the future, so with minor changes,
       * control could just be made to fall through to a reset
       * after this loop, it just depends on what happens during
       * development.
       */
      while ( state_has_moves ( state , player ) )
        {
          /*
           * The logic inside this loop effectively handles a single
           * turn, allowing an unlimited number of commands which are
           * not moves to be performed, followed by a single move.
           *
           * Notice that both players must be trusted for this system
           * to work as-is, otherwise any player could modify the
           * state of the game to their advantage. This is a standing
           * security issue, but one which can be ignored at the
           * moment for the academic purposes of the project.
           */

          /*
           * Initialize the keep_turn flag.
           */
          bool keep_turn = true;

          /*
           * While the player has not yet made a move, it is still
           * the player's turn. Thus, this loop terminates only after
           * a move has been made, processing any other commands
           * the player gives during the current turn. Control stays
           * with the player anyways if he has no moves, as he has
           * lost and the losing player is responsible for resetting
           * the board.
           */
          while ( keep_turn || ( ! state_has_moves ( state , player ) ) )
            {
              /*
               * This logic effectively handles a single command from
               * the current player. This involves reading the command
               * from the player's input pipe, interpreting and
               * executing the command, and returning the result of
               * the command to the player as appropriate.
               */

              /*
               * Initialize the command buffer.
               */
              //char* cmd = malloc ( sizeof ( char ) * CMD_BUFFER_SIZE );
              char* cmd = NULL;
              size_t cmdlen = 0;

              /*
               * Read the next command from stdin.
               *
               * Might try and modify this to avoid the buffer.
               */
              getline ( &cmd , &cmdlen , stdin );

              /*
               * Extract the verb of the command, this is always the
               * first word of the command, in a HTTP-like format.
               */
              char* verb = strtok ( cmd , " \n" );


              /*
               * Use an if-else chain statement to select the proper
               * code to execute for each verb.
               */
              if ( ! verb )
                {
                  /*
                   * If the entry was just a newline, ignore it.
                   */
                }
                
              else if ( ! strcmp ( verb , VERB_TERM ) )
                {
                  /*
                   * If the term signal is given, then jump to the
                   * term_exit branch.
                   */

                  goto term_exit;
                }

              else if ( ! strcmp ( verb , VERB_LOAD ) )
                {
                  cmd_load ( cmd , state );
                }

              else if ( ! strcmp ( verb , VERB_SAVE ) )
                {
                  cmd_save ( cmd , state );
                }

              else if ( ! strcmp ( verb , VERB_TGET ) )
                {
                  cmd_tget ( cmd , state );
                }

              else if ( ! strcmp ( verb , VERB_TSET ) )
                {
                  cmd_tset ( cmd , state );
                }

              else if ( ! strcmp ( verb , VERB_MOVE ) )
                {
                  /*
                   * This code executes if the verb is the move command.
                   * It then parses the remainder of the command to
                   * determine its validity. If the command is well-
                   * structured and the move is legal, the move is made
                   * and the moved flag set to true. Otherwise, a 400
                   * BAD SYNTAX error will be returned. If the move
                   * requested is well-formed but illegal, a 403 MOVE
                   * FORBIDDEN error is returned. Assuming no errors
                   * occur, a 200 OK message is returned.
                   */

                  cmd_move ( cmd , state );

                  keep_turn = false;
                }

              else
                {
                  /*
                   * If we don't recognize the given verb, we do the
                   * safe thing and return the verb nonexistant error.
                   */
                  //puts ( "PCIP/1.0 404 NOTVERB" );
                  puts ( "NULL" );
                }


              /*
               * Deallocate the command buffer.
               */
              free ( cmd );
           }
          
          /*
           * Increment the player indexer with wraparound. Set the
           * pipes pointing to the current player's input and
           * output.
           *
           * Trust me, I have a reason for putting it here.
           */
          indexer = ( indexer + 1 ) % PLAYER_COUNT;
          player = players[indexer];
          state->player = *player;

          /*
           * Announce the turn change.
           */
          printf ( "PCIP/1.0 201 NEW TURN\n%c\n" , *player );
       }


      /*
       * This is the interpreter loop's aforementioned implicit fall
       * through case for processing end of game conditions.
       *
       * Given the termination condition of the previous loop, the
       * player input and output pipes now point to the loosing
       * player, who is now responsible for resetting the game.
       */
    }


  /*
   * If the term command is given, the program jumps to this point,
   * just before deallocation of top-level dynamic resources occurs.
   * Note that breaking out of a switch statement and a triple nested 
   * do-while loop *is* a legitimate use of goto.
   */
term_exit:


  /*
   * Clean up.
   */

  /*
   * Deallocate the game state.
   */
  free_state ( state );


  /*
   * If we got this far without an incident, the program should have
   * run successfully, so we return the corresponding status code.
   */
  return EXIT_SUCCESS;
};
Beispiel #14
0
void emulator_load_state()
{
	state_load();
}
Beispiel #15
0
int main(int argc, char *argv[])
{
  int c;
  struct state *state = NULL;
#if TEST_BUILD
  struct test_case *test_case;
#endif
  prefs_init();

  while(1) {
    int option_index = 0;
    static struct option long_options[] = {
      {"cart",                  required_argument, 0, OPT_CART },
      {"force-extreme-disasm",  no_argument,       0, OPT_FORCE_EXTREME_DISASM },
      {"crop-screen",           no_argument,       0, OPT_CROP_SCREEN },
      {"loglevels" ,            required_argument, 0, OPT_LOGLEVELS },
      {"audio-device" ,         required_argument, 0, OPT_AUDIO_DEVICE },
#if TEST_BUILD
      {"test-case",             required_argument, 0, OPT_TEST_MODE},
#endif
      {0,                       0,                 0, 0 }
    };
    c = getopt_long(argc, argv, "a:b:c:t:s:hdpyVAMvq", long_options, &option_index);
    if(c == -1) break;

    switch(c) {
    case 'a':
      prefs_set("diskimage", optarg);
      break;
    case 'b':
      prefs_set("diskimage2", optarg);
      break;
    case 'c':
      prefs_set("hdimage", optarg);
      break;
    case 't':
      prefs_set("tosimage", optarg);
      break;
    case 's':
      prefs_set("stateimage", optarg);
      break;
    case OPT_CART:
      prefs_set("cartimage", optarg);
      break;
    case OPT_FORCE_EXTREME_DISASM:
      cprint_all = 1;
      break;
    case OPT_CROP_SCREEN:
      crop_screen = 1;
      break;
    case OPT_LOGLEVELS:
      diag_set_module_levels(optarg);
      break;
    case OPT_AUDIO_DEVICE:
      if(!strncmp("list", optarg, 4)) {
        audio_device = -1;
      } else {
        audio_device = atoi(optarg);
      }
      break;
#if TEST_BUILD
    case OPT_TEST_MODE:
      test_case_name = xstrdup(optarg);
      test_mode = 1;
      break;
#endif
    case 'd':
      debugger = 1;
      break;
    case 'p':
      ppmoutput = 1;
      break;
    case 'y':
      psgoutput = 1;
      break;
    case 'v':
      verbosity++;
      break;
    case 'q':
      verbosity = MAX(1, verbosity-1);
      break;
    case 'V':
      vsync_delay = 1;
      break;
    case 'A':
      play_audio = 1;
      break;
    case 'M':
      monitor_sm124 = 1;
      break;
    case 'h':
    default:
      printf("Usage: %s [-AdMpqvVy] [-a diskimage1] [-b diskimage2] [-c hdimage] [-t tosimage] [-s stateimage]\n",
	     argv[0]);
      exit(-1);
      break;
    }
  }

  /* Do not crop screen while debugging */
  if(debugger) {
    crop_screen = 0;
  }
  
  if((prefs.diskimage == NULL) && (argv[optind] != NULL))
    prefs_set("diskimage", argv[optind]);

  SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK|SDL_INIT_AUDIO);

#if TEST_BUILD
  if(test_mode) {
    test_case = test_init(test_case_name);
    if(test_case) {
      if(test_case->cartridge_name) {
        prefs_set("cartimage", test_case->cartridge_name);
      }
      if(test_case->floppy_name) {
        prefs_set("diskimage", test_case->floppy_name);
      }
    } else {
      printf("DEBUG: Could not load test case %s\n", test_case_name);
      exit(-3);
    }
  }
#endif
  
  /* Must run before hardware module inits */
  mmu_init();

  /* This must also be run before hardware modules.
     It gives a dummy area for some memory regions to not
     cause bus errors */
  mmu_fallback_init(); 

  /* Actual hardware */
  ram_init();
  rom_init();
  cpu_init();
  if(prefs.cartimage) {
    cartridge_init(prefs.cartimage);
  } else {
    cartridge_init(NULL);
  }
  psg_init();
  midi_init();
  acia_init();
  ikbd_init();
#if INCLUDE_RTC
  rtc_init();
#endif
  dma_init();
  fdc_init();
  hdc_init(prefs.hdimage);
  mfp_init();
  screen_disable(0);
  glue_init();
  shifter_init();
  if(debugger) {
    debug_init();
    cpu_halt_for_debug();
  }
  screen_init();
  
  floppy_init(prefs.diskimage, prefs.diskimage2);

  if(prefs.stateimage) {
    state = state_load(prefs.stateimage);
  }

  if(state != NULL)
    state_restore(state);

  memset(&reset, 0, sizeof reset);
  reset.sa_sigaction = reset_action;
  sigaction(SIGHUP, &reset, NULL);

  while(cpu_run(CPU_RUN));
  return 0;
}