From f38c75f06dc914bcfe9d7db9249790dfd24fd750 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Sat, 28 Nov 2020 18:58:33 -0500 Subject: [PATCH] GBHawk: some accuracy improvements --- .../Consoles/Nintendo/GBHawk/GBC_GB_PPU.cs | 6 ++++++ .../Consoles/Nintendo/GBHawk/GBC_PPU.cs | 14 +++++++++++++- .../Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs | 2 ++ .../Consoles/Nintendo/GBHawk/PPU.cs | 2 ++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_GB_PPU.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_GB_PPU.cs index e1d9a97e8f..5128231d2a 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_GB_PPU.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_GB_PPU.cs @@ -330,6 +330,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk VRAM_access_read = VRAM_access_read_PPU & VRAM_access_read_HDMA; VRAM_access_write_HDMA = false; VRAM_access_write = VRAM_access_write_PPU & VRAM_access_write_HDMA; + + // reading from open bus still returns 0xFF on DMA access, see dma_hiram_read_result_cgb04c_out1.gbc + Core.bus_value = 0xFF; } else { @@ -399,6 +402,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk VRAM_access_write_HDMA = false; VRAM_access_write = VRAM_access_write_PPU & VRAM_access_write_HDMA; + // reading from open bus still returns 0xFF on DMA access, see dma_hiram_read_result_cgb04c_out1.gbc + Core.bus_value = 0xFF; + if (LCDC.Bit(7)) { last_HBL = LY; } else { last_HBL = 0xFF; } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs index ec933eba10..fd5fb96532 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs @@ -328,6 +328,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk VRAM_access_read = VRAM_access_read_PPU & VRAM_access_read_HDMA; VRAM_access_write_HDMA = false; VRAM_access_write = VRAM_access_write_PPU & VRAM_access_write_HDMA; + + // reading from open bus still returns 0xFF on DMA access, see dma_hiram_read_result_cgb04c_out1.gbc + Core.bus_value = 0xFF; } else { @@ -355,6 +358,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk Core.VRAM[(Core.VRAM_Bank * 0x2000) + cur_DMA_dest] = HDMA_byte; cur_DMA_dest = (ushort)((cur_DMA_dest + 1) & 0x1FFF); cur_DMA_src = (ushort)((cur_DMA_src + 1) & 0xFFFF); + + // similar to normal DMA, except HDMA transfers when A14 is high always access SRAM if (cur_DMA_src >= 0xE000) { cur_DMA_src &= 0xBFFF; } HDMA_length--; @@ -395,6 +400,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk VRAM_access_write_HDMA = false; VRAM_access_write = VRAM_access_write_PPU & VRAM_access_write_HDMA; + // reading from open bus still returns 0xFF on DMA access, see dma_hiram_read_result_cgb04c_out1.gbc + Core.bus_value = 0xFF; + if (LCDC.Bit(7)) { last_HBL = LY; } else { last_HBL = 0xFF; } } @@ -423,6 +431,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk Core.VRAM[(Core.VRAM_Bank * 0x2000) + cur_DMA_dest] = HDMA_byte; cur_DMA_dest = (ushort)((cur_DMA_dest + 1) & 0x1FFF); cur_DMA_src = (ushort)((cur_DMA_src + 1) & 0xFFFF); + + // similar to normal DMA, except HDMA transfers when A14 is high always access SRAM if (cur_DMA_src >= 0xE000) { cur_DMA_src &= 0xBFFF; } HDMA_length--; @@ -704,7 +714,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk if (LY_inc == 0) { - if (cycle == 10) + if (cycle == LY_153_change) { LY_read = LY; } @@ -1817,6 +1827,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk LYC_offset = 2; glitch_state = false; + + LY_153_change = 10; } } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs index 632fbebf74..1fc1f322e0 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs @@ -319,6 +319,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk ppu.LYC_offset = double_speed ? 1 : 2; + ppu.LY_153_change = double_speed ? 8 : 10; + return 0; } else diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/PPU.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/PPU.cs index df81229e0c..8dce39c21f 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/PPU.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/PPU.cs @@ -117,6 +117,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk public bool pal_change_blocked; // in compatability mode, you can change palette values but not displayed color public int LYC_offset; // in double speed mode it appears timing changes for LYC int public bool glitch_state; // writing to STAT to enable HBL interrupt won't trigger it if the ppu just turned on + public int LY_153_change; // the timing of LYC chaning to 153 looks like it varies with speed mode // variables not in state public int total_counter; @@ -284,6 +285,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk ser.Sync(nameof(pal_change_blocked), ref pal_change_blocked); ser.Sync(nameof(LYC_offset), ref LYC_offset); ser.Sync(nameof(glitch_state), ref glitch_state); + ser.Sync(nameof(LY_153_change), ref LY_153_change); } } }