1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-09 21:29:53 +00:00

Factored out the dull and repetitious stuff of writing n bytes of the same value.

This commit is contained in:
Thomas Harte 2017-08-14 15:50:36 -04:00
parent d7bed958b3
commit 4df9307d25
3 changed files with 27 additions and 32 deletions

View File

@ -428,19 +428,11 @@ void i8272::posit_event(int event_type) {
begin_writing(); begin_writing();
if(get_is_double_density()) { if(get_is_double_density()) {
for(int c = 0; c < 50; c++) { write_n_bytes(50, 0x4e);
write_byte(0x4e); write_n_bytes(12, 0x00);
}
for(int c = 0; c < 12; c++) {
write_byte(0x00);
}
} else { } else {
for(int c = 0; c < 11; c++) { write_n_bytes(11, 0xff);
write_byte(0xff); write_n_bytes(6, 0x00);
}
for(int c = 0; c < 6; c++) {
write_byte(0x00);
}
} }
WAIT_FOR_EVENT(Event::DataWritten); WAIT_FOR_EVENT(Event::DataWritten);
@ -572,28 +564,28 @@ void i8272::posit_event(int event_type) {
// Write start-of-track. // Write start-of-track.
if(get_is_double_density()) { if(get_is_double_density()) {
for(int c = 0; c < 80; c++) write_byte(0x4e); write_n_bytes(80, 0x4e);
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::MFMIndexSync); for(int c = 0; c < 3; c++) write_raw_short(Storage::Encodings::MFM::MFMIndexSync);
write_byte(Storage::Encodings::MFM::IndexAddressByte); write_byte(Storage::Encodings::MFM::IndexAddressByte);
for(int c = 0; c < 50; c++) write_byte(0x4e); write_n_bytes(50, 0x4e);
} else { } else {
for(int c = 0; c < 40; c++) write_byte(0xff); write_n_bytes(40, 0xff);
for(int c = 0; c < 6; c++) write_byte(0x00); write_n_bytes(6, 0x00);
write_raw_short(Storage::Encodings::MFM::FMIndexAddressMark); 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); WAIT_FOR_EVENT(Event::DataWritten);
sector_ = 0; sector_ = 0;
format_track_write_sector: format_track_write_sector:
if(get_is_double_density()) { 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); for(int c = 0; c < 3; c++) write_raw_short(Storage::Encodings::MFM::MFMSync);
get_crc_generator().set_value(Storage::Encodings::MFM::MFMPostSyncCRCValue); get_crc_generator().set_value(Storage::Encodings::MFM::MFMPostSyncCRCValue);
write_byte(Storage::Encodings::MFM::IDAddressByte); write_byte(Storage::Encodings::MFM::IDAddressByte);
} else { } else {
for(int c = 0; c < 6; c++) write_byte(0x00); write_n_bytes(6, 0x00);
get_crc_generator().reset(); get_crc_generator().reset();
write_raw_short(Storage::Encodings::MFM::FMIDAddressMark); write_raw_short(Storage::Encodings::MFM::FMIDAddressMark);
} }
@ -619,28 +611,22 @@ void i8272::posit_event(int event_type) {
// Write the sector body. // Write the sector body.
if(get_is_double_density()) { if(get_is_double_density()) {
for(int c = 0; c < 22; c++) write_byte(0x4e); write_n_bytes(22, 0x4e);
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); for(int c = 0; c < 3; c++) write_raw_short(Storage::Encodings::MFM::MFMSync);
get_crc_generator().set_value(Storage::Encodings::MFM::MFMPostSyncCRCValue); get_crc_generator().set_value(Storage::Encodings::MFM::MFMPostSyncCRCValue);
write_byte(Storage::Encodings::MFM::DataAddressByte); write_byte(Storage::Encodings::MFM::DataAddressByte);
} else { } else {
for(int c = 0; c < 11; c++) write_byte(0xff); write_n_bytes(11, 0xff);
for(int c = 0; c < 6; c++) write_byte(0x00); write_n_bytes(6, 0x00);
get_crc_generator().reset(); get_crc_generator().reset();
write_raw_short(Storage::Encodings::MFM::FMDataAddressMark); write_raw_short(Storage::Encodings::MFM::FMDataAddressMark);
} }
for(int c = 0; c < (128 << command_[2]); c++) { write_n_bytes(128 << command_[2], command_[5]);
write_byte(command_[5]);
}
write_crc(); write_crc();
// Write the prescribed gap. // Write the prescribed gap.
if(get_is_double_density()) { write_n_bytes(command_[4], get_is_double_density() ? 0x4e : 0xff);
for(int c = 0; c < command_[4]; c++) write_byte(0x4e);
} else {
for(int c = 0; c < command_[4]; c++) write_byte(0xff);
}
// Consider repeating. // Consider repeating.
sector_++; sector_++;

View File

@ -181,3 +181,7 @@ void MFMController::write_crc() {
write_byte(crc >> 8); write_byte(crc >> 8);
write_byte(crc & 0xff); write_byte(crc & 0xff);
} }
void MFMController::write_n_bytes(int quantity, uint8_t value) {
while(quantity--) write_byte(value);
}

View File

@ -113,6 +113,11 @@ class MFMController: public Controller {
*/ */
void write_crc(); void write_crc();
/*!
Calls @c write_byte with @c value, @c quantity times.
*/
void write_n_bytes(int quantity, uint8_t value);
private: private:
// Storage::Disk::Controller // Storage::Disk::Controller
virtual void process_input_bit(int value, unsigned int cycles_since_index_hole); virtual void process_input_bit(int value, unsigned int cycles_since_index_hole);