mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-23 20:29:42 +00:00
Added one basic timing test, for now: implied nop should be two cycles.
This commit is contained in:
parent
d19f8ed507
commit
e8f70398c1
@ -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 <CSTestMachineJamHandler> jamHandler;
|
||||
|
||||
@end
|
||||
|
@ -95,4 +95,8 @@ class MachineJamHandler: public CPU6502::AllRAMProcessor::JamHandler {
|
||||
delete _cppJamHandler;
|
||||
}
|
||||
|
||||
- (uint32_t)timestamp {
|
||||
return _processor.get_timestamp();
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user