1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-22 12:33:29 +00:00

Merge pull request #1299 from TomHarte/SpectreNIB

Mildly clean up around NIBs.
This commit is contained in:
Thomas Harte 2024-01-02 09:52:55 -05:00 committed by GitHub
commit ce2337f91e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 9 deletions

View File

@ -61,7 +61,12 @@ void DiskII::set_control(Control control, bool on) {
if(stepper_mask_&2) direction += (((stepper_position_ - 2) + 4)&7) - 4;
if(stepper_mask_&4) direction += (((stepper_position_ - 4) + 4)&7) - 4;
if(stepper_mask_&8) direction += (((stepper_position_ - 6) + 4)&7) - 4;
const int bits_set = (stepper_mask_&1) + ((stepper_mask_ >> 1)&1) + ((stepper_mask_ >> 2)&1) + ((stepper_mask_ >> 3)&1);
// TODO: when adopting C++20, replace with std::popcount.
int bits_set = stepper_mask_;
bits_set = (bits_set & 0x5) + ((bits_set >> 1) & 0x5);
bits_set = (bits_set & 0x3) + ((bits_set >> 2) & 0x3);
direction /= bits_set;
// Compare to the stepper position to decide whether that pulls in the current cog notch,
@ -126,7 +131,7 @@ void DiskII::run_for(const Cycles cycles) {
if(inputs_&input_mode) {
// state_ & 0x80 should be the current level sent to the disk;
// therefore transitions in that bit should become flux transitions
drives_[active_drive_].write_bit(!!((state_ ^ address) & 0x80));
drives_[active_drive_].write_bit((state_ ^ address) & 0x80);
}
// TODO: surely there's a less heavyweight solution than inline updates?
@ -179,7 +184,7 @@ void DiskII::decide_clocking_preference() {
}
bool DiskII::is_write_protected() {
return !!(stepper_mask_ & 2) | drives_[active_drive_].get_is_read_only();
return (stepper_mask_ & 2) || drives_[active_drive_].get_is_read_only();
}
void DiskII::set_state_machine(const std::vector<uint8_t> &state_machine) {

View File

@ -55,6 +55,8 @@ long NIB::file_offset(Track::Address address) {
}
std::shared_ptr<::Storage::Disk::Track> NIB::get_track_at_position(::Storage::Disk::Track::Address address) {
static constexpr size_t MinimumSyncByteCount = 4;
// NIBs contain data for a fixed quantity of integer-position tracks underneath a single head only.
//
// Therefore:
@ -77,9 +79,9 @@ std::shared_ptr<::Storage::Disk::Track> NIB::get_track_at_position(::Storage::Di
}
// NIB files leave sync bytes implicit and make no guarantees
// about overall track positioning. The attempt works by locating
// any single run of FF that is sufficiently long and marking the last
// five as including slip bits.
// about overall track positioning. This attempt to map to real
// flux locates any single run of FF that is sufficiently long
// and marks the last few as including slip bits.
std::set<size_t> sync_locations;
for(size_t index = 0; index < track_data.size(); ++index) {
// Count the number of FFs starting from here.
@ -90,9 +92,9 @@ std::shared_ptr<::Storage::Disk::Track> NIB::get_track_at_position(::Storage::Di
++length;
}
// If that's at least five, regress and mark all as syncs.
if(length >= 5) {
for(int c = 0; c < 5; c++) {
// If that's long enough, regress and mark syncs.
if(length >= MinimumSyncByteCount) {
for(int c = 0; c < int(MinimumSyncByteCount); c++) {
end = (end + track_data.size() - 1) % track_data.size();
sync_locations.insert(end);
}