2016-09-26 01:24:16 +00:00
|
|
|
//
|
|
|
|
// Drive.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 25/09/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Drive.hpp"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace Storage::Disk;
|
|
|
|
|
|
|
|
Drive::Drive()
|
2016-12-03 16:59:28 +00:00
|
|
|
: head_position_(0), head_(0) {}
|
2016-09-26 01:24:16 +00:00
|
|
|
|
|
|
|
void Drive::set_disk(std::shared_ptr<Disk> disk)
|
|
|
|
{
|
2016-12-03 16:59:28 +00:00
|
|
|
disk_ = disk;
|
2016-09-26 01:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Drive::has_disk()
|
|
|
|
{
|
2016-12-03 16:59:28 +00:00
|
|
|
return (bool)disk_;
|
2016-09-26 01:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Drive::get_is_track_zero()
|
|
|
|
{
|
2016-12-03 16:59:28 +00:00
|
|
|
return head_position_ == 0;
|
2016-09-26 01:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Drive::step(int direction)
|
|
|
|
{
|
2016-12-03 16:59:28 +00:00
|
|
|
head_position_ = std::max(head_position_ + direction, 0);
|
2016-09-26 01:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Drive::set_head(unsigned int head)
|
|
|
|
{
|
2016-12-03 16:59:28 +00:00
|
|
|
head_ = head;
|
2016-09-26 01:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<Track> Drive::get_track()
|
|
|
|
{
|
2016-12-03 16:59:28 +00:00
|
|
|
if(disk_) return disk_->get_track_at_position(head_, (unsigned int)head_position_);
|
2016-09-26 01:24:16 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|