1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-12-27 05:32:04 +00:00
r65emu/spiram.cpp

39 lines
690 B
C++
Raw Normal View History

2014-10-18 11:33:48 +00:00
#include <SPI.h>
#include <SpiRAM.h>
#include "memory.h"
#include "spiram.h"
#include "hardware.h"
extern SPIClass SPIRAM_DEV;
SpiRAM spiRam(SPIRAM_DEV, SPIRAM_CS);
void spiram::operator=(byte b)
{
2014-10-22 18:47:06 +00:00
spiRam.write_byte(_acc, b);
2014-10-18 11:33:48 +00:00
}
spiram::operator byte()
{
2014-10-22 18:47:06 +00:00
return spiRam.read_byte(_acc);
2014-10-18 11:33:48 +00:00
}
void spiram::checkpoint(Stream &s)
{
2014-11-15 23:24:47 +00:00
byte buf[Memory::page_size];
2015-11-30 14:49:56 +00:00
for (unsigned i = 0; i < pages(); i++) {
2014-10-22 18:47:06 +00:00
spiRam.read_stream(i * 256, buf, sizeof(buf));
2014-11-15 23:24:47 +00:00
s.write(buf, sizeof(buf));
2014-10-22 18:47:06 +00:00
}
2014-10-18 11:33:48 +00:00
}
void spiram::restore(Stream &s)
{
2014-11-15 23:24:47 +00:00
byte buf[Memory::page_size];
2015-11-30 14:49:56 +00:00
for (unsigned i = 0; i < pages(); i++) {
2014-11-15 23:24:47 +00:00
s.readBytes((char *)buf, sizeof(buf));
2014-10-22 18:47:06 +00:00
spiRam.write_stream(i * 256, buf, sizeof(buf));
}
2014-10-18 11:33:48 +00:00
}