diff --git a/OSBindings/Mac/Clock SignalTests/m68kDecoderTests.mm b/OSBindings/Mac/Clock SignalTests/m68kDecoderTests.mm index b89b46906..b1d9248a8 100644 --- a/OSBindings/Mac/Clock SignalTests/m68kDecoderTests.mm +++ b/OSBindings/Mac/Clock SignalTests/m68kDecoderTests.mm @@ -15,8 +15,34 @@ using namespace InstructionSet::M68k; @interface m68kDecoderTests : XCTestCase @end +namespace { + +template NSString *operand(Preinstruction instruction) { + switch(instruction.mode()) { + default: return @""; + + case AddressingMode::DataRegisterDirect: + return [NSString stringWithFormat:@"D%d", instruction.reg()]; + + case AddressingMode::AddressRegisterDirect: + return [NSString stringWithFormat:@"A%d", instruction.reg()]; + case AddressingMode::AddressRegisterIndirect: + return [NSString stringWithFormat:@"(A%d)", instruction.reg()]; + case AddressingMode::AddressRegisterIndirectWithPostincrement: + return [NSString stringWithFormat:@"(A%d)+", instruction.reg()]; + case AddressingMode::AddressRegisterIndirectWithPredecrement: + return [NSString stringWithFormat:@"-(A%d)", instruction.reg()]; + } +} + +} + @implementation m68kDecoderTests +- (NSString *)operand:(int)operand instruction:(Preinstruction)instruction { + return @""; +} + - (void)testInstructionSpecs { NSData *const testData = [NSData dataWithContentsOfURL: @@ -42,6 +68,22 @@ using namespace InstructionSet::M68k; XCTAssertEqualObjects(@"None", expected, "%@ should decode as %@", instrName, expected); continue; } + + NSString *instruction; + switch(found.operation) { + case Operation::ABCD: instruction = @"ABCD"; break; + + // For now, skip any unmapped operations. + default: continue; + } + + NSString *const operand1 = operand<0>(found); + NSString *const operand2 = operand<1>(found); + + if(operand1.length) instruction = [instruction stringByAppendingFormat:@" %@", operand1]; + if(operand2.length) instruction = [instruction stringByAppendingFormat:@", %@", operand2]; + + XCTAssertEqualObjects(instruction, expected, "%@ should decode as %@; got %@", instrName, expected, instruction); } }