mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-03 08:05:40 +00:00
59 lines
1.8 KiB
Swift
59 lines
1.8 KiB
Swift
|
//
|
||
|
// BCDTest.swift
|
||
|
// Clock Signal
|
||
|
//
|
||
|
// Created by Thomas Harte on 04/10/2016.
|
||
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import Foundation
|
||
|
import XCTest
|
||
|
|
||
|
class BCDTest: XCTestCase, CSTestMachineJamHandler {
|
||
|
|
||
|
func testBCD() {
|
||
|
if let filename = Bundle(for: type(of: self)).path(forResource: "BCDTEST_beeb", ofType: nil) {
|
||
|
if let bcdTest = try? Data(contentsOf: URL(fileURLWithPath: filename)) {
|
||
|
let machine = CSTestMachine()
|
||
|
machine.jamHandler = self
|
||
|
|
||
|
machine.setData(bcdTest, atAddress: 0x2900)
|
||
|
|
||
|
// install a launchpad
|
||
|
machine.setValue(0x20, forAddress:0x200) // JSR 0x2900
|
||
|
machine.setValue(0x00, forAddress:0x201)
|
||
|
machine.setValue(0x29, forAddress:0x202)
|
||
|
machine.setValue(0x4c, forAddress:0x203) // JMP 0x0203
|
||
|
machine.setValue(0x03, forAddress:0x204)
|
||
|
machine.setValue(0x02, forAddress:0x205)
|
||
|
|
||
|
machine.setValue(0x200, for: CSTestMachineRegister.programCounter)
|
||
|
|
||
|
machine.setValue(CSTestMachineJamOpcode, forAddress:0xffee) // OSWRCH
|
||
|
machine.setValue(CSTestMachineJamOpcode, forAddress:0xffff) // end of test
|
||
|
|
||
|
while(machine.value(for: .programCounter) != 0x203) {
|
||
|
machine.runForNumber(ofCycles: 1000)
|
||
|
}
|
||
|
XCTAssert(machine.value(forAddress:0x84) == 0, output)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fileprivate var output: String = ""
|
||
|
func testMachine(_ machine: CSTestMachine!, didJamAtAddress address: UInt16) {
|
||
|
|
||
|
switch address {
|
||
|
case 0xffee:
|
||
|
let character = machine.value(for: CSTestMachineRegister.A)
|
||
|
output.append(Character(UnicodeScalar(character)!))
|
||
|
|
||
|
machine.returnFromSubroutine()
|
||
|
|
||
|
default:
|
||
|
let hexAddress = String(format:"%04x", address)
|
||
|
NSException(name: NSExceptionName(rawValue: "Failed Test"), reason: "Processor jammed unexpectedly at \(hexAddress)", userInfo: nil).raise()
|
||
|
}
|
||
|
}
|
||
|
}
|