1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-12-27 20:32:55 +00:00
r65emu/spiram.cpp
2018-11-16 10:25:23 +00:00

42 lines
734 B
C++

#include "hardware.h"
#if defined(USE_SPIRAM)
#include <SPI.h>
#include <SpiRAM.h>
#include "memory.h"
#include "spiram.h"
extern SPIClass SPIRAM_DEV;
SpiRAM spiRam(SPIRAM_DEV, SPIRAM_CS);
void spiram::operator=(uint8_t b)
{
spiRam.write_byte(_acc, b);
}
spiram::operator uint8_t()
{
return spiRam.read_byte(_acc);
}
void spiram::checkpoint(Stream &s)
{
uint8_t buf[Memory::page_size];
for (unsigned i = 0; i < pages(); i++) {
spiRam.read_stream(i * 256, buf, sizeof(buf));
s.write(buf, sizeof(buf));
}
}
void spiram::restore(Stream &s)
{
uint8_t buf[Memory::page_size];
for (unsigned i = 0; i < pages(); i++) {
s.readBytes((char *)buf, sizeof(buf));
spiRam.write_stream(i * 256, buf, sizeof(buf));
}
}
#endif