2015-07-16 23:53:53 +00:00
|
|
|
//
|
2015-07-17 00:52:16 +00:00
|
|
|
// WolfgangLorenzTests.swift
|
|
|
|
// Clock Signal
|
2015-07-16 23:53:53 +00:00
|
|
|
//
|
|
|
|
// 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-16 23:53:53 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
2015-07-17 00:52:16 +00:00
|
|
|
import Foundation
|
2015-07-16 23:53:53 +00:00
|
|
|
|
2021-08-04 02:08:50 +00:00
|
|
|
// Unused Lorenz tests:
|
|
|
|
//
|
|
|
|
// cpuport (tests the 6510 IO ports, I assume);
|
|
|
|
// cputiming (unclear what this times against, probably requires VIC-II delays?);
|
|
|
|
// mmu (presumably requires C64 paging?)
|
|
|
|
// mmufetch (as above)
|
|
|
|
// nmi
|
|
|
|
|
2017-06-04 01:54:42 +00:00
|
|
|
class WolfgangLorenzTests: XCTestCase, CSTestMachineTrapHandler {
|
2020-10-10 13:34:29 +00:00
|
|
|
|
2020-10-10 14:11:57 +00:00
|
|
|
// MARK: - 6502 Tests
|
2017-11-08 03:51:06 +00:00
|
|
|
|
2020-10-10 14:11:57 +00:00
|
|
|
func testStart() {
|
|
|
|
runTest(" start", processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testLDA() {
|
|
|
|
runTest("lda", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor6502)
|
2020-10-10 02:23:54 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testSTA() {
|
|
|
|
runTest("sta", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor6502)
|
2020-10-10 03:26:35 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testLDX() {
|
|
|
|
runTest("ldx", suffixes: ["b", "z", "zy", "a", "ay"], processor: .processor6502)
|
2020-10-10 03:26:35 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testSTX() {
|
|
|
|
runTest("stx", suffixes: ["z", "zy", "a"], processor: .processor6502)
|
2020-10-10 03:26:35 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testLDY() {
|
|
|
|
runTest("ldy", suffixes: ["b", "z", "zx", "a", "ax"], processor: .processor6502)
|
2020-10-10 03:26:35 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testSTY() {
|
|
|
|
runTest("sty", suffixes: ["z", "zx", "a"], processor: .processor6502)
|
2020-10-10 13:34:29 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testTransfers() {
|
|
|
|
testTransfers(processor: .processor6502)
|
2020-10-10 13:34:29 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testStack() {
|
|
|
|
testStack(processor: .processor6502)
|
2020-10-10 03:26:35 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testIncsAndDecs() {
|
|
|
|
testIncsAndDecs(processor: .processor6502)
|
2020-10-10 02:23:54 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testASL() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("asl", suffixes: ["n", "z", "zx", "a", "ax"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testLSR() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("lsr", suffixes: ["n", "z", "zx", "a", "ax"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testROL() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("rol", suffixes: ["n", "z", "zx", "a", "ax"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testROR() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("ror", suffixes: ["n", "z", "zx", "a", "ax"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testAND() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("and", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testORA() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("ora", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testEOR() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("eor", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor6502)
|
2020-10-10 13:34:29 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testFlagManipulation() {
|
2020-10-10 15:30:15 +00:00
|
|
|
testFlagManipulation(processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testADC() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("adc", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testSBC() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("sbc", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testCompare() {
|
2020-10-10 21:26:41 +00:00
|
|
|
testCompare(processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testBIT() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("bit", suffixes: ["z", "a"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testFlow() {
|
2020-10-10 21:26:41 +00:00
|
|
|
testFlow(processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testBranch() {
|
2020-10-10 21:26:41 +00:00
|
|
|
testBranch(processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testNOP() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("nop", suffixes: ["n", "b", "z", "zx", "a", "ax"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testASO() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("aso", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testRLA() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("rla", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testLSE() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("lse", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testRRA() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("rra", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testDCM() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("dcm", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testINS() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("ins", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testLAX() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("lax", suffixes: ["z", "zy", "a", "ay", "ix", "iy"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testAXS() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("axs", suffixes: ["z", "zy", "a", "ix"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testALR() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("alrb", processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testARR() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("arrb", processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testSBX() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("sbxb", processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testSHA() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("sha", suffixes: ["ay", "iy"], processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testSHX() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("shxay", processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testSHY() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("shyax", processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testSHS() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("shsay", processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testLXA() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("lxab", processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testANE() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("aneb", processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testANC() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("ancb", processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testLAS() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("lasay", processor: .processor6502)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testSBCB() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("sbcb(eb)", processor: .processor6502)
|
2020-10-10 14:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: - 65816 Tests
|
|
|
|
|
|
|
|
func testStart65816() {
|
|
|
|
runTest(" start", processor: .processor65816)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testLDA65816() {
|
|
|
|
runTest("lda", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor65816)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testSTA65816() {
|
|
|
|
runTest("sta", suffixes: ["z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor65816)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testLDX65816() {
|
|
|
|
runTest("ldx", suffixes: ["b", "z", "zy", "a", "ay"], processor: .processor65816)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testSTX65816() {
|
|
|
|
runTest("stx", suffixes: ["z", "zy", "a"], processor: .processor65816)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testLDY65816() {
|
|
|
|
runTest("ldy", suffixes: ["b", "z", "zx", "a", "ax"], processor: .processor65816)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testSTY65816() {
|
|
|
|
runTest("sty", suffixes: ["z", "zx", "a"], processor: .processor65816)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testTransfers65816() {
|
|
|
|
testTransfers(processor: .processor65816)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testStack65816() {
|
|
|
|
testStack(processor: .processor65816)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testIncsAndDecs65816() {
|
|
|
|
testIncsAndDecs(processor: .processor65816)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
func testASL65816() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("asl", suffixes: ["n", "z", "zx", "a", "ax"], processor: .processor65816)
|
2020-10-10 14:11:57 +00:00
|
|
|
}
|
|
|
|
func testLSR65816() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("lsr", suffixes: ["n", "z", "zx", "a", "ax"], processor: .processor65816)
|
2020-10-10 14:11:57 +00:00
|
|
|
}
|
|
|
|
func testROL65816() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("rol", suffixes: ["n", "z", "zx", "a", "ax"], processor: .processor65816)
|
2020-10-10 14:11:57 +00:00
|
|
|
}
|
|
|
|
func testROR65816() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("ror", suffixes: ["n", "z", "zx", "a", "ax"], processor: .processor65816)
|
2020-10-10 14:11:57 +00:00
|
|
|
}
|
|
|
|
func testAND65816() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("and", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor65816)
|
2020-10-10 14:11:57 +00:00
|
|
|
}
|
|
|
|
func testORA65816() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("ora", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor65816)
|
2020-10-10 14:11:57 +00:00
|
|
|
}
|
|
|
|
func testEOR65816() {
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest("eor", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"], processor: .processor65816)
|
2020-10-10 14:11:57 +00:00
|
|
|
}
|
2020-10-10 15:30:15 +00:00
|
|
|
func testFlagManipulation65816() {
|
|
|
|
testFlagManipulation(processor: .processor65816)
|
|
|
|
}
|
2020-10-10 21:13:16 +00:00
|
|
|
/*
|
|
|
|
ADC and SBC tests don't apply, as the 65816 follows the 65C02 in setting flags based on the outcome of decimal
|
|
|
|
results, whereas Lorenzz's tests expect the original 6502 behaviour of setting flags based an intermediate value.
|
|
|
|
*/
|
2020-10-10 21:26:41 +00:00
|
|
|
func testCompare65816() {
|
|
|
|
testCompare(processor: .processor65816)
|
|
|
|
}
|
|
|
|
func testBIT65816() {
|
|
|
|
runTest("bit", suffixes: ["z", "a"], processor: .processor65816)
|
|
|
|
}
|
2020-10-20 01:02:46 +00:00
|
|
|
/*
|
|
|
|
The flow tests don't apply; the 65816 [and 65C02] reset the decimal flag upon a BRK, but the 6502 that Lorenz
|
|
|
|
tests doesn't do so.
|
|
|
|
*/
|
2020-10-10 21:26:41 +00:00
|
|
|
func testBranch65816() {
|
|
|
|
testBranch(processor: .processor65816)
|
|
|
|
}
|
2020-10-20 01:02:46 +00:00
|
|
|
/* The NOP tests also don't apply; the 65816 has only one, well-defined NOP. */
|
2020-10-10 14:11:57 +00:00
|
|
|
|
|
|
|
|
2021-07-31 01:21:16 +00:00
|
|
|
// MARK: - CIA Tests
|
|
|
|
|
2021-08-04 02:08:50 +00:00
|
|
|
func testNMI() {
|
|
|
|
// TODO: Requires serial register.
|
|
|
|
runTest("nmi", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
2021-07-31 01:21:16 +00:00
|
|
|
func testCIA1TA() {
|
|
|
|
runTest("cia1ta", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
2021-08-03 21:19:35 +00:00
|
|
|
func testCIA1TB() {
|
|
|
|
runTest("cia1tb", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
2021-08-03 20:58:51 +00:00
|
|
|
func testCIA1TAB() {
|
2021-08-04 02:08:50 +00:00
|
|
|
// Tests Port B timer output. TODO.
|
2021-08-03 20:58:51 +00:00
|
|
|
runTest("cia1tab", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
2021-08-03 21:19:35 +00:00
|
|
|
func testCIA1TB123() {
|
2021-08-04 02:08:50 +00:00
|
|
|
// Tests 6526 TOD clock. TODO.
|
2021-08-03 21:19:35 +00:00
|
|
|
runTest("cia1tb123", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCIA2TA() {
|
|
|
|
runTest("cia2ta", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCIA2TB() {
|
|
|
|
runTest("cia2tb", suffixes: [""], processor: .processor6502)
|
2021-08-03 20:58:51 +00:00
|
|
|
}
|
|
|
|
|
2021-08-03 21:19:35 +00:00
|
|
|
func testCIA2TB123() {
|
|
|
|
runTest("cia1tb123", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCIA1PB6() {
|
|
|
|
runTest("cia1pb6", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCIA1PB7() {
|
|
|
|
runTest("cia1pb7", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCIA2PB6() {
|
|
|
|
runTest("cia2pb6", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCIA2PB7() {
|
|
|
|
runTest("cia2pb7", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
2021-07-31 01:21:16 +00:00
|
|
|
|
2021-08-04 02:08:50 +00:00
|
|
|
func testCIALoadTH() {
|
|
|
|
runTest("loadth", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCIACntPhi2() {
|
|
|
|
runTest("cnto2", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCIAICR() {
|
|
|
|
runTest("icr01", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCIAIMR() {
|
|
|
|
runTest("imr", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCIAFLIPOS() {
|
|
|
|
runTest("flipos", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCIAOneShot() {
|
|
|
|
runTest("oneshot", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCIACNTDefault() {
|
|
|
|
runTest("cntdef", suffixes: [""], processor: .processor6502)
|
|
|
|
}
|
|
|
|
|
2020-10-10 14:11:57 +00:00
|
|
|
// MARK: - Collections
|
|
|
|
|
|
|
|
func testTransfers(processor: CSTestMachine6502Processor) {
|
2020-10-10 14:53:17 +00:00
|
|
|
for test in ["taxn", "tayn", "txan", "tyan", "tsxn", "txsn"] {
|
|
|
|
runTest(test, processor: processor)
|
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
}
|
|
|
|
func testStack(processor: CSTestMachine6502Processor) {
|
2020-10-10 15:30:15 +00:00
|
|
|
for test in ["phan", "plan", "phpn", "plpn"] {
|
|
|
|
runTest(test, processor: processor)
|
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
}
|
|
|
|
func testIncsAndDecs(processor: CSTestMachine6502Processor) {
|
2020-10-10 21:26:41 +00:00
|
|
|
for test in ["inxn", "inyn", "dexn", "deyn", "incz", "inczx", "inca", "incax", "decz", "deczx", "deca", "decax"] {
|
|
|
|
runTest(test, processor: processor)
|
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
}
|
2020-10-10 14:53:17 +00:00
|
|
|
func testFlagManipulation(processor: CSTestMachine6502Processor) {
|
2020-10-10 15:30:15 +00:00
|
|
|
for test in ["clcn", "secn", "cldn", "sedn", "clin", "sein", "clvn"] {
|
|
|
|
runTest(test, processor: processor)
|
|
|
|
}
|
2020-10-10 14:53:17 +00:00
|
|
|
}
|
2020-10-10 21:26:41 +00:00
|
|
|
func testCompare(processor: CSTestMachine6502Processor) {
|
|
|
|
runTest("cmp", suffixes: ["b", "z", "zx", "a", "ax", "ay", "ix", "iy"], processor: processor)
|
|
|
|
runTest("cpx", suffixes: ["b", "z", "a"], processor: processor)
|
|
|
|
runTest("cpy", suffixes: ["b", "z", "a"], processor: processor)
|
|
|
|
}
|
|
|
|
func testFlow(processor: CSTestMachine6502Processor) {
|
|
|
|
for test in ["brkn", "rtin", "jsrw", "rtsn", "jmpw", "jmpi"] {
|
|
|
|
// JMP indirect is explicitly different on a 65C02 and 65816, not having
|
|
|
|
// the page wraparound bug. So run that test only on a plain 6502.
|
|
|
|
if test == "jmpi" && processor != .processor6502 {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
runTest(test, processor: processor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func testBranch(processor: CSTestMachine6502Processor) {
|
|
|
|
for test in ["beqr", "bner", "bmir", "bplr", "bcsr", "bccr", "bvsr", "bvcr"] {
|
|
|
|
runTest(test, processor: processor)
|
|
|
|
}
|
|
|
|
}
|
2020-10-10 14:11:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
// MARK: - Test Running
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2020-10-10 14:11:57 +00:00
|
|
|
fileprivate func runTest(_ name: String, suffixes: [String], processor: CSTestMachine6502Processor) {
|
2015-07-17 00:15:30 +00:00
|
|
|
for suffix in suffixes {
|
|
|
|
let testName = name + suffix
|
2020-10-10 15:22:23 +00:00
|
|
|
runTest(testName, processor: processor)
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
fileprivate var output: String = ""
|
2020-10-10 14:11:57 +00:00
|
|
|
fileprivate func runTest(_ name: String, processor: CSTestMachine6502Processor) {
|
2017-05-15 12:18:57 +00:00
|
|
|
var machine: CSTestMachine6502!
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2021-07-31 01:21:16 +00:00
|
|
|
let bundle = Bundle(for: type(of: self))
|
|
|
|
let mainBundle = Bundle.main
|
2023-05-12 18:14:45 +00:00
|
|
|
if let testFilename = bundle.url(forResource: name, withExtension: nil),
|
2021-07-31 01:21:16 +00:00
|
|
|
let kernelFilename = mainBundle.url(forResource: "kernal.901227-02", withExtension: "bin", subdirectory: "ROMImages/Commodore64") {
|
|
|
|
if let testData = try? Data(contentsOf: testFilename), let kernelData = try? Data(contentsOf: kernelFilename) {
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2021-07-31 01:21:16 +00:00
|
|
|
machine = CSTestMachine6502(processor: processor, hasCIAs: true)
|
2017-06-04 01:54:42 +00:00
|
|
|
machine.trapHandler = self
|
2015-07-17 00:15:30 +00:00
|
|
|
output = ""
|
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
let dataPointer = (testData as NSData).bytes.bindMemory(to: UInt8.self, capacity: testData.count)
|
2020-10-14 01:38:30 +00:00
|
|
|
let loadAddress = UInt32(dataPointer[0]) | (UInt32(dataPointer[1]) << 8)
|
2020-10-13 01:53:27 +00:00
|
|
|
let contents = testData.subdata(in: 2 ..< testData.count)
|
2015-07-31 00:51:32 +00:00
|
|
|
|
|
|
|
machine.setData(contents, atAddress: loadAddress)
|
2021-07-31 01:21:16 +00:00
|
|
|
machine.setData(kernelData, atAddress: 0xe000)
|
2015-07-31 00:51:32 +00:00
|
|
|
|
2020-10-10 01:39:34 +00:00
|
|
|
// Cf. http://www.softwolves.com/arkiv/cbm-hackers/7/7114.html for the steps being taken here.
|
|
|
|
|
2021-07-31 01:21:16 +00:00
|
|
|
// Signal in-border, set up NMI and IRQ vectors as defaults.
|
|
|
|
machine.setValue(0xff, forAddress: 0xd011)
|
|
|
|
|
|
|
|
machine.setValue(0x66, forAddress: 0x0316)
|
|
|
|
machine.setValue(0xfe, forAddress: 0x0317)
|
|
|
|
machine.setValue(0x31, forAddress: 0x0314)
|
|
|
|
machine.setValue(0xea, forAddress: 0x0315)
|
|
|
|
|
2020-10-10 01:39:34 +00:00
|
|
|
// Initialise memory locations as instructed.
|
2015-07-31 00:51:32 +00:00
|
|
|
machine.setValue(0x00, forAddress: 0x0002)
|
|
|
|
machine.setValue(0x00, forAddress: 0xa002)
|
|
|
|
machine.setValue(0x80, forAddress: 0xa003)
|
|
|
|
machine.setValue(0xff, forAddress: 0x01fe)
|
|
|
|
machine.setValue(0x7f, forAddress: 0x01ff)
|
|
|
|
machine.setValue(0x48, forAddress: 0xfffe)
|
|
|
|
machine.setValue(0xff, forAddress: 0xffff)
|
|
|
|
|
2020-10-10 01:39:34 +00:00
|
|
|
// Place the Commodore's default IRQ handler.
|
2020-09-28 02:20:13 +00:00
|
|
|
let irqHandler: [UInt8] = [
|
2015-07-31 00:51:32 +00:00
|
|
|
0x48, 0x8a, 0x48, 0x98, 0x48, 0xba, 0xbd, 0x04, 0x01,
|
|
|
|
0x29, 0x10, 0xf0, 0x03, 0x6c, 0x16, 0x03, 0x6c, 0x14, 0x03
|
2020-09-28 02:20:13 +00:00
|
|
|
]
|
|
|
|
machine.setData(Data(irqHandler), atAddress: 0xff48)
|
2015-07-31 00:51:32 +00:00
|
|
|
|
2020-10-10 01:39:34 +00:00
|
|
|
// Set a couple of trap addresses to capture test output.
|
2017-06-04 01:54:42 +00:00
|
|
|
machine.addTrapAddress(0xffd2) // print character
|
|
|
|
machine.addTrapAddress(0xffe4) // scan keyboard
|
|
|
|
|
2020-10-10 01:39:34 +00:00
|
|
|
// Set a couple of test addresses that indicate failure.
|
2017-06-04 01:54:42 +00:00
|
|
|
machine.addTrapAddress(0x8000) // exit
|
|
|
|
machine.addTrapAddress(0xa474) // exit
|
|
|
|
|
2020-10-10 01:39:34 +00:00
|
|
|
// Ensure that any of those addresses return control.
|
2017-06-04 01:54:42 +00:00
|
|
|
machine.setValue(0x60, forAddress:0xffd2) // 0x60 is RTS
|
|
|
|
machine.setValue(0x60, forAddress:0xffe4)
|
|
|
|
machine.setValue(0x60, forAddress:0x8000)
|
|
|
|
machine.setValue(0x60, forAddress:0xa474)
|
|
|
|
|
2020-10-10 01:39:34 +00:00
|
|
|
// Commodore's load routine resides at $e16f; this is used to spot the end of a test.
|
|
|
|
machine.setData(Data([0x4c, 0x6f, 0xe1]), atAddress: 0xe16f)
|
2015-07-31 00:51:32 +00:00
|
|
|
|
2020-10-10 01:39:34 +00:00
|
|
|
// Seed program entry.
|
|
|
|
machine.setValue(0x0801, for: .programCounter)
|
|
|
|
machine.setValue(0xfd, for: .stackPointer)
|
|
|
|
machine.setValue(0x04, for: .flags)
|
2020-10-10 03:22:48 +00:00
|
|
|
|
|
|
|
// For consistency when debugging; otherwise immaterial.
|
|
|
|
machine.setValue(0x00, for: .A)
|
|
|
|
machine.setValue(0x00, for: .X)
|
|
|
|
machine.setValue(0x00, for: .Y)
|
2015-07-31 00:51:32 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-17 00:15:30 +00:00
|
|
|
|
|
|
|
if machine == nil {
|
2021-07-31 01:21:16 +00:00
|
|
|
NSException(name: NSExceptionName(rawValue: "Failed Test"), reason: "Couldn't load kernel, or file \(name)", userInfo: nil).raise()
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
|
|
|
|
2020-10-10 01:39:34 +00:00
|
|
|
while machine.value(for: .lastOperationAddress) != 0xe16f && !machine.isJammed {
|
2016-09-16 02:12:12 +00:00
|
|
|
machine.runForNumber(ofCycles: 1000)
|
2015-07-31 00:51:32 +00:00
|
|
|
}
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2020-10-10 01:39:34 +00:00
|
|
|
if machine.isJammed {
|
|
|
|
let hexAddress = String(format:"%04x", machine.value(for: .lastOperationAddress))
|
2016-09-16 02:12:12 +00:00
|
|
|
NSException(name: NSExceptionName(rawValue: "Failed Test"), reason: "Processor jammed unexpectedly at \(hexAddress)", userInfo: nil).raise()
|
2015-07-17 00:15:30 +00:00
|
|
|
}
|
2015-07-31 00:51:32 +00:00
|
|
|
}
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
func petsciiToString(_ string: String) -> String {
|
2015-07-31 00:51:32 +00:00
|
|
|
let petsciiToCharCommon: [String] = [
|
|
|
|
"?", "?", "?", "[RUN/STOP]", "?", "[WHT]", "?", "?", "[SHIFT DISABLE]", "[SHIFT ENABLE]", "?", "?", "?", "\r", "[TEXT MODE]", "?",
|
|
|
|
"?", "\n", "[RVS ON]", "[HOME]", "[DEL]", "?", "?", "?", "?", "?", "?", "?", "[RED]", "[RIGHT]", "[GRN]", "[BLU]",
|
|
|
|
|
|
|
|
" ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
|
|
|
|
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?",
|
|
|
|
];
|
|
|
|
|
|
|
|
let petsciiToCharRegular: [String] = [
|
|
|
|
"@", "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", "[", "£", "]", "↑", "←",
|
|
|
|
]
|
|
|
|
let petsciiToCharInverse: [String] = [
|
|
|
|
"@", "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", "[", "£", "]", "↑", "←",
|
|
|
|
]
|
|
|
|
|
|
|
|
var result: String = ""
|
|
|
|
for character in string.utf16 {
|
|
|
|
let charInt: Int = Int(character)
|
|
|
|
|
|
|
|
var stringToAppend = ""
|
|
|
|
|
|
|
|
if charInt&0x7f < petsciiToCharCommon.count {
|
|
|
|
stringToAppend = petsciiToCharCommon[charInt&0x7f]
|
|
|
|
} else {
|
|
|
|
let lookupTable = (charInt > 0x80) ? petsciiToCharInverse : petsciiToCharRegular
|
|
|
|
let lookupIndex = (charInt&0x7f) - petsciiToCharCommon.count
|
|
|
|
if lookupIndex < lookupTable.count {
|
|
|
|
stringToAppend = lookupTable[lookupIndex]
|
|
|
|
} else {
|
|
|
|
stringToAppend += "!"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result += stringToAppend
|
|
|
|
}
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
return result
|
|
|
|
}
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2017-06-04 01:54:42 +00:00
|
|
|
func testMachine(_ testMachine: CSTestMachine, didTrapAtAddress address: UInt16) {
|
|
|
|
let testMachine6502 = testMachine as! CSTestMachine6502
|
2015-07-31 00:51:32 +00:00
|
|
|
switch address {
|
|
|
|
case 0xffd2:
|
2017-06-04 01:54:42 +00:00
|
|
|
testMachine6502.setValue(0x00, forAddress: 0x030c)
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2017-06-04 01:54:42 +00:00
|
|
|
let character = testMachine6502.value(for: CSTestMachine6502Register.A)
|
2016-09-16 02:12:12 +00:00
|
|
|
output.append(Character(UnicodeScalar(character)!))
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
case 0xffe4:
|
2017-06-04 01:54:42 +00:00
|
|
|
testMachine6502.setValue(0x3, for:CSTestMachine6502Register.A)
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
case 0x8000, 0xa474:
|
2020-10-10 15:22:23 +00:00
|
|
|
NSException(name: NSExceptionName(rawValue: "Failed test"), reason: petsciiToString(output), userInfo: nil).raise()
|
2015-07-17 00:15:30 +00:00
|
|
|
|
|
|
|
case 0x0000:
|
2016-09-16 02:12:12 +00:00
|
|
|
NSException(name: NSExceptionName(rawValue: "Failed test"), reason: "Execution hit 0000", userInfo: nil).raise()
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2015-07-31 00:51:32 +00:00
|
|
|
default:
|
2015-07-17 00:15:30 +00:00
|
|
|
let hexAddress = String(format:"%04x", address)
|
2016-09-16 02:12:12 +00:00
|
|
|
NSException(name: NSExceptionName(rawValue: "Failed Test"), reason: "Processor jammed unexpectedly at \(hexAddress)", userInfo: nil).raise()
|
2015-07-31 00:51:32 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-17 00:15:30 +00:00
|
|
|
|
2015-07-16 23:53:53 +00:00
|
|
|
}
|