2016-09-26 01:24:16 +00:00
|
|
|
//
|
|
|
|
// Plus3.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 25/09/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-09-26 01:24:16 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "Plus3.hpp"
|
|
|
|
|
|
|
|
using namespace Electron;
|
|
|
|
|
2017-09-01 02:29:24 +00:00
|
|
|
Plus3::Plus3() : WD1770(P1770) {
|
2016-12-28 23:52:36 +00:00
|
|
|
set_control_register(last_control_, 0xff);
|
|
|
|
}
|
2016-11-26 15:29:30 +00:00
|
|
|
|
2017-03-26 18:34:47 +00:00
|
|
|
void Plus3::set_disk(std::shared_ptr<Storage::Disk::Disk> disk, int drive) {
|
|
|
|
if(!drives_[drive]) {
|
2017-09-16 01:18:36 +00:00
|
|
|
drives_[drive].reset(new Storage::Disk::Drive(8000000, 300, 2));
|
2016-11-22 00:11:57 +00:00
|
|
|
if(drive == selected_drive_) set_drive(drives_[drive]);
|
|
|
|
}
|
|
|
|
drives_[drive]->set_disk(disk);
|
2016-09-26 01:24:16 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 18:34:47 +00:00
|
|
|
void Plus3::set_control_register(uint8_t control) {
|
2016-09-26 01:24:16 +00:00
|
|
|
// bit 0 => enable or disable drive 1
|
|
|
|
// bit 1 => enable or disable drive 2
|
|
|
|
// bit 2 => side select
|
|
|
|
// bit 3 => single density select
|
2016-12-26 02:06:58 +00:00
|
|
|
|
|
|
|
uint8_t changes = control ^ last_control_;
|
|
|
|
last_control_ = control;
|
2016-12-28 23:52:36 +00:00
|
|
|
set_control_register(control, changes);
|
|
|
|
}
|
2016-12-26 02:06:58 +00:00
|
|
|
|
2017-03-26 18:34:47 +00:00
|
|
|
void Plus3::set_control_register(uint8_t control, uint8_t changes) {
|
|
|
|
if(changes&3) {
|
|
|
|
switch(control&3) {
|
2016-12-26 02:06:58 +00:00
|
|
|
case 0: selected_drive_ = -1; set_drive(nullptr); break;
|
|
|
|
default: selected_drive_ = 0; set_drive(drives_[0]); break;
|
|
|
|
case 2: selected_drive_ = 1; set_drive(drives_[1]); break;
|
|
|
|
}
|
|
|
|
}
|
2017-03-26 18:34:47 +00:00
|
|
|
if(changes & 0x04) {
|
2016-12-26 02:06:58 +00:00
|
|
|
if(drives_[0]) drives_[0]->set_head((control & 0x04) ? 1 : 0);
|
|
|
|
if(drives_[1]) drives_[1]->set_head((control & 0x04) ? 1 : 0);
|
2016-09-26 01:24:16 +00:00
|
|
|
}
|
2016-12-26 02:06:58 +00:00
|
|
|
if(changes & 0x08) set_is_double_density(!(control & 0x08));
|
2016-09-26 01:24:16 +00:00
|
|
|
}
|
2017-09-12 02:10:56 +00:00
|
|
|
|
|
|
|
void Plus3::set_motor_on(bool on) {
|
|
|
|
// TODO: this status should transfer if the selected drive changes. But the same goes for
|
|
|
|
// writing state, so plenty of work to do in general here.
|
|
|
|
get_drive().set_motor_on(on);
|
|
|
|
}
|
2018-05-11 01:54:10 +00:00
|
|
|
|
|
|
|
void Plus3::set_activity_observer(Activity::Observer *observer) {
|
|
|
|
drives_[0]->set_activity_observer(observer, "Drive 1", true);
|
|
|
|
drives_[1]->set_activity_observer(observer, "Drive 2", true);
|
|
|
|
}
|