2015-07-17 00:52:16 +00:00
|
|
|
//
|
|
|
|
// KlausDormanTests.swift
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 16/07/2015.
|
|
|
|
// Copyright © 2015 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
func errorForTrapAddress(address: UInt16) -> String? {
|
|
|
|
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
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
if let filename = NSBundle(forClass: self.dynamicType).pathForResource("6502_functional_test", ofType: "bin") {
|
|
|
|
if let functionalTest = NSData(contentsOfFile: filename) {
|
|
|
|
let machine = CSTestMachine()
|
2015-07-17 00:52:16 +00:00
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
machine.setData(functionalTest, atAddress: 0)
|
|
|
|
machine.setValue(0x400, forRegister: CSTestMachineRegister.ProgramCounter)
|
2015-07-17 00:52:16 +00:00
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
while true {
|
|
|
|
let oldPC = machine.valueForRegister(CSTestMachineRegister.LastOperationAddress)
|
|
|
|
machine.runForNumberOfCycles(1000)
|
|
|
|
let newPC = machine.valueForRegister(CSTestMachineRegister.LastOperationAddress)
|
2015-07-17 00:52:16 +00:00
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
if newPC == oldPC {
|
|
|
|
let error = errorForTrapAddress(oldPC)
|
2016-06-29 01:29:43 +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
|
|
|
}
|