Browse Source

Emulator: Add opcode LDH or LD 0xff00

master
Riyyi 2 years ago
parent
commit
2a234fabfd
  1. 31
      src/cpu.cpp
  2. 4
      src/cpu.h

31
src/cpu.cpp

@ -111,6 +111,27 @@ void CPU::ld8()
}
}
void CPU::ldh8()
{
uint8_t opcode = consumeMemory();
switch (opcode) {
case 0xe0:
// LD ($ff00 + n),A == LDH (n),A
// Put value in A into address (0xff00 + next byte in memory):
m_wait_cycles += 12;
writeFf(m_a);
break;
case 0xf0:
// LD A,($ff00 + n) == LDH A,(n)
// Put value at address (0xff00 + next byte in memory) into A:
m_wait_cycles += 12;
m_a = readFf();
break;
default:
VERIFY_NOT_REACHED();
}
}
void CPU::ld16()
{
uint8_t opcode = consumeMemory();
@ -179,6 +200,16 @@ uint8_t CPU::consumeMemory()
return Emu::the().readMemory(m_pc++);
}
void CPU::writeFf(uint32_t value)
{
Emu::the().writeMemory(immediate8() | (0xff << 8), value);
}
uint32_t CPU::readFf()
{
return Emu::the().readMemory(immediate8() | (0xff << 8));
}
void CPU::setBc(uint32_t value)
{
m_b = value >> 8;

4
src/cpu.h

@ -39,6 +39,7 @@ public:
// 8-bit
void ld8();
void ldh8();
// 16-bit
void ld16();
@ -61,6 +62,9 @@ private:
uint32_t immediate8() { return consumeMemory(); }
uint32_t immediate16() { return consumeMemory() | (consumeMemory() << 8); }
void writeFf(uint32_t value);
uint32_t readFf();
void setBc(uint32_t value);
void setDe(uint32_t value);
void setHl(uint32_t value);

Loading…
Cancel
Save