1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-11 00:52:13 +00:00
CLK/OSBindings/Mac/Clock SignalTests/Comparative68000.hpp

57 lines
1.5 KiB
C++
Raw Normal View History

//
// Comparative68000.hpp
// Clock SignalTests
//
// Created by Thomas Harte on 29/04/2019.
// Copyright © 2019 Thomas Harte. All rights reserved.
//
#pragma once
#include <zlib.h>
2023-05-10 22:13:01 +00:00
#include "68000.hpp"
2023-05-10 22:13:01 +00:00
class ComparativeBusHandler: public CPU::MC68000::BusHandler {
public:
ComparativeBusHandler(const char *trace_name) {
trace = gzopen(trace_name, "rt");
}
~ComparativeBusHandler() {
gzclose(trace);
}
void will_perform(uint32_t address, uint16_t) {
// Obtain the next line from the trace file.
char correct_state[300] = "\n";
gzgets(trace, correct_state, sizeof(correct_state));
++line_count;
// Generate state locally.
const auto state = get_state().registers;
char local_state[300];
2022-11-12 01:29:59 +00:00
snprintf(local_state, sizeof(local_state), "%04x: %02x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n",
address,
state.status,
state.data[0], state.data[1], state.data[2], state.data[3], state.data[4], state.data[5], state.data[6], state.data[7],
state.address[0], state.address[1], state.address[2], state.address[3], state.address[4], state.address[5], state.address[6],
state.stack_pointer()
);
// Check that the two coincide.
if(strcmp(correct_state, local_state)) {
fprintf(stderr, "Diverges at line %d\n", line_count);
2019-04-29 20:55:21 +00:00
fprintf(stderr, "Good: %s", correct_state);
fprintf(stderr, "Bad: %s", local_state);
throw std::exception();
}
}
2023-05-10 22:13:01 +00:00
virtual CPU::MC68000::State get_state() = 0;
private:
int line_count = 0;
gzFile trace;
};