Implement mem device for bootrom overlay
This commit is contained in:
parent
e4a6b1f9b4
commit
e859f8ad2c
3 changed files with 95 additions and 0 deletions
50
memory/bootrom_overlay.cpp
Normal file
50
memory/bootrom_overlay.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "memory/bootrom_overlay.h"
|
||||
|
||||
BootRom::BootRom(Mem_device* lowmem, Mem_device* highmem, Mem_device* backend)
|
||||
: lowmem(lowmem), highmem(highmem), backend(backend), enabled(true)
|
||||
{}
|
||||
|
||||
void BootRom::enable()
|
||||
{
|
||||
enabled = true;
|
||||
}
|
||||
void BootRom::disable()
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
void BootRom::write8(u16 addr, u8 data)
|
||||
{
|
||||
if(enabled && (lowrange.contains(addr) || highrange.contains(addr)))
|
||||
return;
|
||||
|
||||
backend->write8(addr, data);
|
||||
}
|
||||
|
||||
u8 BootRom::read8(u16 addr)
|
||||
{
|
||||
if(enabled && lowrange.contains(addr))
|
||||
return lowmem->read8(addr);
|
||||
else if(enabled && highrange.contains(addr))
|
||||
return highmem->read8(addr);
|
||||
else
|
||||
return backend->read8(addr);
|
||||
}
|
||||
|
||||
void BootRom::write16(u16 addr, u16 data)
|
||||
{
|
||||
if(enabled && (lowrange.contains(addr) || highrange.contains(addr)))
|
||||
return;
|
||||
|
||||
backend->write16(addr, data);
|
||||
}
|
||||
|
||||
u16 BootRom::read16(u16 addr)
|
||||
{
|
||||
if(enabled && lowrange.contains(addr))
|
||||
return lowmem->read16(addr);
|
||||
else if(enabled && highrange.contains(addr))
|
||||
return highmem->read16(addr);
|
||||
else
|
||||
return backend->read16(addr);
|
||||
}
|
28
memory/bootrom_overlay.h
Normal file
28
memory/bootrom_overlay.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
#include <memory/mem_device.h>
|
||||
|
||||
class BootRom : Mem_device
|
||||
{
|
||||
private:
|
||||
Mem_device* lowmem;
|
||||
Mem_device* highmem;
|
||||
|
||||
Mem_device* backend;
|
||||
|
||||
const Range lowrange(0x0000, 0x00FF);
|
||||
const Range highrange(0x0200, 0x08FF);
|
||||
|
||||
bool enabled;
|
||||
public:
|
||||
BootRom(Mem_device* lowmem, Mem_device* highmem, Mem_device* backend);
|
||||
|
||||
void enable();
|
||||
void disable();
|
||||
|
||||
virtual void write8(u16 addr, u8 data);
|
||||
virtual u8 read8(u16 addr);
|
||||
|
||||
virtual void write16(u16 addr, u16 data);
|
||||
virtual u16 read16(u16 addr);
|
||||
|
||||
}
|
|
@ -2,6 +2,23 @@
|
|||
|
||||
#include "types.h"
|
||||
|
||||
class Range {
|
||||
private:
|
||||
u16 start;
|
||||
u16 end;
|
||||
|
||||
public:
|
||||
constexpr Range(u16 start, u16 end)
|
||||
: start(start), end(end)
|
||||
{};
|
||||
|
||||
inline
|
||||
bool contains(u16 addr)
|
||||
{
|
||||
return addr >= start && addr <= end;
|
||||
}
|
||||
};
|
||||
|
||||
class Mem_device {
|
||||
public:
|
||||
virtual void write8(u16 addr, u8 data) = 0;
|
||||
|
|
Loading…
Reference in a new issue