2016-10-04 11:52:44 +00:00
|
|
|
//
|
|
|
|
// BCDTest.swift
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 04/10/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-10-04 11:52:44 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import XCTest
|
|
|
|
|
2017-07-26 02:48:44 +00:00
|
|
|
class BCDTest: XCTestCase, CSTestMachineTrapHandler {
|
2016-10-04 11:52:44 +00:00
|
|
|
|
|
|
|
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)) {
|
2020-09-27 02:31:50 +00:00
|
|
|
let machine = CSTestMachine6502(processor: .processor6502)
|
2017-07-26 02:48:44 +00:00
|
|
|
machine.trapHandler = self
|
2016-10-04 11:52:44 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2017-05-18 01:44:08 +00:00
|
|
|
machine.setValue(0x200, for: .programCounter)
|
2016-10-04 11:52:44 +00:00
|
|
|
|
2017-07-26 02:55:45 +00:00
|
|
|
machine.setValue(0x60, forAddress:0xffee)
|
|
|
|
machine.addTrapAddress(0xffee) // OSWRCH, an RTS
|
2016-10-04 11:52:44 +00:00
|
|
|
|
|
|
|
while(machine.value(for: .programCounter) != 0x203) {
|
|
|
|
machine.runForNumber(ofCycles: 1000)
|
|
|
|
}
|
|
|
|
XCTAssert(machine.value(forAddress:0x84) == 0, output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 02:42:54 +00:00
|
|
|
private var output: String = ""
|
2017-07-26 02:48:44 +00:00
|
|
|
func testMachine(_ testMachine: CSTestMachine, didTrapAtAddress address: UInt16) {
|
|
|
|
let machine6502 = testMachine as! CSTestMachine6502
|
2016-10-04 11:52:44 +00:00
|
|
|
|
2017-07-26 02:55:45 +00:00
|
|
|
// Only OSWRCH is trapped, so...
|
|
|
|
let character = machine6502.value(for: .A)
|
|
|
|
output.append(Character(UnicodeScalar(character)!))
|
2016-10-04 11:52:44 +00:00
|
|
|
}
|
2020-10-18 02:42:54 +00:00
|
|
|
|
2016-10-04 11:52:44 +00:00
|
|
|
}
|