mirror of
https://github.com/jscrane/r65emu.git
synced 2024-12-26 14:29:31 +00:00
48 lines
884 B
C++
48 lines
884 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::begin(byte cs, int module)
|
|
{
|
|
SPI_for_SD.setModule(module);
|
|
SPI_for_SD.setClockDivider(SPI_CLOCK_DIV16);
|
|
SPI_for_SD.setDataMode(SPI_MODE0);
|
|
pinMode(PF_3, OUTPUT);
|
|
pinMode(cs, OUTPUT);
|
|
}
|
|
|
|
void spiram::operator=(byte b)
|
|
{
|
|
spiRam.write_byte(_acc, b);
|
|
}
|
|
|
|
spiram::operator byte()
|
|
{
|
|
return spiRam.read_byte(_acc);
|
|
}
|
|
|
|
void spiram::checkpoint(Stream &s)
|
|
{
|
|
char buf[Memory::page_size];
|
|
for (int i = 0; i < pages(); i++) {
|
|
spiRam.read_stream(i * 256, buf, sizeof(buf));
|
|
s.write((byte *)buf, sizeof(buf));
|
|
}
|
|
}
|
|
|
|
void spiram::restore(Stream &s)
|
|
{
|
|
char buf[Memory::page_size];
|
|
for (int i = 0; i < pages(); i++) {
|
|
s.readBytes(buf, sizeof(buf));
|
|
spiRam.write_stream(i * 256, buf, sizeof(buf));
|
|
}
|
|
}
|
|
|