mirror of https://github.com/mlaux/gb6.git
update lcd every 456 cycles
This commit is contained in:
parent
3d6d3a0171
commit
b0c690c693
|
@ -32,7 +32,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
cpu.pc = 0;
|
cpu.pc = 0;
|
||||||
|
|
||||||
for (executed = 0; executed < 100000; executed++) {
|
// for (executed = 0; executed < 100000; executed++) {
|
||||||
|
while (1) {
|
||||||
dmg_step(&dmg);
|
dmg_step(&dmg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
src/cpu.c
15
src/cpu.c
|
@ -300,6 +300,9 @@ static void extended_insn(struct cpu *cpu, u8 insn)
|
||||||
shift_right // TODO SRL
|
shift_right // TODO SRL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
printf(" %s\n", instructions[insn + 0x100].format);
|
||||||
|
cpu->cycle_count += instructions[insn + 0x100].cycles;
|
||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case 0:
|
case 0:
|
||||||
write_reg(cpu, reg, funcs[bit](cpu, read_reg(cpu, reg)));
|
write_reg(cpu, reg, funcs[bit](cpu, read_reg(cpu, reg)));
|
||||||
|
@ -330,6 +333,7 @@ void cpu_step(struct cpu *cpu)
|
||||||
u8 opc = cpu->mem_read(cpu->mem_model, cpu->pc);
|
u8 opc = cpu->mem_read(cpu->mem_model, cpu->pc);
|
||||||
printf("0x%04x %s\n", cpu->pc, instructions[opc].format);
|
printf("0x%04x %s\n", cpu->pc, instructions[opc].format);
|
||||||
cpu->pc++;
|
cpu->pc++;
|
||||||
|
cpu->cycle_count += instructions[opc].cycles;
|
||||||
switch (opc) {
|
switch (opc) {
|
||||||
case 0: // NOP
|
case 0: // NOP
|
||||||
break;
|
break;
|
||||||
|
@ -500,6 +504,7 @@ void cpu_step(struct cpu *cpu)
|
||||||
temp = read8(cpu, cpu->pc);
|
temp = read8(cpu, cpu->pc);
|
||||||
if ((opc == 0x20) ^ flag_isset(cpu, FLAG_ZERO)) {
|
if ((opc == 0x20) ^ flag_isset(cpu, FLAG_ZERO)) {
|
||||||
cpu->pc += *((signed char *) &temp) + 1;
|
cpu->pc += *((signed char *) &temp) + 1;
|
||||||
|
cpu->cycle_count += instructions[opc].cycles_branch - instructions[opc].cycles;
|
||||||
} else {
|
} else {
|
||||||
cpu->pc++;
|
cpu->pc++;
|
||||||
}
|
}
|
||||||
|
@ -650,19 +655,19 @@ void cpu_step(struct cpu *cpu)
|
||||||
add(cpu, read8(cpu, cpu->pc), 1);
|
add(cpu, read8(cpu, cpu->pc), 1);
|
||||||
cpu->pc++;
|
cpu->pc++;
|
||||||
break;
|
break;
|
||||||
case 0xe0: // LDH (a8),A
|
case 0xe0: // LD (a8),A
|
||||||
write16(cpu, 0xff00 + read8(cpu, cpu->pc), cpu->a);
|
write8(cpu, 0xff00 + read8(cpu, cpu->pc), cpu->a);
|
||||||
cpu->pc++;
|
cpu->pc++;
|
||||||
break;
|
break;
|
||||||
case 0xe2: // LD (C),A
|
case 0xe2: // LD (C),A
|
||||||
write8(cpu, 0xff00 + cpu->c, cpu->a);
|
write8(cpu, 0xff00 + cpu->c, cpu->a);
|
||||||
break;
|
break;
|
||||||
case 0xea: // LD (a16),A
|
case 0xea: // LD (a16),A
|
||||||
write16(cpu, read16(cpu, cpu->pc), cpu->a);
|
write8(cpu, read16(cpu, cpu->pc), cpu->a);
|
||||||
cpu->pc += 2;
|
cpu->pc += 2;
|
||||||
break;
|
break;
|
||||||
case 0xf0: // LDH A,(a8)
|
case 0xf0: // LD A,(a8)
|
||||||
cpu->a = read16(cpu, 0xff00 + read8(cpu, cpu->pc));
|
cpu->a = read8(cpu, 0xff00 + read8(cpu, cpu->pc));
|
||||||
cpu->pc++;
|
cpu->pc++;
|
||||||
break;
|
break;
|
||||||
case 0xf2: // LD A,(C)
|
case 0xf2: // LD A,(C)
|
||||||
|
|
|
@ -75,8 +75,8 @@ void dmg_step(void *_dmg)
|
||||||
// all other hw
|
// all other hw
|
||||||
cpu_step(dmg->cpu);
|
cpu_step(dmg->cpu);
|
||||||
|
|
||||||
if (dmg->cpu->pc % 456 == 0) {
|
// each line takes 456 cycles
|
||||||
// each line takes 456 cycles
|
if (dmg->cpu->cycle_count % 456 == 0) {
|
||||||
lcd_step(dmg->lcd);
|
lcd_step(dmg->lcd);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -49,4 +49,5 @@ void lcd_step(struct lcd *lcd)
|
||||||
// step to next scanline 0-153
|
// step to next scanline 0-153
|
||||||
u8 next_scanline = (lcd_read(lcd, REG_LY) + 1) % 154;
|
u8 next_scanline = (lcd_read(lcd, REG_LY) + 1) % 154;
|
||||||
lcd_write(lcd, REG_LY, next_scanline);
|
lcd_write(lcd, REG_LY, next_scanline);
|
||||||
|
// printf("update lcd %d\n", next_scanline);
|
||||||
}
|
}
|
Loading…
Reference in New Issue