Superdrive: more commands and status requests.

This commit is contained in:
Maxim Poliakovski 2022-02-07 15:05:57 +01:00
parent b9fbd9b7c9
commit 9aaf441625
2 changed files with 73 additions and 8 deletions

View File

@ -35,20 +35,45 @@ MacSuperDrive::MacSuperDrive()
this->name = "Superdrive";
this->supported_types = HWCompType::FLOPPY_DRV;
this->media_kind = MediaKind::high_density;
this->has_disk = 0; // drive is empty
this->media_kind = MediaKind::high_density;
this->has_disk = 0; // drive is empty
this->eject_latch = 0; // eject latch is off
this->drive_mode = RecMethod::MFM; // assume MFM mode by default
this->motor_stat = 0; // spindle motor is off
this->is_ready = 0; // drive not ready
}
void MacSuperDrive::command(uint8_t addr, uint8_t value)
{
uint8_t new_motor_stat;
LOG_F(9, "Superdrive: command addr=0x%X, value=%d", addr, value);
switch(addr) {
case CommandAddr::Step_Direction:
this->step_dir = value ? -1 : 1;
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->is_ready = 1;
LOG_F(INFO, "Superdrive: turn spindle motor on");
} else {
LOG_F(INFO, "Superdrive: turn spindle motor off");
}
}
break;
case CommandAddr::Reset_Eject_Latch:
if (value) {
LOG_F(INFO, "Superdrive: turn spindle motor off");
} else {
LOG_F(INFO, "Superdrive: turn spindle motor on");
this->eject_latch = 0;
}
break;
case CommandAddr::Switch_Drive_Mode:
if (this->drive_mode != (value ^ 1)) {
switch_drive_mode(value ^ 1); // reverse logic
this->is_ready = 1;
}
break;
default:
@ -61,6 +86,12 @@ uint8_t MacSuperDrive::status(uint8_t addr)
LOG_F(9, "Superdrive: status request, addr = 0x%X", addr);
switch(addr) {
case StatusAddr::Step_Status:
return 1; // not sure what should be returned here
case StatusAddr::Motor_Status:
return this->motor_stat ^ 1; // reverse logic
case StatusAddr::Eject_Latch:
return this->eject_latch;
case StatusAddr::MFM_Support:
return 1; // Superdrive does support MFM encoding scheme
case StatusAddr::Double_Sided:
@ -68,7 +99,13 @@ uint8_t MacSuperDrive::status(uint8_t addr)
case StatusAddr::Drive_Exists:
return 0; // tell the world I'm here
case StatusAddr::Disk_In_Drive:
return this->has_disk ^ 1; // reverse logic (active low)!
return this->has_disk ^ 1; // reverse logic (active low)!
case StatusAddr::Write_Protect:
return this->wr_protect ^ 1; // reverse logic
case StatusAddr::Drive_Mode:
return this->drive_mode;
case StatusAddr::Drive_Ready:
return this->is_ready ^ 1; // reverse logic
case StatusAddr::Media_Kind:
return this->media_kind ^ 1; // reverse logic!
default:
@ -95,6 +132,9 @@ int MacSuperDrive::insert_disk(std::string& img_path)
// swallow all raw disk data at once!
this->img_conv->get_raw_disk_data(this->disk_data.get());
// disk is write-enabled by default
this->wr_protect = 0;
// everything is set up, let's say we got a disk
this->has_disk = 1;
} else {
@ -111,7 +151,12 @@ void MacSuperDrive::set_disk_phys_params()
this->num_sides = this->img_conv->get_number_of_sides();
this->media_kind = this->img_conv->get_rec_density();
if (rec_method == RecMethod::GCR) {
switch_drive_mode(this->rec_method);
}
void MacSuperDrive::switch_drive_mode(int mode)
{
if (mode == RecMethod::GCR) {
// Apple GCR speeds per group of 16 tracks
static int gcr_rpm_per_group[5] = {394, 429, 472, 525, 590};
@ -128,6 +173,8 @@ void MacSuperDrive::set_disk_phys_params()
blk_num += 12 - grp;
}
}
this->drive_mode = RecMethod::GCR;
} else {
int sectors_per_track = this->media_kind ? 18 : 9;
@ -138,5 +185,7 @@ void MacSuperDrive::set_disk_phys_params()
this->rpm_per_track[trk] = 300;
this->track_start_block[trk] = trk * sectors_per_track;
}
this->drive_mode = RecMethod::MFM;
}
}

View File

@ -35,16 +35,25 @@ namespace MacSuperdrive {
/** Apple Drive status request addresses. */
enum StatusAddr : uint8_t {
Step_Status = 1,
Motor_Status = 2,
Eject_Latch = 3,
MFM_Support = 5,
Double_Sided = 6,
Drive_Exists = 7,
Disk_In_Drive = 8,
Write_Protect = 9,
Drive_Mode = 0xD,
Drive_Ready = 0xE,
Media_Kind = 0xF
};
/** Apple Drive command addresses. */
enum CommandAddr : uint8_t {
Motor_On_Off = 2,
Step_Direction = 0,
Motor_On_Off = 2,
Reset_Eject_Latch = 4,
Switch_Drive_Mode = 5,
};
/** Type of media currently in the drive. */
@ -70,12 +79,19 @@ public:
protected:
void set_disk_phys_params();
void switch_drive_mode(int mode);
private:
uint8_t has_disk;
uint8_t eject_latch;
uint8_t motor_stat; // spindle motor status: 1 - on, 0 - off
uint8_t drive_mode; // drive mode: 0 - GCR, 1 - MFM
uint8_t is_ready;
int step_dir; // step direction -1/+1
// physical parameters of the currently inserted disk
uint8_t media_kind;
uint8_t wr_protect;
int rec_method;
int num_tracks;
int num_sides;