Browse Source

Emulator: Add some more opcodes

master
Riyyi 2 years ago
parent
commit
07345d0552
  1. 49
      src/cpu.cpp
  2. 4
      src/cpu.h

49
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();
}

4
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);

Loading…
Cancel
Save