1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-10-28 07:25:06 +00:00

banked memory support (#32)

This commit is contained in:
Stephen Crane 2024-09-20 14:34:07 +01:00 committed by GitHub
parent 706e27c213
commit 4c01c406b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 15 deletions

View File

@ -23,6 +23,8 @@ public:
inline bool halted() { return _halted; }
Memory &memory() const { return _mem; }
protected:
CPU(Memory &mem): _mem(mem), _halted(false) {}
Memory &_mem;

View File

@ -1,6 +1,7 @@
#include <Arduino.h>
#include <stdint.h>
#include <stddef.h>
#include "memory.h"
#include "hardware.h"
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(USE_LITTLEFS) || defined(USE_SPIRAM)
@ -16,7 +17,6 @@
#include <LittleFS.h>
#endif
#include "memory.h"
#include "CPU.h"
#if defined(USE_SPIRAM)
@ -25,8 +25,6 @@
spiram sram(SPIRAM_SIZE);
#endif
Memory memory;
static CPU *_cpu;
bool hardware_reset() {
@ -69,7 +67,7 @@ bool hardware_reset() {
void hardware_init(CPU &cpu) {
_cpu = &cpu;
memory.begin();
cpu.memory().begin();
#if defined(DEBUGGING) || defined(CPU_DEBUG) || defined(USE_SERIAL)
Serial.begin(TERMINAL_SPEED);
@ -123,7 +121,7 @@ bool hardware_run(unsigned instructions) {
void hardware_checkpoint(Stream &s) {
unsigned ds = 0;
for (unsigned i = 0; i < 0x10000; i += ds) {
Memory::Device *dev = memory.get(i);
Memory::Device *dev = _cpu->memory().get(i);
dev->checkpoint(s);
ds = dev->pages() * Memory::page_size;
}
@ -133,7 +131,7 @@ void hardware_checkpoint(Stream &s) {
void hardware_restore(Stream &s) {
unsigned ds = 0;
for (unsigned i = 0; i < 0x10000; i += ds) {
Memory::Device *dev = memory.get(i);
Memory::Device *dev = _cpu->memory().get(i);
dev->restore(s);
ds = dev->pages() * Memory::page_size;
}

View File

@ -28,9 +28,6 @@ bool hardware_debug_cpu();
#if defined(__SPIRAM_H__) && defined(USE_SPIRAM)
extern class spiram sram;
#endif
#ifdef __MEMORY_H__
extern class Memory memory;
#endif
#if defined(DEBUGGING)
#define DBG(x) Serial.x

View File

@ -16,7 +16,7 @@ public:
class Device: public Checkpointable {
public:
Device (unsigned uint8_ts): _pages(uint8_ts/page_size) {}
Device (unsigned bytes): _pages(bytes / page_size) {}
virtual ~Device () {}
unsigned pages () const { return _pages; }
@ -38,14 +38,11 @@ public:
unsigned _pages;
};
// insert a new device instance
//
void put (Device &d, address at);
void put (Device &d, address at, unsigned ep) { d._pages = ep; put(d, at); }
Device *get (address at) const { return _pages[at/page_size]; }
// primary access interface
//
virtual Device *get (address at) const { return _pages[at/page_size]; }
Device &operator[] (address a) {
Device *d = get (a);
d->access (a);