From e29049d4070e922f6775aef8ca7445b756d60063 Mon Sep 17 00:00:00 2001 From: emufan <geoster3d@gmail.com> Date: Sun, 26 Dec 2021 14:04:58 +0200 Subject: [PATCH] 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. --- src/common/emulator.h | 6 ++++-- src/cpu/iop/dma.cc | 7 ++----- src/gs/gif.cc | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/common/emulator.h b/src/common/emulator.h index d64014c..dd5dcbc 100644 --- a/src/common/emulator.h +++ b/src/common/emulator.h @@ -58,7 +58,7 @@ namespace common void write(uint32_t addr, T data); 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); @@ -135,8 +135,10 @@ namespace common } 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>; h->c = c; h->writer = (Writer<T>)writer; diff --git a/src/cpu/iop/dma.cc b/src/cpu/iop/dma.cc index 53f188f..bc34ed8 100644 --- a/src/cpu/iop/dma.cc +++ b/src/cpu/iop/dma.cc @@ -10,11 +10,8 @@ namespace iop emulator(emu) { /* Register our functions to the Emulator. */ - const uint32_t PAGE1 = common::Emulator::calculate_page(0x1f801080); - const uint32_t PAGE2 = common::Emulator::calculate_page(0x1f801500); - - emulator->add_handler(PAGE1, this, &DMAController::read, &DMAController::write); - emulator->add_handler(PAGE2, this, &DMAController::read, &DMAController::write); + emulator->add_handler(0x1f801080, this, &DMAController::read, &DMAController::write); + emulator->add_handler(0x1f801500, this, &DMAController::read, &DMAController::write); } void DMAController::tick() diff --git a/src/gs/gif.cc b/src/gs/gif.cc index 11d2336..55a742a 100644 --- a/src/gs/gif.cc +++ b/src/gs/gif.cc @@ -22,8 +22,7 @@ namespace gs GIF::GIF(common::Emulator* parent) : emulator(parent) { - uint32_t PAGE1 = common::Emulator::calculate_page(0x10003000); - emulator->add_handler(PAGE1, this, &GIF::read, &GIF::write); + emulator->add_handler(0x10003000, this, &GIF::read, &GIF::write); } uint32_t GIF::read(uint32_t addr) -- GitLab