2018-02-07 15:20:26 +00:00
|
|
|
#ifdef TEENSYDUINO
|
|
|
|
#include <Arduino.h>
|
2020-07-04 12:04:26 +00:00
|
|
|
#include "teensy-println.h"
|
2018-02-07 15:20:26 +00:00
|
|
|
#endif
|
|
|
|
|
2018-01-10 09:13:04 +00:00
|
|
|
#include "vmram.h"
|
|
|
|
#include <string.h>
|
2021-01-10 02:32:40 +00:00
|
|
|
#include "serialize.h"
|
2018-01-10 13:05:49 +00:00
|
|
|
#include "globals.h"
|
2018-01-10 09:13:04 +00:00
|
|
|
|
2020-07-07 01:31:37 +00:00
|
|
|
#ifdef TEENSYDUINO
|
2021-01-10 02:32:40 +00:00
|
|
|
#include "iocompat.h"
|
2020-07-07 01:31:37 +00:00
|
|
|
EXTMEM uint8_t preallocatedRam[591*256];
|
|
|
|
#else
|
2021-01-10 02:32:40 +00:00
|
|
|
#include <stdio.h>
|
2020-07-07 01:31:37 +00:00
|
|
|
uint8_t preallocatedRam[591*256];
|
|
|
|
#endif
|
|
|
|
|
2018-01-10 09:13:04 +00:00
|
|
|
#ifndef TEENSYDUINO
|
|
|
|
#include <assert.h>
|
|
|
|
#else
|
2020-07-04 12:04:26 +00:00
|
|
|
#define assert(x) { if (!(x)) {print("assertion failed at "); println(__LINE__); delay(10000);} }
|
2018-02-07 15:20:26 +00:00
|
|
|
//#define assert(x) { }
|
2018-01-10 09:13:04 +00:00
|
|
|
#endif
|
|
|
|
|
2018-01-10 13:05:49 +00:00
|
|
|
// Serializing token for RAM data
|
|
|
|
#define RAMMAGIC 'R'
|
|
|
|
|
2018-01-10 09:13:04 +00:00
|
|
|
VMRam::VMRam() {memset(preallocatedRam, 0, sizeof(preallocatedRam)); }
|
|
|
|
|
|
|
|
VMRam::~VMRam() { }
|
|
|
|
|
|
|
|
void VMRam::init()
|
|
|
|
{
|
|
|
|
for (uint32_t i=0; i<sizeof(preallocatedRam); i++) {
|
|
|
|
preallocatedRam[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-07 15:20:26 +00:00
|
|
|
uint8_t VMRam::readByte(uint32_t addr)
|
|
|
|
{
|
|
|
|
return preallocatedRam[addr];
|
|
|
|
}
|
2018-01-10 09:13:04 +00:00
|
|
|
|
2018-02-07 15:20:26 +00:00
|
|
|
void VMRam::writeByte(uint32_t addr, uint8_t value)
|
|
|
|
{
|
|
|
|
preallocatedRam[addr] = value;
|
|
|
|
}
|
2018-01-10 13:05:49 +00:00
|
|
|
|
|
|
|
bool VMRam::Serialize(int8_t fd)
|
|
|
|
{
|
|
|
|
uint32_t size = sizeof(preallocatedRam);
|
2021-01-10 02:32:40 +00:00
|
|
|
serializeMagic(RAMMAGIC);
|
|
|
|
serialize32(size);
|
2018-01-10 13:05:49 +00:00
|
|
|
|
2020-06-28 19:24:49 +00:00
|
|
|
if (g_filemanager->write(fd, preallocatedRam, sizeof(preallocatedRam)) != sizeof(preallocatedRam))
|
2021-01-10 02:32:40 +00:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
serializeMagic(RAMMAGIC);
|
2018-01-10 13:05:49 +00:00
|
|
|
|
|
|
|
return true;
|
2021-01-10 02:32:40 +00:00
|
|
|
|
|
|
|
err:
|
|
|
|
return false;
|
2018-01-10 13:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool VMRam::Deserialize(int8_t fd)
|
|
|
|
{
|
2021-01-10 02:32:40 +00:00
|
|
|
deserializeMagic(RAMMAGIC);
|
|
|
|
uint32_t size;
|
|
|
|
deserialize32(size);
|
2018-01-10 13:05:49 +00:00
|
|
|
|
2020-06-28 19:24:49 +00:00
|
|
|
if (g_filemanager->read(fd, preallocatedRam, size) != size)
|
2021-01-10 02:32:40 +00:00
|
|
|
goto err;
|
2018-01-10 13:05:49 +00:00
|
|
|
|
2021-01-10 02:32:40 +00:00
|
|
|
deserializeMagic(RAMMAGIC);
|
2018-01-10 13:05:49 +00:00
|
|
|
|
|
|
|
return true;
|
2021-01-10 02:32:40 +00:00
|
|
|
|
|
|
|
err:
|
|
|
|
return false;
|
2018-01-10 13:05:49 +00:00
|
|
|
}
|
2018-02-07 15:20:26 +00:00
|
|
|
|
|
|
|
bool VMRam::Test()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|