mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-19 23:32:28 +00:00
These tests appear to be against a real 6502.
This commit is contained in:
parent
4a87aa06a5
commit
4c32fc9b11
@ -16,14 +16,15 @@ class NeskellTests: XCTestCase {
|
|||||||
private func runTest(resource: String, codeAddress: UInt32) -> CSTestMachine6502? {
|
private func runTest(resource: String, codeAddress: UInt32) -> CSTestMachine6502? {
|
||||||
if let filename = Bundle(for: type(of: self)).path(forResource: resource, ofType: "bin") {
|
if let filename = Bundle(for: type(of: self)).path(forResource: resource, ofType: "bin") {
|
||||||
if let functionalTest = try? Data(contentsOf: URL(fileURLWithPath: filename)) {
|
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.setData(functionalTest, atAddress: codeAddress)
|
||||||
machine.setValue(UInt16(codeAddress), for: .programCounter)
|
machine.setValue(UInt16(codeAddress), for: .programCounter)
|
||||||
|
machine.setValue(0xff, for: .stackPointer)
|
||||||
|
|
||||||
// Install the halt-forever trailer.
|
// Install the halt-forever trailer.
|
||||||
let targetAddress = UInt32(codeAddress + UInt32(functionalTest.count))
|
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)
|
machine.setData(infiniteStop, atAddress: targetAddress)
|
||||||
|
|
||||||
while true {
|
while true {
|
||||||
@ -61,4 +62,13 @@ class NeskellTests: XCTestCase {
|
|||||||
assertStack(machine: result, contents: [0x42, 0x42, 0x41, 0x41, 0x00, 0x01, 0xCE, 0xCF, 0xC0, 0xD0]);
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user