From f0a4d1d8ec9e373e443dcaeb24110df457f70a3b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 13 Jan 2023 21:54:59 -0500 Subject: [PATCH] Wire up did-page notifications. --- Machines/MSX/MSX.cpp | 12 ++++++++++-- Machines/MSX/MemorySlotHandler.cpp | 6 +++--- Machines/MSX/MemorySlotHandler.hpp | 8 +++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Machines/MSX/MSX.cpp b/Machines/MSX/MSX.cpp index 43e910c8b..f1d0ce280 100644 --- a/Machines/MSX/MSX.cpp +++ b/Machines/MSX/MSX.cpp @@ -142,7 +142,8 @@ class ConcreteMachine: public MachineTypes::JoystickMachine, public Configurable::Device, public ClockingHint::Observer, - public Activity::Source { + public Activity::Source, + public MSX::MemorySlotChangeHandler { private: static constexpr int RAMMemorySlot = 3; static constexpr int RAMMemorySubSlot = 0; @@ -163,7 +164,8 @@ class ConcreteMachine: speaker_(mixer_), tape_player_(3579545 * 2), i8255_port_handler_(*this, audio_toggle_, tape_player_), - ay_port_handler_(tape_player_) { + ay_port_handler_(tape_player_), + memory_slots_{{*this}, {*this}, {*this}, {*this}} { set_clock_rate(3579545); clear_all_keys(); @@ -424,6 +426,10 @@ class ConcreteMachine: update_paging(); } + void did_page() final { + update_paging(); + } + void update_paging() { uint8_t primary = primary_slots_; @@ -826,6 +832,8 @@ class ConcreteMachine: /// Optionally attaches non-default logic to any of the four things selectable /// via the primary slot register. struct MemorySlot: public MSX::MemorySlot { + using MSX::MemorySlot::MemorySlot; + HalfCycles cycles_since_update; std::unique_ptr handler; }; diff --git a/Machines/MSX/MemorySlotHandler.cpp b/Machines/MSX/MemorySlotHandler.cpp index 28f160af1..6e5f503ae 100644 --- a/Machines/MSX/MemorySlotHandler.cpp +++ b/Machines/MSX/MemorySlotHandler.cpp @@ -12,7 +12,7 @@ using namespace MSX; -MemorySlot::MemorySlot() { +MemorySlot::MemorySlot(MemorySlotChangeHandler &handler) : handler_(handler) { for(int subslot = 0; subslot < 4; subslot++) { for(int region = 0; region < 8; region++) { read_pointers_[subslot][region] = unmapped.data(); @@ -73,7 +73,7 @@ void MemorySlot::map(int subslot, std::size_t source_address, uint16_t destinati source_address += 8192; } - // TODO: need to indicate that mapping changed. + handler_.did_page(); } void MemorySlot::unmap(int subslot, uint16_t destination_address, std::size_t length) { @@ -85,7 +85,7 @@ void MemorySlot::unmap(int subslot, uint16_t destination_address, std::size_t le read_pointers_[subslot][(destination_address >> 13) + c] = nullptr; } - // TODO: need to indicate that mapping changed. + handler_.did_page(); } template void MemorySlot::map(int subslot, std::size_t source_address, uint16_t destination_address, std::size_t length); diff --git a/Machines/MSX/MemorySlotHandler.hpp b/Machines/MSX/MemorySlotHandler.hpp index d20cba8a9..cac6ed032 100644 --- a/Machines/MSX/MemorySlotHandler.hpp +++ b/Machines/MSX/MemorySlotHandler.hpp @@ -30,9 +30,13 @@ */ namespace MSX { +struct MemorySlotChangeHandler { + virtual void did_page() = 0; +}; + class MemorySlot { public: - MemorySlot(); + MemorySlot(MemorySlotChangeHandler &); /// Attempts to write the argument as the secondary paging selection. void set_secondary_paging(uint8_t); @@ -89,6 +93,8 @@ class MemorySlot { uint8_t *write_pointers_[4][8]; uint8_t secondary_paging_ = 0; + MemorySlotChangeHandler &handler_; + using MemoryChunk = std::array; inline static MemoryChunk unmapped{0xff}; inline static MemoryChunk scratch;