diff --git a/OSBindings/Mac/Clock SignalTests/Z80MemptrTests.swift b/OSBindings/Mac/Clock SignalTests/Z80MemptrTests.swift index 5b7dd6aef..2b5e82f78 100644 --- a/OSBindings/Mac/Clock SignalTests/Z80MemptrTests.swift +++ b/OSBindings/Mac/Clock SignalTests/Z80MemptrTests.swift @@ -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) + } } } diff --git a/Processors/Z80/Z80.hpp b/Processors/Z80/Z80.hpp index d59898f10..6849613e9 100644 --- a/Processors/Z80/Z80.hpp +++ b/Processors/Z80/Z80.hpp @@ -619,7 +619,7 @@ template 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 */