mirror of
https://github.com/mlaux/gb6.git
synced 2024-09-27 09:56:08 +00:00
some instructions
This commit is contained in:
parent
3e264da356
commit
b52d5ce100
23
src/cpu.c
23
src/cpu.c
@ -66,6 +66,18 @@ void cpu_panic(struct cpu *cpu)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline u8 read8(struct cpu *cpu, u16 address)
|
||||||
|
{
|
||||||
|
return cpu->mem_read(cpu->mem_model, address);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline u16 read16(struct cpu *cpu, u16 address)
|
||||||
|
{
|
||||||
|
u8 low = read8(cpu, address);
|
||||||
|
u8 high = read8(cpu, address + 1);
|
||||||
|
return high << 8 | low;
|
||||||
|
}
|
||||||
|
|
||||||
void cpu_step(struct cpu *cpu)
|
void cpu_step(struct cpu *cpu)
|
||||||
{
|
{
|
||||||
u8 opc = cpu->mem_read(cpu->mem_model, cpu->pc);
|
u8 opc = cpu->mem_read(cpu->mem_model, cpu->pc);
|
||||||
@ -73,6 +85,17 @@ void cpu_step(struct cpu *cpu)
|
|||||||
case 0: // NOP
|
case 0: // NOP
|
||||||
cpu->pc++;
|
cpu->pc++;
|
||||||
break;
|
break;
|
||||||
|
case 0x21: // LD HL, d16
|
||||||
|
write_hl(cpu, read16(cpu, cpu->pc + 1));
|
||||||
|
cpu->pc += 3;
|
||||||
|
break;
|
||||||
|
case 0xc3: // JP a16
|
||||||
|
cpu->pc = read16(cpu, cpu->pc + 1);
|
||||||
|
break;
|
||||||
|
case 0xaf: // XOR A
|
||||||
|
cpu->a = 0;
|
||||||
|
cpu->pc++;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
printf("unknown opcode %02x\n", opc);
|
printf("unknown opcode %02x\n", opc);
|
||||||
cpu_panic(cpu);
|
cpu_panic(cpu);
|
||||||
|
Loading…
Reference in New Issue
Block a user