2019-07-10 20:05:59 +00:00
|
|
|
//
|
|
|
|
// MacintoshDoubleDensityDrive.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 10/07/2019.
|
|
|
|
// Copyright © 2019 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "MacintoshDoubleDensityDrive.hpp"
|
|
|
|
|
2019-07-12 01:42:34 +00:00
|
|
|
/*
|
|
|
|
Sources used pervasively:
|
|
|
|
|
|
|
|
http://members.iinet.net.au/~kalandi/apple/AUG/1991/11%20NOV.DEC/DISK.STUFF.html
|
|
|
|
Apple Guide to the Macintosh Family Hardware
|
|
|
|
Inside Macintosh III
|
|
|
|
*/
|
|
|
|
|
2019-07-10 20:05:59 +00:00
|
|
|
using namespace Apple::Macintosh;
|
|
|
|
|
2024-11-30 20:53:58 +00:00
|
|
|
DoubleDensityDrive::DoubleDensityDrive(const int input_clock_rate, const bool is_800k) :
|
2019-07-10 20:05:59 +00:00
|
|
|
IWMDrive(input_clock_rate, is_800k ? 2 : 1), // Only 800kb drives are double sided.
|
|
|
|
is_800k_(is_800k) {
|
|
|
|
// Start with a valid rotation speed.
|
|
|
|
if(is_800k) {
|
2019-07-30 19:08:55 +00:00
|
|
|
Drive::set_rotation_speed(393.3807f);
|
2019-07-10 20:05:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-10 20:22:06 +00:00
|
|
|
// MARK: - Speed Selection
|
|
|
|
|
2024-11-30 20:53:58 +00:00
|
|
|
void DoubleDensityDrive::did_step(const Storage::Disk::HeadPosition to_position) {
|
2019-07-10 20:22:06 +00:00
|
|
|
// The 800kb drive automatically selects rotation speed as a function of
|
|
|
|
// head position; the 400kb drive doesn't do so.
|
|
|
|
if(is_800k_) {
|
|
|
|
/*
|
|
|
|
Numbers below cribbed from the Kryoflux forums; specifically:
|
|
|
|
https://forum.kryoflux.com/viewtopic.php?t=1090
|
|
|
|
|
|
|
|
They can almost be worked out algorithmically, since the point is to
|
|
|
|
produce an almost-constant value for speed*(number of sectors), and:
|
|
|
|
|
|
|
|
393.3807 * 12 = 4720.5684
|
|
|
|
429.1723 * 11 = 4720.895421
|
|
|
|
472.1435 * 10 = 4721.435
|
|
|
|
524.5672 * 9 = 4721.1048
|
|
|
|
590.1098 * 8 = 4720.8784
|
|
|
|
|
|
|
|
So 4721 / (number of sectors per track in zone) would give essentially
|
|
|
|
the same results.
|
|
|
|
*/
|
|
|
|
const int zone = to_position.as_int() >> 4;
|
|
|
|
switch(zone) {
|
2019-07-30 19:08:55 +00:00
|
|
|
case 0: Drive::set_rotation_speed(393.3807f); break;
|
|
|
|
case 1: Drive::set_rotation_speed(429.1723f); break;
|
|
|
|
case 2: Drive::set_rotation_speed(472.1435f); break;
|
|
|
|
case 3: Drive::set_rotation_speed(524.5672f); break;
|
|
|
|
default: Drive::set_rotation_speed(590.1098f); break;
|
2019-07-10 20:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-30 20:53:58 +00:00
|
|
|
void DoubleDensityDrive::set_rotation_speed(const float revolutions_per_minute) {
|
2019-07-30 19:08:55 +00:00
|
|
|
if(!is_800k_) {
|
|
|
|
// Don't allow drive speeds to drop below 10 RPM, as a temporary sop
|
|
|
|
// to sanity.
|
|
|
|
Drive::set_rotation_speed(std::max(10.0f, revolutions_per_minute));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-10 20:05:59 +00:00
|
|
|
// MARK: - Control input/output.
|
|
|
|
|
2024-11-30 20:53:58 +00:00
|
|
|
void DoubleDensityDrive::set_enabled(const bool enabled) {
|
2019-08-02 20:26:23 +00:00
|
|
|
// Disabling a drive also stops its motor.
|
|
|
|
if(!enabled) set_motor_on(false);
|
2019-07-10 20:05:59 +00:00
|
|
|
}
|
|
|
|
|
2024-11-30 20:53:58 +00:00
|
|
|
void DoubleDensityDrive::set_control_lines(const int lines) {
|
2019-07-10 20:17:51 +00:00
|
|
|
const auto old_state = control_state_;
|
|
|
|
control_state_ = lines;
|
|
|
|
|
|
|
|
// Catch low-to-high LSTRB transitions.
|
|
|
|
if((old_state ^ control_state_) & control_state_ & Line::LSTRB) {
|
2019-07-12 17:17:24 +00:00
|
|
|
switch(control_state_ & (Line::CA2 | Line::CA1 | Line::CA0 | Line::SEL)) {
|
2019-07-10 20:17:51 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
2019-07-12 01:42:34 +00:00
|
|
|
case 0: // Set step direction — CA2 set => step outward.
|
2019-07-12 17:17:24 +00:00
|
|
|
case Line::CA2:
|
2019-07-10 20:17:51 +00:00
|
|
|
step_direction_ = (control_state_ & Line::CA2) ? -1 : 1;
|
|
|
|
break;
|
|
|
|
|
2019-07-12 01:42:34 +00:00
|
|
|
case Line::CA1: // Set drive motor — CA2 set => motor off.
|
2019-07-12 17:17:24 +00:00
|
|
|
case Line::CA1|Line::CA2:
|
2019-07-10 20:17:51 +00:00
|
|
|
set_motor_on(!(control_state_ & Line::CA2));
|
|
|
|
break;
|
|
|
|
|
2019-07-12 17:17:24 +00:00
|
|
|
case Line::CA0: // Initiate a step.
|
|
|
|
step(Storage::Disk::HeadPosition(step_direction_));
|
2019-07-10 20:17:51 +00:00
|
|
|
break;
|
|
|
|
|
2019-07-12 17:17:24 +00:00
|
|
|
case Line::SEL|Line::CA2: // Reset new disk flag.
|
|
|
|
has_new_disk_ = false;
|
2019-07-12 01:42:34 +00:00
|
|
|
break;
|
|
|
|
|
2019-07-12 17:17:24 +00:00
|
|
|
case Line::CA2 | Line::CA1 | Line::CA0: // Eject the disk.
|
|
|
|
set_disk(nullptr);
|
2019-07-10 20:17:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-07-10 20:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DoubleDensityDrive::read() {
|
2019-07-10 20:17:51 +00:00
|
|
|
switch(control_state_ & (CA2 | CA1 | CA0 | SEL)) {
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case 0: // Head step direction.
|
|
|
|
// (0 = inward)
|
|
|
|
return step_direction_ <= 0;
|
|
|
|
|
|
|
|
case SEL: // Disk in place.
|
|
|
|
// (0 = disk present)
|
|
|
|
return !has_disk();
|
|
|
|
|
|
|
|
case CA0: // Disk head step completed.
|
|
|
|
// (0 = still stepping)
|
2019-07-11 02:39:56 +00:00
|
|
|
return true; // TODO: stepping delay. But at the main Drive level.
|
2019-07-10 20:17:51 +00:00
|
|
|
|
|
|
|
case CA0|SEL: // Disk locked.
|
|
|
|
// (0 = write protected)
|
|
|
|
return !get_is_read_only();
|
|
|
|
|
|
|
|
case CA1: // Disk motor running.
|
|
|
|
// (0 = motor on)
|
|
|
|
return !get_motor_on();
|
|
|
|
|
|
|
|
case CA1|SEL: // Head at track 0.
|
|
|
|
// (0 = at track 0)
|
2019-07-12 01:42:34 +00:00
|
|
|
// "This bit becomes valid beginning 12 msec after the step that places the head at track 0."
|
2019-07-10 20:17:51 +00:00
|
|
|
return !get_is_track_zero();
|
|
|
|
|
2019-07-12 01:42:34 +00:00
|
|
|
case CA1|CA0: // Disk has been ejected.
|
2020-11-18 22:20:48 +00:00
|
|
|
// (1 = user has ejected disk)
|
|
|
|
//
|
|
|
|
// TODO: does this really mean _user_ has ejected disk? If so then I should avoid
|
|
|
|
// changing the flag upon a programmatic eject.
|
|
|
|
return has_new_disk_;
|
2019-07-12 01:42:34 +00:00
|
|
|
|
2019-07-10 20:17:51 +00:00
|
|
|
case CA1|CA0|SEL: // Tachometer.
|
|
|
|
// (arbitrary)
|
|
|
|
return get_tachometer();
|
|
|
|
|
|
|
|
case CA2: // Read data, lower head.
|
|
|
|
set_head(0);
|
2019-07-12 01:42:34 +00:00
|
|
|
return false;
|
2019-07-10 20:17:51 +00:00
|
|
|
|
|
|
|
case CA2|SEL: // Read data, upper head.
|
|
|
|
set_head(1);
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case CA2|CA1: // Single- or double-sided drive.
|
|
|
|
// (0 = single sided)
|
|
|
|
return get_head_count() != 1;
|
|
|
|
|
|
|
|
case CA2|CA1|CA0: // "Present/HD" (per the Mac Plus ROM)
|
|
|
|
// (0 = ??HD??)
|
2019-07-12 01:42:34 +00:00
|
|
|
//
|
|
|
|
// Alternative explanation: "Disk ready for reading?"
|
|
|
|
// (0 = ready)
|
2019-07-10 20:17:51 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case CA2|CA1|CA0|SEL: // Drive installed.
|
|
|
|
// (0 = present, 1 = missing)
|
2020-11-11 22:30:22 +00:00
|
|
|
return false;
|
2019-07-10 20:17:51 +00:00
|
|
|
}
|
2019-07-10 20:05:59 +00:00
|
|
|
}
|
2019-07-12 17:17:24 +00:00
|
|
|
|
2020-11-18 22:20:48 +00:00
|
|
|
void DoubleDensityDrive::did_set_disk(bool did_replace) {
|
|
|
|
has_new_disk_ = did_replace;
|
2019-07-12 17:17:24 +00:00
|
|
|
}
|