This commit is contained in:
Matt Laux 2019-04-18 23:18:53 -05:00
parent 2e77b9112b
commit a4c720a0fb
1 changed files with 19 additions and 0 deletions

View File

@ -175,6 +175,19 @@ static void xor(struct cpu *regs, u8 value)
clear_flag(regs, FLAG_CARRY);
}
static void push(struct cpu *cpu, u16 value)
{
write16(cpu, cpu->sp - 2, value & 0xff);
write16(cpu, cpu->sp - 1, value >> 8);
cpu->sp -= 2;
}
static u16 pop(struct cpu *cpu)
{
cpu->sp += 2;
return read16(cpu, cpu->sp - 1) << 8 | read16(cpu, cpu->sp - 2);
}
void cpu_step(struct cpu *cpu)
{
u8 temp;
@ -261,6 +274,12 @@ void cpu_step(struct cpu *cpu)
case 0x94:
subtract(cpu, cpu->h);
break;
case 0xcd: // CALL a16
temp = read16(cpu, cpu->pc);
cpu->pc += 2;
push(cpu, cpu->pc);
cpu->pc = temp;
break;
case 0xc3: // JP a16
cpu->pc = read16(cpu, cpu->pc);
break;