From 07345d055283b19a9bef651f171ff08761a068f5 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 22 Aug 2022 13:10:30 +0200 Subject: [PATCH] Emulator: Add some more opcodes --- src/cpu.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++----- src/cpu.h | 4 ++++ 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/cpu.cpp b/src/cpu.cpp index f626793..db42fa2 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -77,11 +77,8 @@ void CPU::add() uint8_t opcode = consumeMemory(); uint8_t immediate = consumeMemory(); switch (opcode) { - case 0xc6: // ADD A,d8 - // Program counter +2 - m_pc += 2; - - // Clock cycles +8 + case 0xc6: + // ADD A,d8 m_wait_cycles += 8; // Flags: Z0HC @@ -101,6 +98,19 @@ void CPU::add() } } +void CPU::ld8() +{ + uint8_t opcode = consumeMemory(); + switch (opcode) { + case 0x3e: + m_wait_cycles += 8; + m_a = immediate8(); + break; + default: + VERIFY_NOT_REACHED(); + } +} + void CPU::ld16() { uint8_t opcode = consumeMemory(); @@ -123,6 +133,35 @@ void CPU::ld16() m_sp = immediate16(); break; } + case 0x08: { + m_wait_cycles += 20; + // TODO + break; + } + case 0xf8: { + m_wait_cycles += 12; + // TODO + // TODO flags + break; + } + case 0xf9: { + m_wait_cycles += 8; + m_sp = hl(); + break; + } + default: + VERIFY_NOT_REACHED(); + } +} + +void CPU::jp16() +{ + uint8_t opcode = consumeMemory(); + switch (opcode) { + case 0xc3: + m_wait_cycles += 16; + m_pc = immediate16(); + break; default: VERIFY_NOT_REACHED(); } diff --git a/src/cpu.h b/src/cpu.h index 85cb025..16b491c 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -38,6 +38,7 @@ public: // Load Instructions // 8-bit + void ld8(); // 16-bit void ld16(); @@ -45,6 +46,8 @@ public: // ------------------------------------- // Jumps and Subroutines + void jp16(); + // ------------------------------------- // Stack Operations Instructions @@ -55,6 +58,7 @@ private: uint8_t peekMemory(int32_t offset = 0) const; uint8_t consumeMemory(); + uint32_t immediate8() { return consumeMemory(); } uint32_t immediate16() { return consumeMemory() | (consumeMemory() << 8); } void setBc(uint32_t value);