beginning ppu

This commit is contained in:
2025-02-01 00:48:49 -07:00
parent 5206c3871e
commit f4cbfd09c8
25 changed files with 683 additions and 43 deletions

View File

@ -5,7 +5,7 @@
//process CPU instructions...
void cpu_set_flags(cpu_context *ctx, u8 z, u8 n, u8 h, u8 c){
void cpu_set_flags(cpu_context *ctx, int8_t z, int8_t n, int8_t h, int8_t c){
if (z != -1){
BIT_SET(ctx->regs.f, 7, z)
}
@ -52,7 +52,7 @@ static void proc_daa(cpu_context *ctx) {
}
static void proc_cpl(cpu_context *ctx) {
ctx->regs.a = -ctx->regs.a;
ctx->regs.a = ~ctx->regs.a;
cpu_set_flags(ctx, -1, 1, 1, -1);
}
@ -112,7 +112,7 @@ static void proc_rra(cpu_context *ctx) {
static void proc_cb(cpu_context *ctx) {
u8 op = ctx->fetched_data;
reg_type reg = decode_reg(op & 0b111);
u8 bit = (op >> 3) & 0xb111;
u8 bit = (op >> 3) & 0b111;
u8 bit_op = (op >> 6) & 0b11;
u8 reg_val = cpu_read_reg8(reg);
emu_cycles(1);
@ -138,6 +138,7 @@ static void proc_cb(cpu_context *ctx) {
reg_val |= (1 << bit);
cpu_set_reg8(reg, reg_val);
return;
default: break;
}
bool flagC = CPU_FLAG_C;
@ -148,7 +149,7 @@ static void proc_cb(cpu_context *ctx) {
bool setC = false;
u8 result = (reg_val << 1) & 0xFF;
if(reg_val & (1 << 7) != 0) {
if((reg_val & (1 << 7)) != 0) {
result |= 1;
setC = true;
}
@ -322,7 +323,7 @@ static void proc_add(cpu_context *ctx) {
if(ctx->cur_inst->reg_1 == RT_SP) {
z = 0;
h = (cpu_read_reg(ctx->cur_inst->reg_1) & 0xF) + (ctx->fetched_data & 0xF) >= 0x10;
c = (int)(cpu_read_reg(ctx->cur_inst->reg_1) & 0xFF) + (int)(ctx->fetched_data & 0xFF) > 0x100;
c = (int)(cpu_read_reg(ctx->cur_inst->reg_1) & 0xFF) + (int)(ctx->fetched_data & 0xFF) >= 0x100;
}
cpu_set_reg(ctx->cur_inst->reg_1, val & 0xFFFF);
@ -349,7 +350,7 @@ static void proc_inc(cpu_context *ctx) {
return;
}
cpu_set_flags(ctx, val == 0, 0, (val & 0x0F), -1);
cpu_set_flags(ctx, val == 0, 0, (val & 0x0F) == 0, -1);
}
static void proc_dec(cpu_context *ctx) {
@ -432,8 +433,8 @@ static void proc_ld(cpu_context *ctx) {
u8 cflag = (cpu_read_reg(ctx->cur_inst->reg_2) & 0xFF) + (ctx->fetched_data & 0xFF) >= 0x100;
cpu_set_flags(ctx, 0, 0, hflag, cflag);
cpu_set_reg(ctx->cur_inst->reg_1, cpu_read_reg(ctx->cur_inst->reg_2) + (char)ctx->fetched_data);
return;
}
cpu_set_reg(ctx->cur_inst->reg_1, ctx->fetched_data);
}