From 743eac8c55848cd0ecd16cb4166b20d433dabab6 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 28 May 2017 14:55:14 -0400 Subject: [PATCH] Implemented EXX to complete the base page. 83 failures. --- Processors/Z80/Z80.hpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Processors/Z80/Z80.hpp b/Processors/Z80/Z80.hpp index 9ae063986..e70f27113 100644 --- a/Processors/Z80/Z80.hpp +++ b/Processors/Z80/Z80.hpp @@ -112,7 +112,7 @@ struct MicroOp { ADD16, ADC16, SBC16, CP8, SUB8, SBC8, ADD8, ADC8, - ExDEHL, ExAFAFDash, + ExDEHL, ExAFAFDash, EXX, EI, DI, @@ -572,7 +572,7 @@ template class Processor: public MicroOpScheduler { /* 0xd4 CALL NC */ CALL(TestNC), /* 0xd5 PUSH DE */ Program(WAIT(1), PUSH(de_)), /* 0xd6 SUB n */ Program(FETCH(temp8_, pc_), {MicroOp::SUB8, &temp8_}), /* 0xd7 RST 10h */ RST(), - /* 0xd8 RET C */ RET(TestC), /* 0xd9 EXX */ XX, + /* 0xd8 RET C */ RET(TestC), /* 0xd9 EXX */ Program({MicroOp::EXX}), /* 0xda JP C */ JP(TestC), /* 0xdb IN A, (n) */Program(FETCH(temp16_.bytes.low, pc_), {MicroOp::Move8, &a_, &temp16_.bytes.high}, IN(temp16_, a_)), /* 0xdc CALL C */ CALL(TestC), /* 0xdd [DD page] */Program({MicroOp::SetInstructionPage, &dd_page_}), /* 0xde SBC A, n */ Program(FETCH(temp8_, pc_), {MicroOp::SBC8, &temp8_}), @@ -1009,6 +1009,8 @@ template class Processor: public MicroOpScheduler { *(uint16_t *)operation->destination = (uint16_t)result; } break; +#pragma mark - Conditionals + case MicroOp::TestNZ: if(!zero_result_) { move_to_next_program(); checkSchedule(); } break; case MicroOp::TestZ: if(zero_result_) { move_to_next_program(); checkSchedule(); } break; case MicroOp::TestNC: if(carry_flag_) { move_to_next_program(); checkSchedule(); } break; @@ -1018,10 +1020,13 @@ template class Processor: public MicroOpScheduler { case MicroOp::TestP: if(sign_result_ & 0x80) { move_to_next_program(); checkSchedule(); } break; case MicroOp::TestM: if(!(sign_result_ & 0x80)) { move_to_next_program(); checkSchedule(); } break; +#pragma mark - Exchange + +#define swap(a, b) temp = a.full; a.full = b.full; b.full = temp; + case MicroOp::ExDEHL: { - uint16_t temp = de_.full; - de_.full = hl_.full; - hl_.full = temp; + uint16_t temp; + swap(de_, hl_); } break; case MicroOp::ExAFAFDash: { @@ -1033,6 +1038,15 @@ template class Processor: public MicroOpScheduler { afDash_.bytes.low = f; } break; + case MicroOp::EXX: { + uint16_t temp; + swap(de_, deDash_); + swap(bc_, bcDash_); + swap(hl_, hlDash_); + } break; + +#undef swap + #pragma mark - Repetition case MicroOp::LDIR: {