alright, the control flow gets through the entire boot rom

it actually looks pretty okay
This commit is contained in:
Matt Laux 2019-10-22 02:30:25 -05:00
parent b42faf8149
commit 657dcb0da2
4 changed files with 11 additions and 13 deletions

View File

@ -32,8 +32,8 @@ int main(int argc, char *argv[])
cpu.pc = 0;
for (executed = 0; executed < 100000; executed++) {
cpu_step(&cpu);
for (executed = 0; executed < 1000000; executed++) {
dmg_step(&dmg);
}
rom_free(&rom);

View File

@ -125,6 +125,7 @@ static void inc_with_carry(struct cpu *regs, u8 *reg)
(*reg)++;
if(*reg == 0)
set_flag(regs, FLAG_ZERO);
else clear_flag(regs, FLAG_ZERO);
}
static void dec_with_carry(struct cpu *regs, u8 *reg)
@ -135,6 +136,7 @@ static void dec_with_carry(struct cpu *regs, u8 *reg)
(*reg)--;
if(*reg == 0)
set_flag(regs, FLAG_ZERO);
else clear_flag(regs, FLAG_ZERO);
}
static u8 rotate_left(struct cpu *regs, u8 reg)
@ -179,6 +181,7 @@ static void xor(struct cpu *regs, u8 value)
regs->a ^= value;
if(regs->a == 0)
set_flag(regs, FLAG_ZERO);
else clear_flag(regs, FLAG_ZERO);
clear_flag(regs, FLAG_SIGN);
clear_flag(regs, FLAG_HALF_CARRY);
clear_flag(regs, FLAG_CARRY);
@ -189,6 +192,7 @@ static void or(struct cpu *regs, u8 value)
regs->a |= value;
if(regs->a == 0)
set_flag(regs, FLAG_ZERO);
else clear_flag(regs, FLAG_ZERO);
clear_flag(regs, FLAG_SIGN);
clear_flag(regs, FLAG_HALF_CARRY);
clear_flag(regs, FLAG_CARRY);
@ -199,6 +203,8 @@ static void and(struct cpu *cpu, u8 value)
cpu->a &= value;
if(cpu->a == 0) {
set_flag(cpu, FLAG_ZERO);
} else {
clear_flag(cpu, FLAG_ZERO);
}
clear_flag(cpu, FLAG_SIGN);
set_flag(cpu, FLAG_HALF_CARRY);
@ -650,6 +656,7 @@ void cpu_step(struct cpu *cpu)
case 0xbd: subtract(cpu, cpu->l, 0, 1); break;
case 0xbe: subtract(cpu, read8(cpu, read_hl(cpu)), 0, 1); break;
case 0xbf: subtract(cpu, cpu->a, 0, 1); break;
case 0xfe: subtract(cpu, read8(cpu, cpu->pc), 0, 1); cpu->pc++; break;
// RST
case 0xc7: push(cpu, cpu->pc); cpu->pc = 0x00; break;
@ -689,11 +696,7 @@ void cpu_step(struct cpu *cpu)
case 0xf0: // LDH A,(a8)
cpu->a = read16(cpu, 0xff00 + read8(cpu, cpu->pc));
cpu->pc++;
case 0xfe: // CP d8
if (cpu->a - read8(cpu, cpu->pc) > 0x80) {
set_flag(cpu, FLAG_SIGN);
}
cpu->pc++;
printf("scanline was %d\n", cpu->a);
break;
case 0xf2: // LD A,(C)
cpu->a = read8(cpu, 0xff00 + cpu->c);

View File

@ -19,8 +19,7 @@ u8 dmg_read(void *_dmg, u16 address)
struct dmg *dmg = (struct dmg *) _dmg;
if (address < 0x100) {
return dmg_boot_rom[address];
}
if (address < 0x4000) {
} else if (address < 0x4000) {
return dmg->rom->data[address];
} else if (address < 0x8000) {
// TODO switchable rom bank

View File

@ -25,10 +25,6 @@ u8 lcd_read(struct lcd *lcd, u16 addr)
void lcd_write(struct lcd *lcd, u16 addr, u8 value)
{
if (addr == REG_LY) {
// writing to this register always resets it
value = 0;
}
lcd->regs[addr - REG_LCD_BASE] = value;
}