From 4c32fc9b11ffc1a10b0f39de899553c39d8599cc Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 21 Sep 2023 10:22:04 -0400 Subject: [PATCH] These tests appear to be against a real 6502. --- .../Mac/Clock SignalTests/NeskellTests.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/OSBindings/Mac/Clock SignalTests/NeskellTests.swift b/OSBindings/Mac/Clock SignalTests/NeskellTests.swift index dfc449fe0..4534cadf7 100644 --- a/OSBindings/Mac/Clock SignalTests/NeskellTests.swift +++ b/OSBindings/Mac/Clock SignalTests/NeskellTests.swift @@ -16,14 +16,15 @@ class NeskellTests: XCTestCase { private func runTest(resource: String, codeAddress: UInt32) -> CSTestMachine6502? { if let filename = Bundle(for: type(of: self)).path(forResource: resource, ofType: "bin") { if let functionalTest = try? Data(contentsOf: URL(fileURLWithPath: filename)) { - let machine = CSTestMachine6502(processor: .processorNES6502) + let machine = CSTestMachine6502(processor: .processor6502) machine.setData(functionalTest, atAddress: codeAddress) machine.setValue(UInt16(codeAddress), for: .programCounter) + machine.setValue(0xff, for: .stackPointer) // Install the halt-forever trailer. let targetAddress = UInt32(codeAddress + UInt32(functionalTest.count)) - let infiniteStop = Data([0x38, 0xb0, 0xfe]) // i.e. SEC; BCS -2 + let infiniteStop = Data([0x4c, UInt8(targetAddress & 0xff), UInt8((targetAddress >> 8) & 0xff)]) // i.e. JMP to self. machine.setData(infiniteStop, atAddress: targetAddress) while true { @@ -61,4 +62,13 @@ class NeskellTests: XCTestCase { assertStack(machine: result, contents: [0x42, 0x42, 0x41, 0x41, 0x00, 0x01, 0xCE, 0xCF, 0xC0, 0xD0]); } } + + func testBCD() { + if let result = runTest(resource: "bcd_add_sub_test", codeAddress: 0x600) { + XCTAssertEqual(result.value(for: .stackPointer), 0xf6) + XCTAssertEqual(result.value(for: .flags), 0xbc) // Diverge from original in taking B as set when magically + // peaking inside. + assertStack(machine: result, contents: [0x87, 0x91, 0x29, 0x27, 0x34, 0x73, 0x41, 0x46, 0x05]); + } + } }