1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-11 08:30:55 +00:00

Converted remaining spaces to real tabs.

This commit is contained in:
Thomas Harte 2015-07-30 20:51:32 -04:00
parent 1fa7a77793
commit 20c2d98b9a
6 changed files with 218 additions and 216 deletions

View File

@ -11,23 +11,23 @@ import XCTest
class AllSuiteATests: XCTestCase { class AllSuiteATests: XCTestCase {
func testAllSuiteA() { func testAllSuiteA() {
if let filename = NSBundle(forClass: self.dynamicType).pathForResource("AllSuiteA", ofType: "bin") { if let filename = NSBundle(forClass: self.dynamicType).pathForResource("AllSuiteA", ofType: "bin") {
if let allSuiteA = NSData(contentsOfFile: filename) { if let allSuiteA = NSData(contentsOfFile: filename) {
let machine = CSTestMachine() let machine = CSTestMachine()
machine.setData(allSuiteA, atAddress: 0x4000) machine.setData(allSuiteA, atAddress: 0x4000)
machine.setValue(CSTestMachineJamOpcode, forAddress:0x45c0); // end machine.setValue(CSTestMachineJamOpcode, forAddress:0x45c0); // end
machine.setValue(0x4000, forRegister: CSTestMachineRegister.ProgramCounter) machine.setValue(0x4000, forRegister: CSTestMachineRegister.ProgramCounter)
while !machine.isJammed { while !machine.isJammed {
machine.runForNumberOfCycles(1000) machine.runForNumberOfCycles(1000)
} }
if machine.valueForAddress(0x0210) != 0xff { if machine.valueForAddress(0x0210) != 0xff {
NSException(name: "Failed AllSuiteA", reason: "Failed test \(machine.valueForAddress(0x0210))", userInfo: nil).raise() NSException(name: "Failed AllSuiteA", reason: "Failed test \(machine.valueForAddress(0x0210))", userInfo: nil).raise()
} }
} }
} }
} }
} }

View File

@ -11,50 +11,50 @@ import XCTest
class KlausDormannTests: XCTestCase { class KlausDormannTests: XCTestCase {
func testKlausDormann() { func testKlausDormann() {
func errorForTrapAddress(address: UInt16) -> String? { func errorForTrapAddress(address: UInt16) -> String? {
let hexAddress = String(format:"%04x", address) let hexAddress = String(format:"%04x", address)
switch address { switch address {
case 0x3399: return nil // success! case 0x3399: return nil // success!
case 0x33a7: return "Decimal ADC result has wrong value" case 0x33a7: return "Decimal ADC result has wrong value"
case 0x3502: return "Binary SBC result has wrong value" case 0x3502: return "Binary SBC result has wrong value"
case 0x33b9: return "Decimal SBC result has wrong value" case 0x33b9: return "Decimal SBC result has wrong value"
case 0x33c0: return "Decimal SBC wrong carry flag" case 0x33c0: return "Decimal SBC wrong carry flag"
case 0x36d1: return "BRK: unexpected BRK or IRQ" case 0x36d1: return "BRK: unexpected BRK or IRQ"
case 0x36ac, 0x36f6: return "Improper JSR return address on stack" case 0x36ac, 0x36f6: return "Improper JSR return address on stack"
case 0x36e5: return "BRK flag not set on stack" case 0x36e5: return "BRK flag not set on stack"
case 0x26d2: return "ASL zpg,x produced incorrect flags" case 0x26d2: return "ASL zpg,x produced incorrect flags"
default: return "Unknown error at \(hexAddress)" default: return "Unknown error at \(hexAddress)"
} }
} }
if let filename = NSBundle(forClass: self.dynamicType).pathForResource("6502_functional_test", ofType: "bin") { if let filename = NSBundle(forClass: self.dynamicType).pathForResource("6502_functional_test", ofType: "bin") {
if let functionalTest = NSData(contentsOfFile: filename) { if let functionalTest = NSData(contentsOfFile: filename) {
let machine = CSTestMachine() let machine = CSTestMachine()
machine.setData(functionalTest, atAddress: 0) machine.setData(functionalTest, atAddress: 0)
machine.setValue(0x400, forRegister: CSTestMachineRegister.ProgramCounter) machine.setValue(0x400, forRegister: CSTestMachineRegister.ProgramCounter)
while true { while true {
let oldPC = machine.valueForRegister(CSTestMachineRegister.LastOperationAddress) let oldPC = machine.valueForRegister(CSTestMachineRegister.LastOperationAddress)
machine.runForNumberOfCycles(1000) machine.runForNumberOfCycles(1000)
let newPC = machine.valueForRegister(CSTestMachineRegister.LastOperationAddress) let newPC = machine.valueForRegister(CSTestMachineRegister.LastOperationAddress)
if newPC == oldPC { if newPC == oldPC {
let error = errorForTrapAddress(oldPC) let error = errorForTrapAddress(oldPC)
if let error = error { if let error = error {
NSException(name: "Failed test", reason: error, userInfo: nil).raise() NSException(name: "Failed test", reason: error, userInfo: nil).raise()
} else { } else {
return return
} }
} }
} }
} }
} }
} }
} }

