Beispiel #1
0
// ----------------------------------------------------------------------------
// Load
// ----------------------------------------------------------------------------
bool bios_Load(std::string filename) {
    if(filename.empty( ) || filename.length( ) == 0) {
        logger_LogError("Bios filename is invalid.", BIOS_SOURCE);
        return false;
    }

    bios_Release( );
    logger_LogInfo("Opening bios file " + filename + ".", BIOS_SOURCE);

    bios_size = archive_GetUncompressedFileSize(filename);
    if(bios_size == 0) {
        FILE* file = fopen(filename.c_str( ), "rb");
        if(file == NULL) {
#ifndef WII
            logger_LogError("Failed to open the bios file " + filename + " for reading.", BIOS_SOURCE);
#endif
            return false;
        }

        if(fseek(file, 0, SEEK_END)) {
            fclose(file);
            logger_LogError("Failed to find the end of the bios file.", BIOS_SOURCE);
            return false;
        }

        bios_size = ftell(file);
        if(fseek(file, 0, SEEK_SET)) {
            fclose(file);
            logger_LogError("Failed to find the size of the bios file.", BIOS_SOURCE);
            return false;
        }

        bios_data = new byte[bios_size];
        if(fread(bios_data, 1, bios_size, file) != bios_size && ferror(file)) {
            fclose(file);
            logger_LogError("Failed to read the bios data.", BIOS_SOURCE);
            bios_Release( );
            return false;
        }

        fclose(file);
    }
    else {
        bios_data = new byte[bios_size];
        archive_Uncompress(filename, bios_data, bios_size);
    }

    bios_filename = filename;
    return true;
}
Beispiel #2
0
// ----------------------------------------------------------------------------
// Load
// ----------------------------------------------------------------------------
bool cartridge_Load(char *filename) {
  if(strlen(filename) == 0) {
	fprintf(stderr,"Cartridge filename is invalid.");
    //logger_LogError("Cartridge filename is invalid.", CARTRIDGE_SOURCE);
    return false;
  }
  
  cartridge_Release();
  //logger_LogInfo("Opening cartridge file " + filename + ".");
  
  byte* data = NULL;
  uint size = archive_GetUncompressedFileSize(filename);
  if(size == 0) {
    int file = open(filename, O_RDONLY | O_BINARY);
    if (file < 0) {
      fprintf(stderr,"Failed to open the cartridge file %s for reading", filename);
      //logger_LogError("Failed to open the cartridge file " + filename + " for reading.", CARTRIDGE_SOURCE);
      return false;  
    }

#if 0
    if(lseek(file, 0L, SEEK_END) <0) {
      close(file);
      //logger_LogError("Failed to find the end of the cartridge file.", CARTRIDGE_SOURCE);
      return false;
    }
    size = ftell(file);
    if(lseek(file, 0L, SEEK_SET)<0) {
      close(file);
      //logger_LogError("Failed to find the size of the cartridge file.", CARTRIDGE_SOURCE);
      return false;
    }
#endif

	struct stat fileStat;
    if (stat(filename,&fileStat) < 0)  {
      fprintf(stderr,"Failed to find the size of the cartridge file.");
      //logger_LogError("Failed to find the size of the cartridge file.", CARTRIDGE_SOURCE);
      return false;
    }
	
	size = fileStat.st_size;
    data = (char *) malloc(size);
    if( (read(file, (char *) data, size) < 0) /*&& ferror(file)*/) {
      close(file);
	  fprintf(stderr,"Failed to read the cartridge data.");
      //logger_LogError("Failed to read the cartridge data.", CARTRIDGE_SOURCE);
      cartridge_Release( );
      free(data);
      return false;
    }    

    close(file);    
  }
  else {
    data = (char *) malloc(size);
    archive_Uncompress(filename, data, size);
  }

  if(!_cartridge_Load(data, size)) {
	  fprintf(stderr,"Failed to load the cartridge data into memory.\n");
    //logger_LogError("Failed to load the cartridge data into memory.", CARTRIDGE_SOURCE);
    free(data);
    return false;
  }
  if(data != NULL) {
	gameCRC = crc32(0, data, size);
	free(data);
  }
  strcpy(cartridge_filename, filename);
  return true;
}
Beispiel #3
0
// ----------------------------------------------------------------------------
// Load
// ----------------------------------------------------------------------------
bool bios_Load(char* filename) {
  if(strlen(filename) == 0) {
#if 0
    logger_LogError("Bios filename is invalid.", BIOS_SOURCE);
#endif
    return false;
  }
  
  bios_Release( );
#if 0
  logger_LogInfo("Opening bios file " + filename + ".");
#endif

  bios_size = archive_GetUncompressedFileSize(filename);
  if(bios_size == 0) {
    FILE* file = fopen(filename, "rb");
    if(file == NULL) {
#if 0
      logger_LogError("Failed to open the bios file " + filename + " for reading.", BIOS_SOURCE);
#endif
      return false;
    } 
  
    fseek(file, 0, SEEK_END);
#if 0
    if(fseek(file, 0, SEEK_END)) {
      fclose(file);
      logger_LogError("Failed to find the end of the bios file.", BIOS_SOURCE);
      return false;
    }
#endif
  
    bios_size = ftell(file);
    fseek(file, 0, SEEK_SET);
#if 0
    if(fseek(file, 0, SEEK_SET)) {
      fclose(file);
      logger_LogError("Failed to find the size of the bios file.", BIOS_SOURCE);
      return false;
    }
#endif
  
    bios_data = (char *) malloc(bios_size);
    fread(bios_data, 1, bios_size, file);
#if 0
    if(fread(bios_data, 1, bios_size, file) != bios_size && ferror(file)) {
      fclose(file);
      logger_LogError("Failed to read the bios data.", BIOS_SOURCE);
      bios_Release( );
      return false;
    }
#endif
  
    fclose(file);
  }
  else {
    bios_data = (char *) malloc(bios_size);
    archive_Uncompress(filename, bios_data, bios_size);
  }

  strcpy(bios_filename,filename);
  return true; 
}