Ejemplo n.º 1
0
const char * Nes_State_::write_blocks( Nes_File_Writer& out ) const
{
    if ( nes_valid )
    {
        nes_state_t s = nes;
        s.timestamp *= 5;
        RETURN_ERR( write_nes_state( out, s ) );
    }

    if ( cpu_valid )
    {
        cpu_state_t s;
        memset( &s, 0, sizeof s );
        s.pc = cpu->pc;
        s.s = cpu->sp;
        s.a = cpu->a;
        s.x = cpu->x;
        s.y = cpu->y;
        s.p = cpu->status;
        RETURN_ERR( write_nes_state( out, s ) );
    }

    if ( ppu_valid )
    {
        ppu_state_t s = *ppu;
        RETURN_ERR( write_nes_state( out, s ) );
    }

    if ( apu_valid )
    {
        apu_state_t s = *apu;
        RETURN_ERR( write_nes_state( out, s ) );
    }

    if ( joypad_valid )
    {
        joypad_state_t s = *joypad;
        RETURN_ERR( write_nes_state( out, s ) );
    }

    if ( mapper_valid )
        RETURN_ERR( out.write_block( FOUR_CHAR('MAPR'), mapper->data, mapper->size ) );

    if ( ram_valid )
        RETURN_ERR( out.write_block( FOUR_CHAR('LRAM'), ram, ram_size ) );

    if ( spr_ram_valid )
        RETURN_ERR( out.write_block( FOUR_CHAR('SPRT'), spr_ram, spr_ram_size ) );

    if ( nametable_size )
    {
        RETURN_ERR( out.write_block_header( FOUR_CHAR('NTAB'), nametable_size ) );
        RETURN_ERR( out.write( nametable, 0x800 ) );
        if ( nametable_size > 0x800 )
            RETURN_ERR( out.write( chr, 0x800 ) );
    }

    if ( chr_size )
        RETURN_ERR( out.write_block( FOUR_CHAR('CHRR'), chr, chr_size ) );

    if ( sram_size )
        RETURN_ERR( out.write_block( FOUR_CHAR('SRAM'), sram, sram_size ) );

    return 0;
}
Ejemplo n.º 2
0
blargg_err_t Nes_Snapshot::write_blocks( Nes_File_Writer& out ) const
{
	if ( nes_valid )
	{
		nes_state_t s = nes;
		s.pal = false;
		s.timestamp = nes.timestamp * 15;
		BLARGG_RETURN_ERR( write_nes_state( out, s ) );
	}
	
	if ( cpu_valid )
	{
		cpu_state_t s;
		memset( &s, 0, sizeof s );
		s.pc = cpu.pc;
		s.s = cpu.sp;
		s.a = cpu.a;
		s.x = cpu.x;
		s.y = cpu.y;
		s.p = cpu.status;
		BLARGG_RETURN_ERR( write_nes_state( out, s ) );
	}
	
	if ( ppu_valid )
	{
		ppu_state_t s = ppu;
		BLARGG_RETURN_ERR( write_nes_state( out, s ) );
	}
	
	if ( apu_valid )
	{
		apu_snapshot_t s = apu;
		BLARGG_RETURN_ERR( write_nes_state( out, s ) );
	}
	
	if ( joypad_valid )
	{
		joypad_state_t s = joypad;
		BLARGG_RETURN_ERR( write_nes_state( out, s ) );
	}
	
	if ( mapper_valid )
		BLARGG_RETURN_ERR( out.write_block( 'MAPR', mapper.data, mapper.size ) );
	
	if ( ram_valid )
		BLARGG_RETURN_ERR( out.write_block( 'LRAM', ram, sizeof ram ) );
	
	if ( spr_ram_valid )
		BLARGG_RETURN_ERR( out.write_block( 'SPRT', spr_ram, sizeof spr_ram ) );
	
	if ( nametable_size )
		BLARGG_RETURN_ERR( out.write_block( 'NTAB', nametable, nametable_size ) );
	
	if ( chr_size )
		BLARGG_RETURN_ERR( out.write_block( 'CHRR', chr, chr_size ) );
	
	if ( sram_size )
		BLARGG_RETURN_ERR( out.write_block( 'SRAM', sram, sram_size ) );
	
	return blargg_success;
}