1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-09-29 16:55:59 +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:
Thomas Harte 2017-07-21 23:01:35 -04:00
parent 660f0e4c40
commit d51b66c204
2 changed files with 12 additions and 5 deletions

View File

@ -9,9 +9,10 @@
import XCTest
class Z80MemptrTests: XCTestCase {
private let machine = CSTestMachineZ80()
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
let machine = CSTestMachineZ80()
machine.setValue(0x0000, for: .programCounter)
machine.setData(Data(bytes: program), atAddress: 0x0000)
@ -24,11 +25,17 @@ class Z80MemptrTests: XCTestCase {
// LD A,(addr)
func testLDAnn() {
let program: [UInt8] = [
var program: [UInt8] = [
0x3a, 0x00, 0x00
]
let result = test(program: program, length: 13, initialValue: 0xffff)
XCTAssertEqual(result, 0x0001)
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)
XCTAssertEqual(result, expectedResult)
}
}
}

View File

@ -619,7 +619,7 @@ template <class T> class Processor {
/* 0x37 SCF */ StdInstr({MicroOp::SCF}),
/* 0x38 JR C */ JR(TestC),
/* 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}),
/* 0x3c INC A; 0x3d DEC A; 0x3e LD A, n */