memory - Add bank device
This commit is contained in:
parent
c82d966ba1
commit
0c52f9d2e0
3 changed files with 68 additions and 0 deletions
1
Makeconf
1
Makeconf
|
@ -3,6 +3,7 @@ modules := memory/device \
|
||||||
memory/ram \
|
memory/ram \
|
||||||
memory/bootrom_overlay \
|
memory/bootrom_overlay \
|
||||||
memory/register \
|
memory/register \
|
||||||
|
memory/bank \
|
||||||
cpu/cpu \
|
cpu/cpu \
|
||||||
cpu/decoder
|
cpu/decoder
|
||||||
|
|
||||||
|
|
44
memory/bank.cpp
Normal file
44
memory/bank.cpp
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
#include <memory/bank.h>
|
||||||
|
|
||||||
|
Bank::Bank()
|
||||||
|
: banks(), current_bank(nullptr)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void Bank::addBank(u8 idx, Mem_device* dev)
|
||||||
|
{
|
||||||
|
banks[idx] = dev;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bank::setBank(u8 idx)
|
||||||
|
{
|
||||||
|
auto it = banks.find(idx);
|
||||||
|
if(it == banks.end())
|
||||||
|
current_bank = nullptr;
|
||||||
|
else
|
||||||
|
current_bank = it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Bank::write8(u16 addr, u8 data)
|
||||||
|
{
|
||||||
|
if(current_bank == nullptr) return;
|
||||||
|
current_bank->write8(addr, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
u8 Bank::read8(u16 addr)
|
||||||
|
{
|
||||||
|
if(current_bank == nullptr) return 0xFFu;
|
||||||
|
return current_bank->read8(addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bank::write16(u16 addr, u16 data)
|
||||||
|
{
|
||||||
|
if(current_bank == nullptr) return;
|
||||||
|
current_bank->write16(addr, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
u16 Bank::read16(u16 addr)
|
||||||
|
{
|
||||||
|
if(current_bank == nullptr) return 0xFFu;
|
||||||
|
return current_bank->read16(addr);
|
||||||
|
}
|
23
memory/bank.h
Normal file
23
memory/bank.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory/device.h>
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
class Bank : public Mem_device {
|
||||||
|
private:
|
||||||
|
Mem_device* current_bank;
|
||||||
|
std::map<u8, Mem_device*> banks;
|
||||||
|
public:
|
||||||
|
Bank();
|
||||||
|
|
||||||
|
void addBank(u8 idx, Mem_device* dev);
|
||||||
|
|
||||||
|
void setBank(u8 bank);
|
||||||
|
|
||||||
|
void write8(u16 addr, u8 data);
|
||||||
|
u8 read8(u16 addr);
|
||||||
|
|
||||||
|
void write16(u16 addr, u16 data);
|
||||||
|
u16 read16(u16 addr);
|
||||||
|
};
|
Loading…
Reference in a new issue