Skip to content

Commit

Permalink
GB: Fixed: The Gameboy should have scanlines 0 to 153 #81
Browse files Browse the repository at this point in the history
Still need to unify lcd cycles and cpu cycles, I'm sure where's out of sync everywhere....
  • Loading branch information
ducalex committed Aug 21, 2023
1 parent 530effc commit 1473ae3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
28 changes: 11 additions & 17 deletions retro-core/components/gnuboy/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// For cycle accurate emulation this needs to be 1
// Anything above 10 have diminishing returns
#define COUNTERS_TICK_PERIOD 8
#define CPU_DISASSEMBLER 0

static const byte cycles_table[256] =
{
Expand Down Expand Up @@ -312,8 +313,10 @@ IRAM_ATTR int cpu_emulate(int cycles)
}
IME = IMA;

// if (cpu.disassemble)
// cpu_disassemble(PC, 1);
#if CPU_DISASSEMBLER
if (cpu.disassemble && !rg_input_read_gamepad())
cpu_disassemble(PC, 1);
#endif

op = FETCH;
clen = cycles_table[op];
Expand Down Expand Up @@ -823,7 +826,7 @@ IRAM_ATTR int cpu_emulate(int cycles)
}


#ifdef CPU_DISASSEMBLER
#if CPU_DISASSEMBLER

static const char *mnemonic_table[256] =
{
Expand Down Expand Up @@ -951,22 +954,13 @@ void cpu_disassemble(unsigned pc, int count)

printf(
"%04X: %-10.10s %-16.16s"
" SP=%04X.%04X BC=%04X.%02X.%02X DE=%04X.%02X"
" HL=%04X.%02X A=%02X F=%02X %c%c%c%c%c"
" SP=%04X BC=%04X DE=%04X HL=%04X A=%02X F=%02X"
" %c%c%c%c%c"
" IE=%02X IF=%02X LCDC=%02X STAT=%02X LY=%02X LYC=%02X"
" \n",
baseaddr,
operands,
mnemonic,
SP, readw(SP),
BC, readb(BC), readb(0xFF00 | C),
DE, readb(DE),
HL, readb(HL), A,
F, (IME ? 'I' : '-'),
((F & 0x80) ? 'Z' : '-'),
((F & 0x40) ? 'N' : '-'),
((F & 0x20) ? 'H' : '-'),
((F & 0x10) ? 'C' : '-'),
baseaddr, operands, mnemonic,
SP, BC, DE, HL, A, F,
(IME ? 'I' : '-'), ((F & 0x80) ? 'Z' : '-'), ((F & 0x40) ? 'N' : '-'), ((F & 0x20) ? 'H' : '-'), ((F & 0x10) ? 'C' : '-'),
R_IE, R_IF, R_LCDC, R_STAT, R_LY, R_LYC
);
}
Expand Down
2 changes: 1 addition & 1 deletion retro-core/components/gnuboy/gnuboy.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void gnuboy_run(bool draw)

// LCD is powered down, it won't touch LY or do vblank
if (!(R_LCDC & 0x80)) {
cycles += 152 * 228;
cycles += 154 * 228;
cycles -= cpu_emulate(cycles);
return;
}
Expand Down
13 changes: 10 additions & 3 deletions retro-core/components/gnuboy/lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,10 @@ void lcd_emulate(int cycles)
hw_interrupt(IF_VBLANK, 1);
CYCLES += 228;
}
else CYCLES += 10;
else
{
CYCLES += 10;
}
stat_change(1); /* -> vblank */
break;
}
Expand All @@ -786,12 +789,16 @@ void lcd_emulate(int cycles)
CYCLES += 40;
break;
}
else if (R_LY < 152)
else if (R_LY < 153)
{
CYCLES += 228;
else if (R_LY == 152)
}
else if (R_LY == 153)
{
/* Handling special case on the last line; see
docs/HACKING */
CYCLES += 28;
}
else
{
R_LY = -1;
Expand Down

0 comments on commit 1473ae3

Please sign in to comment.