Exemple #1
0
static int
machine_load_rom_bank_from_file( memory_page* bank_map, size_t which,
                                 int page_num, const char *filename,
                                 size_t expected_length, int custom )
{
  compat_fd fd;
  int error;
  utils_file rom;

  fd = utils_find_auxiliary_file( filename, UTILS_AUXILIARY_ROM );
  if( fd == COMPAT_FILE_OPEN_FAILED ) {
    ui_error( UI_ERROR_ERROR, "couldn't find ROM '%s'", filename );
    return 1;
  }
  
  error = utils_read_fd( fd, filename, &rom );
  if( error ) return error;
  
  if( rom.length != expected_length ) {
    ui_error( UI_ERROR_ERROR,
	      "ROM '%s' is %ld bytes long; expected %ld bytes",
	      filename, (unsigned long)rom.length,
	      (unsigned long)expected_length );
    utils_close_file( &rom );
    return 1;
  }

  error = machine_load_rom_bank_from_buffer( bank_map, which, page_num,
                                             rom.buffer, rom.length, custom );

  error |= utils_close_file( &rom );

  return error;
}
Exemple #2
0
void
menu_help_keyboard( int action )
{
  int error, fd;
  utils_file file;
  widget_picture_data info;

  static const char *filename = "keyboard.scr";

  fd = utils_find_auxiliary_file( filename, UTILS_AUXILIARY_LIB );
  if( fd == -1 ) {
    ui_error( UI_ERROR_ERROR, "couldn't find keyboard picture ('%s')",
	      filename );
    return;
  }
  
  error = utils_read_fd( fd, filename, &file ); if( error ) return;

  if( file.length != 6912 ) {
    ui_error( UI_ERROR_ERROR, "keyboard picture ('%s') is not 6912 bytes long",
	      filename );
    utils_close_file( &file );
    return;
  }

  info.filename = filename;
  info.screen = file.buffer;
  info.border = 0;

  widget_do( WIDGET_TYPE_PICTURE, &info );

  if( utils_close_file( &file ) ) return;
}
Exemple #3
0
/* Load a snap to start the current tape autoloading */
static int
tape_autoload( libspectrum_machine hardware )
{
  int error; const char *id; compat_fd fd;
  char filename[80];
  utils_file snap;
  libspectrum_id_t type;

  id = machine_get_id( hardware );
  if( !id ) {
    ui_error( UI_ERROR_ERROR, "Unknown machine type %d!", hardware );
    return 1;
  }

  /* Look for an autoload snap. Try .szx first, then .z80 */
  type = LIBSPECTRUM_ID_SNAPSHOT_SZX;
  snprintf( filename, sizeof(filename), "tape_%s.szx", id );
  fd = utils_find_auxiliary_file( filename, UTILS_AUXILIARY_LIB );
  if( fd == COMPAT_FILE_OPEN_FAILED ) {
    type = LIBSPECTRUM_ID_SNAPSHOT_Z80;
    snprintf( filename, sizeof(filename), "tape_%s.z80", id );
    fd = utils_find_auxiliary_file( filename, UTILS_AUXILIARY_LIB );
  }
    
  /* If we couldn't find either, give up */
  if( fd == COMPAT_FILE_OPEN_FAILED ) {
    ui_error( UI_ERROR_ERROR,
	      "Couldn't find autoload snap for machine type '%s'", id );
    return 1;
  }

  error = utils_read_fd( fd, filename, &snap );
  if( error ) return error;

  error = snapshot_read_buffer( snap.buffer, snap.length, type );
  if( error ) { utils_close_file( &snap ); return error; }

  if( utils_close_file( &snap ) ) {
    ui_error( UI_ERROR_ERROR, "Couldn't close '%s': %s", filename,
	      strerror( errno ) );
    return 1;
  }
    
  return 0;
}