1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-17 21:30:14 +00:00

Continue conversion of logging.

This commit is contained in:
Thomas Harte 2024-01-19 22:02:26 -05:00
parent b5e3858c46
commit b61317ba7e
14 changed files with 107 additions and 78 deletions

View File

@ -12,9 +12,7 @@
#include "../../Outputs/Log.hpp"
namespace {
Log::Logger<Log::Source::WDFDC> logger;
}
using namespace WD;

View File

@ -8,19 +8,18 @@
#include "Executor.hpp"
#include "../../Machines/Utility/MemoryFuzzer.hpp"
#include "../../Outputs/Log.hpp"
#include <algorithm>
#include <cassert>
#include <cstring>
#include "../../Machines/Utility/MemoryFuzzer.hpp"
#define LOG_PREFIX "[M50740] "
#include "../../Outputs/Log.hpp"
using namespace InstructionSet::M50740;
namespace {
constexpr int port_remap[] = {0, 1, 2, 0, 3};
Log::Logger<Log::Source::M50740> logger;
}
Executor::Executor(PortHandler &port_handler) : port_handler_(port_handler) {
@ -83,13 +82,13 @@ uint8_t Executor::read(uint16_t address) {
port_handler_.run_ports_for(cycles_since_port_handler_.flush<Cycles>());
switch(address) {
default:
LOG("Unrecognised read from " << PADHEX(4) << address);
logger.error().append("Unrecognised read from %02x", address);
return 0xff;
// "Port R"; sixteen four-bit ports
case 0xd0: case 0xd1: case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd6: case 0xd7:
case 0xd8: case 0xd9: case 0xda: case 0xdb: case 0xdc: case 0xdd: case 0xde: case 0xdf:
LOG("Unimplemented Port R read from " << PADHEX(4) << address);
logger.error().append("Unimplemented Port R read from %04x", address);
return 0x00;
// Ports P0P3.
@ -134,7 +133,7 @@ void Executor::write(uint16_t address, uint8_t value) {
// ROM 'writes' are almost as easy (albeit unexpected).
if(address >= 0x100) {
LOG("Attempted ROM write of " << PADHEX(2) << value << " to " << PADHEX(4) << address);
logger.info().append("Attempted ROM write of %02x to %04x", value, address);
return;
}
@ -143,13 +142,13 @@ void Executor::write(uint16_t address, uint8_t value) {
switch(address) {
default:
LOG("Unrecognised write of " << PADHEX(2) << value << " to " << PADHEX(4) << address);
logger.error().append("Unrecognised write of %02x to %04x", value, address);
break;
// "Port R"; sixteen four-bit ports
case 0xd0: case 0xd1: case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd6: case 0xd7:
case 0xd8: case 0xd9: case 0xda: case 0xdb: case 0xdc: case 0xdd: case 0xde: case 0xdf:
LOG("Unimplemented Port R write of " << PADHEX(2) << value << " from " << PADHEX(4) << address);
logger.error().append("Unimplemented Port R write of %02x to %04x", value, address);
break;
// Ports P0P3.
@ -779,7 +778,7 @@ template <Operation operation> void Executor::perform(uint8_t *operand [[maybe_u
*/
default:
LOG("Unimplemented operation: " << operation);
logger.error().append("Unimplemented operation: %d", operation);
assert(false);
}
#undef set_nz
@ -823,13 +822,13 @@ inline void Executor::subtract_duration(int duration) {
}
} break;
case 0x04:
LOG("TODO: Timer X; Pulse output mode");
logger.error().append("TODO: Timer X; Pulse output mode");
break;
case 0x08:
LOG("TODO: Timer X; Event counter mode");
logger.error().append("TODO: Timer X; Event counter mode");
break;
case 0x0c:
LOG("TODO: Timer X; Pulse width measurement mode");
logger.error().append("TODO: Timer X; Pulse width measurement mode");
break;
}
}

View File

@ -6,15 +6,10 @@
// Copyright © 2021 Thomas Harte. All rights reserved.
//
#ifndef NDEBUG
#define NDEBUG
#endif
#define LOG_PREFIX "[Copper] "
#include "../../Outputs/Log.hpp"
#include "Chipset.hpp"
#include "Copper.hpp"
#include "Chipset.hpp"
#include "../../Outputs/Log.hpp"
using namespace Amiga;
@ -31,6 +26,8 @@ bool satisfies_raster(uint16_t position, uint16_t blitter_status, uint16_t *inst
return (position & mask) >= (instruction[0] & mask);
}
Log::Logger<Log::Source::AmigaCopper> logger;
}
//
@ -85,7 +82,7 @@ bool Copper::advance_dma(uint16_t position, uint16_t blitter_status) {
case State::Waiting:
if(satisfies_raster(position, blitter_status, instruction_)) {
LOG("Unblocked waiting for " << PADHEX(4) << instruction_[0] << " at " << PADHEX(4) << position << " with mask " << PADHEX(4) << (instruction_[1] & 0x7ffe));
logger.info().append("Unblocked waiting for %04x at %04x with mask %04x", instruction_[0], position, instruction_[1] & 0x7ffe);
state_ = State::FetchFirstWord;
}
return false;
@ -94,7 +91,7 @@ bool Copper::advance_dma(uint16_t position, uint16_t blitter_status) {
instruction_[0] = ram_[address_ & ram_mask_];
++address_;
state_ = State::FetchSecondWord;
LOG("First word fetch at " << PADHEX(4) << position);
logger.info().append("First word fetch at %04x", position);
break;
case State::FetchSecondWord: {
@ -105,7 +102,7 @@ bool Copper::advance_dma(uint16_t position, uint16_t blitter_status) {
// Read in the second instruction word.
instruction_[1] = ram_[address_ & ram_mask_];
++address_;
LOG("Second word fetch at " << PADHEX(4) << position);
logger.info().append("Second word fetch at %04x", position);
// Check for a MOVE.
if(!(instruction_[0] & 1)) {
@ -113,7 +110,7 @@ bool Copper::advance_dma(uint16_t position, uint16_t blitter_status) {
// Stop if this move would be a privilege violation.
instruction_[0] &= 0x1fe;
if((instruction_[0] < 0x10) || (instruction_[0] < 0x20 && !(control_&1))) {
LOG("Invalid MOVE to " << PADHEX(4) << instruction_[0] << "; stopping");
logger.info().append("Invalid MOVE to %04x; stopping", instruction_[0]);
state_ = State::Stopped;
break;
}

View File

@ -8,13 +8,12 @@
#include "Chipset.hpp"
#ifndef NDEBUG
#define NDEBUG
#endif
#define LOG_PREFIX "[Disk] "
#include "../../Outputs/Log.hpp"
namespace {
Log::Logger<Log::Source::AmigaDisk> logger;
}
using namespace Amiga;
// MARK: - Disk DMA.
@ -46,7 +45,7 @@ void Chipset::DiskDMA::set_length(uint16_t value) {
buffer_read_ = buffer_write_ = 0;
if(dma_enable_) {
LOG("Disk DMA " << (write_ ? "write" : "read") << " of " << length_ << " to " << PADHEX(8) << pointer_[0]);
logger.info().append("Disk DMA %s of %d to %08x", write_ ? "write" : "read", length_, pointer_[0]);
}
state_ = sync_with_word_ ? State::WaitingForSync : State::Reading;
@ -110,7 +109,7 @@ void Chipset::DiskController::process_input_bit(int value) {
}
void Chipset::DiskController::set_sync_word(uint16_t value) {
LOG("Set disk sync word to " << PADHEX(4) << value);
logger.info().append("Set disk sync word to %04x", value);
sync_word_ = value;
}
@ -128,7 +127,7 @@ void Chipset::DiskController::set_control(uint16_t control) {
bit_length.clock_rate = (control & 0x100) ? 500000 : 250000;
set_expected_bit_length(bit_length);
LOG((sync_with_word_ ? "Will" : "Won't") << " sync with word; bit length is " << ((control & 0x100) ? "short" : "long"));
logger.info().append("%s sync with word; bit length is %s", sync_with_word_ ? "Will" : "Won't", (control & 0x100) ? "short" : "long");
}
void Chipset::DiskController::process_index_hole() {
@ -182,7 +181,7 @@ void Chipset::DiskController::set_mtr_sel_side_dir_step(uint8_t value) {
// ID and definitely latch the new motor state.
if(!is_selected) {
drive_ids_[c] <<= 1;
LOG("Shifted drive ID shift register for drive " << +c << " to " << PADHEX(4) << std::bitset<16>{drive_ids_[c]});
logger.info().append("Shifted drive ID shift register for drive %d to %08x", c, drive_ids_[c]);
} else {
// Motor transition on -> off => reload register.
if(!motor_on && drive.get_motor_on()) {
@ -191,7 +190,7 @@ void Chipset::DiskController::set_mtr_sel_side_dir_step(uint8_t value) {
// 0x5555'5555 = 5.25" drive;
// 0x0000'0000 = no drive.
drive_ids_[c] = 0xffff'ffff;
LOG("Reloaded drive ID shift register for drive " << +c);
logger.info().append("Reloaded drive ID shift register for drive %d", c);
}
// Also latch the new motor state.
@ -204,7 +203,7 @@ void Chipset::DiskController::set_mtr_sel_side_dir_step(uint8_t value) {
// Possibly step.
if(did_step && is_selected) {
LOG("Stepped drive " << +c << " by " << std::dec << +direction.as_int());
logger.info().append("Stepped drive %d by %d", c, direction.as_int());
drive.step(direction);
}
}

View File

@ -8,11 +8,14 @@
#include "ReactiveDevice.hpp"
#define LOG_PREFIX "[ADB device] "
#include "../../../Outputs/Log.hpp"
using namespace Apple::ADB;
namespace {
Log::Logger<Log::Source::ADBDevice> logger;
}
ReactiveDevice::ReactiveDevice(Apple::ADB::Bus &bus, uint8_t adb_device_id) :
bus_(bus),
device_id_(bus.add_device(this)),
@ -125,7 +128,7 @@ void ReactiveDevice::adb_bus_did_observe_event(Bus::Event event, uint8_t value)
phase_ = Phase::AwaitingAttention;
command_ = decode_command(value);
// LOG(command_);
// logger.info().append("%d", command_);
// If this command doesn't apply here, but a service request is requested,
// post a service request.

View File

@ -50,7 +50,7 @@ namespace {
constexpr int CLOCK_RATE = 7833600;
constexpr auto KEYBOARD_CLOCK_RATE = HalfCycles(CLOCK_RATE / 100000);
Log::Logger<Log::Source::Macintosh> logger;
// Former default PRAM:
//
@ -723,7 +723,7 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
if(port == Port::B && line == Line::Two) {
keyboard_.set_input(value);
}
else LOG("Unhandled control line output: " << (port ? 'B' : 'A') << int(line));
else logger.error().append("Unhandled 6522 control line output: %c%d", port ? 'B' : 'A', int(line));
}
void run_for(HalfCycles duration) {

View File

@ -8,10 +8,13 @@
#include "IntelligentKeyboard.hpp"
#include "../../../Outputs/Log.hpp"
#include <algorithm>
#define LOG_PREFIX "[IKYB] "
#include "../../../Outputs/Log.hpp"
namespace {
Log::Logger<Log::Source::IntelligentKeyboard> logger;
}
using namespace Atari::ST;
@ -157,7 +160,7 @@ void IntelligentKeyboard::dispatch_command(uint8_t command) {
// If not, exit. If so, perform and drop out of the switch.
switch(command_sequence_.front()) {
default:
LOG("Unrecognised IKBD command " << PADHEX(2) << +command);
logger.error().append("Unrecognised IKBD command %02x", command);
break;
case 0x80:
@ -260,11 +263,11 @@ void IntelligentKeyboard::reset() {
}
void IntelligentKeyboard::resume() {
LOG("Unimplemented: resume");
logger.error().append("Unimplemented: resume");
}
void IntelligentKeyboard::pause() {
LOG("Unimplemented: pause");
logger.error().append("Unimplemented: pause");
}
void IntelligentKeyboard::disable_mouse() {
@ -287,7 +290,7 @@ void IntelligentKeyboard::set_mouse_position(uint16_t x, uint16_t y) {
}
void IntelligentKeyboard::set_mouse_keycode_reporting(uint8_t, uint8_t) {
LOG("Unimplemented: set mouse keycode reporting");
logger.error().append("Unimplemented: set mouse keycode reporting");
}
void IntelligentKeyboard::set_mouse_threshold(uint8_t x, uint8_t y) {
@ -309,7 +312,7 @@ void IntelligentKeyboard::set_mouse_y_upward() {
}
void IntelligentKeyboard::set_mouse_button_actions(uint8_t) {
LOG("Unimplemented: set mouse button actions");
logger.error().append("Unimplemented: set mouse button actions");
}
void IntelligentKeyboard::interrogate_mouse_position() {
@ -499,9 +502,9 @@ void IntelligentKeyboard::interrogate_joysticks() {
}
void IntelligentKeyboard::set_joystick_monitoring_mode(uint8_t) {
LOG("Unimplemented: joystick monitoring mode");
logger.error().append("Unimplemented: joystick monitoring mode");
}
void IntelligentKeyboard::set_joystick_fire_button_monitoring_mode() {
LOG("Unimplemented: joystick fire button monitoring mode");
logger.error().append("Unimplemented: joystick fire button monitoring mode");
}

View File

@ -36,6 +36,10 @@
#include <array>
#include <cstdint>
namespace {
Log::Logger<Log::Source::Vic20> logger;
}
namespace Commodore::Vic20 {
enum ROMSlot {
@ -530,12 +534,12 @@ class ConcreteMachine:
const uint16_t tape_buffer_pointer = uint16_t(ram_[0xb2]) | uint16_t(ram_[0xb3] << 8);
header->serialise(&ram_[tape_buffer_pointer], 0x8000 - tape_buffer_pointer);
hold_tape_ = true;
LOG("Vic-20: Found header");
logger.info().append("Found header");
} else {
// no header found, so pretend this hack never interceded
tape_->get_tape()->set_offset(tape_position);
hold_tape_ = false;
LOG("Vic-20: Didn't find header");
logger.info().append("Didn't find header");
}
// clear status and the verify flag
@ -576,11 +580,11 @@ class ConcreteMachine:
m6502_.set_value_of(CPU::MOS6502::Register::ProgramCounter, 0xfccf);
*value = 0xea; // i.e. NOP implied
hold_tape_ = true;
LOG("Vic-20: Found data");
logger.info().append("Found data");
} else {
tape_->get_tape()->set_offset(tape_position);
hold_tape_ = false;
LOG("Vic-20: Didn't find data");
logger.info().append("Didn't find data");
}
}
}

View File

@ -18,11 +18,13 @@
#include "../../Analyser/Static/Enterprise/Target.hpp"
#include "../../ClockReceiver/JustInTime.hpp"
#include "../../Outputs/Log.hpp"
#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp"
#include "../../Processors/Z80/Z80.hpp"
#define LOG_PREFIX "[Enterprise] "
#include "../../Outputs/Log.hpp"
namespace {
Log::Logger<Log::Source::Enterprise> logger;
}
namespace Enterprise {
@ -347,7 +349,7 @@ template <bool has_disk_controller, bool is_6mhz> class ConcreteMachine:
case PartialMachineCycle::Input:
switch(address & 0xff) {
default:
LOG("Unhandled input from " << PADHEX(2) << (address & 0xff));
logger.error().append("Unhandled input from %02x", address & 0xff);
*cycle.value = 0xff;
break;
@ -412,7 +414,7 @@ template <bool has_disk_controller, bool is_6mhz> class ConcreteMachine:
case PartialMachineCycle::Output:
switch(address & 0xff) {
default:
LOG("Unhandled output: " << PADHEX(2) << *cycle.value << " to " << PADHEX(2) << (address & 0xff));
logger.error().append("Unhandled output: %02x to %02x", *cycle.value, address & 0xff);
break;
case 0x10: case 0x11: case 0x12: case 0x13:
@ -511,12 +513,12 @@ template <bool has_disk_controller, bool is_6mhz> class ConcreteMachine:
break;
case 0xb6:
// Just 8 bits of printer data.
LOG("TODO: printer output " << PADHEX(2) << *cycle.value);
logger.info().append("TODO: printer output: %02x", *cycle.value);
break;
case 0xb7:
// b0 = serial data out
// b1 = serial status out
LOG("TODO: serial output " << PADHEX(2) << *cycle.value);
logger.info().append("TODO: serial output: %02x", *cycle.value);
break;
}
break;

View File

@ -49,6 +49,10 @@
#include "../../Analyser/Static/MSX/Target.hpp"
namespace {
Log::Logger<Log::Source::MSX> logger;
}
namespace MSX {
class AYPortHandler: public GI::AY38910::PortHandler {
@ -874,14 +878,14 @@ class ConcreteMachine:
// b0-b3: keyboard line
machine_.set_keyboard_line(value & 0xf);
} break;
default: LOG("Unrecognised: MSX set 8255 output port " << port << " to value " << PADHEX(2) << value); break;
default: logger.error().append("Unrecognised: MSX set 8255 output port %d to value %02x", port, value); break;
}
}
uint8_t get_value(int port) {
if(port == 1) {
return machine_.read_keyboard();
} else LOG("MSX attempted to read from 8255 port " << port);
} else logger.error().append("MSX attempted to read from 8255 port %d");
return 0xff;
}

View File

@ -23,7 +23,6 @@
#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp"
#include "../../Outputs/Speaker/Implementation/CompoundSource.hpp"
#define LOG_PREFIX "[SMS] "
#include "../../Outputs/Log.hpp"
#include "../../Analyser/Static/Sega/Target.hpp"
@ -34,6 +33,7 @@
namespace {
constexpr int audio_divider = 1;
Log::Logger<Log::Source::MasterSystem> logger;
}
namespace Sega {
@ -255,17 +255,17 @@ template <Analyser::Static::Sega::Target::Model model> class ConcreteMachine:
}
if(write_pointers_[address >> 10]) write_pointers_[address >> 10][address & 1023] = *cycle.value;
// else LOG("Ignored write to ROM");
// else logger.info().append("Ignored write to ROM");
break;
case CPU::Z80::PartialMachineCycle::Input:
switch(address & 0xc1) {
case 0x00:
LOG("TODO: [input] memory control");
logger.error().append("TODO: [input] memory control");
*cycle.value = 0xff;
break;
case 0x01:
LOG("TODO: [input] I/O port control");
logger.error().append("TODO: [input] I/O port control");
*cycle.value = 0xff;
break;
case 0x40:
@ -305,7 +305,7 @@ template <Analyser::Static::Sega::Target::Model model> class ConcreteMachine:
} break;
default:
ERROR("[input] Clearly some sort of typo");
logger.error().append("[input] Clearly some sort of typo");
break;
}
break;
@ -315,7 +315,7 @@ template <Analyser::Static::Sega::Target::Model model> class ConcreteMachine:
case 0x00: // i.e. even ports less than 0x40.
if constexpr (is_master_system(model)) {
// TODO: Obey the RAM enable.
LOG("Memory control: " << PADHEX(2) << +memory_control_);
logger.info().append("Memory control: %02x", memory_control_);
memory_control_ = *cycle.value;
page_cartridge();
}
@ -357,7 +357,7 @@ template <Analyser::Static::Sega::Target::Model model> class ConcreteMachine:
break;
default:
ERROR("[output] Clearly some sort of typo");
logger.error().append("[output] Clearly some sort of typo");
break;
}
break;

View File

@ -8,11 +8,15 @@
#pragma once
#include <cstdio>
#include <cstdarg>
namespace Log {
// TODO: if adopting C++20, std::format would be a better model to apply below.
// But I prefer C files to C++ streams, so here it is for now.
enum class Source {
ADBDevice,
ADBGLU,
Amiga,
AmigaDisk,
@ -41,6 +45,7 @@ enum class Source {
TapeUEF,
TMS9918,
TZX,
Vic20,
WDFDC,
};
@ -54,6 +59,8 @@ constexpr bool is_enabled(Source source) {
default: return true;
// The following are all things I'm not actively working on.
case Source::AmigaCopper:
case Source::AmigaDisk:
case Source::IWM:
case Source::MFP68901:
case Source::NCR5380:
@ -65,27 +72,35 @@ constexpr const char *prefix(Source source) {
switch(source) {
default: return nullptr;
case Source::ADBDevice: return "ADB device";
case Source::ADBGLU: return "ADB GLU";
case Source::AmigaCopper: return "Copper";
case Source::AmigaDisk: return "Disk";
case Source::AtariST: return "AtariST";
case Source::CommodoreStaticAnalyser: return "Commodore StaticAnalyser";
case Source::CommodoreStaticAnalyser: return "Commodore Static Analyser";
case Source::Enterprise: return "Enterprise";
case Source::i8272: return "i8272";
case Source::IntelligentKeyboard: return "IKYB";
case Source::IWM: return "IWM";
case Source::M50740: return "M50740";
case Source::Macintosh: return "Macintosh";
case Source::MasterSystem: return "SMS";
case Source::MFP68901: return "MFP68901";
case Source::MultiMachine: return "Multi machine";
case Source::MultiMachine: return "Multi-machine";
case Source::MSX: return "MSX";
case Source::NCR5380: return "5380";
case Source::OpenGL: return "OpenGL";
case Source::PCMTrack: return "PCM Track";
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::Vic20: return "Vic20";
case Source::WDFDC: return "WD FDC";
}
}
#include <cstdio>
#include <cstdarg>
template <Source source>
class Logger {
public:

View File

@ -60,6 +60,8 @@ constexpr GLenum formatForDepth(std::size_t depth) {
}
}
Log::Logger<Log::Source::OpenGL> logger;
}
template <typename T> void ScanTarget::allocate_buffer(const T &array, GLuint &buffer_name, GLuint &vertex_array_name) {
@ -343,7 +345,7 @@ void ScanTarget::update(int, int output_height) {
// Work with the accumulation_buffer_ potentially starts from here onwards; set its flag.
while(is_drawing_to_accumulation_buffer_.test_and_set());
if(did_create_accumulation_texture) {
LOG("Changed output resolution to " << proportional_width << " by " << framebuffer_height);
logger.info().append("Changed output resolution to %d by %d", proportional_width, framebuffer_height);
display_metrics_.announce_did_resize();
std::unique_ptr<OpenGL::TextureTarget> new_framebuffer(
new TextureTarget(

View File

@ -55,7 +55,10 @@ class ScanTarget: public Outputs::Display::BufferingScanTarget { // TODO: use pr
struct OpenGLVersionDumper {
OpenGLVersionDumper() {
// Note the OpenGL version, as the first thing this class does prior to construction.
LOG("Constructing scan target with OpenGL " << glGetString(GL_VERSION) << "; shading language version " << glGetString(GL_SHADING_LANGUAGE_VERSION));
Log::Logger<Log::Source::OpenGL>().info().append(
"Constructing scan target with OpenGL %s; shading language version %s",
glGetString(GL_VERSION),
glGetString(GL_SHADING_LANGUAGE_VERSION));
}
} dumper_;
#endif