Finished CPU instructions and created ui window.

This commit is contained in:
2025-01-31 14:39:38 -07:00
parent 83c5a7cbe6
commit 9a6dc67c3e
12 changed files with 265 additions and 33 deletions

View File

@ -33,6 +33,46 @@ static void proc_nop(cpu_context *ctx) {
}
static void proc_daa(cpu_context *ctx) {
u8 u = 0;
int fc = 0;
if(CPU_FLAG_H || (!CPU_FLAG_N && (ctx->regs.a & 0xF) >9)) {
u = 6;
}
if(CPU_FLAG_C || (!CPU_FLAG_N && ctx->regs.a > 0x99)) {
u |= 0x60;
fc = 1;
}
ctx->regs.a += CPU_FLAG_N ? -u : u;
cpu_set_flags(ctx, ctx->regs.a == 0, -1, 0, fc);
}
static void proc_cpl(cpu_context *ctx) {
ctx->regs.a = -ctx->regs.a;
cpu_set_flags(ctx, -1, 1, 1, -1);
}
static void proc_scf(cpu_context *ctx) {
cpu_set_flags(ctx, -1, 0, 0, 1);
}
static void proc_ccf(cpu_context *ctx) {
cpu_set_flags(ctx, -1, 0, 0, CPU_FLAG_C ^ 1);
}
static void proc_halt(cpu_context *ctx) {
ctx->halted = true;
}
static void proc_stop(cpu_context *ctx) {
printf("CPU STOP!\n");
NO_IMPL
}
static void proc_rlca(cpu_context *ctx) {
u8 u = ctx->regs.a;
bool c = (u >> 7) & 1;
@ -51,11 +91,22 @@ static void proc_rrca(cpu_context *ctx) {
}
static void proc_rla(cpu_context *ctx) {
u8 u = ctx->regs.a;
u8 cf = CPU_FLAG_C;
u8 c = (u >> 7) & 1;
ctx->regs.a = (u << 1) | cf;
cpu_set_flags(ctx, 0, 0, 0, c);
}
static void proc_rra(cpu_context *ctx) {
u8 carry = CPU_FLAG_C;
u8 new_c = ctx->regs.a & 1;
ctx->regs.a >>= 1;
ctx->regs.a |= (carry << 7);
cpu_set_flags(ctx, 0, 0, 0, new_c);
}
static void proc_cb(cpu_context *ctx) {
@ -360,6 +411,10 @@ static void proc_di(cpu_context *ctx) {
ctx->int_master_enabled = false;
}
static void proc_ei(cpu_context *ctx) {
ctx->enabling_ime = true;
}
static void proc_ld(cpu_context *ctx) {
if(ctx->dest_is_mem) {
if(is_16_bit(ctx->cur_inst->reg_2)) {
@ -471,7 +526,18 @@ IN_PROC processors[] = {
[IN_XOR] = proc_xor,
[IN_OR] = proc_or,
[IN_CP] = proc_cp,
[IN_CB] = proc_cb
[IN_RLCA] = proc_rlca,
[IN_RRCA] = proc_rrca,
[IN_RRA] = proc_rra,
[IN_RLA] = proc_rla,
[IN_STOP] = proc_stop,
[IN_HALT] = proc_halt,
[IN_DAA] = proc_daa,
[IN_CPL] = proc_cpl,
[IN_SCF] = proc_scf,
[IN_CCF] = proc_ccf,
[IN_CB] = proc_cb,
[IN_EI] = proc_ei
};
IN_PROC inst_get_processor(in_type type) {