1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-07-16 02:28:59 +00:00
r65emu/spiram.cpp

42 lines
734 B
C++
Raw Normal View History

2018-11-16 10:25:23 +00:00
#include "hardware.h"
#if defined(USE_SPIRAM)
2014-10-18 11:33:48 +00:00
#include <SPI.h>
#include <SpiRAM.h>
#include "memory.h"
#include "spiram.h"
2018-08-10 12:54:00 +00:00
2014-10-18 11:33:48 +00:00
extern SPIClass SPIRAM_DEV;
SpiRAM spiRam(SPIRAM_DEV, SPIRAM_CS);
2018-08-13 13:41:23 +00:00
void spiram::operator=(uint8_t b)
2014-10-18 11:33:48 +00:00
{
2018-08-14 05:18:57 +00:00
spiRam.write_byte(_acc, b);
2014-10-18 11:33:48 +00:00
}
2018-08-13 13:41:23 +00:00
spiram::operator uint8_t()
2014-10-18 11:33:48 +00:00
{
2018-08-14 05:18:57 +00:00
return spiRam.read_byte(_acc);
2014-10-18 11:33:48 +00:00
}
void spiram::checkpoint(Stream &s)
{
2018-08-13 13:41:23 +00:00
uint8_t 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)
{
2018-08-13 13:41:23 +00:00
uint8_t 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
}
2018-08-10 12:54:00 +00:00
#endif