Browse Source

Emulator: Add opcode $cd

master
Riyyi 2 years ago
parent
commit
7e54c733a8
  1. 26
      src/cpu.cpp
  2. 1
      src/cpu.h

26
src/cpu.cpp

@ -77,6 +77,7 @@ void CPU::update()
case 0x3e: ld8(); break; case 0x3e: ld8(); break;
case 0xc3: jp16(); break; case 0xc3: jp16(); break;
case 0xc6: add(); break; case 0xc6: add(); break;
case 0xcd: call(); break;
case 0xe0: ldh8(); break; case 0xe0: ldh8(); break;
case 0xf0: ldh8(); break; case 0xf0: ldh8(); break;
case 0xf8: ld16(); break; case 0xf8: ld16(); break;
@ -265,6 +266,31 @@ void CPU::ld16()
} }
} }
void CPU::call()
{
uint8_t opcode = pcRead();
switch (opcode) {
case 0xcd: {
// CALL nn
m_wait_cycles += 24;
uint32_t data = pcRead16();
// Push address of next 2 bytes in memory onto stack
m_sp = (m_sp - 1) & 0xffff;
write(m_sp, data >> 8);
m_sp = (m_sp - 1) & 0xffff;
write(m_sp, data & 0x00ff);
// Jump to this address
m_pc = data;
break;
}
default:
VERIFY_NOT_REACHED();
}
}
void CPU::jp16() void CPU::jp16()
{ {
uint8_t opcode = pcRead(); uint8_t opcode = pcRead();

1
src/cpu.h

@ -47,6 +47,7 @@ public:
// ------------------------------------- // -------------------------------------
// Jumps and Subroutines // Jumps and Subroutines
void call();
void jp16(); void jp16();
// ------------------------------------- // -------------------------------------

Loading…
Cancel
Save