From 7e47329e2a0efb8d9834671148c090986ba3e750 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 19 Jan 2024 14:16:13 -0500 Subject: [PATCH] Update use of logger. --- Components/1770/1770.cpp | 2 +- Components/8272/i8272.cpp | 96 +++++++++++++------------ Components/8530/z8530.cpp | 2 +- Components/9918/Implementation/9918.cpp | 10 +-- Machines/Apple/AppleIIgs/ADB.cpp | 5 +- Machines/Atari/ST/AtariST.cpp | 7 +- Outputs/Log.hpp | 7 +- Storage/State/SZX.cpp | 3 +- Storage/Tape/Formats/TZX.cpp | 9 ++- Storage/Tape/Formats/TapeUEF.cpp | 9 ++- 10 files changed, 87 insertions(+), 63 deletions(-) diff --git a/Components/1770/1770.cpp b/Components/1770/1770.cpp index 4884c8c61..8181a58fd 100644 --- a/Components/1770/1770.cpp +++ b/Components/1770/1770.cpp @@ -13,7 +13,7 @@ namespace { -auto logger = Log::Logger(); +Log::Logger logger; } diff --git a/Components/8272/i8272.cpp b/Components/8272/i8272.cpp index c6ae10bd2..6f7592b79 100644 --- a/Components/8272/i8272.cpp +++ b/Components/8272/i8272.cpp @@ -10,6 +10,12 @@ #include "../../Outputs/Log.hpp" +namespace { + +Log::Logger logger; + +} + using namespace Intel::i8272; i8272::i8272(BusHandler &bus_handler, Cycles clock_rate) : @@ -54,7 +60,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 " << PADDEC(0) << drives_[c].target_head_position << " versus believed " << int(drives_[c].head_position)); + logger.info().append("Target %d versus believed %d", drives_[c].target_head_position, 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; @@ -303,17 +309,17 @@ 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 " << PADDEC(0) << cylinder_ << " " << head_ " " << sector_ << " " << size_); +// logger.info().append("Seeking " << PADDEC(0) << cylinder_ << " " << head_ " " << sector_ << " " << size_); find_next_sector: FIND_HEADER(); if(!index_hole_limit_) { // Two index holes have passed wihout finding the header sought. -// LOG("Not found"); +// logger.info().append("Not found"); status_.set(Status1::NoData); goto abort; } index_hole_count_ = 0; -// LOG("Header"); +// logger.info().append("Header"); READ_HEADER(); if(index_hole_count_) { // This implies an index hole was sighted within the header. Error out. @@ -324,11 +330,11 @@ void i8272::posit_event(int event_type) { // This implies a CRC error in the header; mark as such but continue. status_.set(Status1::DataError); } -// LOG("Considering << PADHEX(2) << header_[0] << " " << header_[1] << " " << header_[2] << " " << header_[3] << " [" << get_crc_generator().get_value() << "]"); +// logger.info().append("Considering %02x %02x %02x %02x [%04x]", 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 -// LOG("Proceeding"); +// logger.info().append("Proceeding"); switch(command_.command()) { default: case Command::ReadData: @@ -343,13 +349,13 @@ void i8272::posit_event(int event_type) { // Performs the read data or read deleted data command. read_data: -// LOG(PADHEX(2) << "Read [deleted] data [" -// << int(command_[2]) << " " -// << int(command_[3]) << " " -// << int(command_[4]) << " " -// << int(command_[5]) << " ... " -// << int(command_[6]) << " " -// << int(command_[8]) << "]"); +// logger.info().append("Read [deleted] data [%02x %02x %02x %02x ... %02x %02x]", +// command_[2], +// command_[3], +// command_[4], +// command_[5], +// command_[6], +// command_[8]); read_next_data: goto read_write_find_header; @@ -433,13 +439,13 @@ void i8272::posit_event(int event_type) { goto post_st012chrn; write_data: -// LOG(PADHEX(2) << "Write [deleted] data [" -// << int(command_[2]) << " " -// << int(command_[3]) << " " -// << int(command_[4]) << " " -// << int(command_[5]) << " ... " -// << int(command_[6]) << " " -// << int(command_[8]) << "]"); +// logger.info().append("Write [deleted] data [%02x %02x %02x %02x ... %02x %02x]", +// command_[2], +// command_[3], +// command_[4], +// command_[5], +// command_[6], +// command_[8]); if(get_drive().get_is_read_only()) { status_.set(Status1::NotWriteable); @@ -474,7 +480,7 @@ void i8272::posit_event(int event_type) { goto write_loop; } - LOG("Wrote " << PADDEC(0) << distance_into_section_ << " bytes"); + logger.info().append("Wrote %d bytes", distance_into_section_); write_crc(); expects_input_ = false; WAIT_FOR_EVENT(Event::DataWritten); @@ -490,7 +496,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. -// LOG(PADHEX(2) << "Read ID [" << int(command_[0]) << " " << int(command_[1]) << "]"); +// logger.info().append("Read ID [%02x %02x]", command_[0], 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. @@ -512,11 +518,11 @@ void i8272::posit_event(int event_type) { // Performs read track. read_track: -// LOG(PADHEX(2) << "Read track [" -// << int(command_[2]) << " " -// << int(command_[3]) << " " -// << int(command_[4]) << " " -// << int(command_[5]) << "]"); +// logger.info().append("Read track [%02x %02x %02x %02x]" +// command_[2], +// command_[3], +// command_[4], +// command_[5]); // Wait for the index hole. WAIT_FOR_EVENT(Event::IndexHole); @@ -557,7 +563,7 @@ void i8272::posit_event(int event_type) { // Performs format [/write] track. format_track: - LOG("Format track"); + logger.info().append("Format track"); if(get_drive().get_is_read_only()) { status_.set(Status1::NotWriteable); goto abort; @@ -601,12 +607,8 @@ void i8272::posit_event(int event_type) { break; } - LOG(PADHEX(2) << "W:" - << int(header_[0]) << " " - << int(header_[1]) << " " - << int(header_[2]) << " " - << int(header_[3]) << ", " - << get_crc_generator().get_value()); + logger.info().append("W: %02x %02x %02x %02x, %04x", + header_[0], header_[1], header_[2], header_[3], get_crc_generator().get_value()); write_crc(); // Write the sector body. @@ -638,15 +640,15 @@ void i8272::posit_event(int event_type) { goto post_st012chrn; scan_low: - ERROR("Scan low unimplemented!!"); + logger.error().append("Scan low unimplemented!!"); goto wait_for_command; scan_low_or_equal: - ERROR("Scan low or equal unimplemented!!"); + logger.error().append("Scan low or equal unimplemented!!"); goto wait_for_command; scan_high_or_equal: - ERROR("Scan high or equal unimplemented!!"); + logger.error().append("Scan high or equal unimplemented!!"); goto wait_for_command; // Performs both recalibrate and seek commands. These commands occur asynchronously, so the actual work @@ -677,11 +679,11 @@ void i8272::posit_event(int event_type) { // up in run_for understands to mean 'keep going until track 0 is active'). if(command_.command() != Command::Recalibrate) { drives_[drive].target_head_position = command_.seek_target(); - LOG(PADHEX(2) << "Seek to " << int(command_.seek_target())); + logger.info().append("Seek to %d", command_.seek_target()); } else { drives_[drive].target_head_position = -1; drives_[drive].head_position = 0; - LOG("Recalibrate"); + logger.info().append("Recalibrate"); } // Check whether any steps are even needed; if not then mark as completed already. @@ -694,7 +696,7 @@ void i8272::posit_event(int event_type) { // Performs sense interrupt status. sense_interrupt_status: - LOG("Sense interrupt status"); + logger.info().append("Sense interrupt status"); { // Find the first drive that is in the CompletedSeeking state. int found_drive = -1; @@ -722,7 +724,7 @@ void i8272::posit_event(int event_type) { // Performs specify. specify: // Just store the values, and terminate the command. - LOG("Specify"); + logger.info().append("Specify"); step_rate_time_ = command_.specify_specs().step_rate_time; head_unload_time_ = command_.specify_specs().head_unload_time; head_load_time_ = command_.specify_specs().head_load_time; @@ -733,7 +735,7 @@ void i8272::posit_event(int event_type) { goto wait_for_command; sense_drive_status: - LOG("Sense drive status"); + logger.info().append("Sense drive status"); { int drive = command_.target().drive; select_drive(drive); @@ -772,11 +774,13 @@ 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(PADHEX(2) << "Result to " << int(command_[0] & 0x1f) << ", main " << int(main_status_) << "; "); -// for(std::size_t c = 0; c < result_stack_.size(); c++) { -// LOGNBR(" " << int(result_stack_[result_stack_.size() - 1 - c])); +// { +// auto line = logger.info(); +// line.append("Result to %02x, main %02x", command_[0] & 0x1f, main_status_); +// for(std::size_t c = 0; c < result_stack_.size(); c++) { +// line.append(" %02x", result_stack_[result_stack_.size() - 1 - c]); +// } // } -// LOGNBR(std::endl); // Set ready to send data to the processor, no longer in non-DMA execution phase. is_executing_ = false; diff --git a/Components/8530/z8530.cpp b/Components/8530/z8530.cpp index 3c3d68990..8077f0df6 100644 --- a/Components/8530/z8530.cpp +++ b/Components/8530/z8530.cpp @@ -262,7 +262,7 @@ void z8530::Channel::write(bool data, uint8_t pointer, uint8_t value) { switch((value >> 3)&7) { default: /* Do nothing. */ break; case 2: -// LOG("reset ext/status interrupts."); +// log.info().append("reset ext/status interrupts."); external_status_interrupt_ = false; external_interrupt_status_ = 0; break; diff --git a/Components/9918/Implementation/9918.cpp b/Components/9918/Implementation/9918.cpp index 0def9e79b..4539d43a2 100644 --- a/Components/9918/Implementation/9918.cpp +++ b/Components/9918/Implementation/9918.cpp @@ -22,6 +22,8 @@ namespace { constexpr unsigned int CRTCyclesPerLine = 1365; constexpr unsigned int CRTCyclesDivider = 4; +Log::Logger logger; + } template @@ -837,7 +839,7 @@ void Base::commit_register(int reg, uint8_t value) { Storage::solid_background_ = value & 0x20; Storage::sprites_enabled_ = !(value & 0x02); if(value & 0x01) { - LOG("TODO: Yamaha greyscale"); + logger.error().append("TODO: Yamaha greyscale"); } // b7: "1 = input on colour bus, enable mouse; 1 = output on colour bus, disable mouse" [documentation clearly in error] // b6: 1 = enable light pen @@ -854,7 +856,7 @@ void Base::commit_register(int reg, uint8_t value) { // TODO: on the Yamaha, at least, tie this interrupt overtly to vertical state. if(value & 0x08) { - LOG("TODO: Yamaha interlace mode"); + logger.error().append("TODO: Yamaha interlace mode"); } // b7: 1 = 212 lines of pixels; 0 = 192 @@ -918,7 +920,7 @@ void Base::commit_register(int reg, uint8_t value) { case 20: case 21: case 22: -// LOG("TODO: Yamaha colour burst selection; " << PADHEX(2) << +value); +// logger.error().append("TODO: Yamaha colour burst selection; %02x", value); // Documentation is "fill with 0s for no colour burst; magic pattern for colour burst" break; @@ -1004,7 +1006,7 @@ void Base::commit_register(int reg, uint8_t value) { // Kill the command immediately if it's done in zero operations // (e.g. a line of length 0). if(!Storage::command_ && (value >> 4)) { - LOG("TODO: Yamaha command " << PADHEX(2) << +value); + logger.error().append("TODO: Yamaha command %02x", value); } // Seed timing information if a command was found. diff --git a/Machines/Apple/AppleIIgs/ADB.cpp b/Machines/Apple/AppleIIgs/ADB.cpp index 97fa9dff2..283109af0 100644 --- a/Machines/Apple/AppleIIgs/ADB.cpp +++ b/Machines/Apple/AppleIIgs/ADB.cpp @@ -16,7 +16,6 @@ #include "../../../InstructionSets/M50740/Parser.hpp" #include "../../../InstructionSets/Disassembler.hpp" -#define LOG_PREFIX "[ADB GLU] " #include "../../../Outputs/Log.hpp" using namespace Apple::IIgs::ADB; @@ -40,6 +39,8 @@ enum class MicrocontrollerFlags: uint8_t { CommandRegisterFull = 0x40, }; +Log::Logger logger; + } GLU::GLU() : @@ -246,7 +247,7 @@ void GLU::set_port_output(int port, uint8_t value) { case 3: if(modifier_state_ != (value & 0x30)) { modifier_state_ = value & 0x30; - LOG("Modifier state: " << int(value & 0x30)); + logger.info().append("Modifier state: %02x", modifier_state_); } // Output is inverted respective to input; the microcontroller diff --git a/Machines/Atari/ST/AtariST.cpp b/Machines/Atari/ST/AtariST.cpp index 56dd9c0de..794338acf 100644 --- a/Machines/Atari/ST/AtariST.cpp +++ b/Machines/Atari/ST/AtariST.cpp @@ -29,7 +29,6 @@ #include "../../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp" -#define LOG_PREFIX "[ST] " #include "../../../Outputs/Log.hpp" #include "../../Utility/MemoryPacker.hpp" @@ -37,6 +36,10 @@ #include "../../../Analyser/Static/AtariST/Target.hpp" +namespace { +Log::Logger logger; +} + namespace Atari { namespace ST { @@ -186,7 +189,7 @@ class ConcreteMachine: // Check for assertion of reset. if(cycle.operation & CPU::MC68000::Operation::Reset) { - LOG("Unhandled Reset"); + logger.error().append("Unhandled Reset"); } // A null cycle leaves nothing else to do. diff --git a/Outputs/Log.hpp b/Outputs/Log.hpp index 3e980299b..e44207e4a 100644 --- a/Outputs/Log.hpp +++ b/Outputs/Log.hpp @@ -13,7 +13,7 @@ namespace Log { // But I prefer C files to C++ streams, so here it is for now. enum class Source { - ADB, + ADBGLU, Amiga, AmigaDisk, AmigaCopper, @@ -61,11 +61,16 @@ constexpr const char *prefix(Source source) { switch(source) { default: return nullptr; + case Source::ADBGLU: return "ADB GLU"; + case Source::AtariST: return "AtariST"; case Source::CommodoreStaticAnalyser: return "Commodore StaticAnalyser"; case Source::i8272: return "i8272"; case Source::NCR5380: return "5380"; case Source::SCSI: return "SCSI"; case Source::SCC: return "SCC"; + case Source::SZX: return "SZX"; + case Source::TapeUEF: return "UEF"; + case Source::TZX: return "TZX"; case Source::WDFDC: return "WD FDC"; } } diff --git a/Storage/State/SZX.cpp b/Storage/State/SZX.cpp index 064c82799..38b97bc72 100644 --- a/Storage/State/SZX.cpp +++ b/Storage/State/SZX.cpp @@ -25,6 +25,7 @@ namespace { constexpr uint32_t block(const char *str) { return uint32_t(str[0] | (str[1] << 8) | (str[2] << 16) | (str[3] << 24)); } +Log::Logger logger; } @@ -81,7 +82,7 @@ std::unique_ptr SZX::load(const std::string &file_name switch(blockID) { default: - LOG("Unhandled block " << char(blockID) << char(blockID >> 8) << char(blockID >> 16) << char(blockID >> 24)); + logger.info().append("Unhandled block %c%c%c%c", char(blockID), char(blockID >> 8), char(blockID >> 16), char(blockID >> 24)); break; // ZXSTZ80REGS diff --git a/Storage/Tape/Formats/TZX.cpp b/Storage/Tape/Formats/TZX.cpp index b082ae95f..230194425 100644 --- a/Storage/Tape/Formats/TZX.cpp +++ b/Storage/Tape/Formats/TZX.cpp @@ -14,8 +14,11 @@ using namespace Storage::Tape; namespace { -const unsigned int StandardTZXClock = 3500000; -const unsigned int TZXClockMSMultiplier = 3500; + +constexpr unsigned int StandardTZXClock = 3500000; +constexpr unsigned int TZXClockMSMultiplier = 3500; +Log::Logger logger; + } TZX::TZX(const std::string &file_name) : @@ -92,7 +95,7 @@ void TZX::get_next_pulses() { default: // In TZX each chunk has a different way of stating or implying its length, // so there is no route past an unimplemented chunk. - LOG("Unknown TZX chunk: " << PADHEX(4) << chunk_id); + logger.error().append("Unknown TZX chunk: %04x", chunk_id); set_is_at_end(true); return; } diff --git a/Storage/Tape/Formats/TapeUEF.cpp b/Storage/Tape/Formats/TapeUEF.cpp index b98211811..dd0d5c3fd 100644 --- a/Storage/Tape/Formats/TapeUEF.cpp +++ b/Storage/Tape/Formats/TapeUEF.cpp @@ -12,9 +12,14 @@ #include #include -#define LOG_PREFIX "[UEF] " #include "../../../Outputs/Log.hpp" +namespace { + +Log::Logger logger; + +} + // MARK: - ZLib extensions static float gzgetfloat(gzFile file) { @@ -156,7 +161,7 @@ void UEF::get_next_pulses() { break; default: - LOG("Skipping chunk of type " << PADHEX(4) << next_chunk.id); + logger.info().append("Skipping chunk of type %04x", next_chunk.id); break; }