1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-07-21 18:29:30 +00:00

checkpointing

This commit is contained in:
Stephen Crane 2014-10-22 19:47:06 +01:00
parent e695cb91ab
commit 1df2a2d030
2 changed files with 33 additions and 31 deletions

View File

@ -36,25 +36,27 @@ bool hardware_init(CPU &cpu) {
}
void hardware_checkpoint(Stream &s) {
_cpu->checkpoint(s);
Memory::Device *d = 0;
for (unsigned i = 0; i < 0x10000; i += Memory::page_size) {
unsigned ds = 0;
for (unsigned i = 0; i < 0x10000; i += ds) {
Memory::Device *dev = memory.get(i);
if (dev && dev != d) {
d = dev;
d->checkpoint(s);
}
if (dev) {
dev->checkpoint(s);
ds = dev->pages() * Memory::page_size;
} else
ds = Memory::page_size;
}
_cpu->checkpoint(s);
}
void hardware_restore(Stream &s) {
_cpu->restore(s);
Memory::Device *d = 0;
for (unsigned i = 0; i < 0x10000; i += Memory::page_size) {
unsigned ds = 0;
for (unsigned i = 0; i < 0x10000; i += ds) {
Memory::Device *dev = memory.get(i);
if (dev && dev != d) {
d = dev;
d->restore(s);
}
if (dev) {
dev->restore(s);
ds = dev->pages() * Memory::page_size;
} else
ds = Memory::page_size;
}
_cpu->restore(s);
}

View File

@ -10,38 +10,38 @@ SpiRAM spiRam(SPIRAM_DEV, SPIRAM_CS);
void spiram::begin(byte cs, int module)
{
SPI_for_SD.setModule(module);
SPI_for_SD.setClockDivider(SPI_CLOCK_DIV16);
SPI_for_SD.setDataMode(SPI_MODE0);
pinMode(PF_3, OUTPUT);
pinMode(cs, OUTPUT);
SPI_for_SD.setModule(module);
SPI_for_SD.setClockDivider(SPI_CLOCK_DIV16);
SPI_for_SD.setDataMode(SPI_MODE0);
pinMode(PF_3, OUTPUT);
pinMode(cs, OUTPUT);
}
void spiram::operator=(byte b)
{
spiRam.write_byte(_acc, b);
spiRam.write_byte(_acc, b);
}
spiram::operator byte()
{
return spiRam.read_byte(_acc);
return spiRam.read_byte(_acc);
}
void spiram::checkpoint(Stream &s)
{
char buf[Memory::page_size];
for (int i = 0; i < pages(); i++) {
spiRam.read_stream(i * Memory::page_size, buf, sizeof(buf));
s.write((byte *)buf, sizeof(buf));
}
char buf[Memory::page_size];
for (int i = 0; i < pages(); i++) {
spiRam.read_stream(i * 256, buf, sizeof(buf));
s.write((byte *)buf, sizeof(buf));
}
}
void spiram::restore(Stream &s)
{
char buf[Memory::page_size];
for (int i = 0; i < pages(); i++) {
s.readBytes(buf, sizeof(buf));
spiRam.write_stream(i * Memory::page_size, buf, sizeof(buf));
}
char buf[Memory::page_size];
for (int i = 0; i < pages(); i++) {
s.readBytes(buf, sizeof(buf));
spiRam.write_stream(i * 256, buf, sizeof(buf));
}
}