Example #1
0
PICO_INTERNAL int PicoCdSaveState(void *file)
{
	unsigned char buff[0x60];
	void *ym2612_regs = YM2612GetRegs();

	areaWrite("PicoSMCD", 1, 8, file);
	areaWrite(&PicoVer, 1, 4, file);

	memset(buff, 0, sizeof(buff));
	PicoAreaPackCpu(buff, 0);
	CHECKED_WRITE_BUFF(CHUNK_M68K,  buff);
	CHECKED_WRITE_BUFF(CHUNK_RAM,   Pico.ram);
	CHECKED_WRITE_BUFF(CHUNK_VRAM,  Pico.vram);
	CHECKED_WRITE_BUFF(CHUNK_ZRAM,  Pico.zram);
	CHECKED_WRITE_BUFF(CHUNK_CRAM,  Pico.cram);
	CHECKED_WRITE_BUFF(CHUNK_VSRAM, Pico.vsram);
	CHECKED_WRITE_BUFF(CHUNK_MISC,  Pico.m);
	CHECKED_WRITE_BUFF(CHUNK_VIDEO, Pico.video);
	if(PicoOpt&7) {
		memset(buff, 0, sizeof(buff));
		z80_pack(buff);
		CHECKED_WRITE_BUFF(CHUNK_Z80, buff);
	}
	if(PicoOpt&3)
		CHECKED_WRITE(CHUNK_PSG, 28*4, sn76496_regs);
	if(PicoOpt&1)
		CHECKED_WRITE(CHUNK_FM, 0x200+4, ym2612_regs);

	if (PicoMCD & 1)
	{
		Pico_mcd->m.audio_offset = mp3_get_offset();
		memset(buff, 0, sizeof(buff));
		PicoAreaPackCpu(buff, 1);
		if (Pico_mcd->s68k_regs[3]&4) // 1M mode?
			wram_1M_to_2M(Pico_mcd->word_ram2M);
        	Pico_mcd->m.hint_vector = *(unsigned short *)(Pico_mcd->bios + 0x72);

		CHECKED_WRITE_BUFF(CHUNK_S68K,     buff);
		CHECKED_WRITE_BUFF(CHUNK_PRG_RAM,  Pico_mcd->prg_ram);
		CHECKED_WRITE_BUFF(CHUNK_WORD_RAM, Pico_mcd->word_ram2M); // in 2M format
		CHECKED_WRITE_BUFF(CHUNK_PCM_RAM,  Pico_mcd->pcm_ram);
		CHECKED_WRITE_BUFF(CHUNK_BRAM,     Pico_mcd->bram);
		CHECKED_WRITE_BUFF(CHUNK_GA_REGS,  Pico_mcd->s68k_regs); // GA regs, not CPU regs
		CHECKED_WRITE_BUFF(CHUNK_PCM,      Pico_mcd->pcm);
		CHECKED_WRITE_BUFF(CHUNK_CDD,      Pico_mcd->cdd);
		CHECKED_WRITE_BUFF(CHUNK_CDC,      Pico_mcd->cdc);
		CHECKED_WRITE_BUFF(CHUNK_SCD,      Pico_mcd->scd);
		CHECKED_WRITE_BUFF(CHUNK_RC,       Pico_mcd->rot_comp);
		CHECKED_WRITE_BUFF(CHUNK_MISC_CD,  Pico_mcd->m);

		if (Pico_mcd->s68k_regs[3]&4) // convert back
			wram_2M_to_1M(Pico_mcd->word_ram2M);
	}

	return 0;
}
void BinaryFile::WriteRawData(const void* const data, const unsigned length) const
{
    CHECKED_WRITE(libendian::write((const char*)data, length, file));
}
void BinaryFile::WriteUnsignedShort(uint16_t i) const
{
    CHECKED_WRITE(libendian::le_write_us(i, file));
}
void BinaryFile::WriteUnsignedChar(unsigned char i) const
{
    CHECKED_WRITE(libendian::write(&i, 1, file));
}
void BinaryFile::WriteUnsignedInt(uint32_t i) const
{
    CHECKED_WRITE(libendian::le_write_ui(i, file));
}