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 opcode = consumeMemory();
uint8_t immediate = consumeMemory(); uint8_t immediate = consumeMemory();
switch (opcode) { switch (opcode) {
case 0xc6: // ADD A,d8 case 0xc6:
// Program counter +2 // ADD A,d8
m_pc += 2;
// Clock cycles +8
m_wait_cycles += 8; m_wait_cycles += 8;
// Flags: Z0HC // 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() void CPU::ld16()
{ {
uint8_t opcode = consumeMemory(); uint8_t opcode = consumeMemory();
@ -123,6 +133,35 @@ void CPU::ld16()
m_sp = immediate16(); m_sp = immediate16();
break; 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: default:
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }

4
src/cpu.h

@ -38,6 +38,7 @@ public:
// Load Instructions // Load Instructions
// 8-bit // 8-bit
void ld8();
// 16-bit // 16-bit
void ld16(); void ld16();
@ -45,6 +46,8 @@ public:
// ------------------------------------- // -------------------------------------
// Jumps and Subroutines // Jumps and Subroutines
void jp16();
// ------------------------------------- // -------------------------------------
// Stack Operations Instructions // Stack Operations Instructions
@ -55,6 +58,7 @@ private:
uint8_t peekMemory(int32_t offset = 0) const; uint8_t peekMemory(int32_t offset = 0) const;
uint8_t consumeMemory(); uint8_t consumeMemory();
uint32_t immediate8() { return consumeMemory(); }
uint32_t immediate16() { return consumeMemory() | (consumeMemory() << 8); } uint32_t immediate16() { return consumeMemory() | (consumeMemory() << 8); }
void setBc(uint32_t value); void setBc(uint32_t value);

Loading…
Cancel
Save