Implemented most cpu instructions

This commit is contained in:
2025-01-31 12:24:55 -07:00
parent dd1c6d2e0e
commit 83c5a7cbe6
8 changed files with 487 additions and 18 deletions

View File

@ -1,4 +1,5 @@
#include <cpu.h>
#include <bus.h>
extern cpu_context ctx;
@ -50,6 +51,45 @@ void cpu_set_reg(reg_type rt, u16 val) {
}
}
u8 cpu_read_reg8(reg_type rt) {
switch(rt) {
case RT_A: return ctx.regs.a;
case RT_F: return ctx.regs.f;
case RT_B: return ctx.regs.b;
case RT_C: return ctx.regs.c;
case RT_D: return ctx.regs.d;
case RT_E: return ctx.regs.e;
case RT_H: return ctx.regs.h;
case RT_L: return ctx.regs.l;
case RT_HL: {
return bus_read(cpu_read_reg(RT_HL));
}
default:
printf("**ERR INVALID REG8: %d\n", rt);
NO_IMPL
}
}
void cpu_set_reg8(reg_type rt, u8 val) {
switch(rt) {
case RT_A: ctx.regs.a = val & 0XFF; break;
case RT_F: ctx.regs.f = val & 0XFF; break;
case RT_B: ctx.regs.b = val & 0XFF; break;
case RT_C: ctx.regs.c = val & 0XFF; break;
case RT_D: ctx.regs.d = val & 0XFF; break;
case RT_E: ctx.regs.e = val & 0XFF; break;
case RT_H: ctx.regs.h = val & 0XFF; break;
case RT_L: ctx.regs.l = val & 0XFF; break;
case RT_HL: bus_write(cpu_read_reg(RT_HL), val); break;
default:
printf("**ERR INVALID REG8: %d\n", rt);
NO_IMPL
}
}
cpu_registers *cpu_get_regs() {
return &ctx.regs;
}