suspend/resume fixed for new memory model

This commit is contained in:
Jorj Bauer 2018-01-10 08:05:49 -05:00
parent 18e43b7784
commit 3890fc3dbd
4 changed files with 61 additions and 59 deletions

View File

@ -103,8 +103,6 @@ AppleMMU::AppleMMU(AppleDisplay *display)
slots[i] = NULL;
}
allocateMemory();
this->display = display;
this->display->setSwitches(&switches);
resetRAM(); // initialize RAM, load ROM
@ -113,7 +111,6 @@ AppleMMU::AppleMMU(AppleDisplay *display)
AppleMMU::~AppleMMU()
{
delete display;
// FIXME: clean up the memory we allocated
}
bool AppleMMU::Serialize(int8_t fd)
@ -134,27 +131,14 @@ bool AppleMMU::Serialize(int8_t fd)
g_filemanager->writeByte(fd, slotLatch);
g_filemanager->writeByte(fd, preWriteFlag ? 1 : 0);
// FIXME: write the RAM
#if 0
for (uint16_t i=0; i<0x100; i++) {
for (uint8_t j=0; j<5; j++) {
g_filemanager->writeByte(fd, MMUMAGIC);
if (ramPages[i][j]) {
g_filemanager->writeByte(fd, 1);
for (uint16_t k=0; k<0x100; k++) {
g_filemanager->writeByte(fd, ramPages[i][j][k]);
}
} else {
g_filemanager->writeByte(fd, 0);
}
}
}
#endif
if (!g_ram.Serialize(fd))
return false;
// readPages & writePages don't need suspending, but we will need to
// recalculate after resume
// Not suspending/resuming slots b/c they're a fixed configuration
// in this project.
// in this project. Should probably checksum them though. FIXME.
g_filemanager->writeByte(fd, MMUMAGIC);
return true;
@ -181,38 +165,8 @@ bool AppleMMU::Deserialize(int8_t fd)
slotLatch = g_filemanager->readByte(fd);
preWriteFlag = g_filemanager->readByte(fd);
for (uint16_t i=0; i<0x100; i++) {
for (uint8_t j=0; j<5; j++) {
if (g_filemanager->readByte(fd) != MMUMAGIC) {
#ifndef TEENSYDUINO
printf("Page %d/%d bad magic\n", i, j);
#endif
return false;
}
// FIXME: deserialize RAM
#if 0
if (g_filemanager->readByte(fd)) {
// This page has data
#ifndef TEENSYDUINO
if (!ramPages[i][j]) {
printf("ERROR: shouldn't be writing to this page\n");
exit(1);
}
#endif
for (uint16_t k=0; k<0x100; k++) {
ramPages[i][j][k] = g_filemanager->readByte(fd);
}
} else {
#ifndef TEENSYDUINO
if (ramPages[i][j]) {
printf("ERROR: this page exists but wasn't serialized?\n");
exit(1);
}
#endif
}
#endif
}
if (!g_ram.Deserialize(fd)) {
return false;
}
if (g_filemanager->readByte(fd) != MMUMAGIC)
@ -963,11 +917,6 @@ void AppleMMU::setSlot(int8_t slotnum, Slot *peripheral)
}
}
void AppleMMU::allocateMemory()
{
// FIXME: don't need this any more, I don't think, since it's allocated by g_ram
}
void AppleMMU::updateMemoryPages()
{
if (auxRamRead) {

View File

@ -56,8 +56,6 @@ class AppleMMU : public MMU {
void setAppleKey(int8_t which, bool isDown);
protected:
void allocateMemory();
void resetDisplay();
uint8_t readSwitches(uint16_t address);
void writeSwitches(uint16_t address, uint8_t v);

View File

@ -1,5 +1,6 @@
#include "vmram.h"
#include <string.h>
#include "globals.h"
#ifndef TEENSYDUINO
#include <assert.h>
@ -7,6 +8,9 @@
#define assert(x)
#endif
// Serializing token for RAM data
#define RAMMAGIC 'R'
VMRam::VMRam() {memset(preallocatedRam, 0, sizeof(preallocatedRam)); }
VMRam::~VMRam() { }
@ -21,3 +25,51 @@ void VMRam::init()
uint8_t VMRam::readByte(uint32_t addr) { assert(addr < sizeof(preallocatedRam)); return preallocatedRam[addr]; }
void VMRam::writeByte(uint32_t addr, uint8_t value) { assert(addr < sizeof(preallocatedRam)); preallocatedRam[addr] = value; }
bool VMRam::Serialize(int8_t fd)
{
g_filemanager->writeByte(fd, RAMMAGIC);
uint32_t size = sizeof(preallocatedRam);
g_filemanager->writeByte(fd, (size >> 24) & 0xFF);
g_filemanager->writeByte(fd, (size >> 16) & 0xFF);
g_filemanager->writeByte(fd, (size >> 8) & 0xFF);
g_filemanager->writeByte(fd, (size ) & 0xFF);
for (uint32_t pos = 0; pos < sizeof(preallocatedRam); pos++) {
g_filemanager->writeByte(fd, preallocatedRam[pos]);
}
g_filemanager->writeByte(fd, RAMMAGIC);
return true;
}
bool VMRam::Deserialize(int8_t fd)
{
if (g_filemanager->readByte(fd) != RAMMAGIC) {
return false;
}
uint32_t size = 0;
size = g_filemanager->readByte(fd);
size <<= 8;
size |= g_filemanager->readByte(fd);
size <<= 8;
size |= g_filemanager->readByte(fd);
size <<= 8;
size |= g_filemanager->readByte(fd);
if (size != sizeof(preallocatedRam)) {
return false;
}
for (uint32_t pos = 0; pos < sizeof(preallocatedRam); pos++) {
preallocatedRam[pos] = g_filemanager->readByte(fd);
}
if (g_filemanager->readByte(fd) != RAMMAGIC) {
return false;
}
return true;
}

View File

@ -15,6 +15,9 @@ class VMRam {
uint8_t readByte(uint32_t addr);
void writeByte(uint32_t addr, uint8_t value);
bool Serialize(int8_t fd);
bool Deserialize(int8_t fd);
private:
uint8_t preallocatedRam[591*256]; // 591 pages of RAM
};