superdrive: Separate function for set_motor_stat.

This commit is contained in:
joevt 2024-05-01 03:27:09 -07:00 committed by dingusdev
parent 30582cfb05
commit a62954d1a7
2 changed files with 21 additions and 18 deletions

View File

@ -55,8 +55,6 @@ void MacSuperDrive::reset_params()
void MacSuperDrive::command(uint8_t addr, uint8_t value) 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); LOG_F(9, "%s: command addr=0x%X, value=%d", this->get_name().c_str(), addr, value);
switch(addr) { switch(addr) {
@ -72,22 +70,7 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
} }
break; break;
case CommandAddr::Motor_On_Off: case CommandAddr::Motor_On_Off:
new_motor_stat = value ^ 1; this->set_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());
}
}
break; break;
case CommandAddr::Eject_Disk: case CommandAddr::Eject_Disk:
if (value) { 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) uint8_t MacSuperDrive::status(uint8_t addr)
{ {
LOG_F(9, "%s: status request, addr = 0x%X", this->get_name().c_str(), addr); LOG_F(9, "%s: status request, addr = 0x%X", this->get_name().c_str(), addr);

View File

@ -102,6 +102,7 @@ public:
void command(uint8_t addr, uint8_t value); void command(uint8_t addr, uint8_t value);
uint8_t status(uint8_t addr); uint8_t status(uint8_t addr);
int insert_disk(std::string& img_path, int write_flag); 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); void init_track_search(int pos);
uint64_t sync_to_disk(); uint64_t sync_to_disk();
uint64_t next_addr_mark_delay(uint8_t *next_sect_num); uint64_t next_addr_mark_delay(uint8_t *next_sect_num);