View File

@ -9,11 +9,11 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, CSTestMachineRegister) { typedef NS_ENUM(NSInteger, CSTestMachineRegister) {
CSTestMachineRegisterLastOperationAddress, CSTestMachineRegisterLastOperationAddress,
CSTestMachineRegisterProgramCounter, CSTestMachineRegisterProgramCounter,
CSTestMachineRegisterStackPointer, CSTestMachineRegisterStackPointer,
CSTestMachineRegisterFlags, CSTestMachineRegisterFlags,
CSTestMachineRegisterA CSTestMachineRegisterA
}; };
extern const uint8_t CSTestMachineJamOpcode; extern const uint8_t CSTestMachineJamOpcode;

View File

@ -10,29 +10,29 @@ import XCTest
import Foundation import Foundation
class WolfgangLorenzTests: XCTestCase, CSTestMachineJamHandler { class WolfgangLorenzTests: XCTestCase, CSTestMachineJamHandler {
func testWolfgangLorenzStart() { func testWolfgangLorenzStart() {
self.runWolfgangLorenzTest(" start") self.runWolfgangLorenzTest(" start")
} }
func testWolfgangLorenzLDA() { func testWolfgangLorenzLDA() {
self.runWolfgangLorenzTest("lda", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("lda", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"])
} }
func testWolfgangLorenzSTA() { func testWolfgangLorenzSTA() {
self.runWolfgangLorenzTest("sta", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("sta", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"])
} }
func testWolfgangLorenzLDX() { func testWolfgangLorenzLDX() {
self.runWolfgangLorenzTest("ldx", suffixes: ["b", "z", "zy", "a", "ay"]) self.runWolfgangLorenzTest("ldx", suffixes: ["b", "z", "zy", "a", "ay"])
} }
func testWolfgangLorenzSTX() { func testWolfgangLorenzSTX() {
self.runWolfgangLorenzTest("stx", suffixes: ["z", "zy", "a"]) self.runWolfgangLorenzTest("stx", suffixes: ["z", "zy", "a"])
} }
func testWolfgangLorenzLDY() { func testWolfgangLorenzLDY() {
self.runWolfgangLorenzTest("ldy", suffixes: ["b", "z", "zx", "a", "ax"]) self.runWolfgangLorenzTest("ldy", suffixes: ["b", "z", "zx", "a", "ax"])
} }
func testWolfgangLorenzSTY() { func testWolfgangLorenzSTY() {
self.runWolfgangLorenzTest("sty", suffixes: ["z", "zx", "a"]) self.runWolfgangLorenzTest("sty", suffixes: ["z", "zx", "a"])
} }
func testWolfgangLorenzTransfers() { func testWolfgangLorenzTransfers() {
self.runWolfgangLorenzTest("taxn") self.runWolfgangLorenzTest("taxn")
self.runWolfgangLorenzTest("tayn") self.runWolfgangLorenzTest("tayn")
self.runWolfgangLorenzTest("txan") self.runWolfgangLorenzTest("txan")
@ -40,13 +40,13 @@ class WolfgangLorenzTests: XCTestCase, CSTestMachineJamHandler {
self.runWolfgangLorenzTest("tsxn") self.runWolfgangLorenzTest("tsxn")
self.runWolfgangLorenzTest("txsn") self.runWolfgangLorenzTest("txsn")
} }
func testWolfgangLorenzStack() { func testWolfgangLorenzStack() {
self.runWolfgangLorenzTest("phan") self.runWolfgangLorenzTest("phan")
self.runWolfgangLorenzTest("plan") self.runWolfgangLorenzTest("plan")
self.runWolfgangLorenzTest("phpn") self.runWolfgangLorenzTest("phpn")
self.runWolfgangLorenzTest("plpn") self.runWolfgangLorenzTest("plpn")
} }
func testWolfgangLorenzIncsAndDecs() { func testWolfgangLorenzIncsAndDecs() {
self.runWolfgangLorenzTest("inxn") self.runWolfgangLorenzTest("inxn")
self.runWolfgangLorenzTest("inyn") self.runWolfgangLorenzTest("inyn")
self.runWolfgangLorenzTest("dexn") self.runWolfgangLorenzTest("dexn")
@ -60,28 +60,28 @@ class WolfgangLorenzTests: XCTestCase, CSTestMachineJamHandler {
self.runWolfgangLorenzTest("deca") self.runWolfgangLorenzTest("deca")
self.runWolfgangLorenzTest("decax") self.runWolfgangLorenzTest("decax")
} }
func testWolfgangLorenzASL() { func testWolfgangLorenzASL() {
self.runWolfgangLorenzTest("asl", suffixes: ["n", "z", "zx", "a", "ax"]) self.runWolfgangLorenzTest("asl", suffixes: ["n", "z", "zx", "a", "ax"])
} }
func testWolfgangLorenzLSR() { func testWolfgangLorenzLSR() {
self.runWolfgangLorenzTest("lsr", suffixes: ["n", "z", "zx", "a", "ax"]) self.runWolfgangLorenzTest("lsr", suffixes: ["n", "z", "zx", "a", "ax"])
} }
func testWolfgangLorenzROL() { func testWolfgangLorenzROL() {
self.runWolfgangLorenzTest("rol", suffixes: ["n", "z", "zx", "a", "ax"]) self.runWolfgangLorenzTest("rol", suffixes: ["n", "z", "zx", "a", "ax"])
} }
func testWolfgangLorenzROR() { func testWolfgangLorenzROR() {
self.runWolfgangLorenzTest("ror", suffixes: ["n", "z", "zx", "a", "ax"]) self.runWolfgangLorenzTest("ror", suffixes: ["n", "z", "zx", "a", "ax"])
} }
func testWolfgangLorenzAND() { func testWolfgangLorenzAND() {
self.runWolfgangLorenzTest("and", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("and", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"])
} }
func testWolfgangLorenzORA() { func testWolfgangLorenzORA() {
self.runWolfgangLorenzTest("ora", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("ora", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"])
} }
func testWolfgangLorenzEOR() { func testWolfgangLorenzEOR() {
self.runWolfgangLorenzTest("eor", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("eor", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"])
} }
func testWolfgangLorenzFlagManipulation() { func testWolfgangLorenzFlagManipulation() {
self.runWolfgangLorenzTest("clcn") self.runWolfgangLorenzTest("clcn")
self.runWolfgangLorenzTest("secn") self.runWolfgangLorenzTest("secn")
self.runWolfgangLorenzTest("cldn") self.runWolfgangLorenzTest("cldn")
@ -90,21 +90,21 @@ class WolfgangLorenzTests: XCTestCase, CSTestMachineJamHandler {
self.runWolfgangLorenzTest("sein") self.runWolfgangLorenzTest("sein")
self.runWolfgangLorenzTest("clvn") self.runWolfgangLorenzTest("clvn")
} }
func testWolfgangLorenzADC() { func testWolfgangLorenzADC() {
self.runWolfgangLorenzTest("adc", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("adc", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"])
} }
func testWolfgangLorenzSBC() { func testWolfgangLorenzSBC() {
self.runWolfgangLorenzTest("sbc", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("sbc", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"])
} }
func testWolfgangLorenzCompare() { func testWolfgangLorenzCompare() {
self.runWolfgangLorenzTest("cmp", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("cmp", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"])
self.runWolfgangLorenzTest("cpx", suffixes: ["b", "z", "a"]) self.runWolfgangLorenzTest("cpx", suffixes: ["b", "z", "a"])
self.runWolfgangLorenzTest("cpy", suffixes: ["b", "z", "a"]) self.runWolfgangLorenzTest("cpy", suffixes: ["b", "z", "a"])
} }
func testWolfgangLorenzBIT() { func testWolfgangLorenzBIT() {
self.runWolfgangLorenzTest("bit", suffixes: ["z", "a"]) self.runWolfgangLorenzTest("bit", suffixes: ["z", "a"])
} }
func testWolfgangLorenzFlow() { func testWolfgangLorenzFlow() {
self.runWolfgangLorenzTest("brkn") self.runWolfgangLorenzTest("brkn")
self.runWolfgangLorenzTest("rtin") self.runWolfgangLorenzTest("rtin")
self.runWolfgangLorenzTest("jsrw") self.runWolfgangLorenzTest("jsrw")
@ -112,7 +112,7 @@ class WolfgangLorenzTests: XCTestCase, CSTestMachineJamHandler {
self.runWolfgangLorenzTest("jmpw") self.runWolfgangLorenzTest("jmpw")
self.runWolfgangLorenzTest("jmpi") self.runWolfgangLorenzTest("jmpi")
} }
func testWolfgangLorenzBranch() { func testWolfgangLorenzBranch() {
self.runWolfgangLorenzTest("beqr") self.runWolfgangLorenzTest("beqr")
self.runWolfgangLorenzTest("bner") self.runWolfgangLorenzTest("bner")
self.runWolfgangLorenzTest("bmir") self.runWolfgangLorenzTest("bmir")
@ -122,67 +122,67 @@ class WolfgangLorenzTests: XCTestCase, CSTestMachineJamHandler {
self.runWolfgangLorenzTest("bvsr") self.runWolfgangLorenzTest("bvsr")
self.runWolfgangLorenzTest("bvcr") self.runWolfgangLorenzTest("bvcr")
} }
func testWolfgangLorenzNOP() { func testWolfgangLorenzNOP() {
self.runWolfgangLorenzTest("nop", suffixes: ["n", "b", "z", "zx", "a", "ax"]) self.runWolfgangLorenzTest("nop", suffixes: ["n", "b", "z", "zx", "a", "ax"])
} }
func testWolfgangLorenzASO() { func testWolfgangLorenzASO() {
self.runWolfgangLorenzTest("aso", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("aso", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"])
} }
func testWolfgangLorenzRLA() { func testWolfgangLorenzRLA() {
self.runWolfgangLorenzTest("rla", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("rla", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"])
} }
func testWolfgangLorenzLSE() { func testWolfgangLorenzLSE() {
self.runWolfgangLorenzTest("lse", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("lse", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"])
} }
func testWolfgangLorenzRRA() { func testWolfgangLorenzRRA() {
self.runWolfgangLorenzTest("rra", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("rra", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"])
} }
func testWolfgangLorenzDCM() { func testWolfgangLorenzDCM() {
self.runWolfgangLorenzTest("dcm", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("dcm", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"])
} }
func testWolfgangLorenzINS() { func testWolfgangLorenzINS() {
self.runWolfgangLorenzTest("ins", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("ins", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"])
} }
func testWolfgangLorenzLAX() { func testWolfgangLorenzLAX() {
self.runWolfgangLorenzTest("lax", suffixes: ["z", "zy", "a", "ay", "ix", "iy"]) self.runWolfgangLorenzTest("lax", suffixes: ["z", "zy", "a", "ay", "ix", "iy"])
} }
func testWolfgangLorenzAXS() { func testWolfgangLorenzAXS() {
self.runWolfgangLorenzTest("axs", suffixes: ["z", "zy", "a", "ix"]) self.runWolfgangLorenzTest("axs", suffixes: ["z", "zy", "a", "ix"])
} }
func testWolfgangLorenzALR() { func testWolfgangLorenzALR() {
self.runWolfgangLorenzTest("alrb") self.runWolfgangLorenzTest("alrb")
} }
func testWolfgangLorenzARR() { func testWolfgangLorenzARR() {
self.runWolfgangLorenzTest("arrb") self.runWolfgangLorenzTest("arrb")
} }
func testWolfgangLorenzSBX() { func testWolfgangLorenzSBX() {
self.runWolfgangLorenzTest("sbxb") self.runWolfgangLorenzTest("sbxb")
} }
func testWolfgangLorenzSHA() { func testWolfgangLorenzSHA() {
self.runWolfgangLorenzTest("sha", suffixes: ["ay", "iy"]) self.runWolfgangLorenzTest("sha", suffixes: ["ay", "iy"])
} }
func testWolfgangLorenzSHX() { func testWolfgangLorenzSHX() {
self.runWolfgangLorenzTest("shxay") self.runWolfgangLorenzTest("shxay")
} }
func testWolfgangLorenzSHY() { func testWolfgangLorenzSHY() {
self.runWolfgangLorenzTest("shyax") self.runWolfgangLorenzTest("shyax")
} }
func testWolfgangLorenzSHS() { func testWolfgangLorenzSHS() {
self.runWolfgangLorenzTest("shsay") self.runWolfgangLorenzTest("shsay")
} }
func testWolfgangLorenzLXA() { func testWolfgangLorenzLXA() {
self.runWolfgangLorenzTest("lxab") self.runWolfgangLorenzTest("lxab")
} }
func testWolfgangLorenzANE() { func testWolfgangLorenzANE() {
self.runWolfgangLorenzTest("aneb") self.runWolfgangLorenzTest("aneb")
} }
func testWolfgangLorenzANC() { func testWolfgangLorenzANC() {
self.runWolfgangLorenzTest("ancb") self.runWolfgangLorenzTest("ancb")
} }
func testWolfgangLorenzLAS() { func testWolfgangLorenzLAS() {
self.runWolfgangLorenzTest("lasay") self.runWolfgangLorenzTest("lasay")
} }
func testWolfgangLorenzSBCB() { func testWolfgangLorenzSBCB() {
self.runWolfgangLorenzTest("sbcb(eb)") self.runWolfgangLorenzTest("sbcb(eb)")
} }
@ -193,138 +193,138 @@ class WolfgangLorenzTests: XCTestCase, CSTestMachineJamHandler {
} }
} }
private var output: String = "" private var output: String = ""
private func runWolfgangLorenzTest(name: String) { private func runWolfgangLorenzTest(name: String) {
var machine: CSTestMachine! var machine: CSTestMachine!
if let filename = NSBundle(forClass: self.dynamicType).pathForResource(name, ofType: nil) { if let filename = NSBundle(forClass: self.dynamicType).pathForResource(name, ofType: nil) {
if let testData = NSData(contentsOfFile: filename) { if let testData = NSData(contentsOfFile: filename) {
machine = CSTestMachine() machine = CSTestMachine()
machine.jamHandler = self machine.jamHandler = self
// machine.logActivity = true // machine.logActivity = true
output = "" output = ""
let dataPointer = UnsafePointer<UInt8>(testData.bytes) let dataPointer = UnsafePointer<UInt8>(testData.bytes)
let loadAddress = UInt16(dataPointer[0]) | (UInt16(dataPointer[1]) << 8) let loadAddress = UInt16(dataPointer[0]) | (UInt16(dataPointer[1]) << 8)
let contents = testData.subdataWithRange(NSMakeRange(2, testData.length - 2)) let contents = testData.subdataWithRange(NSMakeRange(2, testData.length - 2))
machine.setData(contents, atAddress: loadAddress) machine.setData(contents, atAddress: loadAddress)
machine.setValue(0x00, forAddress: 0x0002) machine.setValue(0x00, forAddress: 0x0002)
machine.setValue(0x00, forAddress: 0xa002) machine.setValue(0x00, forAddress: 0xa002)
machine.setValue(0x80, forAddress: 0xa003) machine.setValue(0x80, forAddress: 0xa003)
machine.setValue(0xff, forAddress: 0x01fe) machine.setValue(0xff, forAddress: 0x01fe)
machine.setValue(0x7f, forAddress: 0x01ff) machine.setValue(0x7f, forAddress: 0x01ff)
machine.setValue(0x48, forAddress: 0xfffe) machine.setValue(0x48, forAddress: 0xfffe)
machine.setValue(0xff, forAddress: 0xffff) machine.setValue(0xff, forAddress: 0xffff)
let irqHandler = NSData(bytes: [ let irqHandler = NSData(bytes: [
0x48, 0x8a, 0x48, 0x98, 0x48, 0xba, 0xbd, 0x04, 0x01, 0x48, 0x8a, 0x48, 0x98, 0x48, 0xba, 0xbd, 0x04, 0x01,
0x29, 0x10, 0xf0, 0x03, 0x6c, 0x16, 0x03, 0x6c, 0x14, 0x03 0x29, 0x10, 0xf0, 0x03, 0x6c, 0x16, 0x03, 0x6c, 0x14, 0x03
] as [UInt8], length: 19) ] as [UInt8], length: 19)
machine.setData( irqHandler, atAddress: 0xff48) machine.setData( irqHandler, atAddress: 0xff48)
machine.setValue(CSTestMachineJamOpcode, forAddress:0xffd2); // print character machine.setValue(CSTestMachineJamOpcode, forAddress:0xffd2); // print character
machine.setValue(CSTestMachineJamOpcode, forAddress:0xe16f); // load machine.setValue(CSTestMachineJamOpcode, forAddress:0xe16f); // load
machine.setValue(CSTestMachineJamOpcode, forAddress:0xffe4); // scan keyboard machine.setValue(CSTestMachineJamOpcode, forAddress:0xffe4); // scan keyboard
machine.setValue(CSTestMachineJamOpcode, forAddress:0x8000); // exit machine.setValue(CSTestMachineJamOpcode, forAddress:0x8000); // exit
machine.setValue(CSTestMachineJamOpcode, forAddress:0xa474); // exit machine.setValue(CSTestMachineJamOpcode, forAddress:0xa474); // exit
machine.setValue(0x0801, forRegister: CSTestMachineRegister.ProgramCounter) machine.setValue(0x0801, forRegister: CSTestMachineRegister.ProgramCounter)
machine.setValue(0xfd, forRegister: CSTestMachineRegister.StackPointer) machine.setValue(0xfd, forRegister: CSTestMachineRegister.StackPointer)
machine.setValue(0x04, forRegister: CSTestMachineRegister.Flags) machine.setValue(0x04, forRegister: CSTestMachineRegister.Flags)
} }
} }
if machine == nil { if machine == nil {
NSException(name: "Failed Test", reason: "Couldn't load file \(name)", userInfo: nil).raise() NSException(name: "Failed Test", reason: "Couldn't load file \(name)", userInfo: nil).raise()
} }
while !machine.isJammed { while !machine.isJammed {
machine.runForNumberOfCycles(1000) machine.runForNumberOfCycles(1000)
} }
let jammedPC = machine.valueForRegister(CSTestMachineRegister.LastOperationAddress) let jammedPC = machine.valueForRegister(CSTestMachineRegister.LastOperationAddress)
if jammedPC != 0xe16f { if jammedPC != 0xe16f {
let hexAddress = String(format:"%04x", jammedPC) let hexAddress = String(format:"%04x", jammedPC)
NSException(name: "Failed Test", reason: "Processor jammed unexpectedly at \(hexAddress)", userInfo: nil).raise() NSException(name: "Failed Test", reason: "Processor jammed unexpectedly at \(hexAddress)", userInfo: nil).raise()
} }
} }
// MARK: MachineJamHandler // MARK: MachineJamHandler
func petsciiToString(string: String) -> String { func petsciiToString(string: String) -> String {
let petsciiToCharCommon: [String] = [ let petsciiToCharCommon: [String] = [
"?", "?", "?", "[RUN/STOP]", "?", "[WHT]", "?", "?", "[SHIFT DISABLE]", "[SHIFT ENABLE]", "?", "?", "?", "\r", "[TEXT MODE]", "?", "?", "?", "?", "[RUN/STOP]", "?", "[WHT]", "?", "?", "[SHIFT DISABLE]", "[SHIFT ENABLE]", "?", "?", "?", "\r", "[TEXT MODE]", "?",
"?", "\n", "[RVS ON]", "[HOME]", "[DEL]", "?", "?", "?", "?", "?", "?", "?", "[RED]", "[RIGHT]", "[GRN]", "[BLU]", "?", "\n", "[RVS ON]", "[HOME]", "[DEL]", "?", "?", "?", "?", "?", "?", "?", "[RED]", "[RIGHT]", "[GRN]", "[BLU]",
" ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", " ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?",
]; ];
let petsciiToCharRegular: [String] = [ let petsciiToCharRegular: [String] = [
"@", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "@", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "[", "£", "]", "", "", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "[", "£", "]", "", "",
] ]
let petsciiToCharInverse: [String] = [ let petsciiToCharInverse: [String] = [
"@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
"P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "£", "]", "", "", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "£", "]", "", "",
] ]
var result: String = "" var result: String = ""
for character in string.utf16 { for character in string.utf16 {
let charInt: Int = Int(character) let charInt: Int = Int(character)
var stringToAppend = "" var stringToAppend = ""
if charInt&0x7f < petsciiToCharCommon.count { if charInt&0x7f < petsciiToCharCommon.count {
stringToAppend = petsciiToCharCommon[charInt&0x7f] stringToAppend = petsciiToCharCommon[charInt&0x7f]
} else { } else {
let lookupTable = (charInt > 0x80) ? petsciiToCharInverse : petsciiToCharRegular let lookupTable = (charInt > 0x80) ? petsciiToCharInverse : petsciiToCharRegular
let lookupIndex = (charInt&0x7f) - petsciiToCharCommon.count let lookupIndex = (charInt&0x7f) - petsciiToCharCommon.count
if lookupIndex < lookupTable.count { if lookupIndex < lookupTable.count {
stringToAppend = lookupTable[lookupIndex] stringToAppend = lookupTable[lookupIndex]
} else { } else {
stringToAppend += "!" stringToAppend += "!"
} }
} }
result += stringToAppend result += stringToAppend
} }
return result return result
} }
func testMachine(machine: CSTestMachine!, didJamAtAddress address: UInt16) { func testMachine(machine: CSTestMachine!, didJamAtAddress address: UInt16) {
switch address { switch address {
case 0xffd2: case 0xffd2:
machine.setValue(0x00, forAddress: 0x030c) machine.setValue(0x00, forAddress: 0x030c)
let character = machine.valueForRegister(CSTestMachineRegister.A) let character = machine.valueForRegister(CSTestMachineRegister.A)
output.append(Character(UnicodeScalar(character))) output.append(Character(UnicodeScalar(character)))
machine.returnFromSubroutine() machine.returnFromSubroutine()
case 0xffe4: case 0xffe4:
machine.setValue(0x3, forRegister:CSTestMachineRegister.A) machine.setValue(0x3, forRegister:CSTestMachineRegister.A)
machine.returnFromSubroutine() machine.returnFromSubroutine()
case 0x8000, 0xa474: case 0x8000, 0xa474:
NSException(name: "Failed test", reason: self.petsciiToString(output), userInfo: nil).raise() NSException(name: "Failed test", reason: self.petsciiToString(output), userInfo: nil).raise()
case 0x0000: case 0x0000:
NSException(name: "Failed test", reason: "Execution hit 0000", userInfo: nil).raise() NSException(name: "Failed test", reason: "Execution hit 0000", userInfo: nil).raise()
case 0xe16f: // load next (which we consider to be success) case 0xe16f: // load next (which we consider to be success)
break; break;
default: default:
let hexAddress = String(format:"%04x", address) let hexAddress = String(format:"%04x", address)
NSException(name: "Failed Test", reason: "Processor jammed unexpectedly at \(hexAddress)", userInfo: nil).raise() NSException(name: "Failed Test", reason: "Processor jammed unexpectedly at \(hexAddress)", userInfo: nil).raise()
} }
} }
} }

View File

@ -9,30 +9,29 @@
import XCTest import XCTest
class Clock_SignalUITests: XCTestCase { class Clock_SignalUITests: XCTestCase {
override func setUp() { override func setUp() {
super.setUp() super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class. // Put setup code here. This method is called before the invocation of each test method in the class.
// In UI tests it is usually best to stop immediately when a failure occurs. // In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false continueAfterFailure = false
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
if #available(OSX 10.11, *) { if #available(OSX 10.11, *) {
XCUIApplication().launch() XCUIApplication().launch()
} else { } else {
// Fallback on earlier versions // Fallback on earlier versions
} }
} }
override func tearDown() { override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class. // Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown() super.tearDown()
} }
func testExample() { func testExample() {
// Use recording to get started writing UI tests. // Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results. // Use XCTAssert and related functions to verify your tests produce the correct results.
} }
}
}

View File

@ -12,8 +12,8 @@
using namespace Outputs; using namespace Outputs;
static const uint32_t kCRTFixedPointRange = 0xefffffff; static const uint32_t kCRTFixedPointRange = 0xf8ffffff;
static const uint32_t kCRTFixedPointOffset = 0x08000000; static const uint32_t kCRTFixedPointOffset = 0x00800000;
#define kRetraceXMask 0x01 #define kRetraceXMask 0x01
#define kRetraceYMask 0x02 #define kRetraceYMask 0x02
@ -117,14 +117,17 @@ CRT::SyncEvent CRT::next_vertical_sync_event(bool vsync_is_charging, int cycles_
// will an acceptable vertical sync be triggered? // will an acceptable vertical sync be triggered?
if (vsync_is_charging && !_vretrace_counter) { if (vsync_is_charging && !_vretrace_counter) {
if (_sync_capacitor_charge_level < _sync_capacitor_charge_threshold && _sync_capacitor_charge_level + proposedSyncTime >= _sync_capacitor_charge_threshold) { if (_sync_capacitor_charge_level < _sync_capacitor_charge_threshold && _sync_capacitor_charge_level + proposedSyncTime >= _sync_capacitor_charge_threshold) {
proposedSyncTime = _sync_capacitor_charge_threshold - _sync_capacitor_charge_level; uint32_t proposed_sync_y = _rasterPosition.y + (_sync_capacitor_charge_threshold - _sync_capacitor_charge_level) * _scanSpeed.y;
proposedEvent = SyncEvent::StartVSync;
if(proposed_sync_y > (kCRTFixedPointRange * 15) >> 4) {
proposedSyncTime = _sync_capacitor_charge_threshold - _sync_capacitor_charge_level;
proposedEvent = SyncEvent::StartVSync;
}
} }
} }
// will an ongoing vertical sync end? // will an ongoing vertical sync end?
if (_vretrace_counter > 0) { if (_vretrace_counter > 0) {
// && _rasterPosition.y > ((kCRTFixedPointRange * 3) >> 2))
if (_vretrace_counter < proposedSyncTime) { if (_vretrace_counter < proposedSyncTime) {
proposedSyncTime = _vretrace_counter; proposedSyncTime = _vretrace_counter;
proposedEvent = SyncEvent::EndVSync; proposedEvent = SyncEvent::EndVSync;