2022-04-18 11:23:25 +00:00
|
|
|
//
|
|
|
|
// m68kDecoderTests.m
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 18/04/2022.
|
|
|
|
// Copyright 2022 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import <XCTest/XCTest.h>
|
|
|
|
|
2022-04-27 12:05:36 +00:00
|
|
|
#include "../../../InstructionSets/M68k/Decoder.hpp"
|
2022-04-18 11:23:25 +00:00
|
|
|
|
|
|
|
using namespace InstructionSet::M68k;
|
|
|
|
|
2022-04-27 00:32:39 +00:00
|
|
|
@interface M68000DecoderTests : XCTestCase
|
2022-04-18 11:23:25 +00:00
|
|
|
@end
|
|
|
|
|
2022-04-27 00:32:39 +00:00
|
|
|
@implementation M68000DecoderTests
|
2022-04-18 11:23:25 +00:00
|
|
|
|
|
|
|
- (void)testInstructionSpecs {
|
|
|
|
NSData *const testData =
|
|
|
|
[NSData dataWithContentsOfURL:
|
|
|
|
[[NSBundle bundleForClass:[self class]]
|
|
|
|
URLForResource:@"68000ops"
|
|
|
|
withExtension:@"json"
|
|
|
|
subdirectory:@"68000 Decoding"]];
|
|
|
|
|
|
|
|
NSDictionary<NSString *, NSString *> *const decodings = [NSJSONSerialization JSONObjectWithData:testData options:0 error:nil];
|
|
|
|
XCTAssertNotNil(decodings);
|
|
|
|
|
|
|
|
Predecoder<Model::M68000> decoder;
|
|
|
|
for(int instr = 0; instr < 65536; instr++) {
|
|
|
|
NSString *const instrName = [NSString stringWithFormat:@"%04x", instr];
|
|
|
|
NSString *const expected = decodings[instrName];
|
|
|
|
XCTAssertNotNil(expected);
|
|
|
|
|
|
|
|
const auto found = decoder.decode(uint16_t(instr));
|
|
|
|
|
2022-05-12 23:46:08 +00:00
|
|
|
NSString *const instruction = [NSString stringWithUTF8String:found.to_string(instr).c_str()];
|
2022-04-19 00:00:39 +00:00
|
|
|
XCTAssertEqualObjects(instruction, expected, "%@ should decode as %@; got %@", instrName, expected, instruction);
|
2022-04-18 11:23:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|