From a9eb0d02c6238f9b10905da72d41e6a5cc867eb1 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 20 Jun 2018 23:02:32 -0400 Subject: [PATCH 1/2] Returns sanity to 8272 logging. --- Components/8272/i8272.cpp | 46 +++++++++++++++++++++++++++++++-------- Outputs/Log.hpp | 2 ++ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Components/8272/i8272.cpp b/Components/8272/i8272.cpp index d45109ac5..57d8916d4 100644 --- a/Components/8272/i8272.cpp +++ b/Components/8272/i8272.cpp @@ -114,7 +114,7 @@ void i8272::run_for(Cycles cycles) { while(steps--) { // Perform a step. int direction = (drives_[c].target_head_position < drives_[c].head_position) ? -1 : 1; - LOG("Target " << std::dec << drives_[c].target_head_position << " versus believed " << drives_[c].head_position); + LOG("Target " << std::dec << drives_[c].target_head_position << " versus believed " << static_cast(drives_[c].head_position)); select_drive(c); get_drive().step(Storage::Disk::HeadPosition(direction)); if(drives_[c].target_head_position >= 0) drives_[c].head_position += direction; @@ -424,7 +424,14 @@ void i8272::posit_event(int event_type) { // Performs the read data or read deleted data command. read_data: - LOG("Read [deleted] data [" << std::hex << command_[2] << " " << command_[3] << " " << command_[4] << " " << command_[5] << " ... " << command_[6] << " " << command_[8] << "]"); + LOGNBR(std::hex << std::setw(2) << std::left << std::setfill('0')); + LOG("Read [deleted] data [" + << static_cast(command_[2]) << " " + << static_cast(command_[3]) << " " + << static_cast(command_[4]) << " " + << static_cast(command_[5]) << " ... " + << static_cast(command_[6]) << " " + << static_cast(command_[8]) << "]"); read_next_data: goto read_write_find_header; @@ -508,7 +515,14 @@ void i8272::posit_event(int event_type) { goto post_st012chrn; write_data: - LOG("Write [deleted] data [" << std::hex << command_[2] << " " << command_[3] << " " << command_[4] << " " << command_[5] << " ... " << command_[6] << " " << command_[8] << "]"); + LOGNBR(std::hex << std::setw(2) << std::left << std::setfill('0')); + LOG("Write [deleted] data [" + << static_cast(command_[2]) << " " + << static_cast(command_[3]) << " " + << static_cast(command_[4]) << " " + << static_cast(command_[5]) << " ... " + << static_cast(command_[6]) << " " + << static_cast(command_[8]) << "]"); if(get_drive().get_is_read_only()) { SetNotWriteable(); @@ -559,7 +573,8 @@ void i8272::posit_event(int event_type) { // Performs the read ID command. read_id: // Establishes the drive and head being addressed, and whether in double density mode. - LOG("Read ID [" << std::hex << command_[0] << " " << command_[1] << "]"); + LOGNBR(std::hex << std::setw(2) << std::left << std::setfill('0')); + LOG("Read ID [" << static_cast(command_[0]) << " " << static_cast(command_[1]) << "]"); // Sets a maximum index hole limit of 2 then waits either until it finds a header mark or sees too many index holes. // If a header mark is found, reads in the following bytes that produce a header. Otherwise branches to data not found. @@ -581,7 +596,12 @@ void i8272::posit_event(int event_type) { // Performs read track. read_track: - LOG("Read track [" << std::hex << command_[2] << " " << command_[3] << " " << command_[4] << " " << command_[5] << "]"); + LOGNBR(std::hex << std::setw(2) << std::left << std::setfill('0')); + LOG("Read track [" + << static_cast(command_[2]) << " " + << static_cast(command_[3]) << " " + << static_cast(command_[4]) << " " + << static_cast(command_[5]) << "]"); // Wait for the index hole. WAIT_FOR_EVENT(Event::IndexHole); @@ -666,7 +686,13 @@ void i8272::posit_event(int event_type) { break; } - LOG("W: " << std::hex << header_[0] << " " << header_[1] << " " << header_[2] << " " << header_[3] << ", " << get_crc_generator().get_value()); + LOGNBR(std::hex << std::setw(2) << std::left << std::setfill('0')); + LOG("W:" + << static_cast(header_[0]) << " " + << static_cast(header_[1]) << " " + << static_cast(header_[2]) << " " + << static_cast(header_[3]) << ", " + << get_crc_generator().get_value()); write_crc(); // Write the sector body. @@ -737,7 +763,8 @@ void i8272::posit_event(int event_type) { // up in run_for understands to mean 'keep going until track 0 is active'). if(command_.size() > 2) { drives_[drive].target_head_position = command_[2]; - LOG("Seek to " << std::hex << command_[2]); + LOGNBR(std::hex << std::setw(2) << std::left << std::setfill('0')); + LOG("Seek to " << static_cast(command_[2])); } else { drives_[drive].target_head_position = -1; drives_[drive].head_position = 0; @@ -832,9 +859,10 @@ void i8272::posit_event(int event_type) { // Posts whatever is in result_stack_ as a result phase. Be aware that it is a stack, so the // last thing in it will be returned first. post_result: - LOGNBR("Result to " << std::hex << (command_[0] & 0x1f) << ", main " << main_status_); + LOGNBR(std::hex << std::setw(2) << std::left << std::setfill('0')); + LOGNBR("Result to " << static_cast(command_[0] & 0x1f) << ", main " << static_cast(main_status_)); for(std::size_t c = 0; c < result_stack_.size(); c++) { - LOGNBR(result_stack_[result_stack_.size() - 1 - c]); + LOGNBR(static_cast(result_stack_[result_stack_.size() - 1 - c])); } LOGNBR(std::endl); diff --git a/Outputs/Log.hpp b/Outputs/Log.hpp index 36f7e2fe9..3286f92e0 100644 --- a/Outputs/Log.hpp +++ b/Outputs/Log.hpp @@ -18,7 +18,9 @@ #else +#include #include +#include #define LOG(x) std::cout << x << std::endl #define LOGNBR(x) std::cout << x From 5ab4cfee84b2a2793a0ff270241af1f2e6f0662e Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 21 Jun 2018 19:27:54 -0400 Subject: [PATCH 2/2] Factors out repeated hex-size setting. --- Components/8272/i8272.cpp | 29 +++++++++++------------------ Outputs/Log.hpp | 5 +++++ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Components/8272/i8272.cpp b/Components/8272/i8272.cpp index 57d8916d4..1d3cdc9d7 100644 --- a/Components/8272/i8272.cpp +++ b/Components/8272/i8272.cpp @@ -114,7 +114,7 @@ void i8272::run_for(Cycles cycles) { while(steps--) { // Perform a step. int direction = (drives_[c].target_head_position < drives_[c].head_position) ? -1 : 1; - LOG("Target " << std::dec << drives_[c].target_head_position << " versus believed " << static_cast(drives_[c].head_position)); + LOG("Target " << PADDEC(0) << drives_[c].target_head_position << " versus believed " << static_cast(drives_[c].head_position)); select_drive(c); get_drive().step(Storage::Disk::HeadPosition(direction)); if(drives_[c].target_head_position >= 0) drives_[c].head_position += direction; @@ -385,7 +385,7 @@ void i8272::posit_event(int event_type) { // the index hole limit is breached or a sector is found with a cylinder, head, sector and size equal to the // values in the internal registers. index_hole_limit_ = 2; -// LOG("Seeking " << std::dec << cylinder_ << " " << head_ " " << sector_ << " " << size_); +// LOG("Seeking " << PADDEC(0) << cylinder_ << " " << head_ " " << sector_ << " " << size_); find_next_sector: FIND_HEADER(); if(!index_hole_limit_) { @@ -406,7 +406,7 @@ void i8272::posit_event(int event_type) { // This implies a CRC error in the header; mark as such but continue. SetDataError(); } -// LOG("Considering << std::hex << header_[0] << " " << header_[1] << " " << header_[2] << " " << header_[3] << " [" << get_crc_generator().get_value() << "]"); +// LOG("Considering << PADHEX(2) << header_[0] << " " << header_[1] << " " << header_[2] << " " << header_[3] << " [" << get_crc_generator().get_value() << "]"); if(header_[0] != cylinder_ || header_[1] != head_ || header_[2] != sector_ || header_[3] != size_) goto find_next_sector; // Branch to whatever is supposed to happen next @@ -424,8 +424,7 @@ void i8272::posit_event(int event_type) { // Performs the read data or read deleted data command. read_data: - LOGNBR(std::hex << std::setw(2) << std::left << std::setfill('0')); - LOG("Read [deleted] data [" + LOG(PADHEX(2) << "Read [deleted] data [" << static_cast(command_[2]) << " " << static_cast(command_[3]) << " " << static_cast(command_[4]) << " " @@ -515,8 +514,7 @@ void i8272::posit_event(int event_type) { goto post_st012chrn; write_data: - LOGNBR(std::hex << std::setw(2) << std::left << std::setfill('0')); - LOG("Write [deleted] data [" + LOG(PADHEX(2) << "Write [deleted] data [" << static_cast(command_[2]) << " " << static_cast(command_[3]) << " " << static_cast(command_[4]) << " " @@ -557,7 +555,7 @@ void i8272::posit_event(int event_type) { goto write_loop; } - LOG("Wrote " << std::dec << distance_into_section_ << " bytes"); + LOG("Wrote " << PADDEC(0) << distance_into_section_ << " bytes"); write_crc(); expects_input_ = false; WAIT_FOR_EVENT(Event::DataWritten); @@ -573,8 +571,7 @@ void i8272::posit_event(int event_type) { // Performs the read ID command. read_id: // Establishes the drive and head being addressed, and whether in double density mode. - LOGNBR(std::hex << std::setw(2) << std::left << std::setfill('0')); - LOG("Read ID [" << static_cast(command_[0]) << " " << static_cast(command_[1]) << "]"); + LOG(PADHEX(2) << "Read ID [" << static_cast(command_[0]) << " " << static_cast(command_[1]) << "]"); // Sets a maximum index hole limit of 2 then waits either until it finds a header mark or sees too many index holes. // If a header mark is found, reads in the following bytes that produce a header. Otherwise branches to data not found. @@ -596,8 +593,7 @@ void i8272::posit_event(int event_type) { // Performs read track. read_track: - LOGNBR(std::hex << std::setw(2) << std::left << std::setfill('0')); - LOG("Read track [" + LOG(PADHEX(2) << "Read track [" << static_cast(command_[2]) << " " << static_cast(command_[3]) << " " << static_cast(command_[4]) << " " @@ -686,8 +682,7 @@ void i8272::posit_event(int event_type) { break; } - LOGNBR(std::hex << std::setw(2) << std::left << std::setfill('0')); - LOG("W:" + LOG(PADHEX(2) << "W:" << static_cast(header_[0]) << " " << static_cast(header_[1]) << " " << static_cast(header_[2]) << " " @@ -763,8 +758,7 @@ void i8272::posit_event(int event_type) { // up in run_for understands to mean 'keep going until track 0 is active'). if(command_.size() > 2) { drives_[drive].target_head_position = command_[2]; - LOGNBR(std::hex << std::setw(2) << std::left << std::setfill('0')); - LOG("Seek to " << static_cast(command_[2])); + LOG(PADHEX(2) << "Seek to " << static_cast(command_[2])); } else { drives_[drive].target_head_position = -1; drives_[drive].head_position = 0; @@ -859,8 +853,7 @@ void i8272::posit_event(int event_type) { // Posts whatever is in result_stack_ as a result phase. Be aware that it is a stack, so the // last thing in it will be returned first. post_result: - LOGNBR(std::hex << std::setw(2) << std::left << std::setfill('0')); - LOGNBR("Result to " << static_cast(command_[0] & 0x1f) << ", main " << static_cast(main_status_)); + LOGNBR(PADHEX(2) << "Result to " << static_cast(command_[0] & 0x1f) << ", main " << static_cast(main_status_)); for(std::size_t c = 0; c < result_stack_.size(); c++) { LOGNBR(static_cast(result_stack_[result_stack_.size() - 1 - c])); } diff --git a/Outputs/Log.hpp b/Outputs/Log.hpp index 3286f92e0..a274636fc 100644 --- a/Outputs/Log.hpp +++ b/Outputs/Log.hpp @@ -13,6 +13,7 @@ #define LOG(x) #define LOGNBR(x) + #define ERROR(x) #define ERRORNBR(x) @@ -22,8 +23,12 @@ #include #include +#define PADHEX(n) std::hex << std::setw(n) << std::right << std::setfill('0') +#define PADDEC(n) std::dec << std::setw(n) << std::right << std::setfill('0') + #define LOG(x) std::cout << x << std::endl #define LOGNBR(x) std::cout << x + #define ERROR(x) std::cerr << x << std::endl #define ERRORNBR(x) std::cerr << x