diff --git a/Components/8272/i8272.cpp b/Components/8272/i8272.cpp index eb23cf694..e84584876 100644 --- a/Components/8272/i8272.cpp +++ b/Components/8272/i8272.cpp @@ -428,19 +428,11 @@ void i8272::posit_event(int event_type) { begin_writing(); if(get_is_double_density()) { - for(int c = 0; c < 50; c++) { - write_byte(0x4e); - } - for(int c = 0; c < 12; c++) { - write_byte(0x00); - } + write_n_bytes(50, 0x4e); + write_n_bytes(12, 0x00); } else { - for(int c = 0; c < 11; c++) { - write_byte(0xff); - } - for(int c = 0; c < 6; c++) { - write_byte(0x00); - } + write_n_bytes(11, 0xff); + write_n_bytes(6, 0x00); } WAIT_FOR_EVENT(Event::DataWritten); @@ -572,28 +564,28 @@ void i8272::posit_event(int event_type) { // Write start-of-track. if(get_is_double_density()) { - for(int c = 0; c < 80; c++) write_byte(0x4e); - for(int c = 0; c < 12; c++) write_byte(0x00); + write_n_bytes(80, 0x4e); + write_n_bytes(12, 0x00); for(int c = 0; c < 3; c++) write_raw_short(Storage::Encodings::MFM::MFMIndexSync); write_byte(Storage::Encodings::MFM::IndexAddressByte); - for(int c = 0; c < 50; c++) write_byte(0x4e); + write_n_bytes(50, 0x4e); } else { - for(int c = 0; c < 40; c++) write_byte(0xff); - for(int c = 0; c < 6; c++) write_byte(0x00); + write_n_bytes(40, 0xff); + write_n_bytes(6, 0x00); write_raw_short(Storage::Encodings::MFM::FMIndexAddressMark); - for(int c = 0; c < 26; c++) write_byte(0xff); + write_n_bytes(26, 0xff); } WAIT_FOR_EVENT(Event::DataWritten); sector_ = 0; format_track_write_sector: if(get_is_double_density()) { - for(int c = 0; c < 12; c++) write_byte(0x00); + write_n_bytes(12, 0x00); for(int c = 0; c < 3; c++) write_raw_short(Storage::Encodings::MFM::MFMSync); get_crc_generator().set_value(Storage::Encodings::MFM::MFMPostSyncCRCValue); write_byte(Storage::Encodings::MFM::IDAddressByte); } else { - for(int c = 0; c < 6; c++) write_byte(0x00); + write_n_bytes(6, 0x00); get_crc_generator().reset(); write_raw_short(Storage::Encodings::MFM::FMIDAddressMark); } @@ -619,28 +611,22 @@ void i8272::posit_event(int event_type) { // Write the sector body. if(get_is_double_density()) { - for(int c = 0; c < 22; c++) write_byte(0x4e); - for(int c = 0; c < 12; c++) write_byte(0x00); + write_n_bytes(22, 0x4e); + write_n_bytes(12, 0x00); for(int c = 0; c < 3; c++) write_raw_short(Storage::Encodings::MFM::MFMSync); get_crc_generator().set_value(Storage::Encodings::MFM::MFMPostSyncCRCValue); write_byte(Storage::Encodings::MFM::DataAddressByte); } else { - for(int c = 0; c < 11; c++) write_byte(0xff); - for(int c = 0; c < 6; c++) write_byte(0x00); + write_n_bytes(11, 0xff); + write_n_bytes(6, 0x00); get_crc_generator().reset(); write_raw_short(Storage::Encodings::MFM::FMDataAddressMark); } - for(int c = 0; c < (128 << command_[2]); c++) { - write_byte(command_[5]); - } + write_n_bytes(128 << command_[2], command_[5]); write_crc(); // Write the prescribed gap. - if(get_is_double_density()) { - for(int c = 0; c < command_[4]; c++) write_byte(0x4e); - } else { - for(int c = 0; c < command_[4]; c++) write_byte(0xff); - } + write_n_bytes(command_[4], get_is_double_density() ? 0x4e : 0xff); // Consider repeating. sector_++; diff --git a/Storage/Disk/MFMDiskController.cpp b/Storage/Disk/MFMDiskController.cpp index 51f4ac3b2..18eca4fcb 100644 --- a/Storage/Disk/MFMDiskController.cpp +++ b/Storage/Disk/MFMDiskController.cpp @@ -181,3 +181,7 @@ void MFMController::write_crc() { write_byte(crc >> 8); write_byte(crc & 0xff); } + +void MFMController::write_n_bytes(int quantity, uint8_t value) { + while(quantity--) write_byte(value); +} diff --git a/Storage/Disk/MFMDiskController.hpp b/Storage/Disk/MFMDiskController.hpp index 4ace6665e..dde8d425c 100644 --- a/Storage/Disk/MFMDiskController.hpp +++ b/Storage/Disk/MFMDiskController.hpp @@ -113,6 +113,11 @@ class MFMController: public Controller { */ void write_crc(); + /*! + Calls @c write_byte with @c value, @c quantity times. + */ + void write_n_bytes(int quantity, uint8_t value); + private: // Storage::Disk::Controller virtual void process_input_bit(int value, unsigned int cycles_since_index_hole);