From 36076b7ea5c326079a2968d853c2c921def11db9 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 25 Jul 2017 22:38:26 -0400 Subject: [PATCH 1/4] Eliminated final vestige of professed jam handling. This should make it clear which tests still think they can capture jams. --- .../Mac/Clock SignalTests/Bridges/TestMachine6502.h | 8 -------- .../Mac/Clock SignalTests/Bridges/TestMachine6502.mm | 2 -- 2 files changed, 10 deletions(-) diff --git a/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.h b/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.h index e41cf2d31..f6b12bccf 100644 --- a/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.h +++ b/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.h @@ -19,13 +19,6 @@ typedef NS_ENUM(NSInteger, CSTestMachine6502Register) { CSTestMachine6502RegisterY, }; -extern const uint8_t CSTestMachine6502JamOpcode; - -@class CSTestMachine6502; -@protocol CSTestMachine6502JamHandler -- (void)testMachine:(CSTestMachine6502 *)machine didJamAtAddress:(uint16_t)address; -@end - @interface CSTestMachine6502 : CSTestMachine - (void)setData:(NSData *)data atAddress:(uint16_t)startAddress; @@ -40,7 +33,6 @@ extern const uint8_t CSTestMachine6502JamOpcode; @property (nonatomic, readonly) BOOL isJammed; @property (nonatomic, readonly) uint32_t timestamp; -@property (nonatomic, weak) id jamHandler; @property (nonatomic, assign) BOOL irqLine; @property (nonatomic, assign) BOOL nmiLine; diff --git a/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.mm b/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.mm index a9ad4c69f..81e9d1afb 100644 --- a/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.mm +++ b/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.mm @@ -11,8 +11,6 @@ #include "6502AllRAM.hpp" #import "TestMachine+ForSubclassEyesOnly.h" -const uint8_t CSTestMachine6502JamOpcode = CPU::MOS6502::JamOpcode; - #pragma mark - Register enum map static CPU::MOS6502::Register registerForRegister(CSTestMachine6502Register reg) { From 3ca51bedc67b218181c8c847a7039cb5bffbcf41 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 25 Jul 2017 22:48:44 -0400 Subject: [PATCH 2/4] Discovered legitimate uses of the jam opcode so reinstated it. Corrected illegitimate uses. --- .../Clock SignalTests/6502TimingTests.swift | 42 +++++++++---------- .../Mac/Clock SignalTests/BCDTest.swift | 15 +++---- .../Bridges/TestMachine6502.h | 2 + .../Bridges/TestMachine6502.mm | 2 + 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/OSBindings/Mac/Clock SignalTests/6502TimingTests.swift b/OSBindings/Mac/Clock SignalTests/6502TimingTests.swift index d6d8cc8b8..2874dc7ca 100644 --- a/OSBindings/Mac/Clock SignalTests/6502TimingTests.swift +++ b/OSBindings/Mac/Clock SignalTests/6502TimingTests.swift @@ -9,9 +9,10 @@ import Foundation import XCTest -class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler { +class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler { - fileprivate var endTime: UInt32 = 0 + private var endTime: UInt32 = 0 + private let machine = CSTestMachine6502() func testImplied() { let code: [UInt8] = [ @@ -20,7 +21,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler { 0xca, // [2] DEX 0x18, // [2] CLC 0x2a, // [2] ROL A - CSTestMachine6502JamOpcode] + ] self.runTest(code, expectedRunLength: 10) } @@ -37,7 +38,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler { 0xa1, 0x44, // [6] LDA ($44, x) 0xb1, 0x00, // [5] LDA ($00), y (no wrap) 0xb1, 0x02, // [6] LDA ($01), y (wrap) - CSTestMachine6502JamOpcode] + ] self.runTest(code, expectedRunLength: 48) } @@ -45,7 +46,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler { let code: [UInt8] = [ 0x24, 0x2a, // [3] BIT $2a 0x2c, 0x2a, 0x2b, // [4] BIT $2b2a - CSTestMachine6502JamOpcode] + ] self.runTest(code, expectedRunLength: 7) } @@ -61,7 +62,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler { 0x81, 0x44, // [6] STA ($44, x) 0x91, 0x00, // [6] STA ($00), y (no wrap) 0x91, 0x02, // [6] STA ($01), y (wrap) - CSTestMachine6502JamOpcode] + ] self.runTest(code, expectedRunLength: 49) } @@ -72,14 +73,14 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler { 0xee, 0x00, 0x00, // [6] INC $0000 0xfe, 0x00, 0x00, // [7] INC $0000, x (no wrap) 0xfe, 0x02, 0x00, // [7] INC $0002, x (wrap) - CSTestMachine6502JamOpcode] + ] self.runTest(code, expectedRunLength: 31) } func testJSR() { let code: [UInt8] = [ 0x20, 0x04, 0x02, // [6] JSR $0204 - CSTestMachine6502JamOpcode, + 0x00, 0x60, // [6] RTS ] self.runTest(code, expectedRunLength: 12) @@ -90,8 +91,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler { 0x6c, 0x04, 0x00, // [5] JMP ($0004) 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x0b, 0x02, // [3] JMP 020b - CSTestMachine6502JamOpcode, - ] + ] self.runTest(code, expectedRunLength: 8) } @@ -100,8 +100,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler { 0x48, // [3] PHA 0x48, // [3] PHA 0x68, // [4] PLA - CSTestMachine6502JamOpcode, - ] + ] self.runTest(code, expectedRunLength: 10) } @@ -128,7 +127,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - CSTestMachine6502JamOpcode] + ] self.runTest(code, expectedRunLength: 14) } @@ -136,7 +135,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler { let code: [UInt8] = [ 0x8d, 0x08, 0x00, // [4] STA $0008 0xc6, 0xb4, // [5] DEC $B4 - CSTestMachine6502JamOpcode] + ] self.runTest(code, expectedRunLength: 9) } @@ -144,14 +143,14 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler { let code: [UInt8] = [ 0x16, 0x16, // [6] ASL $16, x 0x46, 0x46, // [5] LSR $46 - CSTestMachine6502JamOpcode] + ] self.runTest(code, expectedRunLength: 11) } func testSnippet3() { let code: [UInt8] = [ 0x20, 0x04, 0x02, // [6] JSR $0204 - CSTestMachine6502JamOpcode, + 0x00, 0x86, 0x09, // [3] STX $09 0x86, 0x09, // [3] STX $09 0x85, 0x09, // [3] STA $09 @@ -171,7 +170,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler { 0x86, 0x09, // [3] STX $09 0x87, 0x09, // [3] SAX $09 0x60, // [6] RTS - CSTestMachine6502JamOpcode] + ] self.runTest(code, expectedRunLength: 66) } @@ -191,17 +190,16 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler { 0xd4, 0x00, // [4] NOP zpg, x 0xe2, 0x00, // [2] NOP # 0xf4, 0x00, // [4] NOP zpg, x - CSTestMachine6502JamOpcode] + ] self.runTest(code, expectedRunLength: 43) } func runTest(_ code: [UInt8], expectedRunLength: UInt32) { - let machine = CSTestMachine6502() - - machine.jamHandler = self + machine.trapHandler = self let immediateCode = Data(bytes: UnsafePointer(code), count: code.count) machine.setData(immediateCode, atAddress: 0x200) + machine.addTrapAddress(UInt16(0x200 + code.count)) machine.setValue(0x00, forAddress: 0x0000) machine.setValue(0x00, forAddress: 0x0001) machine.setValue(0xff, forAddress: 0x0002) @@ -220,7 +218,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler { XCTAssert(self.endTime == expectedRunLength, "Took \(self.endTime) cycles to perform rather than \(expectedRunLength)") } - func testMachine(_ machine: CSTestMachine6502!, didJamAtAddress address: UInt16) { + func testMachine(_ testMachine: CSTestMachine, didTrapAtAddress address: UInt16) { if self.endTime == 0 { self.endTime = machine.timestamp - 9 } diff --git a/OSBindings/Mac/Clock SignalTests/BCDTest.swift b/OSBindings/Mac/Clock SignalTests/BCDTest.swift index 619bb3e0a..c7723c722 100644 --- a/OSBindings/Mac/Clock SignalTests/BCDTest.swift +++ b/OSBindings/Mac/Clock SignalTests/BCDTest.swift @@ -9,13 +9,13 @@ import Foundation import XCTest -class BCDTest: XCTestCase, CSTestMachine6502JamHandler { +class BCDTest: XCTestCase, CSTestMachineTrapHandler { func testBCD() { if let filename = Bundle(for: type(of: self)).path(forResource: "BCDTEST_beeb", ofType: nil) { if let bcdTest = try? Data(contentsOf: URL(fileURLWithPath: filename)) { let machine = CSTestMachine6502() - machine.jamHandler = self + machine.trapHandler = self machine.setData(bcdTest, atAddress: 0x2900) @@ -29,8 +29,8 @@ class BCDTest: XCTestCase, CSTestMachine6502JamHandler { machine.setValue(0x200, for: .programCounter) - machine.setValue(CSTestMachine6502JamOpcode, forAddress:0xffee) // OSWRCH - machine.setValue(CSTestMachine6502JamOpcode, forAddress:0xffff) // end of test + machine.addTrapAddress(0xffee) // OSWRCH + machine.addTrapAddress(0xffff) // end of test while(machine.value(for: .programCounter) != 0x203) { machine.runForNumber(ofCycles: 1000) @@ -41,14 +41,15 @@ class BCDTest: XCTestCase, CSTestMachine6502JamHandler { } fileprivate var output: String = "" - func testMachine(_ machine: CSTestMachine6502!, didJamAtAddress address: UInt16) { + func testMachine(_ testMachine: CSTestMachine, didTrapAtAddress address: UInt16) { + let machine6502 = testMachine as! CSTestMachine6502 switch address { case 0xffee: - let character = machine.value(for: .A) + let character = machine6502.value(for: .A) output.append(Character(UnicodeScalar(character)!)) - machine.returnFromSubroutine() + machine6502.returnFromSubroutine() default: let hexAddress = String(format:"%04x", address) diff --git a/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.h b/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.h index f6b12bccf..66a1d0d7e 100644 --- a/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.h +++ b/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.h @@ -19,6 +19,8 @@ typedef NS_ENUM(NSInteger, CSTestMachine6502Register) { CSTestMachine6502RegisterY, }; +extern const uint8_t CSTestMachine6502JamOpcode; + @interface CSTestMachine6502 : CSTestMachine - (void)setData:(NSData *)data atAddress:(uint16_t)startAddress; diff --git a/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.mm b/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.mm index 81e9d1afb..a9ad4c69f 100644 --- a/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.mm +++ b/OSBindings/Mac/Clock SignalTests/Bridges/TestMachine6502.mm @@ -11,6 +11,8 @@ #include "6502AllRAM.hpp" #import "TestMachine+ForSubclassEyesOnly.h" +const uint8_t CSTestMachine6502JamOpcode = CPU::MOS6502::JamOpcode; + #pragma mark - Register enum map static CPU::MOS6502::Register registerForRegister(CSTestMachine6502Register reg) { From 3c254360ba97c570ecf211e176d8f249019db5c1 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 25 Jul 2017 22:55:45 -0400 Subject: [PATCH 3/4] Completed fixture of the 6502 BCD test. --- OSBindings/Mac/Clock SignalTests/BCDTest.swift | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/OSBindings/Mac/Clock SignalTests/BCDTest.swift b/OSBindings/Mac/Clock SignalTests/BCDTest.swift index c7723c722..3775ee43a 100644 --- a/OSBindings/Mac/Clock SignalTests/BCDTest.swift +++ b/OSBindings/Mac/Clock SignalTests/BCDTest.swift @@ -29,8 +29,8 @@ class BCDTest: XCTestCase, CSTestMachineTrapHandler { machine.setValue(0x200, for: .programCounter) - machine.addTrapAddress(0xffee) // OSWRCH - machine.addTrapAddress(0xffff) // end of test + machine.setValue(0x60, forAddress:0xffee) + machine.addTrapAddress(0xffee) // OSWRCH, an RTS while(machine.value(for: .programCounter) != 0x203) { machine.runForNumber(ofCycles: 1000) @@ -44,16 +44,8 @@ class BCDTest: XCTestCase, CSTestMachineTrapHandler { func testMachine(_ testMachine: CSTestMachine, didTrapAtAddress address: UInt16) { let machine6502 = testMachine as! CSTestMachine6502 - switch address { - case 0xffee: - let character = machine6502.value(for: .A) - output.append(Character(UnicodeScalar(character)!)) - - machine6502.returnFromSubroutine() - - default: - let hexAddress = String(format:"%04x", address) - NSException(name: NSExceptionName(rawValue: "Failed Test"), reason: "Processor jammed unexpectedly at \(hexAddress)", userInfo: nil).raise() - } + // Only OSWRCH is trapped, so... + let character = machine6502.value(for: .A) + output.append(Character(UnicodeScalar(character)!)) } } From 37ccb9d3b6b039b73636541ce4e5c1ce5d730423 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 25 Jul 2017 23:00:39 -0400 Subject: [PATCH 4/4] Fixed 6502 timing tests. --- OSBindings/Mac/Clock SignalTests/6502TimingTests.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/OSBindings/Mac/Clock SignalTests/6502TimingTests.swift b/OSBindings/Mac/Clock SignalTests/6502TimingTests.swift index 2874dc7ca..98031b971 100644 --- a/OSBindings/Mac/Clock SignalTests/6502TimingTests.swift +++ b/OSBindings/Mac/Clock SignalTests/6502TimingTests.swift @@ -82,7 +82,8 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler { 0x20, 0x04, 0x02, // [6] JSR $0204 0x00, 0x60, // [6] RTS - ] + ] + machine.addTrapAddress(0x0203) self.runTest(code, expectedRunLength: 12) } @@ -171,6 +172,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler { 0x87, 0x09, // [3] SAX $09 0x60, // [6] RTS ] + machine.addTrapAddress(0x0203) self.runTest(code, expectedRunLength: 66) } @@ -220,7 +222,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachineTrapHandler { func testMachine(_ testMachine: CSTestMachine, didTrapAtAddress address: UInt16) { if self.endTime == 0 { - self.endTime = machine.timestamp - 9 + self.endTime = machine.timestamp - 1 } } }