mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-19 08:31:11 +00:00
Expanded test to hit all 65536 possibilities (and not to allocate a fresh Z80 test machine each time, as that's unnecessary and slow), and fixed implementation to pass test.
This commit is contained in:
parent
660f0e4c40
commit
d51b66c204
@ -9,9 +9,10 @@
|
|||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
class Z80MemptrTests: XCTestCase {
|
class Z80MemptrTests: XCTestCase {
|
||||||
|
private let machine = CSTestMachineZ80()
|
||||||
|
|
||||||
private func test(program : [UInt8], length : Int32, initialValue : UInt16) -> UInt16 {
|
private func test(program : [UInt8], length : Int32, initialValue : UInt16) -> UInt16 {
|
||||||
// Create a machine and install the supplied program at address 0, setting the PC to run from there
|
// Create a machine and install the supplied program at address 0, setting the PC to run from there
|
||||||
let machine = CSTestMachineZ80()
|
|
||||||
machine.setValue(0x0000, for: .programCounter)
|
machine.setValue(0x0000, for: .programCounter)
|
||||||
machine.setData(Data(bytes: program), atAddress: 0x0000)
|
machine.setData(Data(bytes: program), atAddress: 0x0000)
|
||||||
|
|
||||||
@ -24,11 +25,17 @@ class Z80MemptrTests: XCTestCase {
|
|||||||
|
|
||||||
// LD A,(addr)
|
// LD A,(addr)
|
||||||
func testLDAnn() {
|
func testLDAnn() {
|
||||||
let program: [UInt8] = [
|
var program: [UInt8] = [
|
||||||
0x3a, 0x00, 0x00
|
0x3a, 0x00, 0x00
|
||||||
]
|
]
|
||||||
|
for addr in 0 ..< 65536 {
|
||||||
|
program[1] = UInt8(addr & 0x00ff)
|
||||||
|
program[2] = UInt8(addr >> 8)
|
||||||
|
let expectedResult = UInt16((addr + 1) & 0xffff)
|
||||||
|
|
||||||
let result = test(program: program, length: 13, initialValue: 0xffff)
|
let result = test(program: program, length: 13, initialValue: 0xffff)
|
||||||
XCTAssertEqual(result, 0x0001)
|
XCTAssertEqual(result, expectedResult)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -619,7 +619,7 @@ template <class T> class Processor {
|
|||||||
/* 0x37 SCF */ StdInstr({MicroOp::SCF}),
|
/* 0x37 SCF */ StdInstr({MicroOp::SCF}),
|
||||||
/* 0x38 JR C */ JR(TestC),
|
/* 0x38 JR C */ JR(TestC),
|
||||||
/* 0x39 ADD HL, SP */ ADD16(index, sp_),
|
/* 0x39 ADD HL, SP */ ADD16(index, sp_),
|
||||||
/* 0x3a LD A, (nn) */ StdInstr(Read16Inc(pc_, memptr_), Read3(memptr_, a_)),
|
/* 0x3a LD A, (nn) */ StdInstr(Read16Inc(pc_, memptr_), Read3(memptr_, a_), Inc16(memptr_)),
|
||||||
/* 0x3b DEC SP */ Instr(4, {MicroOp::Decrement16, &sp_.full}),
|
/* 0x3b DEC SP */ Instr(4, {MicroOp::Decrement16, &sp_.full}),
|
||||||
|
|
||||||
/* 0x3c INC A; 0x3d DEC A; 0x3e LD A, n */
|
/* 0x3c INC A; 0x3d DEC A; 0x3e LD A, n */
|
||||||
|
Loading…
Reference in New Issue
Block a user