From 4fca30b81f2e4b0133b2f7d9691aa7cca28f258f Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 25 Dec 2016 21:06:58 -0500 Subject: [PATCH] Made the Plus 3 less chatty, documented `invalidate_track`. --- Machines/Electron/Plus3.cpp | 26 ++++++++++++++++++-------- Machines/Electron/Plus3.hpp | 1 + Storage/Disk/DiskController.hpp | 4 ++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Machines/Electron/Plus3.cpp b/Machines/Electron/Plus3.cpp index 52035dd3d..9100a860c 100644 --- a/Machines/Electron/Plus3.cpp +++ b/Machines/Electron/Plus3.cpp @@ -24,18 +24,28 @@ void Plus3::set_disk(std::shared_ptr disk, int drive) void Plus3::set_control_register(uint8_t control) { - // TODO: // bit 0 => enable or disable drive 1 // bit 1 => enable or disable drive 2 // bit 2 => side select // bit 3 => single density select - switch(control&3) + + uint8_t changes = control ^ last_control_; + last_control_ = control; + + if(changes&3) { - case 0: selected_drive_ = -1; set_drive(nullptr); break; - default: selected_drive_ = 0; set_drive(drives_[0]); break; - case 2: selected_drive_ = 1; set_drive(drives_[1]); break; + switch(control&3) + { + case 0: selected_drive_ = -1; set_drive(nullptr); break; + default: selected_drive_ = 0; set_drive(drives_[0]); break; + case 2: selected_drive_ = 1; set_drive(drives_[1]); break; + } } - if(drives_[0]) drives_[0]->set_head((control & 0x04) ? 1 : 0); - if(drives_[1]) drives_[1]->set_head((control & 0x04) ? 1 : 0); - set_is_double_density(!(control & 0x08)); + if(changes & 0x04) + { + invalidate_track(); + if(drives_[0]) drives_[0]->set_head((control & 0x04) ? 1 : 0); + if(drives_[1]) drives_[1]->set_head((control & 0x04) ? 1 : 0); + } + if(changes & 0x08) set_is_double_density(!(control & 0x08)); } diff --git a/Machines/Electron/Plus3.hpp b/Machines/Electron/Plus3.hpp index cd04b3877..8e6b7c0e4 100644 --- a/Machines/Electron/Plus3.hpp +++ b/Machines/Electron/Plus3.hpp @@ -23,6 +23,7 @@ class Plus3 : public WD::WD1770 { private: std::shared_ptr drives_[2]; int selected_drive_; + uint8_t last_control_; }; } diff --git a/Storage/Disk/DiskController.hpp b/Storage/Disk/DiskController.hpp index f309307bc..a39b74b48 100644 --- a/Storage/Disk/DiskController.hpp +++ b/Storage/Disk/DiskController.hpp @@ -49,6 +49,10 @@ class Controller: public DigitalPhaseLockedLoop::Delegate, public TimedEventLoop Sets the current drive. */ void set_drive(std::shared_ptr drive); + + /*! + Announces that the track the drive sees is about to change for a reason unknownt to the controller. + */ void invalidate_track(); /*!