From 685a80f95bab5abcee035b90b765f92054016c5e Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 18 Jun 2018 21:49:57 -0400 Subject: [PATCH] Ensures the Electron Plus 3 properly announces drives to an activity observer. Does away with lazy allocation as not all that helpful, and liable to cause complexity. --- Machines/Electron/Electron.cpp | 4 ++++ Machines/Electron/Plus3.cpp | 19 ++++++++++--------- Machines/Electron/Plus3.hpp | 5 +++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index 11b090a7b..ecdb5bf17 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -485,6 +485,10 @@ class ConcreteMachine: if(activity_observer_) { activity_observer_->register_led(caps_led); activity_observer_->set_led_status(caps_led, caps_led_state_); + + if(plus3_) { + plus3_->set_activity_observer(observer); + } } } diff --git a/Machines/Electron/Plus3.cpp b/Machines/Electron/Plus3.cpp index 10ecf3787..75e08e3ab 100644 --- a/Machines/Electron/Plus3.cpp +++ b/Machines/Electron/Plus3.cpp @@ -11,14 +11,12 @@ using namespace Electron; Plus3::Plus3() : WD1770(P1770) { + drives_.emplace_back(new Storage::Disk::Drive(8000000, 300, 2)); + drives_.emplace_back(new Storage::Disk::Drive(8000000, 300, 2)); set_control_register(last_control_, 0xff); } -void Plus3::set_disk(std::shared_ptr disk, int drive) { - if(!drives_[drive]) { - drives_[drive].reset(new Storage::Disk::Drive(8000000, 300, 2)); - if(drive == selected_drive_) set_drive(drives_[drive]); - } +void Plus3::set_disk(std::shared_ptr disk, size_t drive) { drives_[drive]->set_disk(disk); } @@ -42,8 +40,8 @@ void Plus3::set_control_register(uint8_t control, uint8_t changes) { } } if(changes & 0x04) { - if(drives_[0]) drives_[0]->set_head((control & 0x04) ? 1 : 0); - if(drives_[1]) drives_[1]->set_head((control & 0x04) ? 1 : 0); + drives_[0]->set_head((control & 0x04) ? 1 : 0); + drives_[1]->set_head((control & 0x04) ? 1 : 0); } if(changes & 0x08) set_is_double_density(!(control & 0x08)); } @@ -55,6 +53,9 @@ void Plus3::set_motor_on(bool on) { } void Plus3::set_activity_observer(Activity::Observer *observer) { - drives_[0]->set_activity_observer(observer, "Drive 1", true); - drives_[1]->set_activity_observer(observer, "Drive 2", true); + size_t index = 0; + for(const auto &drive: drives_) { + drive->set_activity_observer(observer, "Drive " + std::to_string(index+1), true); + ++index; + } } diff --git a/Machines/Electron/Plus3.hpp b/Machines/Electron/Plus3.hpp index 8033a940f..ab2486c9d 100644 --- a/Machines/Electron/Plus3.hpp +++ b/Machines/Electron/Plus3.hpp @@ -18,17 +18,18 @@ class Plus3 : public WD::WD1770 { public: Plus3(); - void set_disk(std::shared_ptr disk, int drive); + void set_disk(std::shared_ptr disk, size_t drive); void set_control_register(uint8_t control); void set_activity_observer(Activity::Observer *observer); private: void set_control_register(uint8_t control, uint8_t changes); - std::shared_ptr drives_[2]; + std::vector> drives_; int selected_drive_ = 0; uint8_t last_control_ = 0; void set_motor_on(bool on); + std::string drive_name(size_t drive); }; }