Files
CLK/Machines/Tandy/CoCo/DiskController.cpp
2026-05-25 08:41:46 -04:00

68 lines
1.8 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// DiskController.cpp
// Clock Signal
//
// Created by Thomas Harte on 18/05/2026.
// Copyright © 2026 Thomas Harte. All rights reserved.
//
#include "DiskController.hpp"
using namespace Tandy::CoCo;
DiskController::DiskController() : WD::WD1770(P1773) {
emplace_drives(4, 8'000'000, 300, 2);
WD1770::set_delegate(this);
}
void DiskController::set_control(const uint8_t value) {
// b7: halt flag, 1 = enabled
// b6: drive select 3
// b5: density, 1 = double
// b4: write precompensation, 1 = enable
// b3: drive motors, 1 = on
// b0–b2: drive selects
double_density_ = value & 0x20;
set_is_double_density(value & 0x20);
for_all_drives([&] (Storage::Disk::Drive &drive, size_t) {
drive.set_motor_on(value & 0x8);
});
set_drive((value & 7) | ((value >> 3) & 8));
enable_halt_ = value & 0x80;
update_halt_nmi();
}
void DiskController::set_disk(std::shared_ptr<Storage::Disk::Disk> disk, const size_t drive) {
get_drive(drive).set_disk(disk);
}
void DiskController::set_activity_observer(Activity::Observer *const observer) {
for_all_drives([observer] (Storage::Disk::Drive &drive, size_t index) {
drive.set_activity_observer(observer, "Drive " + std::to_string(index+1), true);
});
}
const Storage::Disk::Disk *DiskController::disk(const std::string &name) {
const Storage::Disk::Disk *result = nullptr;
for_all_drives( [&](Storage::Disk::Drive &drive, size_t) {
const auto disk = drive.disk();
if(disk && disk->represents(name)) {
result = disk;
}
});
return result;
}
void DiskController::wd1770_did_change_output(WD::WD1770 &) {
update_halt_nmi();
}
void DiskController::update_halt_nmi() {
enable_halt_ &= !get_interrupt_request_line();
nmi_ = get_interrupt_request_line() && double_density_;
halt_ = !get_data_request_line() && enable_halt_;
}