working on mooneye test suite

This commit is contained in:
2025-05-30 00:35:44 -06:00
parent 4d6973304d
commit 1f55455a65
7 changed files with 87 additions and 44 deletions

View File

@ -2,6 +2,7 @@
#include <emu.h>
#include <bus.h>
#include <stack.h>
#include <timer.h>
reg_type decode_reg(u8 reg);
@ -51,7 +52,7 @@ static void proc_daa(cpu_context *ctx) {
ctx->regs.a += CPU_FLAG_N ? -u : u;
cpu_set_flags(ctx, ctx->regs.a == 0, -1, 0, fc);
cpu_set_flags(ctx, ctx->regs.a == 0, CPU_FLAG_N, 0, fc);
}
static void proc_cpl(cpu_context *ctx) {
@ -72,6 +73,7 @@ static void proc_halt(cpu_context *ctx) {
}
static void proc_stop(cpu_context *ctx) {
timer_get_context()->div = 0;
printf("CPU STOP!\n");
}
@ -303,10 +305,6 @@ static void proc_add(cpu_context *ctx) {
bool is_16bit = is_16_bit(ctx->cur_inst->reg_1);
if(is_16bit) {
emu_cycles(1);
}
if(ctx->cur_inst->reg_1 == RT_SP) {
val = cpu_read_reg(ctx->cur_inst->reg_1) + (char)ctx->fetched_data;
}
@ -329,6 +327,12 @@ static void proc_add(cpu_context *ctx) {
}
cpu_set_reg(ctx->cur_inst->reg_1, val & 0xFFFF);
if(is_16bit) {
emu_cycles(1);
}
if(ctx->cur_inst->reg_1 == RT_SP) {
emu_cycles(1);
}
cpu_set_flags(ctx, z, 0, h, c);
}
@ -358,10 +362,6 @@ static void proc_inc(cpu_context *ctx) {
static void proc_dec(cpu_context *ctx) {
u16 val = cpu_read_reg(ctx->cur_inst->reg_1) - 1;
if(is_16_bit(ctx->cur_inst->reg_1)) {
//emu_cycles(1);
}
if (ctx->cur_inst->reg_1 == RT_HL && ctx->dest_is_mem) {
val = ctx->fetched_data - 1;
val &= 0xFF;
@ -371,6 +371,10 @@ static void proc_dec(cpu_context *ctx) {
val = cpu_read_reg(ctx->cur_inst->reg_1);
}
if(is_16_bit(ctx->cur_inst->reg_1)) {
emu_cycles(1);
}
if((ctx->cur_opcode & 0x0B) == 0x0B) {
return;
}
@ -394,21 +398,20 @@ static void proc_pop(cpu_context *ctx) {
static void proc_push(cpu_context *ctx) {
u16 val = cpu_read_reg(ctx->cur_inst->reg_1);
emu_cycles(1);
stack_push((val >> 8) & 0xFF);
emu_cycles(1);
stack_push((val & 0xFF));
emu_cycles(1);
emu_cycles(1);
}
static void proc_ldh(cpu_context *ctx) {
if (!ctx->dest_is_mem) {
cpu_set_reg(ctx->cur_inst->reg_1, bus_read(0XFF00 | ctx->fetched_data));
cpu_set_reg(ctx->cur_inst->reg_1, ctx->fetched_data);
} else {
bus_write(0xFF00 | ctx->mem_dest, cpu_read_reg(ctx->cur_inst->reg_2));
emu_cycles(1);
}
emu_cycles(1);
}
static void proc_di(cpu_context *ctx) {
@ -458,12 +461,12 @@ static bool check_condition(cpu_context *ctx) {
static void goto_addr(cpu_context *ctx, u16 addr, bool pushpc){
if (check_condition(ctx)) {
emu_cycles(1);
if(pushpc) {
stack_push16(ctx->regs.pc);
emu_cycles(2);
}
ctx->regs.pc = addr;
emu_cycles(1);
}
}