From 6da018471383641e2a39768a4d3d9f08bbe4f487 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Thu, 18 Aug 2022 02:29:08 +0200 Subject: [PATCH] Emulator: Add opcode example --- src/cpu.cpp | 21 +++++++++++++++++++++ src/cpu.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/cpu.cpp b/src/cpu.cpp index 3e21fed..b1837e2 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -24,3 +24,24 @@ void CPU::update() Emu::the().writeMemory("RAM", 123, 42); printf("fff"); } + +void CPU::add(uint8_t byte, uint8_t immediate) +{ + switch (byte) { + case 0xc6: // ADD A,d8 + // program_counter += 2; + // clock += 8; + + // Flags: Z0HC + m_z = (m_af >> 8) + immediate == 0; + m_n = 0; + m_h = (m_af >> 8) + immediate > 16; + m_c = (m_af >> 8) + immediate > 255; + + // A = A + r + m_af = m_af + (immediate << 8); + break; + default: + break; + } +} diff --git a/src/cpu.h b/src/cpu.h index 0d1fc98..45346df 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -20,6 +20,8 @@ public: // 8-bit Arithmetic and Logic Instructions + void add(uint8_t byte, uint8_t immediate = 0); + // 16-bit Arithmetic Instructions // Bit Operations Instructions