mirror of
https://github.com/JorjBauer/aiie.git
synced 2024-12-22 14:30:34 +00:00
suspend/resume fixed for new memory model
This commit is contained in:
parent
18e43b7784
commit
3890fc3dbd
@ -103,8 +103,6 @@ AppleMMU::AppleMMU(AppleDisplay *display)
|
|||||||
slots[i] = NULL;
|
slots[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
allocateMemory();
|
|
||||||
|
|
||||||
this->display = display;
|
this->display = display;
|
||||||
this->display->setSwitches(&switches);
|
this->display->setSwitches(&switches);
|
||||||
resetRAM(); // initialize RAM, load ROM
|
resetRAM(); // initialize RAM, load ROM
|
||||||
@ -113,7 +111,6 @@ AppleMMU::AppleMMU(AppleDisplay *display)
|
|||||||
AppleMMU::~AppleMMU()
|
AppleMMU::~AppleMMU()
|
||||||
{
|
{
|
||||||
delete display;
|
delete display;
|
||||||
// FIXME: clean up the memory we allocated
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppleMMU::Serialize(int8_t fd)
|
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, slotLatch);
|
||||||
g_filemanager->writeByte(fd, preWriteFlag ? 1 : 0);
|
g_filemanager->writeByte(fd, preWriteFlag ? 1 : 0);
|
||||||
|
|
||||||
// FIXME: write the RAM
|
if (!g_ram.Serialize(fd))
|
||||||
#if 0
|
return false;
|
||||||
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
|
|
||||||
// readPages & writePages don't need suspending, but we will need to
|
// readPages & writePages don't need suspending, but we will need to
|
||||||
// recalculate after resume
|
// recalculate after resume
|
||||||
|
|
||||||
// Not suspending/resuming slots b/c they're a fixed configuration
|
// 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);
|
g_filemanager->writeByte(fd, MMUMAGIC);
|
||||||
return true;
|
return true;
|
||||||
@ -181,38 +165,8 @@ bool AppleMMU::Deserialize(int8_t fd)
|
|||||||
slotLatch = g_filemanager->readByte(fd);
|
slotLatch = g_filemanager->readByte(fd);
|
||||||
preWriteFlag = g_filemanager->readByte(fd);
|
preWriteFlag = g_filemanager->readByte(fd);
|
||||||
|
|
||||||
for (uint16_t i=0; i<0x100; i++) {
|
if (!g_ram.Deserialize(fd)) {
|
||||||
for (uint8_t j=0; j<5; j++) {
|
return false;
|
||||||
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_filemanager->readByte(fd) != MMUMAGIC)
|
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()
|
void AppleMMU::updateMemoryPages()
|
||||||
{
|
{
|
||||||
if (auxRamRead) {
|
if (auxRamRead) {
|
||||||
|
@ -56,8 +56,6 @@ class AppleMMU : public MMU {
|
|||||||
void setAppleKey(int8_t which, bool isDown);
|
void setAppleKey(int8_t which, bool isDown);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void allocateMemory();
|
|
||||||
|
|
||||||
void resetDisplay();
|
void resetDisplay();
|
||||||
uint8_t readSwitches(uint16_t address);
|
uint8_t readSwitches(uint16_t address);
|
||||||
void writeSwitches(uint16_t address, uint8_t v);
|
void writeSwitches(uint16_t address, uint8_t v);
|
||||||
|
52
vmram.cpp
52
vmram.cpp
@ -1,5 +1,6 @@
|
|||||||
#include "vmram.h"
|
#include "vmram.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
#ifndef TEENSYDUINO
|
#ifndef TEENSYDUINO
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -7,6 +8,9 @@
|
|||||||
#define assert(x)
|
#define assert(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Serializing token for RAM data
|
||||||
|
#define RAMMAGIC 'R'
|
||||||
|
|
||||||
VMRam::VMRam() {memset(preallocatedRam, 0, sizeof(preallocatedRam)); }
|
VMRam::VMRam() {memset(preallocatedRam, 0, sizeof(preallocatedRam)); }
|
||||||
|
|
||||||
VMRam::~VMRam() { }
|
VMRam::~VMRam() { }
|
||||||
@ -21,3 +25,51 @@ void VMRam::init()
|
|||||||
uint8_t VMRam::readByte(uint32_t addr) { assert(addr < sizeof(preallocatedRam)); return preallocatedRam[addr]; }
|
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; }
|
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;
|
||||||
|
}
|
||||||
|
3
vmram.h
3
vmram.h
@ -15,6 +15,9 @@ class VMRam {
|
|||||||
uint8_t readByte(uint32_t addr);
|
uint8_t readByte(uint32_t addr);
|
||||||
void writeByte(uint32_t addr, uint8_t value);
|
void writeByte(uint32_t addr, uint8_t value);
|
||||||
|
|
||||||
|
bool Serialize(int8_t fd);
|
||||||
|
bool Deserialize(int8_t fd);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t preallocatedRam[591*256]; // 591 pages of RAM
|
uint8_t preallocatedRam[591*256]; // 591 pages of RAM
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user