From af073578123fd2b464893530789ab6b20de26b85 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Tue, 23 Aug 2022 01:28:16 +0200 Subject: [PATCH] Emulator: Add opcode $a8/$af --- src/cpu.cpp | 23 +++++++++++++++++++++++ src/cpu.h | 1 + 2 files changed, 24 insertions(+) diff --git a/src/cpu.cpp b/src/cpu.cpp index f12e676..4986b1a 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -75,6 +75,8 @@ void CPU::update() case 0x32: ld8(); break; case 0x36: ld8(); break; case 0x3e: ld8(); break; + case 0xa8: xor8(); break; + case 0xaf: xor8(); break; case 0xc3: jp16(); break; case 0xc6: add(); break; case 0xcd: call(); break; @@ -116,6 +118,27 @@ void CPU::add() } } +void CPU::xor8() +{ + uint8_t opcode = pcRead(); + switch (opcode) { + case 0xa8: + // XOR B, flags: Z 0 0 0 + m_nf = m_hf = m_cf = 0; + m_a ^= m_b; + m_zf = m_a == 0; + break; + case 0xaf: + // XOR A, flags: 1 0 0 0 + // A^A will always be 0 + m_a = m_nf = m_hf = m_cf = 0; + m_zf = 1; + break; + default: + VERIFY_NOT_REACHED(); + } +} + void CPU::ld8() { uint8_t opcode = pcRead(); diff --git a/src/cpu.h b/src/cpu.h index 2a99b09..c5c6996 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -25,6 +25,7 @@ public: // 8-bit void add(); + void xor8(); // 16-bit