1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-12-30 09:30:46 +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) { void hardware_checkpoint(Stream &s) {
_cpu->checkpoint(s); unsigned ds = 0;
Memory::Device *d = 0; for (unsigned i = 0; i < 0x10000; i += ds) {
for (unsigned i = 0; i < 0x10000; i += Memory::page_size) {
Memory::Device *dev = memory.get(i); Memory::Device *dev = memory.get(i);
if (dev && dev != d) { if (dev) {
d = dev; dev->checkpoint(s);
d->checkpoint(s); ds = dev->pages() * Memory::page_size;
} } else
ds = Memory::page_size;
} }
_cpu->checkpoint(s);
} }
void hardware_restore(Stream &s) { void hardware_restore(Stream &s) {
_cpu->restore(s); unsigned ds = 0;
Memory::Device *d = 0; for (unsigned i = 0; i < 0x10000; i += ds) {
for (unsigned i = 0; i < 0x10000; i += Memory::page_size) {
Memory::Device *dev = memory.get(i); Memory::Device *dev = memory.get(i);
if (dev && dev != d) { if (dev) {
d = dev; dev->restore(s);
d->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) void spiram::begin(byte cs, int module)
{ {
SPI_for_SD.setModule(module); SPI_for_SD.setModule(module);
SPI_for_SD.setClockDivider(SPI_CLOCK_DIV16); SPI_for_SD.setClockDivider(SPI_CLOCK_DIV16);
SPI_for_SD.setDataMode(SPI_MODE0); SPI_for_SD.setDataMode(SPI_MODE0);
pinMode(PF_3, OUTPUT); pinMode(PF_3, OUTPUT);
pinMode(cs, OUTPUT); pinMode(cs, OUTPUT);
} }
void spiram::operator=(byte b) void spiram::operator=(byte b)
{ {
spiRam.write_byte(_acc, b); spiRam.write_byte(_acc, b);
} }
spiram::operator byte() spiram::operator byte()
{ {
return spiRam.read_byte(_acc); return spiRam.read_byte(_acc);
} }
void spiram::checkpoint(Stream &s) void spiram::checkpoint(Stream &s)
{ {
char buf[Memory::page_size]; char buf[Memory::page_size];
for (int i = 0; i < pages(); i++) { for (int i = 0; i < pages(); i++) {
spiRam.read_stream(i * Memory::page_size, buf, sizeof(buf)); spiRam.read_stream(i * 256, buf, sizeof(buf));
s.write((byte *)buf, sizeof(buf)); s.write((byte *)buf, sizeof(buf));
} }
} }
void spiram::restore(Stream &s) void spiram::restore(Stream &s)
{ {
char buf[Memory::page_size]; char buf[Memory::page_size];
for (int i = 0; i < pages(); i++) { for (int i = 0; i < pages(); i++) {
s.readBytes(buf, sizeof(buf)); s.readBytes(buf, sizeof(buf));
spiRam.write_stream(i * Memory::page_size, buf, sizeof(buf)); spiRam.write_stream(i * 256, buf, sizeof(buf));
} }
} }