1
0
mirror of https://github.com/jscrane/r65emu.git synced 2025-01-15 05:31:30 +00:00
r65emu/spiram.cpp

46 lines
804 B
C++
Raw Normal View History

2018-11-16 10:25:23 +00:00
#include "hardware.h"
#if defined(USE_SPIRAM)
2014-10-18 12:33:48 +01:00
#include <SPI.h>
#include <SpiRAM.h>
#include "memory.h"
#include "spiram.h"
2018-08-10 13:54:00 +01:00
2014-10-18 12:33:48 +01:00
extern SPIClass SPIRAM_DEV;
SpiRAM spiRam(SPIRAM_DEV, SPIRAM_CS);
2018-08-13 14:41:23 +01:00
void spiram::operator=(uint8_t b)
2014-10-18 12:33:48 +01:00
{
2018-08-14 06:18:57 +01:00
spiRam.write_byte(_acc, b);
2014-10-18 12:33:48 +01:00
}
2018-08-13 14:41:23 +01:00
spiram::operator uint8_t()
2014-10-18 12:33:48 +01:00
{
2018-08-14 06:18:57 +01:00
return spiRam.read_byte(_acc);
2014-10-18 12:33:48 +01:00
}
void spiram::checkpoint(Stream &s)
{
2019-02-24 11:50:10 +00:00
#if !defined(NO_CHECKPOINT)
2018-08-13 14:41:23 +01: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 19:47:06 +01: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 19:47:06 +01:00
}
2019-02-24 11:50:10 +00:00
#endif
2014-10-18 12:33:48 +01:00
}
void spiram::restore(Stream &s)
{
2019-02-24 11:50:10 +00:00
#if !defined(NO_CHECKPOINT)
2018-08-13 14:41:23 +01: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 19:47:06 +01:00
spiRam.write_stream(i * 256, buf, sizeof(buf));
}
2019-02-24 11:50:10 +00:00
#endif
2014-10-18 12:33:48 +01:00
}
2018-08-10 13:54:00 +01:00
#endif