xor di and cpu flags

This commit is contained in:
2025-01-30 18:38:29 -07:00
parent 6a82e9fa03
commit 1bf98447a3
6 changed files with 38 additions and 9 deletions

View File

@ -5,6 +5,7 @@ cpu_context ctx = {0};
void cpu_init() {
ctx.regs.pc = 0x100;
ctx.regs.a = 0x01;
}
static void fetch_instruction() {
@ -38,7 +39,7 @@ static void fetch_data() {
return;
}
default:
printf("Unknown Addressing Mode! %d\n", ctx.cur_inst->mode);
printf("Unknown Addressing Mode! %d (%02X)\n", ctx.cur_inst->mode, ctx.cur_opcode);
exit(-7);
return;
}
@ -60,7 +61,7 @@ bool cpu_step() {
u16 pc = ctx.regs.pc;
fetch_instruction();
fetch_data();
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);
printf("%04X: %-7s (%02X %02X %02X) A: %02X B: %02X C: %02X\n", pc, inst_name(ctx.cur_inst->type), 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);

View File

@ -12,6 +12,30 @@ static void proc_nop(cpu_context *ctx) {
}
void cpu_set_flags(cpu_context *ctx, u8 z, u8 n, u8 h, u8 c){
if (z != -1){
BIT_SET(ctx->regs.f, 7, z)
}
if (n != -1){
BIT_SET(ctx->regs.f, 6, n)
}
if (h != -1){
BIT_SET(ctx->regs.f, 5, h)
}
if (c != -1){
BIT_SET(ctx->regs.f, 4, c)
}
}
static void proc_xor(cpu_context *ctx) {
ctx->regs.a ^= ctx->fetched_data & 0XFF;
cpu_set_flags(ctx, ctx->regs.a == 0, 0, 0, 0);
}
static void proc_di(cpu_context *ctx) {
ctx->int_master_enabled = false;
}
static void proc_ld(cpu_context *ctx) {
//TODO
}
@ -43,6 +67,8 @@ IN_PROC processors[] = {
[IN_NOP] = proc_nop,
[IN_LD] = proc_ld,
[IN_JP] = proc_jp,
[IN_DI] = proc_di,
[IN_XOR] = proc_xor
};
IN_PROC inst_get_processor(in_type type) {

View File

@ -11,13 +11,11 @@ instruction instructions[0x100] = {
[0xAF] = {IN_XOR, AM_R, RT_A},
[0xC3] = {IN_JP, AM_D16},
[0xF3] = {IN_DI},
};
instruction *instruction_by_opcode(u8 opcode) {
if (instructions[opcode].type == IN_NONE) {
return NULL;
}
return &instructions[opcode];
}