From e8f70398c1e322b0d25b484f26d5c1a543646cce Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 13 Aug 2015 01:06:56 +0100 Subject: [PATCH] Added one basic timing test, for now: implied nop should be two cycles. --- .../Mac/Clock SignalTests/TestMachine.h | 1 + .../Mac/Clock SignalTests/TestMachine.mm | 4 +++ .../Mac/Clock SignalTests/TimingTests.swift | 32 ++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/OSBindings/Mac/Clock SignalTests/TestMachine.h b/OSBindings/Mac/Clock SignalTests/TestMachine.h index 42a7426da..e0528caf4 100644 --- a/OSBindings/Mac/Clock SignalTests/TestMachine.h +++ b/OSBindings/Mac/Clock SignalTests/TestMachine.h @@ -37,6 +37,7 @@ extern const uint8_t CSTestMachineJamOpcode; - (void)returnFromSubroutine; @property (nonatomic, readonly) BOOL isJammed; +@property (nonatomic, readonly) uint32_t timestamp; @property (nonatomic, weak) id jamHandler; @end diff --git a/OSBindings/Mac/Clock SignalTests/TestMachine.mm b/OSBindings/Mac/Clock SignalTests/TestMachine.mm index c24a3bd93..ffa0d8493 100644 --- a/OSBindings/Mac/Clock SignalTests/TestMachine.mm +++ b/OSBindings/Mac/Clock SignalTests/TestMachine.mm @@ -95,4 +95,8 @@ class MachineJamHandler: public CPU6502::AllRAMProcessor::JamHandler { delete _cppJamHandler; } +- (uint32_t)timestamp { + return _processor.get_timestamp(); +} + @end diff --git a/OSBindings/Mac/Clock SignalTests/TimingTests.swift b/OSBindings/Mac/Clock SignalTests/TimingTests.swift index 1dd9aeecf..2618ddabc 100644 --- a/OSBindings/Mac/Clock SignalTests/TimingTests.swift +++ b/OSBindings/Mac/Clock SignalTests/TimingTests.swift @@ -9,5 +9,35 @@ import Foundation import XCTest -class TimingTests: XCTestCase { +class TimingTests: XCTestCase, CSTestMachineJamHandler { + + private var endTime: UInt32 = 0 + + func testImpliedNOP() { + let code: [UInt8] = [0xea, CSTestMachineJamOpcode] + self.runTest(code, expectedRunLength: 2) + } + + func runTest(code: [UInt8], expectedRunLength: UInt32) { + let machine = CSTestMachine() + + machine.jamHandler = self + + let immediateCode = NSData(bytes: code, length: code.count) + machine.setData(immediateCode, atAddress: 0x200) + machine.setValue(0x200, forRegister: CSTestMachineRegister.ProgramCounter) + + self.endTime = 0 + while self.endTime == 0 { + machine.runForNumberOfCycles(10) + } + + XCTAssert(self.endTime == expectedRunLength, "Took \(self.endTime) cycles to perform") + } + + func testMachine(machine: CSTestMachine!, didJamAtAddress address: UInt16) { + if self.endTime == 0 { + self.endTime = machine.timestamp - 3 + } + } }