2015-07-17 00:52:16 +00:00
|
|
|
//
|
|
|
|
// KlausDormanTests.swift
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 16/07/2015.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2015 Thomas Harte. All rights reserved.
|
2015-07-17 00:52:16 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import XCTest
|
|
|
|
|
|
|
|
class KlausDormannTests: XCTestCase {
|
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
func testKlausDormann() {
|
2015-07-17 00:52:16 +00:00
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
func errorForTrapAddress(_ address: UInt16) -> String? {
|
2015-07-31 00:51:32 +00:00
|
|
|
let hexAddress = String(format:"%04x", address)
|
|
|
|
switch address {
|
|
|
|
case 0x3399: return nil // success!
|
2015-07-17 00:52:16 +00:00
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
case 0x33a7: return "Decimal ADC result has wrong value"
|
|
|
|
case 0x3502: return "Binary SBC result has wrong value"
|
|
|
|
case 0x33b9: return "Decimal SBC result has wrong value"
|
|
|
|
case 0x33c0: return "Decimal SBC wrong carry flag"
|
2015-07-17 00:52:16 +00:00
|
|
|
case 0x36d1: return "BRK: unexpected BRK or IRQ"
|
|
|
|
case 0x36ac, 0x36f6: return "Improper JSR return address on stack"
|
|
|
|
case 0x36e5: return "BRK flag not set on stack"
|
|
|
|
case 0x26d2: return "ASL zpg,x produced incorrect flags"
|
2015-07-31 20:44:53 +00:00
|
|
|
case 0x36c6: return "Unexpected RESET"
|
2015-07-17 00:52:16 +00:00
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
default: return "Unknown error at \(hexAddress)"
|
|
|
|
}
|
|
|
|
}
|
2015-07-17 00:52:16 +00:00
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
if let filename = Bundle(for: type(of: self)).path(forResource: "6502_functional_test", ofType: "bin") {
|
|
|
|
if let functionalTest = try? Data(contentsOf: URL(fileURLWithPath: filename)) {
|
2017-05-15 12:18:57 +00:00
|
|
|
let machine = CSTestMachine6502()
|
2015-07-17 00:52:16 +00:00
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
machine.setData(functionalTest, atAddress: 0)
|
2017-05-17 11:49:48 +00:00
|
|
|
machine.setValue(0x400, for: .programCounter)
|
2015-07-17 00:52:16 +00:00
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
while true {
|
2017-05-17 11:49:48 +00:00
|
|
|
let oldPC = machine.value(for: .lastOperationAddress)
|
2016-09-16 02:12:12 +00:00
|
|
|
machine.runForNumber(ofCycles: 1000)
|
2017-05-17 11:49:48 +00:00
|
|
|
let newPC = machine.value(for: .lastOperationAddress)
|
2015-07-17 00:52:16 +00:00
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
if newPC == oldPC {
|
|
|
|
let error = errorForTrapAddress(oldPC)
|
2017-05-17 11:49:48 +00:00
|
|
|
XCTAssert(error == nil, "Failed with error \(error!)")
|
2016-06-29 23:16:34 +00:00
|
|
|
return
|
2015-07-31 00:51:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-17 00:52:16 +00:00
|
|
|
}
|