blargg_err_t load_( Data_Reader& in ) { int file_size = in.remain(); if ( file_size <= h.size ) return blargg_err_file_type; RETURN_ERR( in.read( &h, h.size ) ); if ( !h.valid_tag() ) return blargg_err_file_type; int gd3_offset = get_le32( h.gd3_offset ) - 0x2C; int remain = file_size - h.size - gd3_offset; byte gd3_h [gd3_header_size]; if ( gd3_offset > 0 && remain >= gd3_header_size ) { RETURN_ERR( in.skip( gd3_offset ) ); RETURN_ERR( in.read( gd3_h, sizeof gd3_h ) ); int gd3_size = check_gd3_header( gd3_h, remain ); if ( gd3_size ) { RETURN_ERR( gd3.resize( gd3_size ) ); RETURN_ERR( in.read( gd3.begin(), gd3.size() ) ); } } return blargg_ok; }
blargg_err_t load_( Data_Reader& in ) { int file_size = in.remain(); if ( file_size <= h.size_min ) return blargg_err_file_type; RETURN_ERR( in.read( &h, h.size_min ) ); if ( !h.valid_tag() ) return blargg_err_file_type; if ( h.size() > h.size_min ) RETURN_ERR( in.read( &h.rf5c68_rate, h.size() - h.size_min ) ); h.cleanup(); int data_offset = get_le32( h.data_offset ) + offsetof( Vgm_Core::header_t, data_offset ); int data_size = file_size - offsetof( Vgm_Core::header_t, data_offset ) - data_offset; int gd3_offset = get_le32( h.gd3_offset ); if ( gd3_offset > 0 ) gd3_offset += offsetof( Vgm_Core::header_t, gd3_offset ); int amount_to_skip = gd3_offset - h.size(); if ( gd3_offset > 0 && gd3_offset > data_offset ) { data_size = gd3_offset - data_offset; amount_to_skip = 0; RETURN_ERR( data.resize( data_size ) ); RETURN_ERR( in.skip( data_offset - h.size() ) ); RETURN_ERR( in.read( data.begin(), data_size ) ); } int remain = file_size - gd3_offset; byte gd3_h [gd3_header_size]; if ( gd3_offset > 0 && remain >= gd3_header_size ) { RETURN_ERR( in.skip( amount_to_skip ) ); RETURN_ERR( in.read( gd3_h, sizeof gd3_h ) ); int gd3_size = check_gd3_header( gd3_h, remain ); if ( gd3_size ) { RETURN_ERR( gd3.resize( gd3_size ) ); RETURN_ERR( in.read( gd3.begin(), gd3.size() ) ); } if ( data_offset > gd3_offset ) { RETURN_ERR( data.resize( data_size ) ); RETURN_ERR( in.skip( data_offset - gd3_offset - sizeof gd3_h - gd3.size() ) ); RETURN_ERR( in.read( data.begin(), data.end() - data.begin() ) ); } } return (blargg_err_t)blargg_ok; }