diff --git a/Storage/Disk/Drive.cpp b/Storage/Disk/Drive.cpp index caf875305..bee294b19 100644 --- a/Storage/Disk/Drive.cpp +++ b/Storage/Disk/Drive.cpp @@ -311,6 +311,15 @@ void Drive::invalidate_track() { // MARK: - Writing void Drive::begin_writing(Time bit_length, bool clamp_to_index_hole) { + // Do nothing if already writing. + if(!is_reading_) return; + + // Get a copy of the track if that hasn't happened yet. + if(!track_) { + setup_track(); + } + + // Store the relevant parameters, and kick off writing. is_reading_ = false; clamp_writing_to_index_hole_ = clamp_to_index_hole; @@ -350,6 +359,10 @@ void Drive::end_writing() { } } +bool Drive::is_writing() { + return !is_reading_; +} + void Drive::set_activity_observer(Activity::Observer *observer, const std::string &name, bool add_motor_led) { observer_ = observer; announce_motor_led_ = add_motor_led; diff --git a/Storage/Disk/Drive.hpp b/Storage/Disk/Drive.hpp index 1b1402ddf..183976938 100644 --- a/Storage/Disk/Drive.hpp +++ b/Storage/Disk/Drive.hpp @@ -100,6 +100,12 @@ class Drive: public ClockingHint::Source, public TimedEventLoop { */ void end_writing(); + /*! + @returns @c true if the drive has received a call to begin_writing but not yet a call to + end_writing; @c false otherwise. + */ + bool is_writing(); + /*! Advances the drive by @c number_of_cycles cycles. */