memory/bus - use Range class
This commit is contained in:
parent
66c98f53fb
commit
317d22b8ab
3 changed files with 8 additions and 10 deletions
|
@ -6,7 +6,7 @@ std::optional<Bus::MapEntry> Bus::find_entry(u16 addr)
|
||||||
{
|
{
|
||||||
for(auto it = map.begin(); it != map.end(); ++it)
|
for(auto it = map.begin(); it != map.end(); ++it)
|
||||||
{
|
{
|
||||||
if (addr >= it->start && addr <= it->end)
|
if (it->range.contains(addr))
|
||||||
return std::make_optional(*it);
|
return std::make_optional(*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ std::optional<Bus::MapEntry> Bus::find_entry(u16 addr)
|
||||||
|
|
||||||
void Bus::map_device(u16 start, u16 end, Mem_device* dev)
|
void Bus::map_device(u16 start, u16 end, Mem_device* dev)
|
||||||
{
|
{
|
||||||
map.push_back(Bus::MapEntry{ start, end, dev });
|
map.push_back(Bus::MapEntry{ Range(start,end), dev });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bus::write8(u16 addr, u8 data)
|
void Bus::write8(u16 addr, u8 data)
|
||||||
|
@ -24,7 +24,7 @@ void Bus::write8(u16 addr, u8 data)
|
||||||
|
|
||||||
if(!mapentry) return;
|
if(!mapentry) return;
|
||||||
|
|
||||||
mapentry->dev->write8(addr - mapentry->start, data);
|
mapentry->dev->write8(addr - mapentry->range.start, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 Bus::read8(u16 addr)
|
u8 Bus::read8(u16 addr)
|
||||||
|
@ -33,19 +33,19 @@ u8 Bus::read8(u16 addr)
|
||||||
|
|
||||||
if(!mapentry) return 0xFFu;
|
if(!mapentry) return 0xFFu;
|
||||||
|
|
||||||
return mapentry->dev->read8(addr - mapentry->start);
|
return mapentry->dev->read8(addr - mapentry->range.start);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bus::write16(u16 addr, u16 data)
|
void Bus::write16(u16 addr, u16 data)
|
||||||
{
|
{
|
||||||
auto mapentry = find_entry(addr);
|
auto mapentry = find_entry(addr);
|
||||||
if(!mapentry) return;
|
if(!mapentry) return;
|
||||||
mapentry->dev->write16(addr - mapentry->start, data);
|
mapentry->dev->write16(addr - mapentry->range.start, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 Bus::read16(u16 addr)
|
u16 Bus::read16(u16 addr)
|
||||||
{
|
{
|
||||||
auto mapentry = find_entry(addr);
|
auto mapentry = find_entry(addr);
|
||||||
if(!mapentry) return 0xFFFFu;
|
if(!mapentry) return 0xFFFFu;
|
||||||
return mapentry->dev->read16(addr - mapentry->start);
|
return mapentry->dev->read16(addr - mapentry->range.start);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
class Bus : public Mem_device {
|
class Bus : public Mem_device {
|
||||||
private:
|
private:
|
||||||
struct MapEntry {
|
struct MapEntry {
|
||||||
u16 start;
|
Range range;
|
||||||
u16 end;
|
|
||||||
Mem_device *dev;
|
Mem_device *dev;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,10 @@
|
||||||
#include <misc/types.h>
|
#include <misc/types.h>
|
||||||
|
|
||||||
class Range {
|
class Range {
|
||||||
private:
|
public:
|
||||||
u16 start;
|
u16 start;
|
||||||
u16 end;
|
u16 end;
|
||||||
|
|
||||||
public:
|
|
||||||
constexpr Range(u16 start, u16 end)
|
constexpr Range(u16 start, u16 end)
|
||||||
: start(start), end(end)
|
: start(start), end(end)
|
||||||
{};
|
{};
|
||||||
|
|
Loading…
Reference in a new issue