mirror of
https://github.com/TomHarte/CLK.git
synced 2026-04-22 08:16:42 +00:00
Reintroduce proper ordering of log comments.
This commit is contained in:
@@ -347,7 +347,8 @@ private:
|
||||
break;
|
||||
|
||||
case Command::WriteCommandByte:
|
||||
// is_tested_ = input_ & 0x4;
|
||||
control_ = input_;
|
||||
check_irqs();
|
||||
// TODO:
|
||||
// b0: 1 = enable first PS/2 port interrupt;
|
||||
// b1: 1 = enable second port interrupt;
|
||||
@@ -393,6 +394,7 @@ private:
|
||||
PICs<model> &pics_;
|
||||
Speaker &speaker_;
|
||||
CPUControl<model> *cpu_control_ = nullptr;
|
||||
uint8_t control_ = 0;
|
||||
|
||||
// Strongly coupled to specific code in the 5170 BIOS, this provides a grossly-inaccurate
|
||||
// linkage between execution speed (-ish) and DRAM refresh. An unambguous nonsense.
|
||||
@@ -472,7 +474,7 @@ private:
|
||||
bool has_output() const {
|
||||
return
|
||||
output_.has_output() ||
|
||||
(keyboard_.output().has_output() && enabled_);
|
||||
(keyboard_.output().has_output() && enabled_ && !(control_ & 0x10));
|
||||
}
|
||||
|
||||
uint8_t next_output() {
|
||||
@@ -480,7 +482,7 @@ private:
|
||||
return output_.next();
|
||||
}
|
||||
|
||||
if(keyboard_.output().has_output() && enabled_) {
|
||||
if(keyboard_.output().has_output() && enabled_ && !(control_ & 0x10)) {
|
||||
return keyboard_.output().next();
|
||||
}
|
||||
|
||||
@@ -489,7 +491,9 @@ private:
|
||||
}
|
||||
|
||||
void check_irqs() {
|
||||
pics_.pic[0].template apply_edge<1>(has_output());
|
||||
pics_.pic[0].template apply_edge<1>(has_output() && (control_ & 1)); // Not sure about whether that bit should inhibit
|
||||
// keyboard controller IRQs. Or if the controller
|
||||
// itself should even trigger them.
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+32
-28
@@ -96,7 +96,7 @@ constexpr EnabledLevel enabled_level(const Source source) {
|
||||
case Source::SCC:
|
||||
case Source::SCSI:
|
||||
case Source::I2C:
|
||||
case Source::PCPOST:
|
||||
// case Source::PCPOST:
|
||||
return EnabledLevel::None;
|
||||
|
||||
case Source::Floppy:
|
||||
@@ -159,39 +159,48 @@ constexpr const char *prefix(const Source source) {
|
||||
template <Source source, bool enabled>
|
||||
struct LogLine;
|
||||
|
||||
template <bool enabled> struct RepeatAccumulator {};
|
||||
template <> struct RepeatAccumulator<true> {
|
||||
struct RepeatAccumulator {
|
||||
std::string last;
|
||||
Source source;
|
||||
|
||||
size_t count = 0;
|
||||
FILE *stream;
|
||||
};
|
||||
|
||||
template <Source source>
|
||||
struct LogLine<source, true> {
|
||||
public:
|
||||
explicit LogLine(RepeatAccumulator<true> &accumulator, FILE *const stream) noexcept :
|
||||
accumulator_(accumulator), stream_(stream) {}
|
||||
explicit LogLine(FILE *const stream) noexcept :
|
||||
stream_(stream) {}
|
||||
|
||||
~LogLine() {
|
||||
if(output_ == accumulator_.last) {
|
||||
++accumulator_.count;
|
||||
thread_local RepeatAccumulator accumulator;
|
||||
|
||||
if(output_ == accumulator.last && source == accumulator.source && stream_ == accumulator.stream) {
|
||||
++accumulator.count;
|
||||
return;
|
||||
}
|
||||
|
||||
static constexpr auto unadorned_prefix = prefix(source);
|
||||
std::string prefix;
|
||||
if(unadorned_prefix) {
|
||||
prefix = "[";
|
||||
prefix += unadorned_prefix;
|
||||
prefix += "] ";
|
||||
if(!accumulator.last.empty()) {
|
||||
const char *const unadorned_prefix = prefix(accumulator.source);
|
||||
std::string prefix;
|
||||
if(unadorned_prefix) {
|
||||
prefix = "[";
|
||||
prefix += unadorned_prefix;
|
||||
prefix += "] ";
|
||||
}
|
||||
|
||||
if(accumulator.count > 1) {
|
||||
fprintf(accumulator.stream, "%s%s [* %zu]\n", prefix.c_str(), accumulator.last.c_str(), accumulator.count);
|
||||
} else {
|
||||
fprintf(accumulator.stream, "%s%s\n", prefix.c_str(), accumulator.last.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if(accumulator_.count > 1) {
|
||||
fprintf(stream_, "%s%s [* %zu]\n", prefix.c_str(), accumulator_.last.c_str(), accumulator_.count);
|
||||
} else {
|
||||
fprintf(stream_, "%s%s\n", prefix.c_str(), accumulator_.last.c_str());
|
||||
}
|
||||
accumulator_.count = 1;
|
||||
accumulator_.last = output_;
|
||||
accumulator.count = 1;
|
||||
accumulator.last = output_;
|
||||
accumulator.source = source;
|
||||
accumulator.stream = stream_;
|
||||
}
|
||||
|
||||
template <size_t size, typename... Args>
|
||||
@@ -214,14 +223,13 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
RepeatAccumulator<true> &accumulator_;
|
||||
FILE *stream_;
|
||||
std::string output_;
|
||||
};
|
||||
|
||||
template <Source source>
|
||||
struct LogLine<source, false> {
|
||||
explicit LogLine(RepeatAccumulator<false> &, FILE *) noexcept {}
|
||||
explicit LogLine(FILE *) noexcept {}
|
||||
|
||||
template <size_t size, typename... Args>
|
||||
auto &append(const char (&)[size], Args...) { return *this; }
|
||||
@@ -236,12 +244,8 @@ public:
|
||||
static constexpr bool InfoEnabled = enabled_level(source) == EnabledLevel::ErrorsAndInfo;
|
||||
static constexpr bool ErrorsEnabled = enabled_level(source) >= EnabledLevel::Errors;
|
||||
|
||||
auto info() { return LogLine<source, InfoEnabled>(last_info_, stdout); }
|
||||
auto error() { return LogLine<source, ErrorsEnabled>(last_error_, stderr); }
|
||||
|
||||
private:
|
||||
RepeatAccumulator<InfoEnabled> last_info_;
|
||||
RepeatAccumulator<ErrorsEnabled> last_error_;
|
||||
static auto info() { return LogLine<source, InfoEnabled>(stdout); }
|
||||
static auto error() { return LogLine<source, ErrorsEnabled>(stderr); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user