From da082673d7e44e57fcaba9eadf5eb03aa540f610 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 15 Sep 2017 21:18:36 -0400 Subject: [PATCH] Drives now have a finite number of heads. The Amstrad volunteers itself to be single sided. Everything else stays as it was. --- Machines/AmstradCPC/AmstradCPC.cpp | 2 +- Machines/Commodore/1540/Implementation/C1540.cpp | 2 +- Machines/Electron/Plus3.cpp | 2 +- Machines/Oric/Microdisc.cpp | 2 +- StaticAnalyser/Commodore/Disk.cpp | 2 +- Storage/Disk/DiskController.cpp | 2 +- Storage/Disk/Drive.cpp | 7 +++++-- Storage/Disk/Drive.hpp | 3 ++- Storage/Disk/Encodings/MFM.cpp | 2 +- 9 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Machines/AmstradCPC/AmstradCPC.cpp b/Machines/AmstradCPC/AmstradCPC.cpp index fe46a63c7..23930dbf9 100644 --- a/Machines/AmstradCPC/AmstradCPC.cpp +++ b/Machines/AmstradCPC/AmstradCPC.cpp @@ -587,7 +587,7 @@ class FDC: public Intel::i8272::i8272 { public: FDC() : i8272(bus_handler_, Cycles(8000000)), - drive_(new Storage::Disk::Drive(8000000, 300)) { + drive_(new Storage::Disk::Drive(8000000, 300, 1)) { set_drive(drive_); } diff --git a/Machines/Commodore/1540/Implementation/C1540.cpp b/Machines/Commodore/1540/Implementation/C1540.cpp index 1944e8f7c..08379641e 100644 --- a/Machines/Commodore/1540/Implementation/C1540.cpp +++ b/Machines/Commodore/1540/Implementation/C1540.cpp @@ -23,7 +23,7 @@ MachineBase::MachineBase() : serial_port_VIA_port_handler_(new SerialPortVIA(serial_port_VIA_)), drive_VIA_(drive_VIA_port_handler_), serial_port_VIA_(*serial_port_VIA_port_handler_), - drive_(new Storage::Disk::Drive(1000000, 300)) { + drive_(new Storage::Disk::Drive(1000000, 300, 2)) { // attach the serial port to its VIA and vice versa serial_port_->set_serial_port_via(serial_port_VIA_port_handler_); serial_port_VIA_port_handler_->set_serial_port(serial_port_); diff --git a/Machines/Electron/Plus3.cpp b/Machines/Electron/Plus3.cpp index c6b4fa9a6..95178291a 100644 --- a/Machines/Electron/Plus3.cpp +++ b/Machines/Electron/Plus3.cpp @@ -16,7 +16,7 @@ Plus3::Plus3() : WD1770(P1770) { void Plus3::set_disk(std::shared_ptr disk, int drive) { if(!drives_[drive]) { - drives_[drive].reset(new Storage::Disk::Drive(8000000, 300)); + drives_[drive].reset(new Storage::Disk::Drive(8000000, 300, 2)); if(drive == selected_drive_) set_drive(drives_[drive]); } drives_[drive]->set_disk(disk); diff --git a/Machines/Oric/Microdisc.cpp b/Machines/Oric/Microdisc.cpp index fb8265c87..2c703cc77 100644 --- a/Machines/Oric/Microdisc.cpp +++ b/Machines/Oric/Microdisc.cpp @@ -30,7 +30,7 @@ Microdisc::Microdisc() : void Microdisc::set_disk(std::shared_ptr disk, int drive) { if(!drives_[drive]) { - drives_[drive].reset(new Storage::Disk::Drive(8000000, 300)); + drives_[drive].reset(new Storage::Disk::Drive(8000000, 300, 2)); if(drive == selected_drive_) set_drive(drives_[drive]); } drives_[drive]->set_disk(disk); diff --git a/StaticAnalyser/Commodore/Disk.cpp b/StaticAnalyser/Commodore/Disk.cpp index b576afe5b..f037cd3a4 100644 --- a/StaticAnalyser/Commodore/Disk.cpp +++ b/StaticAnalyser/Commodore/Disk.cpp @@ -22,7 +22,7 @@ class CommodoreGCRParser: public Storage::Disk::Controller { std::shared_ptr drive; CommodoreGCRParser() : Storage::Disk::Controller(4000000), shift_register_(0), track_(1) { - drive.reset(new Storage::Disk::Drive(4000000, 300)); + drive.reset(new Storage::Disk::Drive(4000000, 300, 2)); set_drive(drive); drive->set_motor_on(true); } diff --git a/Storage/Disk/DiskController.cpp b/Storage/Disk/DiskController.cpp index 429f94695..d4979b590 100644 --- a/Storage/Disk/DiskController.cpp +++ b/Storage/Disk/DiskController.cpp @@ -15,7 +15,7 @@ using namespace Storage::Disk; Controller::Controller(Cycles clock_rate) : clock_rate_multiplier_(128000000 / clock_rate.as_int()), clock_rate_(clock_rate.as_int() * clock_rate_multiplier_), - empty_drive_(new Drive((unsigned int)clock_rate.as_int(), 1)) { + empty_drive_(new Drive((unsigned int)clock_rate.as_int(), 1, 1)) { // seed this class with a PLL, any PLL, so that it's safe to assume non-nullptr later Time one(1); set_expected_bit_length(one); diff --git a/Storage/Disk/Drive.cpp b/Storage/Disk/Drive.cpp index 14f379c8d..130aa1c75 100644 --- a/Storage/Disk/Drive.cpp +++ b/Storage/Disk/Drive.cpp @@ -15,9 +15,10 @@ using namespace Storage::Disk; -Drive::Drive(unsigned int input_clock_rate, int revolutions_per_minute): +Drive::Drive(unsigned int input_clock_rate, int revolutions_per_minute, unsigned int number_of_heads): Storage::TimedEventLoop(input_clock_rate), - rotational_multiplier_(60, revolutions_per_minute) { + rotational_multiplier_(60, revolutions_per_minute), + available_heads_(number_of_heads) { } void Drive::set_disk(const std::shared_ptr &disk) { @@ -51,6 +52,7 @@ void Drive::step(int direction) { } void Drive::set_head(unsigned int head) { + head = std::min(head, available_heads_ - 1); if(head != head_) { head_ = head; track_ = nullptr; @@ -73,6 +75,7 @@ bool Drive::get_is_read_only() { } bool Drive::get_is_ready() { + return true; return ready_index_count_ == 2; } diff --git a/Storage/Disk/Drive.hpp b/Storage/Disk/Drive.hpp index 81e01c48c..1fed32c00 100644 --- a/Storage/Disk/Drive.hpp +++ b/Storage/Disk/Drive.hpp @@ -23,7 +23,7 @@ namespace Disk { class Drive: public Sleeper, public TimedEventLoop { public: - Drive(unsigned int input_clock_rate, int revolutions_per_minute); + Drive(unsigned int input_clock_rate, int revolutions_per_minute, unsigned int number_of_heads); /*! Replaces whatever is in the drive with @c disk. @@ -140,6 +140,7 @@ class Drive: public Sleeper, public TimedEventLoop { // A record of head position and active head. int head_position_ = 0; unsigned int head_ = 0; + unsigned int available_heads_ = 0; // Motor control state. bool motor_is_on_ = false; diff --git a/Storage/Disk/Encodings/MFM.cpp b/Storage/Disk/Encodings/MFM.cpp index 62eef12d7..5d7374f5f 100644 --- a/Storage/Disk/Encodings/MFM.cpp +++ b/Storage/Disk/Encodings/MFM.cpp @@ -244,7 +244,7 @@ Parser::Parser(bool is_mfm) : bit_length.clock_rate = is_mfm ? 500000 : 250000; // i.e. 250 kbps (including clocks) set_expected_bit_length(bit_length); - drive_.reset(new Storage::Disk::Drive(4000000, 300)); + drive_.reset(new Storage::Disk::Drive(4000000, 300, 2)); set_drive(drive_); drive_->set_motor_on(true); }