1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-05 10:28:58 +00:00

Merge pull request #159 from TomHarte/JamReplacement

Corrects those tests broken by withdrawal of the 6502 jam handler functionality
This commit is contained in:
Thomas Harte 2017-07-25 23:01:13 -04:00 committed by GitHub
commit 7922a12f02
3 changed files with 33 additions and 46 deletions

View File

@ -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,16 +73,17 @@ 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
]
]
machine.addTrapAddress(0x0203)
self.runTest(code, expectedRunLength: 12)
}
@ -90,8 +92,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 +101,7 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler {
0x48, // [3] PHA
0x48, // [3] PHA
0x68, // [4] PLA
CSTestMachine6502JamOpcode,
]
]
self.runTest(code, expectedRunLength: 10)
}
@ -128,7 +128,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 +136,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 +144,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 +171,8 @@ class MOS6502TimingTests: XCTestCase, CSTestMachine6502JamHandler {
0x86, 0x09, // [3] STX $09
0x87, 0x09, // [3] SAX $09
0x60, // [6] RTS
CSTestMachine6502JamOpcode]
]
machine.addTrapAddress(0x0203)
self.runTest(code, expectedRunLength: 66)
}
@ -191,17 +192,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<UInt8>(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,9 +220,9 @@ 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
self.endTime = machine.timestamp - 1
}
}
}

View File

@ -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.setValue(0x60, forAddress:0xffee)
machine.addTrapAddress(0xffee) // OSWRCH, an RTS
while(machine.value(for: .programCounter) != 0x203) {
machine.runForNumber(ofCycles: 1000)
@ -41,18 +41,11 @@ 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)
output.append(Character(UnicodeScalar(character)!))
machine.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)!))
}
}

View File

@ -21,11 +21,6 @@ typedef NS_ENUM(NSInteger, CSTestMachine6502Register) {
extern const uint8_t CSTestMachine6502JamOpcode;
@class CSTestMachine6502;
@protocol CSTestMachine6502JamHandler <NSObject>
- (void)testMachine:(CSTestMachine6502 *)machine didJamAtAddress:(uint16_t)address;
@end
@interface CSTestMachine6502 : CSTestMachine
- (void)setData:(NSData *)data atAddress:(uint16_t)startAddress;
@ -40,7 +35,6 @@ extern const uint8_t CSTestMachine6502JamOpcode;
@property (nonatomic, readonly) BOOL isJammed;
@property (nonatomic, readonly) uint32_t timestamp;
@property (nonatomic, weak) id <CSTestMachine6502JamHandler> jamHandler;
@property (nonatomic, assign) BOOL irqLine;
@property (nonatomic, assign) BOOL nmiLine;