From 895b54e9270ff98ad0005a918990e18b38c4ea43 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sat, 20 Aug 2022 03:56:31 +0200 Subject: [PATCH] Emulator: Add opcode function to lookup table --- src/cpu.cpp | 7 +++++-- src/cpu.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cpu.cpp b/src/cpu.cpp index 1ff913d..0cefaf7 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -47,6 +47,7 @@ CPU::CPU(uint32_t frequency) m_shared_registers.emplace("cf", &m_cf); // Add opcode functions to lookup table + m_opcode_lookup_table.emplace(0xc6, std::bind(&CPU::add, this)); m_opcode_lookup_table.emplace(0x08, std::bind(&CPU::ldStack, this)); m_opcode_lookup_table.emplace(0x31, std::bind(&CPU::ldStack, this)); m_opcode_lookup_table.emplace(0xf8, std::bind(&CPU::ldStack, this)); @@ -69,8 +70,10 @@ void CPU::update() // print("This is an update from the CPU\n"); } -void CPU::add(uint8_t opcode, uint8_t immediate) +void CPU::add() { + uint8_t opcode = Emu::the().bootrom()[m_pc]; + uint8_t immediate = Emu::the().bootrom()[m_pc + 1]; switch (opcode) { case 0xc6: // ADD A,d8 // Program counter +2 @@ -98,7 +101,7 @@ void CPU::add(uint8_t opcode, uint8_t immediate) void CPU::ldStack() { - printf("Calling stack LD\n"); + print("Calling stack LD\n"); uint8_t opcode = Emu::the().bootrom()[m_pc]; switch (opcode) { diff --git a/src/cpu.h b/src/cpu.h index ab856b5..b32d558 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -22,7 +22,7 @@ public: // 8-bit Arithmetic and Logic Instructions - void add(uint8_t opcode, uint8_t immediate = 0); + void add(); // 16-bit Arithmetic Instructions