Beispiel #1
0
	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;
	}
Beispiel #2
0
	blargg_err_t load_( Data_Reader& in )
	{
		long file_size = in.remain();
		if ( file_size <= Vgm_Emu::header_size )
			return gme_wrong_file_type;
		
		RETURN_ERR( in.read( &h, Vgm_Emu::header_size ) );
		RETURN_ERR( check_vgm_header( h ) );
		
		long gd3_offset = get_le32( h.gd3_offset ) - 0x2C;
		long remain = file_size - Vgm_Emu::header_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 ) );
			long 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 0;
	}
Beispiel #3
0
	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;
	}
Beispiel #4
0
	blargg_err_t load_( Data_Reader& in )
	{
		long file_size = in.remain();
		if ( file_size < Snes_Spc::spc_min_file_size )
			return gme_wrong_file_type;
		RETURN_ERR( in.read( &header, Spc_Emu::header_size ) );
		RETURN_ERR( check_spc_header( header.tag ) );
		long const xid6_offset = 0x10200;
		long xid6_size = file_size - xid6_offset;
		if ( xid6_size > 0 )
		{
			RETURN_ERR( xid6.resize( xid6_size ) );
			RETURN_ERR( in.skip( xid6_offset - Spc_Emu::header_size ) );
			RETURN_ERR( in.read( xid6.begin(), xid6.size() ) );
		}
		return 0;
	}
Beispiel #5
0
blargg_err_t Nes_Rom::load_ines_rom( Data_Reader& in )
{
	ines_header_t h;
	BLARGG_RETURN_ERR( in.read( &h, sizeof h ) );
	
	if ( 0 != memcmp( h.signature, "NES\x1A", 4 ) )
		return "Not a iNES ROM file";
	
	if ( h.zero [7] ) // handle header defaced by a f*****g idiot's handle
		h.flags2 = 0;
	
	set_mapper( h.flags, h.flags2 );
	
	if ( h.flags & 0x04 ) // skip trainer
		BLARGG_RETURN_ERR( in.skip( 512 ) );
	
	BLARGG_RETURN_ERR( resize_prg( h.prg_count * 16 * 1024L ) );
	BLARGG_RETURN_ERR( resize_chr( h.chr_count * 8 * 1024L ) );
	
	BLARGG_RETURN_ERR( in.read( prg(), prg_size() ) );
	BLARGG_RETURN_ERR( in.read( chr(), chr_size() ) );
	
	return blargg_success;
}