2022-06-07 01:19:57 +00:00
|
|
|
//
|
|
|
|
// 68000ArithmeticTests.m
|
|
|
|
// Clock SignalTests
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 28/06/2019.
|
|
|
|
//
|
|
|
|
// Largely ported from the tests of the Portable 68k Emulator.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import <XCTest/XCTest.h>
|
|
|
|
|
|
|
|
#include "68000.hpp"
|
|
|
|
#include "68000Mk2.hpp"
|
|
|
|
|
2022-06-07 20:56:05 +00:00
|
|
|
#include <array>
|
2022-06-08 18:43:51 +00:00
|
|
|
#include <unordered_map>
|
2022-06-09 17:13:33 +00:00
|
|
|
#include <set>
|
2022-06-07 20:56:05 +00:00
|
|
|
|
2022-06-07 01:19:57 +00:00
|
|
|
namespace {
|
|
|
|
|
2022-06-08 18:43:51 +00:00
|
|
|
struct RandomStore {
|
|
|
|
using CollectionT = std::unordered_map<uint32_t, std::pair<uint8_t, uint8_t>>;
|
|
|
|
CollectionT values;
|
|
|
|
|
|
|
|
void flag(uint32_t address, uint8_t participant) {
|
|
|
|
values[address].first |= participant;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool has(uint32_t address, uint8_t participant) {
|
|
|
|
auto entry = values.find(address);
|
|
|
|
if(entry == values.end()) return false;
|
|
|
|
return entry->second.first & participant;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t value(uint32_t address, uint8_t participant) {
|
|
|
|
auto entry = values.find(address);
|
|
|
|
if(entry != values.end()) {
|
|
|
|
entry->second.first |= participant;
|
|
|
|
return entry->second.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t value = uint8_t(rand() >> 8);
|
|
|
|
values[address] = std::make_pair(participant, value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
values.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-06-07 20:56:05 +00:00
|
|
|
struct Transaction {
|
2022-06-08 13:49:27 +00:00
|
|
|
HalfCycles timestamp;
|
2022-06-07 20:56:05 +00:00
|
|
|
uint8_t function_code = 0;
|
|
|
|
uint32_t address = 0;
|
|
|
|
uint16_t value = 0;
|
|
|
|
bool address_strobe = false;
|
2022-06-08 18:53:04 +00:00
|
|
|
bool read = false;
|
2022-06-13 14:39:06 +00:00
|
|
|
int data_strobes = 0;
|
2022-06-07 20:56:05 +00:00
|
|
|
|
2022-06-08 13:49:27 +00:00
|
|
|
bool operator !=(const Transaction &rhs) const {
|
2022-06-10 20:12:54 +00:00
|
|
|
if(timestamp != rhs.timestamp) return true;
|
2022-06-08 18:43:51 +00:00
|
|
|
// if(function_code != rhs.function_code) return true;
|
2022-06-08 14:51:05 +00:00
|
|
|
if(address != rhs.address) return true;
|
|
|
|
if(value != rhs.value) return true;
|
|
|
|
if(address_strobe != rhs.address_strobe) return true;
|
2022-06-13 14:39:06 +00:00
|
|
|
if(data_strobes != rhs.data_strobes) return true;
|
2022-06-07 20:56:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-06-08 14:51:05 +00:00
|
|
|
|
|
|
|
void print() const {
|
2022-06-13 14:39:06 +00:00
|
|
|
printf("%d: %d%d%d %c %c%c @ %06x %s %04x\n",
|
2022-06-08 14:51:05 +00:00
|
|
|
timestamp.as<int>(),
|
|
|
|
(function_code >> 2) & 1,
|
|
|
|
(function_code >> 1) & 1,
|
|
|
|
(function_code >> 0) & 1,
|
|
|
|
address_strobe ? 'a' : '-',
|
2022-06-13 14:39:06 +00:00
|
|
|
(address_strobe & 1) ? 'b' : '-',
|
|
|
|
(address_strobe & 2) ? 'w' : '-',
|
2022-06-08 14:51:05 +00:00
|
|
|
address,
|
2022-06-08 18:53:04 +00:00
|
|
|
read ? "->" : "<-",
|
2022-06-08 14:51:05 +00:00
|
|
|
value);
|
|
|
|
}
|
2022-06-07 20:56:05 +00:00
|
|
|
};
|
|
|
|
|
2022-06-08 18:53:04 +00:00
|
|
|
struct HarmlessStopException {};
|
|
|
|
|
2022-06-07 01:19:57 +00:00
|
|
|
struct BusHandler {
|
2022-06-08 18:43:51 +00:00
|
|
|
BusHandler(RandomStore &_store, uint8_t _participant) : store(_store), participant(_participant) {}
|
|
|
|
|
2022-06-08 18:53:04 +00:00
|
|
|
void will_perform(uint32_t, uint16_t) {
|
|
|
|
--instructions;
|
|
|
|
if(instructions < 0) {
|
|
|
|
throw HarmlessStopException{};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-07 01:47:10 +00:00
|
|
|
template <typename Microcycle> HalfCycles perform_bus_operation(const Microcycle &cycle, bool is_supervisor) {
|
2022-06-07 20:56:05 +00:00
|
|
|
Transaction transaction;
|
|
|
|
|
|
|
|
// Fill all of the transaction record except the data field; will do that after
|
|
|
|
// any potential read.
|
|
|
|
if(cycle.operation & Microcycle::InterruptAcknowledge) {
|
|
|
|
transaction.function_code = 0b111;
|
|
|
|
} else {
|
|
|
|
transaction.function_code = is_supervisor ? 0x4 : 0x0;
|
|
|
|
transaction.function_code |= (cycle.operation & Microcycle::IsData) ? 0x1 : 0x2;
|
|
|
|
}
|
|
|
|
transaction.address_strobe = cycle.operation & (Microcycle::NewAddress | Microcycle::SameAddress);
|
2022-06-13 14:39:06 +00:00
|
|
|
transaction.data_strobes = cycle.operation & (Microcycle::SelectByte | Microcycle::SelectWord);
|
2022-06-07 20:56:05 +00:00
|
|
|
if(cycle.address) transaction.address = *cycle.address & 0xffff'ff;
|
2022-06-08 13:49:27 +00:00
|
|
|
transaction.timestamp = time;
|
2022-06-08 18:53:04 +00:00
|
|
|
transaction.read = cycle.operation & Microcycle::Read;
|
2022-06-08 13:49:27 +00:00
|
|
|
|
|
|
|
time += cycle.length;
|
2022-06-07 20:56:05 +00:00
|
|
|
|
|
|
|
// Do the operation...
|
|
|
|
const uint32_t address = cycle.address ? (*cycle.address & 0xffff'ff) : 0;
|
|
|
|
switch(cycle.operation & (Microcycle::SelectWord | Microcycle::SelectByte | Microcycle::Read)) {
|
|
|
|
default: break;
|
|
|
|
|
|
|
|
case Microcycle::SelectWord | Microcycle::Read:
|
2022-06-08 18:43:51 +00:00
|
|
|
if(!store.has(address, participant)) {
|
|
|
|
ram[address] = store.value(address, participant);
|
|
|
|
}
|
|
|
|
if(!store.has(address+1, participant)) {
|
|
|
|
ram[address+1] = store.value(address+1, participant);
|
|
|
|
}
|
|
|
|
|
2022-06-07 20:56:05 +00:00
|
|
|
cycle.set_value16((ram[address] << 8) | ram[address + 1]);
|
|
|
|
break;
|
|
|
|
case Microcycle::SelectByte | Microcycle::Read:
|
2022-06-08 18:43:51 +00:00
|
|
|
if(!store.has(address, participant)) {
|
|
|
|
ram[address] = store.value(address, participant);
|
|
|
|
}
|
|
|
|
|
2022-06-07 20:56:05 +00:00
|
|
|
if(address & 1) {
|
|
|
|
cycle.set_value8_low(ram[address]);
|
|
|
|
} else {
|
|
|
|
cycle.set_value8_high(ram[address]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Microcycle::SelectWord:
|
|
|
|
ram[address] = cycle.value8_high();
|
|
|
|
ram[address+1] = cycle.value8_low();
|
2022-06-08 18:43:51 +00:00
|
|
|
store.flag(address, participant);
|
|
|
|
store.flag(address+1, participant);
|
2022-06-07 20:56:05 +00:00
|
|
|
break;
|
|
|
|
case Microcycle::SelectByte:
|
|
|
|
ram[address] = (address & 1) ? cycle.value8_low() : cycle.value8_high();
|
2022-06-08 18:43:51 +00:00
|
|
|
store.flag(address, participant);
|
2022-06-07 20:56:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Add the data value if relevant.
|
2022-06-13 14:39:06 +00:00
|
|
|
if(transaction.data_strobes) {
|
2022-06-07 20:56:05 +00:00
|
|
|
transaction.value = cycle.value16();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push back only if interesting.
|
2022-06-13 14:39:06 +00:00
|
|
|
if(transaction.address_strobe || transaction.data_strobes || transaction.function_code == 7) {
|
2022-06-08 13:49:27 +00:00
|
|
|
if(transaction_delay) {
|
|
|
|
--transaction_delay;
|
2022-06-08 14:56:54 +00:00
|
|
|
|
|
|
|
// Start counting time only from the first recorded transaction.
|
|
|
|
if(!transaction_delay) {
|
|
|
|
time = HalfCycles(0);
|
|
|
|
}
|
2022-06-08 13:49:27 +00:00
|
|
|
} else {
|
2022-06-08 18:53:04 +00:00
|
|
|
transactions.push_back(transaction);
|
2022-06-08 13:49:27 +00:00
|
|
|
}
|
2022-06-07 20:56:05 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 01:47:10 +00:00
|
|
|
return HalfCycles(0);
|
|
|
|
}
|
2022-06-07 01:19:57 +00:00
|
|
|
|
2022-06-07 01:47:10 +00:00
|
|
|
void flush() {}
|
2022-06-07 20:56:05 +00:00
|
|
|
|
2022-06-08 13:49:27 +00:00
|
|
|
int transaction_delay;
|
2022-06-08 18:53:04 +00:00
|
|
|
int instructions;
|
2022-06-08 13:49:27 +00:00
|
|
|
|
|
|
|
HalfCycles time;
|
2022-06-07 20:56:05 +00:00
|
|
|
std::vector<Transaction> transactions;
|
|
|
|
std::array<uint8_t, 16*1024*1024> ram;
|
|
|
|
|
|
|
|
void set_default_vectors() {
|
|
|
|
// Establish that all exception vectors point to 1024-byte blocks of memory.
|
|
|
|
for(int c = 0; c < 256; c++) {
|
2022-06-08 18:43:51 +00:00
|
|
|
const uint32_t target = (c + 2) << 10;
|
|
|
|
const uint32_t address = c << 2;
|
|
|
|
ram[address + 0] = uint8_t(target >> 24);
|
|
|
|
ram[address + 1] = uint8_t(target >> 16);
|
|
|
|
ram[address + 2] = uint8_t(target >> 8);
|
|
|
|
ram[address + 3] = uint8_t(target >> 0);
|
|
|
|
|
|
|
|
store.flag(address+0, participant);
|
|
|
|
store.flag(address+1, participant);
|
|
|
|
store.flag(address+2, participant);
|
|
|
|
store.flag(address+3, participant);
|
2022-06-07 20:56:05 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-08 18:43:51 +00:00
|
|
|
|
|
|
|
RandomStore &store;
|
|
|
|
const uint8_t participant;
|
2022-06-07 01:19:57 +00:00
|
|
|
};
|
|
|
|
|
2022-06-08 18:53:04 +00:00
|
|
|
using OldProcessor = CPU::MC68000::Processor<BusHandler, true, true>;
|
|
|
|
using NewProcessor = CPU::MC68000Mk2::Processor<BusHandler, true, true, true>;
|
2022-06-07 01:19:57 +00:00
|
|
|
|
|
|
|
template <typename M68000> struct Tester {
|
2022-06-08 18:43:51 +00:00
|
|
|
Tester(RandomStore &store, uint8_t participant) : bus_handler(store, participant), processor(bus_handler) {}
|
2022-06-07 01:47:10 +00:00
|
|
|
|
2022-06-08 18:53:04 +00:00
|
|
|
void run_instructions(int instructions) {
|
|
|
|
bus_handler.instructions = instructions;
|
|
|
|
|
|
|
|
try {
|
2022-06-08 20:03:02 +00:00
|
|
|
processor.run_for(HalfCycles(5000)); // Arbitrary, but will definitely exceed any one instruction (by quite a distance).
|
2022-06-08 18:53:04 +00:00
|
|
|
} catch (const HarmlessStopException &) {}
|
2022-06-07 20:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset_with_opcode(uint16_t opcode) {
|
|
|
|
bus_handler.transactions.clear();
|
|
|
|
bus_handler.set_default_vectors();
|
|
|
|
|
2022-06-08 18:43:51 +00:00
|
|
|
const uint32_t address = 3 << 10;
|
|
|
|
bus_handler.ram[address + 0] = uint8_t(opcode >> 8);
|
|
|
|
bus_handler.ram[address + 1] = uint8_t(opcode >> 0);
|
|
|
|
bus_handler.store.flag(address, bus_handler.participant);
|
|
|
|
bus_handler.store.flag(address+1, bus_handler.participant);
|
2022-06-07 20:56:05 +00:00
|
|
|
|
2022-06-10 19:57:54 +00:00
|
|
|
bus_handler.transaction_delay = 12; // i.e. ignore everything from the RESET sequence.
|
2022-06-08 13:49:27 +00:00
|
|
|
bus_handler.time = HalfCycles(0);
|
|
|
|
|
2022-06-07 20:56:05 +00:00
|
|
|
processor.reset();
|
2022-06-07 01:47:10 +00:00
|
|
|
}
|
2022-06-07 01:19:57 +00:00
|
|
|
|
2022-06-07 20:56:05 +00:00
|
|
|
BusHandler bus_handler;
|
|
|
|
M68000 processor;
|
2022-06-07 01:19:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@interface M68000OldVsNewTests : XCTestCase
|
|
|
|
@end
|
|
|
|
|
2022-06-08 18:43:51 +00:00
|
|
|
@implementation M68000OldVsNewTests
|
2022-06-07 01:19:57 +00:00
|
|
|
|
|
|
|
- (void)testOldVsNew {
|
2022-06-08 18:43:51 +00:00
|
|
|
RandomStore random_store;
|
|
|
|
auto oldTester = std::make_unique<Tester<OldProcessor>>(random_store, 0x01);
|
|
|
|
auto newTester = std::make_unique<Tester<NewProcessor>>(random_store, 0x02);
|
2022-06-07 20:56:05 +00:00
|
|
|
InstructionSet::M68k::Predecoder<InstructionSet::M68k::Model::M68000> decoder;
|
|
|
|
|
2022-06-08 18:43:51 +00:00
|
|
|
// Use a fixed seed to guarantee continuity across repeated runs.
|
|
|
|
srand(68000);
|
|
|
|
|
2022-06-10 20:34:05 +00:00
|
|
|
std::set<InstructionSet::M68k::Operation> test_set = {
|
2022-06-10 01:48:15 +00:00
|
|
|
// InstructionSet::M68k::Operation::ABCD, // Old implementation doesn't match flamewing tests, sometimes produces incorrect results.
|
|
|
|
// InstructionSet::M68k::Operation::SBCD, // Old implementation doesn't match flamewing tests, sometimes produces incorrect results.
|
|
|
|
// InstructionSet::M68k::Operation::MOVEb,
|
|
|
|
// InstructionSet::M68k::Operation::MOVEw,
|
|
|
|
// InstructionSet::M68k::Operation::MOVEl,
|
2022-06-10 20:50:38 +00:00
|
|
|
// InstructionSet::M68k::Operation::PEA,
|
2022-06-10 01:48:15 +00:00
|
|
|
// InstructionSet::M68k::Operation::MOVEtoSR, // Old implementation doesn't repeat a PC fetch.
|
|
|
|
// InstructionSet::M68k::Operation::MOVEtoCCR, // Old implementation doesn't repeat a PC fetch.
|
2022-06-11 15:17:18 +00:00
|
|
|
// InstructionSet::M68k::Operation::CMPAl, // Old implementation omits an idle cycle before -(An)
|
2022-06-10 01:48:15 +00:00
|
|
|
// InstructionSet::M68k::Operation::JSR, // Old implementation ends up skipping stack space if the destination throws an address error.
|
2022-06-10 20:50:38 +00:00
|
|
|
// InstructionSet::M68k::Operation::CLRb, // Old implementation omits an idle cycle before -(An)
|
|
|
|
// InstructionSet::M68k::Operation::CLRw, // Old implementation omits an idle cycle before -(An)
|
|
|
|
// InstructionSet::M68k::Operation::NEGXb, // Old implementation omits an idle cycle before -(An)
|
|
|
|
// InstructionSet::M68k::Operation::NEGXw, // Old implementation omits an idle cycle before -(An)
|
|
|
|
// InstructionSet::M68k::Operation::NEGb, // Old implementation omits an idle cycle before -(An)
|
|
|
|
// InstructionSet::M68k::Operation::NEGw, // Old implementation omits an idle cycle before -(An)
|
|
|
|
// InstructionSet::M68k::Operation::NOTb, // Old implementation omits an idle cycle before -(An)
|
|
|
|
// InstructionSet::M68k::Operation::NOTw, // Old implementation omits an idle cycle before -(An)
|
2022-06-10 20:34:05 +00:00
|
|
|
// InstructionSet::M68k::Operation::MULU,
|
|
|
|
// InstructionSet::M68k::Operation::MULS,
|
2022-06-10 01:48:15 +00:00
|
|
|
// InstructionSet::M68k::Operation::DIVU,
|
|
|
|
// InstructionSet::M68k::Operation::DIVS,
|
2022-06-11 15:17:18 +00:00
|
|
|
// InstructionSet::M68k::Operation::TRAP, // Old implementation relocates the idle state near the end to the beginning.
|
|
|
|
// InstructionSet::M68k::Operation::TRAPV, // Old implementation relocates the idle state near the end to the beginning.
|
|
|
|
// InstructionSet::M68k::Operation::CHK, // Old implementation pauses four cycles too long.
|
2022-06-10 19:57:54 +00:00
|
|
|
// InstructionSet::M68k::Operation::TAS, // Old implementation just doesn't match published cycle counts.
|
2022-06-10 20:34:05 +00:00
|
|
|
};
|
2022-06-09 20:18:04 +00:00
|
|
|
|
2022-06-09 17:13:33 +00:00
|
|
|
std::set<InstructionSet::M68k::Operation> failing_operations;
|
|
|
|
for(int c = 0; c < 65536; c++) {
|
2022-06-10 20:50:38 +00:00
|
|
|
// printf("%04x\n", c);
|
2022-06-08 20:15:33 +00:00
|
|
|
|
2022-06-09 20:18:04 +00:00
|
|
|
// Test only defined opcodes that aren't STOP (which will never teminate).
|
2022-06-07 20:56:05 +00:00
|
|
|
const auto instruction = decoder.decode(uint16_t(c));
|
2022-06-09 12:42:31 +00:00
|
|
|
if(
|
|
|
|
instruction.operation == InstructionSet::M68k::Operation::Undefined ||
|
|
|
|
instruction.operation == InstructionSet::M68k::Operation::STOP
|
|
|
|
) {
|
2022-06-07 20:56:05 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-06-09 20:18:04 +00:00
|
|
|
// If a whitelist is in place, adhere to it.
|
|
|
|
if(!test_set.empty() && test_set.find(instruction.operation) == test_set.end()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-06-07 20:56:05 +00:00
|
|
|
// Test each 1000 times.
|
2022-06-10 01:48:15 +00:00
|
|
|
for(int test = 0; test < 100; test++) {
|
2022-06-08 19:12:47 +00:00
|
|
|
// Establish with certainty the initial memory state.
|
2022-06-08 18:43:51 +00:00
|
|
|
random_store.clear();
|
2022-06-07 20:56:05 +00:00
|
|
|
newTester->reset_with_opcode(c);
|
2022-06-08 15:42:42 +00:00
|
|
|
oldTester->reset_with_opcode(c);
|
2022-06-07 20:56:05 +00:00
|
|
|
|
2022-06-08 19:12:47 +00:00
|
|
|
// Generate a random initial register state.
|
|
|
|
auto oldState = oldTester->processor.get_state();
|
|
|
|
auto newState = newTester->processor.get_state();
|
|
|
|
|
|
|
|
for(int c = 0; c < 8; c++) {
|
|
|
|
oldState.data[c] = newState.registers.data[c] = rand() ^ (rand() << 1);
|
|
|
|
if(c != 7) oldState.address[c] = newState.registers.address[c] = rand() << 1;
|
|
|
|
}
|
2022-06-08 20:03:02 +00:00
|
|
|
// Fully to paper over the two 68000s' different ways of doing a faked
|
|
|
|
// reset, pick a random status such that:
|
|
|
|
//
|
|
|
|
// (i) supervisor mode is active;
|
|
|
|
// (ii) trace is inactive; and
|
|
|
|
// (iii) interrupt level is 7.
|
|
|
|
oldState.status = newState.registers.status = (rand() | (1 << 13) | (7 << 8)) & ~(1 << 15);
|
2022-06-08 19:12:47 +00:00
|
|
|
oldState.user_stack_pointer = newState.registers.user_stack_pointer = rand() << 1;
|
2022-06-10 01:48:15 +00:00
|
|
|
oldState.supervisor_stack_pointer = newState.registers.supervisor_stack_pointer = 0x800;
|
|
|
|
|
2022-06-08 19:12:47 +00:00
|
|
|
newTester->processor.set_state(newState);
|
2022-06-08 20:03:02 +00:00
|
|
|
oldTester->processor.set_state(oldState);
|
2022-06-08 19:12:47 +00:00
|
|
|
|
2022-06-08 18:53:04 +00:00
|
|
|
// Run a single instruction.
|
|
|
|
newTester->run_instructions(1);
|
|
|
|
oldTester->run_instructions(1);
|
2022-06-07 20:56:05 +00:00
|
|
|
|
2022-06-08 20:15:33 +00:00
|
|
|
// Grab final states.
|
|
|
|
oldState = oldTester->processor.get_state();
|
|
|
|
newState = newTester->processor.get_state();
|
2022-06-08 14:51:05 +00:00
|
|
|
|
2022-06-08 20:15:33 +00:00
|
|
|
// Compare bus activity only if it doesn't look like an address
|
2022-06-09 20:59:06 +00:00
|
|
|
// error occurred. Don't check those as the old 68000 appears to be wrong
|
|
|
|
// most of the time about function codes, and that bleeds into the stacked data.
|
2022-06-08 20:15:33 +00:00
|
|
|
//
|
|
|
|
// Net effect will be 50% fewer transaction comparisons for instructions that
|
|
|
|
// can trigger an address error.
|
2022-06-10 01:48:15 +00:00
|
|
|
const auto &oldTransactions = oldTester->bus_handler.transactions;
|
|
|
|
const auto &newTransactions = newTester->bus_handler.transactions;
|
2022-06-09 20:59:06 +00:00
|
|
|
if(oldState.program_counter != 0x1404 || newState.registers.program_counter != 0x1404) {
|
2022-06-08 20:15:33 +00:00
|
|
|
auto newIt = newTransactions.begin();
|
|
|
|
auto oldIt = oldTransactions.begin();
|
|
|
|
while(newIt != newTransactions.end() && oldIt != oldTransactions.end()) {
|
|
|
|
if(*newIt != *oldIt) {
|
|
|
|
printf("Mismatch in %s, test %d:\n", instruction.to_string().c_str(), test);
|
|
|
|
|
|
|
|
auto repeatIt = newTransactions.begin();
|
|
|
|
while(repeatIt != newIt) {
|
|
|
|
repeatIt->print();
|
|
|
|
++repeatIt;
|
|
|
|
}
|
|
|
|
printf("---\n");
|
2022-06-09 15:30:22 +00:00
|
|
|
while(newIt != newTransactions.end()) {
|
|
|
|
printf("n: "); newIt->print();
|
|
|
|
++newIt;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
while(oldIt != oldTransactions.end()) {
|
|
|
|
printf("o: "); oldIt->print();
|
|
|
|
++oldIt;
|
|
|
|
}
|
2022-06-08 20:15:33 +00:00
|
|
|
printf("\n");
|
|
|
|
|
2022-06-09 17:13:33 +00:00
|
|
|
failing_operations.insert(instruction.operation);
|
2022-06-08 20:15:33 +00:00
|
|
|
break;
|
2022-06-08 14:51:05 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 20:15:33 +00:00
|
|
|
++newIt;
|
|
|
|
++oldIt;
|
2022-06-08 13:49:27 +00:00
|
|
|
}
|
2022-06-09 20:59:06 +00:00
|
|
|
}
|
2022-06-08 19:12:47 +00:00
|
|
|
|
|
|
|
// Compare registers.
|
|
|
|
bool mismatch = false;
|
|
|
|
for(int c = 0; c < 8; c++) {
|
|
|
|
mismatch |= oldState.data[c] != newState.registers.data[c];
|
|
|
|
if(c != 7) mismatch |= oldState.address[c] != newState.registers.address[c];
|
|
|
|
}
|
|
|
|
mismatch |= oldState.status != newState.registers.status;
|
|
|
|
mismatch |= oldState.program_counter != newState.registers.program_counter;
|
|
|
|
mismatch |= oldState.user_stack_pointer != newState.registers.user_stack_pointer;
|
|
|
|
mismatch |= oldState.supervisor_stack_pointer != newState.registers.supervisor_stack_pointer;
|
|
|
|
|
|
|
|
if(mismatch) {
|
2022-06-09 17:13:33 +00:00
|
|
|
failing_operations.insert(instruction.operation);
|
2022-06-08 19:12:47 +00:00
|
|
|
printf("Registers don't match after %s, test %d\n", instruction.to_string().c_str(), test);
|
2022-06-10 01:48:15 +00:00
|
|
|
for(const auto &transaction: newTransactions) {
|
|
|
|
printf("n: "); transaction.print();
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
for(const auto &transaction: oldTransactions) {
|
|
|
|
printf("o: "); transaction.print();
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
2022-06-08 19:12:47 +00:00
|
|
|
// TODO: more detail here!
|
|
|
|
}
|
2022-06-07 20:56:05 +00:00
|
|
|
}
|
2022-06-07 01:47:10 +00:00
|
|
|
}
|
2022-06-09 17:13:33 +00:00
|
|
|
|
|
|
|
printf("\nAll failing operations:\n");
|
|
|
|
for(const auto operation: failing_operations) {
|
|
|
|
printf("%d,\n", int(operation));
|
|
|
|
}
|
2022-06-07 01:19:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|