jump and nop instructions.

This commit is contained in:
2025-01-30 17:03:56 -07:00
parent cd588671c4
commit ba56bd2491
5 changed files with 130 additions and 8 deletions

View File

@ -10,16 +10,14 @@ void cpu_init() {
static void fetch_instruction() {
ctx.cur_opcode = bus_read(ctx.regs.pc++);
ctx.cur_inst = instruction_by_opcode(ctx.cur_opcode);
if(ctx.cur_inst == NULL){
printf("Unknown Instruction! %d\n", ctx.cur_opcode);
exit(-7);
}
}
static void fetch_data() {
ctx.mem_dest = 0;
ctx.dest_is_mem = false;
if(ctx.cur_inst == NULL) return;
switch(ctx.cur_inst->mode) {
case AM_IMP: return;
case AM_R:
@ -47,7 +45,13 @@ static void fetch_data() {
}
static void execute() {
printf("\tNot executing yet...\n");
IN_PROC proc = inst_get_processor(ctx.cur_inst->type);
if (!proc) {
NO_IMPL
}
proc(&ctx);
}
bool cpu_step() {
@ -56,7 +60,11 @@ bool cpu_step() {
u16 pc = ctx.regs.pc;
fetch_instruction();
fetch_data();
printf("Executing Instruction: %02X PC: %04X\n", ctx.cur_opcode, pc);
printf("%04X: %7s (%02X %02X %02X) A: %02X B: %02X C: %02X\n", pc, ctx.cur_inst != NULL ? inst_name(ctx.cur_inst->type) : "UNK", ctx.cur_opcode, bus_read(pc+1), bus_read(pc+2), ctx.regs.a, ctx.regs.b, ctx.regs.c);
if(ctx.cur_inst == NULL){
printf("Unknown Instruction! %02X\n", ctx.cur_opcode);
exit(-7);
}
execute();
}