From a62954d1a7aabd2a8e5af1476988ad07ccf94dae Mon Sep 17 00:00:00 2001 From: joevt Date: Wed, 1 May 2024 03:27:09 -0700 Subject: [PATCH] superdrive: Separate function for set_motor_stat. --- devices/floppy/superdrive.cpp | 38 ++++++++++++++++++----------------- devices/floppy/superdrive.h | 1 + 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/devices/floppy/superdrive.cpp b/devices/floppy/superdrive.cpp index 98cbcc6..684d324 100644 --- a/devices/floppy/superdrive.cpp +++ b/devices/floppy/superdrive.cpp @@ -55,8 +55,6 @@ void MacSuperDrive::reset_params() void MacSuperDrive::command(uint8_t addr, uint8_t value) { - uint8_t new_motor_stat; - LOG_F(9, "%s: command addr=0x%X, value=%d", this->get_name().c_str(), addr, value); switch(addr) { @@ -72,22 +70,7 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value) } break; case CommandAddr::Motor_On_Off: - new_motor_stat = value ^ 1; - if (this->motor_stat != new_motor_stat) { - this->motor_stat = new_motor_stat; - if (new_motor_stat) { - this->motor_on_time = TimerManager::get_instance()->current_time_ns(); - this->track_start_time = 0; - this->sector_start_time = 0; - this->init_track_search(-1); - this->is_ready = 1; - LOG_F(INFO, "%s: turn spindle motor on", this->get_name().c_str()); - } else { - this->motor_on_time = 0; - this->is_ready = 0; - LOG_F(INFO, "%s: turn spindle motor off", this->get_name().c_str()); - } - } + this->set_motor_stat(value ^ 1); break; case CommandAddr::Eject_Disk: if (value) { @@ -112,6 +95,25 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value) } } +void MacSuperDrive::set_motor_stat(uint8_t new_motor_stat) +{ + if (this->motor_stat != new_motor_stat) { + this->motor_stat = new_motor_stat; + if (new_motor_stat) { + this->motor_on_time = TimerManager::get_instance()->current_time_ns(); + this->track_start_time = 0; + this->sector_start_time = 0; + this->init_track_search(-1); + this->is_ready = 1; + LOG_F(INFO, "%s: turn spindle motor on", this->get_name().c_str()); + } else { + this->motor_on_time = 0; + this->is_ready = 0; + LOG_F(INFO, "%s: turn spindle motor off", this->get_name().c_str()); + } + } +} + uint8_t MacSuperDrive::status(uint8_t addr) { LOG_F(9, "%s: status request, addr = 0x%X", this->get_name().c_str(), addr); diff --git a/devices/floppy/superdrive.h b/devices/floppy/superdrive.h index 47a1789..54b52e9 100644 --- a/devices/floppy/superdrive.h +++ b/devices/floppy/superdrive.h @@ -102,6 +102,7 @@ public: void command(uint8_t addr, uint8_t value); uint8_t status(uint8_t addr); int insert_disk(std::string& img_path, int write_flag); + void set_motor_stat(uint8_t new_motor_stat); void init_track_search(int pos); uint64_t sync_to_disk(); uint64_t next_addr_mark_delay(uint8_t *next_sect_num);