1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-10-31 13:05:08 +00:00
r65emu/spiram.cpp
Stephen Crane a3111fa8a0 bugfixes
2014-11-15 23:24:47 +00:00

39 lines
680 B
C++

#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)
{
spiRam.write_byte(_acc, b);
}
spiram::operator byte()
{
return spiRam.read_byte(_acc);
}
void spiram::checkpoint(Stream &s)
{
byte buf[Memory::page_size];
for (int i = 0; i < pages(); i++) {
spiRam.read_stream(i * 256, buf, sizeof(buf));
s.write(buf, sizeof(buf));
}
}
void spiram::restore(Stream &s)
{
byte buf[Memory::page_size];
for (int i = 0; i < pages(); i++) {
s.readBytes((char *)buf, sizeof(buf));
spiRam.write_stream(i * 256, buf, sizeof(buf));
}
}