Beispiel #1
0
// Set the current board to cur_board, in extra memory.
void set_current_board_ext(struct world *mzx_world, struct board *cur_board)
{
  set_current_board(mzx_world, cur_board);
  retrieve_board_from_extram(cur_board);
}
Beispiel #2
0
void replace_current_board(struct world *mzx_world, char *name)
{
  int current_board_id = mzx_world->current_board_id;
  struct board *src_board = mzx_world->current_board;

  FILE *fp = fopen_unsafe(name, "rb");
  struct zip_archive *zp;

  char version_string[4];
  int file_version;
  int success = 0;

  if(fp)
  {
    if(!fread(version_string, 4, 1, fp))
    {
      error_message(E_IO_READ, 0, NULL);
      fclose(fp);
      return;
    }

    file_version = board_magic(version_string);

    if(file_version > 0 && file_version <= MZX_LEGACY_FORMAT_VERSION)
    {
      // Legacy board.
      clear_board(src_board);

      src_board =
       legacy_load_board_allocate_direct(mzx_world, fp, file_version);

      success = 1;
      fclose(fp);
    }
    else

    if(file_version <= MZX_VERSION)
    {
      int board_id;

      // Regular board or maybe not a board at all.
      zp = zip_open_fp_read(fp);

      // Make sure it's an actual zip.
      if(zp)
      {
        // Make sure the zip contains a board.
        board_id = find_first_board(zp);

        if(board_id >= 0)
        {
          clear_board(src_board);

          src_board =
           load_board_allocate(mzx_world, zp, 0, file_version, board_id);

          success = 1;
        }
      }

      if(!success)
        error_message(E_BOARD_FILE_INVALID, 0, NULL);

      zip_close(zp, NULL);
    }

    else
    {
      error_message(E_BOARD_FILE_FUTURE_VERSION, file_version, NULL);
      fclose(fp);
    }

    if(success)
    {
      // Set up the newly allocated board.
      optimize_null_objects(src_board);

      if(src_board->robot_list)
        src_board->robot_list[0] = &mzx_world->global_robot;

      set_update_done_current(mzx_world);

      set_current_board(mzx_world, src_board);
      mzx_world->board_list[current_board_id] = src_board;
    }
  }
}