not really sure what i was working on

This commit is contained in:
Matthew Laux 2023-10-18 17:14:20 -05:00
parent bad415fa23
commit 5ed288eaa9
3 changed files with 33 additions and 2 deletions

BIN
cli/save.sav Normal file

Binary file not shown.

View File

@ -356,6 +356,32 @@ static void add16(struct cpu *cpu, u16 src)
write_hl(cpu, trunc);
}
static void add_sp(struct cpu *cpu, u8 value)
{
int total = cpu->sp + (signed char) value;
clear_flag(cpu, FLAG_ZERO);
clear_flag(cpu, FLAG_SIGN);
if (total > 0xffff) {
set_flag(cpu, FLAG_CARRY);
} else {
clear_flag(cpu, FLAG_CARRY);
}
cpu->sp = (u16) total;
}
static void ld_hl_sp(struct cpu *cpu, u8 value)
{
int total = cpu->sp + (signed char) value;
clear_flag(cpu, FLAG_ZERO);
clear_flag(cpu, FLAG_SIGN);
if (total > 0xffff) {
set_flag(cpu, FLAG_CARRY);
} else {
clear_flag(cpu, FLAG_CARRY);
}
write_hl(cpu, total);
}
static u8 read_reg(struct cpu *cpu, int index)
{
switch (index) {
@ -1026,6 +1052,10 @@ void cpu_step(struct cpu *cpu)
case 0xe5: // PUSH HL
push(cpu, read_hl(cpu));
break;
case 0xe8:
add_sp(cpu, read8(cpu, cpu->pc));
cpu->pc++;
break;
case 0xe9: // JP HL
cpu->pc = read_hl(cpu);
break;
@ -1051,7 +1081,7 @@ void cpu_step(struct cpu *cpu)
push(cpu, read_af(cpu));
break;
case 0xf8: // LD HL, SP+i8
write_hl(cpu, cpu->sp + (signed) read8(cpu, cpu->pc));
ld_hl_sp(cpu, read8(cpu, cpu->pc));
cpu->pc++;
break;
case 0xf9: // LD SP, HL

View File

@ -263,6 +263,7 @@ static void render_objs(struct dmg *dmg)
static void timer_step(struct dmg *dmg)
{
dmg->timer_div++;
return;
if (!(dmg_read(dmg, REG_TIMER_CONTROL) & TIMER_CONTROL_ENABLED)) {
return;
@ -290,7 +291,7 @@ void dmg_step(void *_dmg)
// order of dependencies? i think cpu needs to step first then update
// all other hw
cpu_step(dmg->cpu);
//timer_step(dmg);
timer_step(dmg);
// each line takes 456 cycles
int cycle_diff = dmg->cpu->cycle_count - dmg->last_lcd_update;