Emulator: Add opcode function to lookup table

This commit is contained in:
Riyyi
2022-08-20 03:56:31 +02:00
parent d511ec8397
commit 895b54e927
2 changed files with 6 additions and 3 deletions
+5 -2
View File
@@ -47,6 +47,7 @@ CPU::CPU(uint32_t frequency)
m_shared_registers.emplace("cf", &m_cf); m_shared_registers.emplace("cf", &m_cf);
// Add opcode functions to lookup table // 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(0x08, std::bind(&CPU::ldStack, this));
m_opcode_lookup_table.emplace(0x31, 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)); 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"); // 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) { switch (opcode) {
case 0xc6: // ADD A,d8 case 0xc6: // ADD A,d8
// Program counter +2 // Program counter +2
@@ -98,7 +101,7 @@ void CPU::add(uint8_t opcode, uint8_t immediate)
void CPU::ldStack() void CPU::ldStack()
{ {
printf("Calling stack LD\n"); print("Calling stack LD\n");
uint8_t opcode = Emu::the().bootrom()[m_pc]; uint8_t opcode = Emu::the().bootrom()[m_pc];
switch (opcode) { switch (opcode) {
+1 -1
View File
@@ -22,7 +22,7 @@ public:
// 8-bit Arithmetic and Logic Instructions // 8-bit Arithmetic and Logic Instructions
void add(uint8_t opcode, uint8_t immediate = 0); void add();
// 16-bit Arithmetic Instructions // 16-bit Arithmetic Instructions