mirror of
				https://github.com/TomHarte/CLK.git
				synced 2025-10-31 05:16:08 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			48 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| //
 | |
| //  DiskIIDrive.cpp
 | |
| //  Clock Signal
 | |
| //
 | |
| //  Created by Thomas Harte on 20/11/2020.
 | |
| //  Copyright © 2020 Thomas Harte. All rights reserved.
 | |
| //
 | |
| 
 | |
| #include "DiskIIDrive.hpp"
 | |
| 
 | |
| #include <bit>
 | |
| 
 | |
| using namespace Apple::Disk;
 | |
| 
 | |
| DiskIIDrive::DiskIIDrive(const int input_clock_rate) :
 | |
| 	IWMDrive(input_clock_rate, 1) {
 | |
| 	Drive::set_rotation_speed(300.0f);
 | |
| }
 | |
| 
 | |
| void DiskIIDrive::set_enabled(const bool enabled) {
 | |
| 	set_motor_on(enabled);
 | |
| }
 | |
| 
 | |
| void DiskIIDrive::set_control_lines(const int lines) {
 | |
| 	// If the stepper magnet selections have changed, and any is on, see how
 | |
| 	// that moves the head.
 | |
| 	if(lines ^ stepper_mask_ && lines) {
 | |
| 		// Convert from a representation of bits set to the centre of pull.
 | |
| 		int direction = 0;
 | |
| 		if(lines&1) direction += (((stepper_position_ - 0) + 4)&7) - 4;
 | |
| 		if(lines&2) direction += (((stepper_position_ - 2) + 4)&7) - 4;
 | |
| 		if(lines&4) direction += (((stepper_position_ - 4) + 4)&7) - 4;
 | |
| 		if(lines&8) direction += (((stepper_position_ - 6) + 4)&7) - 4;
 | |
| 		const int bits_set = std::popcount(uint8_t(lines));
 | |
| 		direction /= bits_set;
 | |
| 
 | |
| 		// Compare to the stepper position to decide whether that pulls in the
 | |
| 		// current cog notch, or grabs a later one.
 | |
| 		step(Storage::Disk::HeadPosition(-direction, 4));
 | |
| 		stepper_position_ = (stepper_position_ - direction + 8) & 7;
 | |
| 	}
 | |
| 	stepper_mask_ = lines;
 | |
| }
 | |
| 
 | |
| bool DiskIIDrive::read() {
 | |
| 	return !!(stepper_mask_ & 2) || is_read_only();
 | |
| }
 |