2019-12-14 19:26:33 +00:00
|
|
|
//
|
|
|
|
// 68000ComparativeTests.cpp
|
|
|
|
// Clock SignalTests
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 14/12/2019.
|
|
|
|
// Copyright © 2019 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import <XCTest/XCTest.h>
|
|
|
|
|
2022-05-17 00:04:13 +00:00
|
|
|
#include "../../../Processors/68000Mk2/68000Mk2.hpp"
|
2022-05-02 00:40:57 +00:00
|
|
|
#include "../../../InstructionSets/M68k/Executor.hpp"
|
2022-05-13 00:23:32 +00:00
|
|
|
#include "../../../InstructionSets/M68k/Decoder.hpp"
|
2019-12-14 19:26:33 +00:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <memory>
|
2019-12-14 20:09:06 +00:00
|
|
|
#include <functional>
|
2019-12-14 19:26:33 +00:00
|
|
|
|
2022-05-17 00:04:13 +00:00
|
|
|
//#define USE_EXECUTOR
|
2022-05-13 20:18:58 +00:00
|
|
|
//#define MAKE_SUGGESTIONS
|
2022-05-03 15:09:57 +00:00
|
|
|
|
2022-05-12 20:35:41 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
/// Binds a 68000 executor to 16mb of RAM.
|
2022-05-18 20:59:37 +00:00
|
|
|
struct TestExecutor {
|
|
|
|
uint8_t *const ram;
|
|
|
|
InstructionSet::M68k::Executor<InstructionSet::M68k::Model::M68000, TestExecutor> processor;
|
2022-05-12 20:35:41 +00:00
|
|
|
|
2022-05-18 20:59:37 +00:00
|
|
|
TestExecutor(uint8_t *ram) : ram(ram), processor(*this) {}
|
2022-05-12 20:35:41 +00:00
|
|
|
|
|
|
|
void run_for_instructions(int instructions) {
|
|
|
|
processor.run_for_instructions(instructions);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initial test-case implementation:
|
|
|
|
// do a very sedate read and write.
|
|
|
|
|
|
|
|
template <typename IntT> IntT read(uint32_t address, InstructionSet::M68k::FunctionCode) {
|
|
|
|
if constexpr (sizeof(IntT) == 1) {
|
|
|
|
return IntT(ram[address & 0xffffff]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if constexpr (sizeof(IntT) == 2) {
|
|
|
|
return IntT(
|
|
|
|
(ram[address & 0xffffff] << 8) |
|
|
|
|
ram[(address+1) & 0xffffff]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if constexpr (sizeof(IntT) == 4) {
|
|
|
|
return IntT(
|
|
|
|
(ram[address & 0xffffff] << 24) |
|
|
|
|
(ram[(address+1) & 0xffffff] << 16) |
|
|
|
|
(ram[(address+2) & 0xffffff] << 8) |
|
|
|
|
ram[(address+3) & 0xffffff]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename IntT> void write(uint32_t address, IntT value, InstructionSet::M68k::FunctionCode) {
|
|
|
|
if constexpr (sizeof(IntT) == 1) {
|
|
|
|
ram[address & 0xffffff] = uint8_t(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if constexpr (sizeof(IntT) == 2) {
|
|
|
|
ram[address & 0xffffff] = uint8_t(value >> 8);
|
|
|
|
ram[(address+1) & 0xffffff] = uint8_t(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if constexpr (sizeof(IntT) == 4) {
|
|
|
|
ram[address & 0xffffff] = uint8_t(value >> 24);
|
|
|
|
ram[(address+1) & 0xffffff] = uint8_t(value >> 16);
|
|
|
|
ram[(address+2) & 0xffffff] = uint8_t(value >> 8);
|
|
|
|
ram[(address+3) & 0xffffff] = uint8_t(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {}
|
2022-05-13 00:52:24 +00:00
|
|
|
int acknowlege_interrupt(int) {
|
|
|
|
return -1;
|
|
|
|
}
|
2022-05-12 20:35:41 +00:00
|
|
|
};
|
|
|
|
|
2022-05-18 20:59:37 +00:00
|
|
|
/// Binds a bus-accurate 68000 to 16mb of RAM.
|
|
|
|
struct TestProcessor: public CPU::MC68000Mk2::BusHandler {
|
|
|
|
uint8_t *const ram;
|
|
|
|
CPU::MC68000Mk2::Processor<TestProcessor, true, false, true> processor;
|
|
|
|
std::function<void(void)> comparitor;
|
|
|
|
|
|
|
|
TestProcessor(uint8_t *ram) : ram(ram), processor(*this) {}
|
|
|
|
|
|
|
|
void will_perform(uint32_t, uint16_t) {
|
|
|
|
--instructions_remaining_;
|
|
|
|
if(!instructions_remaining_) comparitor();
|
|
|
|
}
|
|
|
|
|
|
|
|
HalfCycles perform_bus_operation(const CPU::MC68000Mk2::Microcycle &cycle, int) {
|
|
|
|
using Microcycle = CPU::MC68000Mk2::Microcycle;
|
|
|
|
if(cycle.data_select_active()) {
|
|
|
|
cycle.apply(&ram[cycle.host_endian_byte_address()]);
|
|
|
|
}
|
|
|
|
return HalfCycles(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void run_for_instructions(int instructions, const std::function<void(void)> &compare) {
|
|
|
|
instructions_remaining_ = instructions + 1; // i.e. run up to the will_perform of the instruction after.
|
|
|
|
comparitor = std::move(compare);
|
|
|
|
while(instructions_remaining_) {
|
|
|
|
processor.run_for(HalfCycles(2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int instructions_remaining_;
|
|
|
|
};
|
|
|
|
|
2022-05-12 20:35:41 +00:00
|
|
|
}
|
|
|
|
|
2019-12-14 19:26:33 +00:00
|
|
|
@interface M68000ComparativeTests : XCTestCase
|
|
|
|
@end
|
|
|
|
|
2019-12-16 02:26:47 +00:00
|
|
|
@implementation M68000ComparativeTests {
|
|
|
|
NSSet<NSString *> *_fileSet;
|
|
|
|
NSSet<NSString *> *_testSet;
|
|
|
|
|
|
|
|
NSMutableSet<NSString *> *_failures;
|
|
|
|
NSMutableArray<NSNumber *> *_failingOpcodes;
|
2022-05-13 19:27:11 +00:00
|
|
|
NSMutableDictionary<NSNumber *, NSMutableArray<NSString *> *> *_suggestedCorrections;
|
2022-05-12 20:35:41 +00:00
|
|
|
|
2022-05-15 00:28:54 +00:00
|
|
|
InstructionSet::M68k::Predecoder<InstructionSet::M68k::Model::M68000> _decoder;
|
2022-05-18 20:59:37 +00:00
|
|
|
|
|
|
|
std::array<uint8_t, 16*1024*1024> _ram;
|
|
|
|
std::unique_ptr<TestExecutor> _testExecutor;
|
2019-12-16 02:26:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setUp {
|
2022-05-18 21:10:05 +00:00
|
|
|
// Definitively erase any prior memory contents;
|
|
|
|
// 0xce is arbitrary but hopefully easier to spot
|
|
|
|
// in potential errors than e.g. 0x00 or 0xff.
|
|
|
|
_ram.fill(0xce);
|
|
|
|
|
|
|
|
// TODO: possibly, worry about resetting RAM to 0xce after tests have completed.
|
|
|
|
|
2022-05-18 20:59:37 +00:00
|
|
|
#ifdef USE_EXECUTOR
|
|
|
|
_testExecutor = std::make_unique<TestExecutor>(_ram.data());
|
|
|
|
#endif
|
|
|
|
|
2022-05-13 14:50:16 +00:00
|
|
|
// These will accumulate a list of failing tests and associated opcodes.
|
|
|
|
_failures = [[NSMutableSet alloc] init];
|
|
|
|
_failingOpcodes = [[NSMutableArray alloc] init];
|
|
|
|
|
2022-05-13 19:27:11 +00:00
|
|
|
#ifdef MAKE_SUGGESTIONS
|
|
|
|
_suggestedCorrections = [[NSMutableDictionary alloc] init];
|
|
|
|
#endif
|
|
|
|
|
2019-12-16 02:26:47 +00:00
|
|
|
// To limit tests run to a subset of files and/or of tests, uncomment and fill in below.
|
2022-05-19 14:27:51 +00:00
|
|
|
_fileSet = [NSSet setWithArray:@[@"nbcd_pea.json"]];
|
2020-01-02 01:00:37 +00:00
|
|
|
// _testSet = [NSSet setWithArray:@[@"CHK 41a8"]];
|
2019-12-16 02:26:47 +00:00
|
|
|
}
|
2019-12-14 19:26:33 +00:00
|
|
|
|
|
|
|
- (void)testAll {
|
2019-12-16 02:26:47 +00:00
|
|
|
// Get the full list of available test files.
|
2019-12-14 19:26:33 +00:00
|
|
|
NSBundle *const bundle = [NSBundle bundleForClass:[self class]];
|
|
|
|
NSArray<NSURL *> *const tests = [bundle URLsForResourcesWithExtension:@"json" subdirectory:@"68000 Comparative Tests"];
|
2019-12-15 03:58:51 +00:00
|
|
|
|
2019-12-16 02:26:47 +00:00
|
|
|
// Issue each test file.
|
2019-12-14 19:26:33 +00:00
|
|
|
for(NSURL *url in tests) {
|
2019-12-16 02:26:47 +00:00
|
|
|
// Compare against a file set if one has been supplied.
|
2021-03-19 08:19:49 +00:00
|
|
|
if(_fileSet && ![_fileSet containsObject:[url lastPathComponent]]) continue;
|
2022-05-13 12:02:20 +00:00
|
|
|
// NSLog(@"Testing %@", url);
|
2019-12-14 19:26:33 +00:00
|
|
|
[self testJSONAtURL:url];
|
|
|
|
}
|
2019-12-16 02:26:47 +00:00
|
|
|
|
2022-05-13 12:02:20 +00:00
|
|
|
XCTAssert(_failures.count == 0);
|
2022-05-13 00:23:32 +00:00
|
|
|
|
2022-05-13 12:02:20 +00:00
|
|
|
// Output a summary of failures, if any.
|
|
|
|
if(_failures.count) {
|
|
|
|
NSLog(@"Total failures: %@", @(_failures.count));
|
|
|
|
NSLog(@"Failures: %@", _failures);
|
|
|
|
NSLog(@"Failing opcodes:");
|
|
|
|
|
|
|
|
for(NSNumber *number in _failingOpcodes) {
|
2022-05-15 00:28:54 +00:00
|
|
|
const auto decoded = _decoder.decode(number.intValue);
|
2022-05-13 12:02:20 +00:00
|
|
|
const std::string description = decoded.to_string(number.intValue);
|
|
|
|
NSLog(@"%04x %s", number.intValue, description.c_str());
|
2022-05-13 19:27:11 +00:00
|
|
|
|
|
|
|
for(NSString *suggestion in _suggestedCorrections[number]) {
|
|
|
|
NSLog(@"%@", suggestion);
|
|
|
|
}
|
2022-05-13 12:02:20 +00:00
|
|
|
}
|
2019-12-16 02:26:47 +00:00
|
|
|
}
|
2019-12-14 19:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)testJSONAtURL:(NSURL *)url {
|
2019-12-16 02:26:47 +00:00
|
|
|
// Read the nominated file and parse it as JSON.
|
2019-12-14 19:26:33 +00:00
|
|
|
NSData *const data = [NSData dataWithContentsOfURL:url];
|
|
|
|
NSError *error;
|
|
|
|
NSArray *const jsonContents = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
|
|
|
|
|
|
|
|
if(!data || error || ![jsonContents isKindOfClass:[NSArray class]]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-16 02:26:47 +00:00
|
|
|
// Perform each dictionary in the array as a test.
|
2019-12-14 19:26:33 +00:00
|
|
|
for(NSDictionary *test in jsonContents) {
|
|
|
|
if(![test isKindOfClass:[NSDictionary class]]) continue;
|
2022-05-12 20:35:41 +00:00
|
|
|
|
|
|
|
// Only entries with a name are valid.
|
|
|
|
NSString *const name = test[@"name"];
|
|
|
|
if(!name) continue;
|
|
|
|
|
|
|
|
// Compare against a test set if one has been supplied.
|
|
|
|
if(_testSet && ![_testSet containsObject:name]) continue;
|
|
|
|
|
2022-05-17 00:04:13 +00:00
|
|
|
#ifdef USE_EXECUTOR
|
2022-05-12 20:35:41 +00:00
|
|
|
[self testOperationExecutor:test name:name];
|
2022-05-17 00:04:13 +00:00
|
|
|
#else
|
|
|
|
[self testOperationClassic:test name:name];
|
2022-05-03 15:09:57 +00:00
|
|
|
#endif
|
2019-12-14 19:26:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-12 20:35:41 +00:00
|
|
|
- (void)testOperationClassic:(NSDictionary *)test name:(NSString *)name {
|
2022-05-19 01:00:34 +00:00
|
|
|
struct TerminateMarker {};
|
|
|
|
|
2022-05-18 20:59:37 +00:00
|
|
|
auto uniqueTest68000 = std::make_unique<TestProcessor>(_ram.data());
|
2019-12-14 20:09:06 +00:00
|
|
|
auto test68000 = uniqueTest68000.get();
|
|
|
|
|
|
|
|
{
|
|
|
|
// Apply initial memory state.
|
|
|
|
NSArray<NSNumber *> *const initialMemory = test[@"initial memory"];
|
|
|
|
NSEnumerator<NSNumber *> *enumerator = [initialMemory objectEnumerator];
|
|
|
|
while(true) {
|
|
|
|
NSNumber *const address = [enumerator nextObject];
|
|
|
|
NSNumber *const value = [enumerator nextObject];
|
|
|
|
|
|
|
|
if(!address || !value) break;
|
|
|
|
test68000->ram[address.integerValue ^ 1] = value.integerValue; // Effect a short-resolution endianness swap.
|
|
|
|
}
|
2019-12-14 19:26:33 +00:00
|
|
|
|
2019-12-14 20:09:06 +00:00
|
|
|
// Apply initial processor state.
|
|
|
|
auto state = test68000->processor.get_state();
|
2022-05-19 01:13:34 +00:00
|
|
|
state.registers = [self initialRegisters:test];
|
2019-12-14 20:09:06 +00:00
|
|
|
test68000->processor.set_state(state);
|
2019-12-14 19:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run the thing.
|
2020-02-22 17:34:16 +00:00
|
|
|
const auto comparitor = [=] {
|
2019-12-14 20:09:06 +00:00
|
|
|
const auto state = test68000->processor.get_state();
|
2022-05-19 01:13:34 +00:00
|
|
|
[self test:test name:name compareFinalRegisters:state.registers];
|
2019-12-14 20:09:06 +00:00
|
|
|
|
|
|
|
// Test final memory state.
|
|
|
|
NSArray<NSNumber *> *const finalMemory = test[@"final memory"];
|
|
|
|
NSEnumerator *enumerator = [finalMemory objectEnumerator];
|
|
|
|
while(true) {
|
|
|
|
NSNumber *const address = [enumerator nextObject];
|
|
|
|
NSNumber *const value = [enumerator nextObject];
|
|
|
|
|
|
|
|
if(!address || !value) break;
|
|
|
|
XCTAssertEqual(test68000->ram[address.integerValue ^ 1], value.integerValue, @"%@: Memory at location %@ inconsistent", name, address);
|
2019-12-16 02:26:47 +00:00
|
|
|
if(test68000->ram[address.integerValue ^ 1] != value.integerValue) [_failures addObject:name];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Consider collating extra detail.
|
|
|
|
if([_failures containsObject:name]) {
|
2019-12-16 05:01:18 +00:00
|
|
|
[_failingOpcodes addObject:@((test68000->ram[0x101] << 8) | test68000->ram[0x100])];
|
2019-12-14 20:09:06 +00:00
|
|
|
}
|
2022-05-19 01:00:34 +00:00
|
|
|
|
|
|
|
// Make sure nothing further occurs; keep this test isolated.
|
|
|
|
throw TerminateMarker();
|
2019-12-14 20:09:06 +00:00
|
|
|
};
|
|
|
|
|
2022-05-19 01:00:34 +00:00
|
|
|
try {
|
|
|
|
test68000->run_for_instructions(1, comparitor);
|
|
|
|
} catch(TerminateMarker m) {}
|
2019-12-14 19:26:33 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 12:02:20 +00:00
|
|
|
- (void)setInitialState:(NSDictionary *)test {
|
|
|
|
// Apply initial memory state.
|
|
|
|
NSArray<NSNumber *> *const initialMemory = test[@"initial memory"];
|
|
|
|
NSEnumerator<NSNumber *> *enumerator = [initialMemory objectEnumerator];
|
|
|
|
while(true) {
|
|
|
|
NSNumber *const address = [enumerator nextObject];
|
|
|
|
NSNumber *const value = [enumerator nextObject];
|
2022-05-02 00:40:57 +00:00
|
|
|
|
2022-05-13 12:02:20 +00:00
|
|
|
if(!address || !value) break;
|
2022-05-18 20:59:37 +00:00
|
|
|
_testExecutor->ram[address.integerValue] = value.integerValue;
|
2022-05-13 12:02:20 +00:00
|
|
|
}
|
2022-05-02 00:40:57 +00:00
|
|
|
|
2022-05-13 12:02:20 +00:00
|
|
|
// Apply initial processor state.
|
2022-05-19 01:13:34 +00:00
|
|
|
_testExecutor->processor.set_state([self initialRegisters:test]);
|
2022-05-13 12:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)testOperationExecutor:(NSDictionary *)test name:(NSString *)name {
|
|
|
|
[self setInitialState:test];
|
2022-05-02 00:40:57 +00:00
|
|
|
|
|
|
|
// Run the thing.
|
2022-05-18 20:59:37 +00:00
|
|
|
_testExecutor->run_for_instructions(1);
|
2022-05-02 00:40:57 +00:00
|
|
|
|
|
|
|
// Test the end state.
|
2022-05-18 20:59:37 +00:00
|
|
|
const auto state = _testExecutor->processor.get_state();
|
2022-05-19 01:13:34 +00:00
|
|
|
[self test:test name:name compareFinalRegisters:state];
|
2022-05-02 16:57:45 +00:00
|
|
|
|
2022-05-02 00:40:57 +00:00
|
|
|
// Test final memory state.
|
|
|
|
NSArray<NSNumber *> *const finalMemory = test[@"final memory"];
|
|
|
|
NSEnumerator *enumerator = [finalMemory objectEnumerator];
|
|
|
|
while(true) {
|
|
|
|
NSNumber *const address = [enumerator nextObject];
|
|
|
|
NSNumber *const value = [enumerator nextObject];
|
|
|
|
|
|
|
|
if(!address || !value) break;
|
2022-05-18 20:59:37 +00:00
|
|
|
if(_testExecutor->ram[address.integerValue] != value.integerValue) [_failures addObject:name];
|
2022-05-02 00:40:57 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 12:02:20 +00:00
|
|
|
// If this test is now in the failures set, add the corresponding opcode for
|
|
|
|
// later logging.
|
2022-05-02 00:40:57 +00:00
|
|
|
if([_failures containsObject:name]) {
|
2022-05-18 20:59:37 +00:00
|
|
|
NSNumber *const opcode = @(_testExecutor->read<uint16_t>(0x100, InstructionSet::M68k::FunctionCode()));
|
2022-05-13 19:27:11 +00:00
|
|
|
|
|
|
|
// Add this opcode to the failing list.
|
|
|
|
[_failingOpcodes addObject:opcode];
|
|
|
|
|
|
|
|
// Generate the JSON that would have satisfied this test, at least as far as registers go,
|
|
|
|
// if those are being collected.
|
|
|
|
if(_suggestedCorrections) {
|
|
|
|
NSMutableDictionary *generatedTest = [test mutableCopy];
|
|
|
|
NSMutableDictionary *generatedState = generatedTest[@"final state"] = [test[@"final state"] mutableCopy];
|
|
|
|
for(int c = 0; c < 8; ++c) {
|
|
|
|
const NSString *dX = [@"d" stringByAppendingFormat:@"%d", c];
|
|
|
|
const NSString *aX = [@"a" stringByAppendingFormat:@"%d", c];
|
|
|
|
generatedState[dX] = @(state.data[c]);
|
|
|
|
if(c < 7) generatedState[aX] = @(state.address[c]);
|
|
|
|
}
|
|
|
|
|
|
|
|
generatedState[@"a7"] = @(state.supervisor_stack_pointer);
|
|
|
|
generatedState[@"usp"] = @(state.user_stack_pointer);
|
|
|
|
generatedState[@"sr"] = @(state.status);
|
|
|
|
|
|
|
|
NSString *const generatedJSON =
|
|
|
|
[[NSString alloc] initWithData:
|
|
|
|
[NSJSONSerialization dataWithJSONObject:generatedTest options:0 error:nil]
|
|
|
|
encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
if(_suggestedCorrections[opcode]) {
|
|
|
|
[_suggestedCorrections[opcode] addObject:generatedJSON];
|
|
|
|
} else {
|
|
|
|
_suggestedCorrections[opcode] = [NSMutableArray arrayWithObject:generatedJSON];
|
|
|
|
}
|
|
|
|
}
|
2022-05-02 00:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-19 01:13:34 +00:00
|
|
|
- (InstructionSet::M68k::RegisterSet)initialRegisters:(NSDictionary *)test {
|
|
|
|
InstructionSet::M68k::RegisterSet registers;
|
|
|
|
|
|
|
|
NSDictionary *const initialState = test[@"initial state"];
|
|
|
|
for(int c = 0; c < 8; ++c) {
|
|
|
|
const NSString *dX = [@"d" stringByAppendingFormat:@"%d", c];
|
|
|
|
const NSString *aX = [@"a" stringByAppendingFormat:@"%d", c];
|
|
|
|
|
|
|
|
registers.data[c] = uint32_t([initialState[dX] integerValue]);
|
|
|
|
if(c < 7)
|
|
|
|
registers.address[c] = uint32_t([initialState[aX] integerValue]);
|
|
|
|
}
|
|
|
|
registers.supervisor_stack_pointer = uint32_t([initialState[@"a7"] integerValue]);
|
|
|
|
registers.user_stack_pointer = uint32_t([initialState[@"usp"] integerValue]);
|
|
|
|
registers.status = [initialState[@"sr"] integerValue];
|
|
|
|
registers.program_counter = uint32_t([initialState[@"pc"] integerValue]);
|
|
|
|
|
|
|
|
return registers;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)test:(NSDictionary *)test name:(NSString *)name compareFinalRegisters:(InstructionSet::M68k::RegisterSet)registers {
|
|
|
|
// Test the end state.
|
|
|
|
NSDictionary *const finalState = test[@"final state"];
|
|
|
|
for(int c = 0; c < 8; ++c) {
|
|
|
|
const NSString *dX = [@"d" stringByAppendingFormat:@"%d", c];
|
|
|
|
const NSString *aX = [@"a" stringByAppendingFormat:@"%d", c];
|
|
|
|
|
|
|
|
if(registers.data[c] != [finalState[dX] integerValue]) [_failures addObject:name];
|
|
|
|
if(c < 7 && registers.address[c] != [finalState[aX] integerValue]) [_failures addObject:name];
|
|
|
|
}
|
|
|
|
if(registers.supervisor_stack_pointer != [finalState[@"a7"] integerValue]) [_failures addObject:name];
|
|
|
|
if(registers.user_stack_pointer != [finalState[@"usp"] integerValue]) [_failures addObject:name];
|
|
|
|
|
|
|
|
const uint16_t correctSR = [finalState[@"sr"] integerValue];
|
|
|
|
if(registers.status != correctSR) {
|
|
|
|
const uint16_t opcode = _testExecutor->read<uint16_t>(0x100, InstructionSet::M68k::FunctionCode());
|
|
|
|
const auto instruction = _decoder.decode(opcode);
|
|
|
|
|
|
|
|
// For DIVU and DIVS, for now, test only the well-defined flags.
|
|
|
|
if(
|
|
|
|
instruction.operation != InstructionSet::M68k::Operation::DIVS &&
|
|
|
|
instruction.operation != InstructionSet::M68k::Operation::DIVU
|
|
|
|
) {
|
|
|
|
[_failures addObject:name];
|
|
|
|
} else {
|
|
|
|
uint16_t status_mask = 0xff13; // i.e. extend, which should be unaffected, and overflow, which
|
|
|
|
// is well-defined unless there was a divide by zero. But this
|
|
|
|
// test set doesn't include any divide by zeroes.
|
|
|
|
|
|
|
|
if(!(correctSR & InstructionSet::M68k::ConditionCode::Overflow)) {
|
|
|
|
// If overflow didn't occur then negative and zero are also well-defined.
|
|
|
|
status_mask |= 0x000c;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((registers.status & status_mask) != (([finalState[@"sr"] integerValue]) & status_mask)) {
|
|
|
|
[_failures addObject:name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-14 19:26:33 +00:00
|
|
|
@end
|