From eaf313b0f61e7340f59dcad194279dfc1e6b48c0 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 22 Jul 2017 11:20:21 -0400 Subject: [PATCH] Added a test on LD A, (DE) and LD A, (BC), and adjusted implementation to pass. --- .../Clock SignalTests/Z80MemptrTests.swift | 24 ++++++++++++++++++- Processors/Z80/Z80.hpp | 4 ++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/OSBindings/Mac/Clock SignalTests/Z80MemptrTests.swift b/OSBindings/Mac/Clock SignalTests/Z80MemptrTests.swift index 2b5e82f78..c1e49c6c2 100644 --- a/OSBindings/Mac/Clock SignalTests/Z80MemptrTests.swift +++ b/OSBindings/Mac/Clock SignalTests/Z80MemptrTests.swift @@ -23,7 +23,7 @@ class Z80MemptrTests: XCTestCase { return machine.value(for: .memPtr) } - // LD A,(addr) + // LD A, (addr) func testLDAnn() { var program: [UInt8] = [ 0x3a, 0x00, 0x00 @@ -38,4 +38,26 @@ class Z80MemptrTests: XCTestCase { } } + // LD A, (rp) + func testLDArp() { + let bcProgram: [UInt8] = [ + 0x0a + ] + let deProgram: [UInt8] = [ + 0x1a + ] + for addr in 0 ..< 65536 { + machine.setValue(UInt16(addr), for: .BC) + machine.setValue(UInt16(addr), for: .DE) + + let expectedResult = UInt16((addr + 1) & 0xffff) + + let bcResult = test(program: bcProgram, length: 7, initialValue: 0xffff) + let deResult = test(program: deProgram, length: 7, initialValue: 0xffff) + + XCTAssertEqual(bcResult, expectedResult) + XCTAssertEqual(deResult, expectedResult) + } + } + } diff --git a/Processors/Z80/Z80.hpp b/Processors/Z80/Z80.hpp index 6849613e9..57173e695 100644 --- a/Processors/Z80/Z80.hpp +++ b/Processors/Z80/Z80.hpp @@ -574,7 +574,7 @@ template class Processor { /* 0x07 RLCA */ StdInstr({MicroOp::RLCA}), /* 0x08 EX AF, AF' */ StdInstr({MicroOp::ExAFAFDash}), /* 0x09 ADD HL, BC */ ADD16(index, bc_), - /* 0x0a LD A, (BC) */ StdInstr({MicroOp::Move16, &bc_.full, &memptr_.full}, Read3(memptr_, a_)), + /* 0x0a LD A, (BC) */ StdInstr({MicroOp::Move16, &bc_.full, &memptr_.full}, Read3(memptr_, a_), Inc16(memptr_)), /* 0x0b DEC BC; 0x0c INC C; 0x0d DEC C; 0x0e LD C, n */ DEC_INC_DEC_LD(bc_, bc_.bytes.low), @@ -590,7 +590,7 @@ template class Processor { /* 0x17 RLA */ StdInstr({MicroOp::RLA}), /* 0x18 JR */ StdInstr(ReadInc(pc_, temp8_), InternalOperation(5), {MicroOp::CalculateIndexAddress, &pc_.full}, {MicroOp::Move16, &memptr_.full, &pc_.full}), /* 0x19 ADD HL, DE */ ADD16(index, de_), - /* 0x1a LD A, (DE) */ StdInstr({MicroOp::Move16, &de_.full, &memptr_.full}, Read3(memptr_, a_)), + /* 0x1a LD A, (DE) */ StdInstr({MicroOp::Move16, &de_.full, &memptr_.full}, Read3(memptr_, a_), Inc16(memptr_)), /* 0x1b DEC DE; 0x1c INC E; 0x1d DEC E; 0x1e LD E, n */ DEC_INC_DEC_LD(de_, de_.bytes.low),