From a43ca0db350452f103064ee7ec440045f949d477 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 10 May 2018 22:17:13 -0400 Subject: [PATCH] Makes the Apple II an activity source. --- Components/DiskII/DiskII.cpp | 4 ++++ Components/DiskII/DiskII.hpp | 4 ++++ Machines/AppleII/AppleII.cpp | 18 ++++++++++++++---- Machines/AppleII/Card.hpp | 4 ++++ Machines/AppleII/DiskIICard.cpp | 4 ++++ Machines/AppleII/DiskIICard.hpp | 3 +++ 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Components/DiskII/DiskII.cpp b/Components/DiskII/DiskII.cpp index da897c36c..373c5ccf6 100644 --- a/Components/DiskII/DiskII.cpp +++ b/Components/DiskII/DiskII.cpp @@ -236,3 +236,7 @@ uint8_t DiskII::trigger_address(int address, uint8_t value) { return 0xff; } +void DiskII::set_activity_observer(Activity::Observer *observer) { + drives_[0].set_activity_observer(observer, "Drive 1", true); + drives_[1].set_activity_observer(observer, "Drive 2", true); +} diff --git a/Components/DiskII/DiskII.hpp b/Components/DiskII/DiskII.hpp index fd37e9353..37e083ef8 100644 --- a/Components/DiskII/DiskII.hpp +++ b/Components/DiskII/DiskII.hpp @@ -15,6 +15,8 @@ #include "../../Storage/Disk/Disk.hpp" #include "../../Storage/Disk/Drive.hpp" +#include "../../Activity/Observer.hpp" + #include #include #include @@ -40,6 +42,8 @@ class DiskII: void set_disk(const std::shared_ptr &disk, int drive); bool is_sleeping() override; + void set_activity_observer(Activity::Observer *observer); + private: enum class Control { P0, P1, P2, P3, diff --git a/Machines/AppleII/AppleII.cpp b/Machines/AppleII/AppleII.cpp index f75655762..85eccd9ec 100644 --- a/Machines/AppleII/AppleII.cpp +++ b/Machines/AppleII/AppleII.cpp @@ -8,6 +8,7 @@ #include "AppleII.hpp" +#include "../../Activity/Source.hpp" #include "../ConfigurationTarget.hpp" #include "../CRTMachine.hpp" #include "../KeyboardMachine.hpp" @@ -24,6 +25,7 @@ #include "../../Analyser/Static/AppleII/Target.hpp" +#include #include namespace { @@ -34,7 +36,8 @@ class ConcreteMachine: public KeyboardMachine::Machine, public CPU::MOS6502::BusHandler, public Inputs::Keyboard, - public AppleII::Machine { + public AppleII::Machine, + public Activity::Source { private: struct VideoBusHandler : public AppleII::Video::BusHandler { public: @@ -62,8 +65,8 @@ class ConcreteMachine: speaker_.run_for(audio_queue_, cycles_since_audio_update_.divide(Cycles(audio_divider))); } void update_cards() { - for(int c = 0; c < 7; ++c) { - if(cards_[c]) cards_[c]->run_for(cycles_since_card_update_, stretched_cycles_since_card_update_); + for(const auto &card : cards_) { + if(card) card->run_for(cycles_since_card_update_, stretched_cycles_since_card_update_); } cycles_since_card_update_ = 0; stretched_cycles_since_card_update_ = 0; @@ -80,7 +83,7 @@ class ConcreteMachine: Cycles cycles_since_audio_update_; ROMMachine::ROMFetcher rom_fetcher_; - std::unique_ptr cards_[7]; + std::array, 7> cards_; Cycles cycles_since_card_update_; int stretched_cycles_since_card_update_ = 0; @@ -372,6 +375,13 @@ class ConcreteMachine: } return true; } + + // MARK: Activity::Source + void set_activity_observer(Activity::Observer *observer) override { + for(const auto &card: cards_) { + if(card) card->set_activity_observer(observer); + } + } }; } diff --git a/Machines/AppleII/Card.hpp b/Machines/AppleII/Card.hpp index d7c00cdb6..de89bb75e 100644 --- a/Machines/AppleII/Card.hpp +++ b/Machines/AppleII/Card.hpp @@ -11,6 +11,7 @@ #include "../../Processors/6502/6502.hpp" #include "../../ClockReceiver/ClockReceiver.hpp" +#include "../../Activity/Observer.hpp" namespace AppleII { @@ -21,6 +22,9 @@ class Card { /*! Performs a bus operation; the card is implicitly selected. */ virtual void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) = 0; + + /*! Supplies a target for observers. */ + virtual void set_activity_observer(Activity::Observer *observer) {} }; } diff --git a/Machines/AppleII/DiskIICard.cpp b/Machines/AppleII/DiskIICard.cpp index b0941b28e..527b23b39 100644 --- a/Machines/AppleII/DiskIICard.cpp +++ b/Machines/AppleII/DiskIICard.cpp @@ -40,3 +40,7 @@ void DiskIICard::run_for(Cycles cycles, int stretches) { void DiskIICard::set_disk(const std::shared_ptr &disk, int drive) { diskii_.set_disk(disk, drive); } + +void DiskIICard::set_activity_observer(Activity::Observer *observer) { + diskii_.set_activity_observer(observer); +} diff --git a/Machines/AppleII/DiskIICard.hpp b/Machines/AppleII/DiskIICard.hpp index 7f03d0ddc..849e37f94 100644 --- a/Machines/AppleII/DiskIICard.hpp +++ b/Machines/AppleII/DiskIICard.hpp @@ -24,8 +24,11 @@ namespace AppleII { class DiskIICard: public Card { public: DiskIICard(const ROMMachine::ROMFetcher &rom_fetcher, bool is_16_sector); + void perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) override; void run_for(Cycles cycles, int stretches) override; + void set_activity_observer(Activity::Observer *observer) override; + void set_disk(const std::shared_ptr &disk, int drive); private: