1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 23:52:26 +00:00

Attempted to add a proper exit condition for Zexall.

This commit is contained in:
Thomas Harte 2017-05-28 15:13:47 -04:00
parent 5a4d448cc1
commit 6e83b7d6df

View File

@ -11,6 +11,8 @@ import Foundation
class ZexallTests: XCTestCase, CSTestMachineTrapHandler { class ZexallTests: XCTestCase, CSTestMachineTrapHandler {
fileprivate var done = false
func testZexall() { func testZexall() {
if let filename = Bundle(for: type(of: self)).path(forResource: "zexall", ofType: "com") { if let filename = Bundle(for: type(of: self)).path(forResource: "zexall", ofType: "com") {
if let testData = try? Data(contentsOf: URL(fileURLWithPath: filename)) { if let testData = try? Data(contentsOf: URL(fileURLWithPath: filename)) {
@ -24,34 +26,50 @@ class ZexallTests: XCTestCase, CSTestMachineTrapHandler {
machine.addTrapAddress(0x0005); machine.addTrapAddress(0x0005);
machine.trapHandler = self machine.trapHandler = self
// establish 0 as another trap location, as RST 0h is one of the ways that
// CP/M programs can exit
machine.addTrapAddress(0);
// seed execution at 0x0100 // seed execution at 0x0100
machine.setValue(0x0100, for: .programCounter) machine.setValue(0x0100, for: .programCounter)
// run! // run!
machine.runForNumber(ofCycles: 20) while !done {
machine.runForNumber(ofCycles: 200)
}
} }
} }
} }
func testMachine(_ testMachine: CSTestMachineZ80!, didTrapAtAddress address: UInt16) { func testMachine(_ testMachine: CSTestMachineZ80!, didTrapAtAddress address: UInt16) {
// only 0x0005 was registered as a trap address, so no need further to inspect switch address {
let cRegister = testMachine.value(for: .C) case 0x0005:
if cRegister == 9 { let cRegister = testMachine.value(for: .C)
var address = testMachine.value(for: .DE) switch cRegister {
var character: Character = " " case 9:
var output = "" var address = testMachine.value(for: .DE)
while true { var character: Character = " "
character = Character(UnicodeScalar(testMachine.value(atAddress: address))) var output = ""
if character == "$" { while true {
break character = Character(UnicodeScalar(testMachine.value(atAddress: address)))
if character == "$" {
break
}
output = output + String(character)
address = address + 1
}
print(output)
case 5:
print(String(describing: UnicodeScalar(testMachine.value(for: .E))))
case 0:
done = true
default:
break
} }
output = output + String(character) case 0x0000:
address = address + 1 done = true;
} default:
print(output) break
}
if cRegister == 5 {
print(String(describing: UnicodeScalar(testMachine.value(for: .E))))
} }
} }
} }