From 80b1275e0791a381b71b78f9daab30ff173f887a Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 18 Mar 2018 20:08:45 +0200 Subject: [PATCH 1/2] Fix stat_lyc_onoff --- Core/display.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Core/display.c b/Core/display.c index dda9fab..1adcc50 100755 --- a/Core/display.c +++ b/Core/display.c @@ -311,11 +311,9 @@ static void update_display_state(GB_gameboy_t *gb, uint8_t cycles) if (!(gb->io_registers[GB_IO_LCDC] & 0x80)) { /* LCD is disabled, state is constant */ - /* When the LCD is off, LY is 0 and STAT mode is 0. - Todo: Verify the LY=LYC flag should be on. */ + /* When the LCD is off, LY is 0 and STAT mode is 0. */ gb->io_registers[GB_IO_LY] = 0; gb->io_registers[GB_IO_STAT] &= ~3; - gb->io_registers[GB_IO_STAT] |= 4; gb->effective_scx = gb->io_registers[GB_IO_SCX]; if (gb->hdma_on_hblank) { gb->hdma_on_hblank = false; From b50c97f4a71f2a3d535477ee88c0469f42151cd5 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Mon, 19 Mar 2018 20:01:31 +0200 Subject: [PATCH 2/2] Prevent starting HDMA in the middle of an instruction, making both the CPU and DMA access memory at the same time. Closes #47 --- Core/display.c | 3 +-- Core/gb.h | 1 + Core/z80_cpu.c | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Core/display.c b/Core/display.c index 1adcc50..b55d66f 100755 --- a/Core/display.c +++ b/Core/display.c @@ -528,8 +528,7 @@ static void update_display_state(GB_gameboy_t *gb, uint8_t cycles) } else if (position_in_line == MODE2_LENGTH + MODE3_LENGTH + stat_delay + scx_delay + 16) { if (gb->hdma_on_hblank) { - gb->hdma_on = true; - gb->hdma_cycles = 0; + gb->hdma_starting = true; } } } diff --git a/Core/gb.h b/Core/gb.h index c93aa3d..48171f8 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -276,6 +276,7 @@ struct GB_gameboy_internal_s { int16_t dma_cycles; bool is_dma_restarting; uint8_t last_opcode_read; /* Required to emulte HDMA reads from Exxx */ + bool hdma_starting; ); /* MBC */ diff --git a/Core/z80_cpu.c b/Core/z80_cpu.c index 4794df5..6ff69b4 100644 --- a/Core/z80_cpu.c +++ b/Core/z80_cpu.c @@ -1402,4 +1402,10 @@ void GB_cpu_run(GB_gameboy_t *gb) else { GB_advance_cycles(gb, 4); } + + if (gb->hdma_starting) { + gb->hdma_starting = false; + gb->hdma_on = true; + gb->hdma_cycles = 0; + } }