From 1473ae33ba15787c1a9a2c4a48aeae84c844509e Mon Sep 17 00:00:00 2001 From: Alex Duchesne Date: Mon, 21 Aug 2023 12:09:45 -0400 Subject: [PATCH] GB: Fixed: The Gameboy should have scanlines 0 to 153 #81 Still need to unify lcd cycles and cpu cycles, I'm sure where's out of sync everywhere.... --- retro-core/components/gnuboy/cpu.c | 28 +++++++++++---------------- retro-core/components/gnuboy/gnuboy.c | 2 +- retro-core/components/gnuboy/lcd.c | 13 ++++++++++--- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/retro-core/components/gnuboy/cpu.c b/retro-core/components/gnuboy/cpu.c index 87c8ce80d..047e8b021 100644 --- a/retro-core/components/gnuboy/cpu.c +++ b/retro-core/components/gnuboy/cpu.c @@ -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] = { @@ -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]; @@ -823,7 +826,7 @@ IRAM_ATTR int cpu_emulate(int cycles) } -#ifdef CPU_DISASSEMBLER +#if CPU_DISASSEMBLER static const char *mnemonic_table[256] = { @@ -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 ); } diff --git a/retro-core/components/gnuboy/gnuboy.c b/retro-core/components/gnuboy/gnuboy.c index b3bba0cde..ab9445977 100644 --- a/retro-core/components/gnuboy/gnuboy.c +++ b/retro-core/components/gnuboy/gnuboy.c @@ -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; } diff --git a/retro-core/components/gnuboy/lcd.c b/retro-core/components/gnuboy/lcd.c index 6898688d7..e04c7c6a2 100644 --- a/retro-core/components/gnuboy/lcd.c +++ b/retro-core/components/gnuboy/lcd.c @@ -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; } @@ -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;