From 3eec210b304e18ad83707cfab7c31dab7f0ddb15 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 13 Apr 2021 20:00:29 -0400 Subject: [PATCH] Adds LDI/LDD/LDIR/LDDR tests. --- .../Clock SignalTests/Z80ContentionTests.mm | 72 ++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/OSBindings/Mac/Clock SignalTests/Z80ContentionTests.mm b/OSBindings/Mac/Clock SignalTests/Z80ContentionTests.mm index 85b1ed3ed..15ee17392 100644 --- a/OSBindings/Mac/Clock SignalTests/Z80ContentionTests.mm +++ b/OSBindings/Mac/Clock SignalTests/Z80ContentionTests.mm @@ -54,6 +54,10 @@ struct CapturingZ80: public CPU::Z80::BusHandler { z80_.set_value_of_register(CPU::Z80::Register::StackPointer, initial_sp); } + void set_de(uint16_t value) { + z80_.set_value_of_register(CPU::Z80::Register::DE, value); + } + void run_for(int cycles) { z80_.run_for(HalfCycles(Cycles(cycles))); XCTAssertEqual(bus_records_.size(), cycles * 2); @@ -1219,6 +1223,72 @@ struct ContentionCheck { {initial_sp+1, 3}, {initial_sp, 5}, } z80:z80]; - }} + } +} + +- (void)testLDILDD { + for(const auto &sequence : std::vector>{ + {0xed, 0xa0}, // LDI + {0xed, 0xa8}, // LDD + }) { + CapturingZ80 z80(sequence); + + // Establish a distinct value for DE. + constexpr uint16_t de = 0x9876; + z80.set_de(de); + + z80.run_for(16); + + [self validate48Contention:{ + {initial_pc, 4}, + {initial_pc+1, 4}, + {initial_bc_de_hl, 3}, + {de, 3}, + {de, 1}, + {de, 1}, + } z80:z80]; + [self validatePlus3Contention:{ + {initial_pc, 4}, + {initial_pc+1, 4}, + {initial_bc_de_hl, 3}, + {de, 5}, + } z80:z80]; + } +} + +- (void)testLDIRLDDR { + for(const auto &sequence : std::vector>{ + {0xed, 0xb0}, // LDIR + {0xed, 0xb8}, // LDDR + }) { + CapturingZ80 z80(sequence); + + // Establish a distinct value for DE. + constexpr uint16_t de = 0x9876; + z80.set_de(de); + + z80.run_for(21); + + [self validate48Contention:{ + {initial_pc, 4}, + {initial_pc+1, 4}, + {initial_bc_de_hl, 3}, + {de, 3}, + {de, 1}, + {de, 1}, + {de, 1}, + {de, 1}, + {de, 1}, + {de, 1}, + {de, 1}, + } z80:z80]; + [self validatePlus3Contention:{ + {initial_pc, 4}, + {initial_pc+1, 4}, + {initial_bc_de_hl, 3}, + {de, 10}, + } z80:z80]; + } +} @end