1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-21 21:33:54 +00:00

Wire up did-page notifications.

This commit is contained in:
Thomas Harte 2023-01-13 21:54:59 -05:00
parent fb0241cf6e
commit f0a4d1d8ec
3 changed files with 20 additions and 6 deletions

View File

@ -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<MemorySlotHandler> handler;
};

View File

@ -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<MSX::MemorySlot::AccessType::Read>(int subslot, std::size_t source_address, uint16_t destination_address, std::size_t length);

View File

@ -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<uint8_t, 8192>;
inline static MemoryChunk unmapped{0xff};
inline static MemoryChunk scratch;