From 34a3790e11aa66ee96a9d689b3813f3c07e2ecc9 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 22 Dec 2019 17:56:59 -0500 Subject: [PATCH 1/4] Minor static_cast clean-ups. --- Storage/Disk/Controller/MFMDiskController.cpp | 2 +- Storage/Disk/Encodings/MFM/Shifter.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Storage/Disk/Controller/MFMDiskController.cpp b/Storage/Disk/Controller/MFMDiskController.cpp index aec23893b..7264d70bb 100644 --- a/Storage/Disk/Controller/MFMDiskController.cpp +++ b/Storage/Disk/Controller/MFMDiskController.cpp @@ -80,7 +80,7 @@ void MFMController::process_input_bit(int value) { break; } latest_token_.byte_value = shifter_.get_byte(); - posit_event(static_cast(Event::Token)); + posit_event(int(Event::Token)); } void MFMController::write_bit(int bit) { diff --git a/Storage/Disk/Encodings/MFM/Shifter.cpp b/Storage/Disk/Encodings/MFM/Shifter.cpp index d17098f85..b68c6f210 100644 --- a/Storage/Disk/Encodings/MFM/Shifter.cpp +++ b/Storage/Disk/Encodings/MFM/Shifter.cpp @@ -108,7 +108,7 @@ void Shifter::add_input_bit(int value) { } uint8_t Shifter::get_byte() const { - return static_cast( + return uint8_t( ((shift_register_ & 0x0001) >> 0) | ((shift_register_ & 0x0004) >> 1) | ((shift_register_ & 0x0010) >> 2) | From d25b48878c95967886c73611e2c7ac197c07d17f Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 22 Dec 2019 17:58:33 -0500 Subject: [PATCH 2/4] Cleans up READ_ID macro, inter alia. --- Components/1770/1770.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Components/1770/1770.cpp b/Components/1770/1770.cpp index 081cf3956..9b320645e 100644 --- a/Components/1770/1770.cpp +++ b/Components/1770/1770.cpp @@ -91,6 +91,7 @@ uint8_t WD1770::get_register(int address) { if(status_.type == Status::One) status |= (status_.spin_up ? Flag::SpinUp : 0); } +// LOG("Returned status " << PADHEX(2) << int(status) << " of type " << 1+int(status_.type)); return status; } case 1: return track_; @@ -124,11 +125,13 @@ void WD1770::run_for(const Cycles cycles) { #define END_SECTION() (void)0; } #define READ_ID() \ - if(new_event_type == static_cast(Event::Token)) { \ - if(!distance_into_section_ && get_latest_token().type == Token::ID) {set_data_mode(DataMode::Reading); distance_into_section_++; } \ - else if(distance_into_section_ && distance_into_section_ < 7 && get_latest_token().type == Token::Byte) { \ + if(new_event_type == int(Event::Token)) { \ + if(!distance_into_section_ && get_latest_token().type == Token::ID) {\ + set_data_mode(DataMode::Reading); \ + ++distance_into_section_; \ + } else if(distance_into_section_ && distance_into_section_ < 7 && get_latest_token().type == Token::Byte) { \ header_[distance_into_section_ - 1] = get_latest_token().byte_value; \ - distance_into_section_++; \ + ++distance_into_section_; \ } \ } From b035b92f33a833883729e7df0aeb81b8c53bc42b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 22 Dec 2019 19:58:02 -0500 Subject: [PATCH 3/4] Corrects accidental use of sector contents as addresses in multi-sector reads and writes. As a secondary defect, this was also causing erroneous CRC error reports. --- Components/1770/1770.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Components/1770/1770.cpp b/Components/1770/1770.cpp index 9b320645e..02e70d08c 100644 --- a/Components/1770/1770.cpp +++ b/Components/1770/1770.cpp @@ -324,7 +324,9 @@ void WD1770::posit_event(int new_event_type) { goto wait_for_command; } if(distance_into_section_ == 7) { + distance_into_section_ = 0; set_data_mode(DataMode::Scanning); + if(get_crc_generator().get_value()) { update_status([] (Status &status) { status.crc_error = true; @@ -339,8 +341,6 @@ void WD1770::posit_event(int new_event_type) { }); goto wait_for_command; } - - distance_into_section_ = 0; } goto verify_read_data; @@ -397,6 +397,9 @@ void WD1770::posit_event(int new_event_type) { goto wait_for_command; } + distance_into_section_ = 0; + set_data_mode(DataMode::Scanning); + type2_get_header: WAIT_FOR_EVENT(static_cast(Event::IndexHole) | static_cast(Event::Token)); READ_ID(); @@ -409,8 +412,10 @@ void WD1770::posit_event(int new_event_type) { goto wait_for_command; } if(distance_into_section_ == 7) { - LOG("Considering " << std::dec << int(header_[0]) << "/" << int(header_[2])); + distance_into_section_ = 0; set_data_mode(DataMode::Scanning); + + LOG("Considering " << std::dec << int(header_[0]) << "/" << int(header_[2])); if( header_[0] == track_ && header_[2] == sector_ && (has_motor_on_line() || !(command_&0x02) || ((command_&0x08) >> 3) == header_[1])) { LOG("Found " << std::dec << int(header_[0]) << "/" << int(header_[2])); @@ -427,7 +432,6 @@ void WD1770::posit_event(int new_event_type) { }); goto type2_read_or_write_data; } - distance_into_section_ = 0; } goto type2_get_header; @@ -470,6 +474,9 @@ void WD1770::posit_event(int new_event_type) { header_[distance_into_section_] = get_latest_token().byte_value; distance_into_section_++; if(distance_into_section_ == 2) { + distance_into_section_ = 0; + set_data_mode(DataMode::Scanning); + if(get_crc_generator().get_value()) { LOG("CRC error; terminating"); update_status([this] (Status &status) { @@ -478,11 +485,13 @@ void WD1770::posit_event(int new_event_type) { goto wait_for_command; } + LOG("Finished reading sector " << std::dec << int(sector_)); + if(command_ & 0x10) { sector_++; + LOG("Advancing to search for sector " << std::dec << int(sector_)); goto test_type2_write_protection; } - LOG("Finished reading sector " << std::dec << int(sector_)); goto wait_for_command; } goto type2_check_crc; @@ -630,9 +639,11 @@ void WD1770::posit_event(int new_event_type) { update_status([] (Status &status) { status.data_request = true; }); - distance_into_section_++; + ++distance_into_section_; if(distance_into_section_ == 7) { + distance_into_section_ = 0; + if(get_crc_generator().get_value()) { update_status([] (Status &status) { status.crc_error = true; From ac604b30f3a8fbc6470b08200a2773cc7003b8ec Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 22 Dec 2019 20:59:20 -0500 Subject: [PATCH 4/4] Eliminates dangling `static_cast`s in favour of construction. --- Components/1770/1770.cpp | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/Components/1770/1770.cpp b/Components/1770/1770.cpp index 02e70d08c..96bf28d5d 100644 --- a/Components/1770/1770.cpp +++ b/Components/1770/1770.cpp @@ -18,9 +18,9 @@ using namespace WD; WD1770::WD1770(Personality p) : Storage::Disk::MFMController(8000000), personality_(p), - interesting_event_mask_(static_cast(Event1770::Command)) { + interesting_event_mask_(int(Event1770::Command)) { set_is_double_density(false); - posit_event(static_cast(Event1770::Command)); + posit_event(int(Event1770::Command)); } void WD1770::set_register(int address, uint8_t value) { @@ -30,7 +30,7 @@ void WD1770::set_register(int address, uint8_t value) { if(value == 0xd0) { // Force interrupt **immediately**. LOG("Force interrupt immediately"); - posit_event(static_cast(Event1770::ForceInterrupt)); + posit_event(int(Event1770::ForceInterrupt)); } else { ERROR("!!!TODO: force interrupt!!!"); update_status([] (Status &status) { @@ -39,7 +39,7 @@ void WD1770::set_register(int address, uint8_t value) { } } else { command_ = value; - posit_event(static_cast(Event1770::Command)); + posit_event(int(Event1770::Command)); } } break; @@ -111,16 +111,16 @@ void WD1770::run_for(const Cycles cycles) { const auto number_of_cycles = cycles.as_integral(); if(delay_time_ <= number_of_cycles) { delay_time_ = 0; - posit_event(static_cast(Event1770::Timer)); + posit_event(int(Event1770::Timer)); } else { delay_time_ -= number_of_cycles; } } } -#define WAIT_FOR_EVENT(mask) resume_point_ = __LINE__; interesting_event_mask_ = static_cast(mask); return; case __LINE__: +#define WAIT_FOR_EVENT(mask) resume_point_ = __LINE__; interesting_event_mask_ = int(mask); return; case __LINE__: #define WAIT_FOR_TIME(ms) resume_point_ = __LINE__; delay_time_ = ms * 8000; WAIT_FOR_EVENT(Event1770::Timer); -#define WAIT_FOR_BYTES(count) resume_point_ = __LINE__; distance_into_section_ = 0; WAIT_FOR_EVENT(Event::Token); if(get_latest_token().type == Token::Byte) distance_into_section_++; if(distance_into_section_ < count) { interesting_event_mask_ = static_cast(Event::Token); return; } +#define WAIT_FOR_BYTES(count) resume_point_ = __LINE__; distance_into_section_ = 0; WAIT_FOR_EVENT(Event::Token); if(get_latest_token().type == Token::Byte) distance_into_section_++; if(distance_into_section_ < count) { interesting_event_mask_ = int(Event::Token); return; } #define BEGIN_SECTION() switch(resume_point_) { default: #define END_SECTION() (void)0; } @@ -164,10 +164,10 @@ void WD1770::run_for(const Cycles cycles) { // +--------+----------+-------------------------+ void WD1770::posit_event(int new_event_type) { - if(new_event_type == static_cast(Event::IndexHole)) { + if(new_event_type == int(Event::IndexHole)) { index_hole_count_++; if(index_hole_count_target_ == index_hole_count_) { - posit_event(static_cast(Event1770::IndexHoleTarget)); + posit_event(int(Event1770::IndexHoleTarget)); index_hole_count_target_ = -1; } @@ -182,7 +182,7 @@ void WD1770::posit_event(int new_event_type) { } } - if(new_event_type == static_cast(Event1770::ForceInterrupt)) { + if(new_event_type == int(Event1770::ForceInterrupt)) { interesting_event_mask_ = 0; resume_point_ = 0; update_status([] (Status &status) { @@ -190,7 +190,7 @@ void WD1770::posit_event(int new_event_type) { status.data_request = false; }); } else { - if(!(interesting_event_mask_ & static_cast(new_event_type))) return; + if(!(interesting_event_mask_ & int(new_event_type))) return; interesting_event_mask_ &= ~new_event_type; } @@ -245,6 +245,7 @@ void WD1770::posit_event(int new_event_type) { status.data_request = false; }); + LOG("Step/Seek/Restore with track " << int(track_) << " data " << int(data_)); if(!has_motor_on_line() && !has_head_load_line()) goto test_type1_type; if(has_motor_on_line()) goto begin_type1_spin_up; @@ -281,7 +282,7 @@ void WD1770::posit_event(int new_event_type) { step_direction_ = (data_ > track_); adjust_track: - if(step_direction_) track_++; else track_--; + if(step_direction_) ++track_; else --track_; perform_step: if(!step_direction_ && get_drive().get_is_track_zero()) { @@ -314,7 +315,7 @@ void WD1770::posit_event(int new_event_type) { distance_into_section_ = 0; verify_read_data: - WAIT_FOR_EVENT(static_cast(Event::IndexHole) | static_cast(Event::Token)); + WAIT_FOR_EVENT(int(Event::IndexHole) | int(Event::Token)); READ_ID(); if(index_hole_count_ == 6) { @@ -401,7 +402,7 @@ void WD1770::posit_event(int new_event_type) { set_data_mode(DataMode::Scanning); type2_get_header: - WAIT_FOR_EVENT(static_cast(Event::IndexHole) | static_cast(Event::Token)); + WAIT_FOR_EVENT(int(Event::IndexHole) | int(Event::Token)); READ_ID(); if(index_hole_count_ == 5) { @@ -624,8 +625,8 @@ void WD1770::posit_event(int new_event_type) { distance_into_section_ = 0; read_address_get_header: - WAIT_FOR_EVENT(static_cast(Event::IndexHole) | static_cast(Event::Token)); - if(new_event_type == static_cast(Event::Token)) { + WAIT_FOR_EVENT(int(Event::IndexHole) | int(Event::Token)); + if(new_event_type == int(Event::Token)) { if(!distance_into_section_ && get_latest_token().type == Token::ID) {set_data_mode(DataMode::Reading); distance_into_section_++; } else if(distance_into_section_ && distance_into_section_ < 7 && get_latest_token().type == Token::Byte) { if(status_.data_request) { @@ -667,7 +668,7 @@ void WD1770::posit_event(int new_event_type) { index_hole_count_ = 0; read_track_read_byte: - WAIT_FOR_EVENT(static_cast(Event::Token) | static_cast(Event::IndexHole)); + WAIT_FOR_EVENT(int(Event::Token) | int(Event::IndexHole)); if(index_hole_count_) { goto wait_for_command; } @@ -734,7 +735,7 @@ void WD1770::posit_event(int new_event_type) { case 0xfd: case 0xfe: // clock is 0xc7 = 1010 0000 0010 1010 = 0xa022 write_raw_short( - static_cast( + uint16_t( 0xa022 | ((data_ & 0x80) << 7) | ((data_ & 0x40) << 6) | @@ -802,7 +803,7 @@ void WD1770::set_motor_on(bool motor_on) {} void WD1770::set_head_loaded(bool head_loaded) { head_is_loaded_ = head_loaded; - if(head_loaded) posit_event(static_cast(Event1770::HeadLoad)); + if(head_loaded) posit_event(int(Event1770::HeadLoad)); } ClockingHint::Preference WD1770::preferred_clocking() {