📄 state.c
字号:
#include "shared.h"
#include "dinput.h"
#include "resource.h"
#include "main.h"
#include "input.h"
#include "registry.h"
void save_state(char *pFilename, HANDLE FileHandle)
{
if (FileHandle != INVALID_HANDLE_VALUE)
{
unsigned int BytesWritten;
WriteFile(FileHandle, &vdp, sizeof(t_vdp), &BytesWritten, NULL);
WriteFile(FileHandle, &sms, sizeof(t_sms), &BytesWritten, NULL);
WriteFile(FileHandle, Z80_Context, sizeof(Z80_Regs), &BytesWritten, NULL);
WriteFile(FileHandle, &after_EI, sizeof(int), &BytesWritten, NULL);
WriteFile(FileHandle, &ym2413[0].reg[0], 0x40, &BytesWritten, NULL);
WriteFile(FileHandle, &sn[0], sizeof(t_SN76496), &BytesWritten, NULL);
CloseHandle(FileHandle);
}
}
void load_state(char *pFilename)
{
HANDLE FileHandle;
int BytesRead;
int i;
byte reg[0x40];
FileHandle = CreateFile(pFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (FileHandle == INVALID_HANDLE_VALUE) return;
/* Reset the virtual console */
cpu_reset();
system_reset();
/* Load VDP context */
ReadFile(FileHandle, &vdp, sizeof(t_vdp), &BytesRead, NULL);
/* Load SMS context */
ReadFile(FileHandle, &sms, sizeof(t_sms), &BytesRead, NULL);
/* Load Z80 context */
ReadFile(FileHandle, Z80_Context, sizeof(Z80_Regs), &BytesRead, NULL);
ReadFile(FileHandle, &after_EI, sizeof(int), &BytesRead, NULL);
/* Load YM2413 registers */
ReadFile(FileHandle, ®, 0x40, &BytesRead, NULL);
/* Load SN76489 context */
ReadFile(FileHandle, &sn[0], sizeof(t_SN76496), &BytesRead, NULL);
CloseHandle(FileHandle);
/* Restore callbacks */
z80_set_irq_callback(sms_irq_callback);
cpu_readmap[0] = cart.rom + 0x0000; /* 0000-3FFF */
cpu_readmap[1] = cart.rom + 0x2000;
cpu_readmap[2] = cart.rom + 0x4000; /* 4000-7FFF */
cpu_readmap[3] = cart.rom + 0x6000;
cpu_readmap[4] = cart.rom + 0x0000; /* 0000-3FFF */
cpu_readmap[5] = cart.rom + 0x2000;
cpu_readmap[6] = sms.ram;
cpu_readmap[7] = sms.ram;
cpu_writemap[0] = sms.dummy;
cpu_writemap[1] = sms.dummy;
cpu_writemap[2] = sms.dummy;
cpu_writemap[3] = sms.dummy;
cpu_writemap[4] = sms.dummy;
cpu_writemap[5] = sms.dummy;
cpu_writemap[6] = sms.ram;
cpu_writemap[7] = sms.ram;
sms_mapper_w(3, sms.fcr[3]);
sms_mapper_w(2, sms.fcr[2]);
sms_mapper_w(1, sms.fcr[1]);
sms_mapper_w(0, sms.fcr[0]);
/* Force full pattern cache update */
is_vram_dirty = 1;
memset(vram_dirty, 1, 0x200);
/* Restore palette */
for(i = 0; i < PALETTE_SIZE; i += 1)
palette_sync(i);
/* Restore sound state */
if(snd.enabled)
{
/* Restore YM2413 emulation */
OPLResetChip(ym3812);
/* Clear YM2413 context */
ym2413_reset(0);
/* Restore rhythm enable first */
ym2413_write(0, 0, 0x0E);
ym2413_write(0, 1, reg[0x0E]);
/* User instrument settings */
for(i = 0x00; i <= 0x07; i += 1)
{
ym2413_write(0, 0, i);
ym2413_write(0, 1, reg[i]);
}
/* Channel frequency */
for(i = 0x10; i <= 0x18; i += 1)
{
ym2413_write(0, 0, i);
ym2413_write(0, 1, reg[i]);
}
/* Channel frequency + ctrl. */
for(i = 0x20; i <= 0x28; i += 1)
{
ym2413_write(0, 0, i);
ym2413_write(0, 1, reg[i]);
}
/* Instrument and volume settings */
for(i = 0x30; i <= 0x38; i += 1)
{
ym2413_write(0, 0, i);
ym2413_write(0, 1, reg[i]);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -