1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-23 05:29:23 +00:00

Update logging.

This commit is contained in:
Thomas Harte 2024-01-19 15:38:40 -05:00
parent a1df2ef401
commit b5e3858c46
3 changed files with 68 additions and 69 deletions

View File

@ -8,11 +8,6 @@
#include "IWM.hpp"
#ifndef NDEBUG
#define NDEBUG
#endif
#define LOG_PREFIX "[IWM] "
#include "../../Outputs/Log.hpp"
using namespace Apple;
@ -27,6 +22,8 @@ namespace {
constexpr int Q6 = 1 << 6;
constexpr int Q7 = 1 << 7;
constexpr int SEL = 1 << 8; /* This is an additional input, not available on a Disk II, with a confusingly-similar name to SELECT but a distinct purpose. */
Log::Logger<Log::Source::IWM> logger;
}
IWM::IWM(int clock_rate) :
@ -55,7 +52,7 @@ uint8_t IWM::read(int address) {
switch(state_ & (Q6 | Q7 | ENABLE)) {
default:
LOG("Invalid read\n");
logger.info().append("Invalid read\n");
return 0xff;
// "Read all 1s".
@ -68,9 +65,9 @@ uint8_t IWM::read(int address) {
if(data_register_ & 0x80) {
data_register_ = 0;
// LOG("Reading data: " << PADHEX(2) << int(result));
// logger.info().append("Reading data: %02x", result);
}
// LOG("Reading data register: " << PADHEX(2) << int(result));
// logger.info().append("Reading data register: %02x", result);
return result;
}
@ -103,7 +100,7 @@ uint8_t IWM::read(int address) {
bit 6: 1 = write state (0 = underrun has occurred; 1 = no underrun so far).
bit 7: 1 = write data buffer ready for data (1 = ready; 0 = busy).
*/
// LOG("Reading write handshake: " << PADHEX(2) << int(0x3f | write_handshake_));
// logger.info().append("Reading write handshake: %02x", 0x3f | write_handshake_);
return 0x3f | write_handshake_;
}
@ -134,9 +131,9 @@ void IWM::write(int address, uint8_t input) {
// TEMPORARY. To test for the unimplemented mode.
if(input&0x2) {
LOG("Switched to asynchronous mode");
logger.info().append("Switched to asynchronous mode");
} else {
LOG("Switched to synchronous mode");
logger.info().append("Switched to synchronous mode");
}
switch(mode_ & 0x18) {
@ -145,8 +142,8 @@ void IWM::write(int address, uint8_t input) {
case 0x10: bit_length_ = Cycles(32); break; // slow mode, 8Mhz
case 0x18: bit_length_ = Cycles(16); break; // fast mode, 8Mhz
}
LOG("Mode is now " << PADHEX(2) << int(mode_));
LOG("New bit length is " << std::dec << bit_length_.as_integral());
logger.info().append("Mode is now %02x", mode_);
logger.info().append("New bit length is %d", bit_length_.as<int>());
break;
case Q7|Q6|ENABLE: // Write data register.
@ -260,7 +257,7 @@ void IWM::run_for(const Cycles cycles) {
drives_[active_drive_]->run_for(Cycles(1));
++cycles_since_shift_;
if(cycles_since_shift_ == bit_length_ + error_margin) {
// LOG("Shifting 0 at " << std::dec << cycles_since_shift_.as_integral());
// logger.info().append("Shifting 0 at %d ", cycles_since_shift_.as<int>());
propose_shift(0);
}
}
@ -294,11 +291,11 @@ void IWM::run_for(const Cycles cycles) {
if(!(write_handshake_ & 0x80)) {
shift_register_ = next_output_;
output_bits_remaining_ = 8;
// LOG("Next byte: " << PADHEX(2) << int(shift_register_));
// logger.info().append("Next byte: %02x", shift_register_);
} else {
write_handshake_ &= ~0x40;
if(drives_[active_drive_]) drives_[active_drive_]->end_writing();
LOG("Overrun; done.");
logger.info().append("Overrun; done.");
output_bits_remaining_ = 1;
}
@ -354,7 +351,7 @@ void IWM::select_shift_mode() {
shift_register_ = next_output_;
write_handshake_ |= 0x80 | 0x40;
output_bits_remaining_ = 8;
LOG("Seeding output with " << PADHEX(2) << int(shift_register_));
logger.info().append("Seeding output with %02x", shift_register_);
}
}
@ -368,7 +365,7 @@ void IWM::process_event(const Storage::Disk::Drive::Event &event) {
switch(event.type) {
case Storage::Disk::Track::Event::IndexHole: return;
case Storage::Disk::Track::Event::FluxTransition:
// LOG("Shifting 1 at " << std::dec << cycles_since_shift_.as_integral());
// logger.info().append("Shifting 1 at %d", cycles_since_shift_.as<int>());
propose_shift(1);
break;
}
@ -377,8 +374,8 @@ void IWM::process_event(const Storage::Disk::Drive::Event &event) {
void IWM::propose_shift(uint8_t bit) {
// TODO: synchronous mode.
// LOG("Shifting at " << std::dec << cycles_since_shift_.as_integral());
// LOG("Shifting input");
// logger.info().append("Shifting at %d", cycles_since_shift_.as<int>());
// logger.info().append("Shifting input");
// See above for text from the IWM patent, column 7, around line 35 onwards.
// The error_margin here implements the 'before' part of that contract.
@ -393,7 +390,7 @@ void IWM::propose_shift(uint8_t bit) {
shift_register_ = uint8_t((shift_register_ << 1) | bit);
if(shift_register_ & 0x80) {
// if(data_register_ & 0x80) LOG("Byte missed");
// if(data_register_ & 0x80) logger.info().append("Byte missed");
data_register_ = shift_register_;
shift_register_ = 0;
}

View File

@ -54,6 +54,7 @@ constexpr bool is_enabled(Source source) {
default: return true;
// The following are all things I'm not actively working on.
case Source::IWM:
case Source::MFP68901:
case Source::NCR5380:
case Source::SCC: return false;
@ -68,6 +69,7 @@ constexpr const char *prefix(Source source) {
case Source::AtariST: return "AtariST";
case Source::CommodoreStaticAnalyser: return "Commodore StaticAnalyser";
case Source::i8272: return "i8272";
case Source::IWM: return "IWM";
case Source::MFP68901: return "MFP68901";
case Source::MultiMachine: return "Multi machine";
case Source::NCR5380: return "5380";

View File

@ -14,9 +14,9 @@
using namespace Outputs::Display::OpenGL;
namespace {
// The below is disabled because it isn't context/thread-specific. Which makes it
// fairly 'unuseful'.
// Shader *bound_shader = nullptr;
// The below is disabled because it isn't context-specific. Work to do.
thread_local Shader *bound_shader = nullptr;
Log::Logger<Log::Source::OpenGL> logger;
}
GLuint Shader::compile_shader(const std::string &source, GLenum type) {
@ -25,22 +25,22 @@ GLuint Shader::compile_shader(const std::string &source, GLenum type) {
test_gl(glShaderSource, shader, 1, &c_str, NULL);
test_gl(glCompileShader, shader);
#ifndef NDEBUG
GLint isCompiled = 0;
test_gl(glGetShaderiv, shader, GL_COMPILE_STATUS, &isCompiled);
if(isCompiled == GL_FALSE) {
GLint logLength;
test_gl(glGetShaderiv, shader, GL_INFO_LOG_LENGTH, &logLength);
if(logLength > 0) {
const auto length = std::vector<GLchar>::size_type(logLength);
std::vector<GLchar> log(length);
test_gl(glGetShaderInfoLog, shader, logLength, &logLength, log.data());
LOG("Compile log:\n" << log.data());
}
if constexpr (logger.enabled) {
GLint isCompiled = 0;
test_gl(glGetShaderiv, shader, GL_COMPILE_STATUS, &isCompiled);
if(isCompiled == GL_FALSE) {
GLint logLength;
test_gl(glGetShaderiv, shader, GL_INFO_LOG_LENGTH, &logLength);
if(logLength > 0) {
const auto length = std::vector<GLchar>::size_type(logLength);
std::vector<GLchar> log(length);
test_gl(glGetShaderInfoLog, shader, logLength, &logLength, log.data());
logger.error().append("Compile log: %s", log.data());
}
throw (type == GL_VERTEX_SHADER) ? VertexShaderCompilationError : FragmentShaderCompilationError;
throw (type == GL_VERTEX_SHADER) ? VertexShaderCompilationError : FragmentShaderCompilationError;
}
}
#endif
return shader;
}
@ -69,41 +69,41 @@ void Shader::init(const std::string &vertex_shader, const std::string &fragment_
for(const auto &binding : attribute_bindings) {
test_gl(glBindAttribLocation, shader_program_, binding.index, binding.name.c_str());
#ifndef NDEBUG
const auto error = glGetError();
switch(error) {
case 0: break;
case GL_INVALID_VALUE:
LOG("GL_INVALID_VALUE when attempting to bind " << binding.name << " to index " << binding.index << " (i.e. index is greater than or equal to GL_MAX_VERTEX_ATTRIBS)");
break;
case GL_INVALID_OPERATION:
LOG("GL_INVALID_OPERATION when attempting to bind " << binding.name << " to index " << binding.index << " (i.e. name begins with gl_)");
break;
default:
LOG("Error " << error << " when attempting to bind " << binding.name << " to index " << binding.index);
break;
if constexpr (logger.enabled) {
const auto error = glGetError();
switch(error) {
case 0: break;
case GL_INVALID_VALUE:
logger.error().append("GL_INVALID_VALUE when attempting to bind %s to index %d (i.e. index is greater than or equal to GL_MAX_VERTEX_ATTRIBS)", binding.name.c_str(), binding.index);
break;
case GL_INVALID_OPERATION:
logger.error().append("GL_INVALID_OPERATION when attempting to bind %s to index %d (i.e. name begins with gl_)", binding.name.c_str(), binding.index);
break;
default:
logger.error().append("Error %d when attempting to bind %s to index %d", error, binding.name.c_str(), binding.index);
break;
}
}
#endif
}
test_gl(glLinkProgram, shader_program_);
#ifndef NDEBUG
GLint logLength;
test_gl(glGetProgramiv, shader_program_, GL_INFO_LOG_LENGTH, &logLength);
if(logLength > 0) {
GLchar *log = new GLchar[std::size_t(logLength)];
test_gl(glGetProgramInfoLog, shader_program_, logLength, &logLength, log);
LOG("Link log:\n" << log);
delete[] log;
}
if constexpr (logger.enabled) {
GLint logLength;
test_gl(glGetProgramiv, shader_program_, GL_INFO_LOG_LENGTH, &logLength);
if(logLength > 0) {
std::vector<GLchar> log(logLength);
test_gl(glGetProgramInfoLog, shader_program_, logLength, &logLength, log.data());
logger.error().append("Link log: %s", log.data());
}
GLint didLink = 0;
test_gl(glGetProgramiv, shader_program_, GL_LINK_STATUS, &didLink);
if(didLink == GL_FALSE) {
throw ProgramLinkageError;
GLint didLink = 0;
test_gl(glGetProgramiv, shader_program_, GL_LINK_STATUS, &didLink);
if(didLink == GL_FALSE) {
throw ProgramLinkageError;
}
}
#endif
}
Shader::~Shader() {
@ -139,7 +139,7 @@ void Shader::enable_vertex_attribute_with_pointer(const std::string &name, GLint
test_gl(glVertexAttribPointer, GLuint(location), size, type, normalised, stride, pointer);
test_gl(glVertexAttribDivisor, GLuint(location), divisor);
} else {
LOG("Couldn't enable vertex attribute " << name);
logger.error().append("Couldn't enable vertex attribute %s", name.c_str());
}
}
@ -147,10 +147,10 @@ void Shader::enable_vertex_attribute_with_pointer(const std::string &name, GLint
#define with_location(func, ...) {\
const GLint location = glGetUniformLocation(shader_program_, name.c_str()); \
if(location == -1) { \
LOG("Couldn't get location for uniform " << name); \
logger.error().append("Couldn't get location for uniform %s", name.c_str()); \
} else { \
func(location, __VA_ARGS__); \
if(glGetError()) LOG("Error setting uniform " << name << " via " << #func); \
if(glGetError()) logger.error().append("Error setting uniform %s via %s", name.c_str(), #func); \
} \
}