Skip to content
Snippets Groups Projects
Commit e29049d4 authored by Geo Ster's avatar Geo Ster
Browse files

Register handlers with addresses

* Since the components will never give pages directly, let them
use addresses instead and compute the page in the register function
to save some work on the component side.
parent 3c4945af
No related branches found
No related tags found
No related merge requests found
...@@ -58,7 +58,7 @@ namespace common ...@@ -58,7 +58,7 @@ namespace common
void write(uint32_t addr, T data); void write(uint32_t addr, T data);
template <typename T = uint32_t, typename R, typename W> template <typename T = uint32_t, typename R, typename W>
void add_handler(int page, Component* c, R reader, W writer); void add_handler(uint32_t address, Component* c, R reader, W writer);
static const uint32_t calculate_page(const uint32_t addr); static const uint32_t calculate_page(const uint32_t addr);
...@@ -135,8 +135,10 @@ namespace common ...@@ -135,8 +135,10 @@ namespace common
} }
template <typename T, typename R, typename W> template <typename T, typename R, typename W>
inline void Emulator::add_handler(int page, Component* c, R reader, W writer) inline void Emulator::add_handler(uint32_t address, Component* c, R reader, W writer)
{ {
uint32_t page = calculate_page(address);
auto h = new Handler<T>; auto h = new Handler<T>;
h->c = c; h->c = c;
h->writer = (Writer<T>)writer; h->writer = (Writer<T>)writer;
......
...@@ -10,11 +10,8 @@ namespace iop ...@@ -10,11 +10,8 @@ namespace iop
emulator(emu) emulator(emu)
{ {
/* Register our functions to the Emulator. */ /* Register our functions to the Emulator. */
const uint32_t PAGE1 = common::Emulator::calculate_page(0x1f801080); emulator->add_handler(0x1f801080, this, &DMAController::read, &DMAController::write);
const uint32_t PAGE2 = common::Emulator::calculate_page(0x1f801500); emulator->add_handler(0x1f801500, this, &DMAController::read, &DMAController::write);
emulator->add_handler(PAGE1, this, &DMAController::read, &DMAController::write);
emulator->add_handler(PAGE2, this, &DMAController::read, &DMAController::write);
} }
void DMAController::tick() void DMAController::tick()
......
...@@ -22,8 +22,7 @@ namespace gs ...@@ -22,8 +22,7 @@ namespace gs
GIF::GIF(common::Emulator* parent) : GIF::GIF(common::Emulator* parent) :
emulator(parent) emulator(parent)
{ {
uint32_t PAGE1 = common::Emulator::calculate_page(0x10003000); emulator->add_handler(0x10003000, this, &GIF::read, &GIF::write);
emulator->add_handler(PAGE1, this, &GIF::read, &GIF::write);
} }
uint32_t GIF::read(uint32_t addr) uint32_t GIF::read(uint32_t addr)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment