cpu/decoder - Fix H and C bits for ADD SP, e8 and LD HL, SP + e8
This commit is contained in:
parent
c7cb345c08
commit
cfa32424c7
3 changed files with 15 additions and 2 deletions
12
cpu/cpu.cpp
12
cpu/cpu.cpp
|
@ -261,6 +261,18 @@ void Cpu::add16(u16& out, u16 lhs, u16 rhs)
|
|||
out = (u16)res32;
|
||||
}
|
||||
|
||||
void Cpu::add16_8(u16& out, u16 lhs, s8 rhs)
|
||||
{
|
||||
s16 rhs16 = rhs;
|
||||
u16 res4 = (lhs & 0x0F) + (rhs & 0x0F);
|
||||
state.halfcarry = (res4 & 0x10);
|
||||
u16 res8 = (lhs & 0xFF) + (rhs & 0xFF);
|
||||
state.carry = (res8 & 0x100);
|
||||
state.subtract = false;
|
||||
u32 res32 = lhs + rhs;
|
||||
out = (u16)res32;
|
||||
}
|
||||
|
||||
bool Cpu::handleInterrupts()
|
||||
{
|
||||
// Once there's an interrupt we exit halt mode
|
||||
|
|
|
@ -149,6 +149,7 @@ private:
|
|||
|
||||
void aluop8(AluOp op, u8 lhs, u8 rhs, u8& out, bool update_carry = true);
|
||||
void add16(u16& out, u16 lhs, u16 rhs);
|
||||
void add16_8(u16& out, u16 lhs, s8 rhs);
|
||||
|
||||
inline
|
||||
void aluop8(AluOp op, u8 rhs, bool update_carry = true)
|
||||
|
|
|
@ -427,12 +427,12 @@ void Cpu::executeInstruction()
|
|||
state.stopped = true;
|
||||
break;
|
||||
case 0xE8: // ADD SP, e8
|
||||
add16(state.SP, state.SP, (s32)((s8)readPC8()));
|
||||
add16_8(state.SP, state.SP, readPC8());
|
||||
state.zero = false;
|
||||
mcycles = 4;
|
||||
break;
|
||||
case 0xF8: // LD HL, SP + e8
|
||||
add16(state.HL, state.SP, (s32)((s8)readPC8()));
|
||||
add16_8(state.SP, state.SP, readPC8());
|
||||
state.zero = false;
|
||||
mcycles = 3;
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue