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,6 +1,7 @@
#include <cpu.h>
#include <bus.h>
#include <common.h>
#include <emu.h>
cpu_context ctx = {0};
@ -29,12 +30,19 @@ bool cpu_step() {
if(!ctx.halted) {
u16 pc = ctx.regs.pc;
fetch_instruction();
printf("%04X: %-7s (%02X %02X %02X) AF: %02X%02X BC: %02X%02X DE: %02X%02X HL: %02X%02X SP: %04X PC: %04X\n", pc, inst_name(ctx.cur_inst->type), ctx.cur_opcode, bus_read(pc+1), bus_read(pc+2), ctx.regs.a, ctx.regs.f, ctx.regs.b, ctx.regs.c, ctx.regs.d, ctx.regs.e, ctx.regs.h, ctx.regs.l, ctx.regs.sp, ctx.regs.pc);
fetch_data();
char flags[16];
sprintf(flags, "%c%c%c%c",
ctx.regs.f & (1 << 7) ? 'Z' : '-',
ctx.regs.f & (1 << 6) ? 'N' : '-',
ctx.regs.f & (1 << 5) ? 'H' : '-',
ctx.regs.f & (1 << 4) ? 'C' : '-'
);
printf("%08lX - %04X: %-7s (%02X %02X %02X) A: %02X F: %s BC: %02X%02X DE: %02X%02X HL: %02X%02X SP: %04X PC: %04X\n", emu_get_context()->ticks, pc, inst_name(ctx.cur_inst->type), ctx.cur_opcode, bus_read(pc+1), bus_read(pc+2), ctx.regs.a, flags, ctx.regs.b, ctx.regs.c, ctx.regs.d, ctx.regs.e, ctx.regs.h, ctx.regs.l, ctx.regs.sp, ctx.regs.pc);
if(ctx.cur_inst == NULL){
printf("Unknown Instruction! %02X\n", ctx.cur_opcode);
exit(-7);
}
fetch_data();
execute();
}