From 8bd739a4c84608b67b08725b5e5a21967df2617a Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Thu, 7 May 2020 11:24:08 -0400 Subject: [PATCH] GBHawk: ppu cleanup and more aaccuracy edge case work --- .../Consoles/Nintendo/GBHawk/GBC_GB_PPU.cs | 14 ++++---- .../Consoles/Nintendo/GBHawk/GBC_PPU.cs | 15 ++++---- .../Consoles/Nintendo/GBHawk/GB_PPU.cs | 34 ++++++++++++------- .../Consoles/Nintendo/GBHawk/MemoryMap.cs | 27 ++++++++++++--- 4 files changed, 58 insertions(+), 32 deletions(-) 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 59c67a060b..16a6dfda18 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 @@ -273,7 +273,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk public override void tick() { // Do HDMA ticks - if (HDMA_active) + if (HDMA_active && !Core.cpu.halted && !Core.cpu.stopped) { if (HDMA_length > 0) { @@ -701,11 +701,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // i.e. just keeping track of the lowest x-value sprite if (render_cycle == 0) { - /* - OAM_access_read = false; - OAM_access_write = true; - VRAM_access_read = false; - */ // window X is latched for the scanline, mid-line changes have no effect window_x_latch = window_x; @@ -1199,7 +1194,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk OAM_access_read = true; OAM_access_write = true; VRAM_access_read = true; - VRAM_access_write = true; + VRAM_access_write = true; + + read_case = 18; } else { @@ -1228,6 +1225,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk case 17: read_case--; break; + case 18: + // end of rendering + break; } internal_cycle++; 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 c87fbb0f3e..7db05adfd3 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs @@ -269,7 +269,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk public override void tick() { // Do HDMA ticks - if (HDMA_active) + if (HDMA_active && !Core.cpu.halted && !Core.cpu.stopped) { if (HDMA_length > 0) { @@ -704,11 +704,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // i.e. just keeping track of the lowest x-value sprite if (render_cycle == 0) { - /* - OAM_access_read = false; - OAM_access_write = true; - VRAM_access_read = false; - */ // window X is latched for the scanline, mid-line changes have no effect window_x_latch = window_x; @@ -1158,7 +1153,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk case 8: // done reading, we are now in phase 0 pre_render = true; - // the other interrupts appear to be delayed by 1 CPU cycle, so do the same here if (hbl_countdown > 0) { hbl_countdown--; @@ -1168,7 +1162,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk OAM_access_read = true; OAM_access_write = true; VRAM_access_read = true; - VRAM_access_write = true; + VRAM_access_write = true; + + read_case = 18; } else { @@ -1197,6 +1193,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk case 17: read_case--; break; + case 18: + // end of rendering + break; } internal_cycle++; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs index de014e983f..e4131f7a7c 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs @@ -459,11 +459,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // i.e. just keeping track of the lowest x-value sprite if (render_cycle == 0) { - /* - OAM_access_read = false; - OAM_access_write = true; - VRAM_access_read = false; - */ // window X is latched for the scanline, mid-line changes have no effect window_x_latch = window_x; @@ -620,6 +615,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk if (pixel_counter == 160) { + hbl_countdown = 2; read_case = 8; } } @@ -874,15 +870,26 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk case 8: // done reading, we are now in phase 0 pre_render = true; - STAT &= 0xFC; - STAT |= 0x00; + if (hbl_countdown > 0) + { + hbl_countdown--; + if (hbl_countdown == 0) + { + VRAM_access_read = true; + VRAM_access_write = true; + OAM_access_read = true; + OAM_access_write = true; - if (STAT.Bit(3)) { HBL_INT = true; } + read_case = 18; + } + else + { + STAT &= 0xFC; + STAT |= 0x00; - OAM_access_read = true; - OAM_access_write = true; - VRAM_access_read = true; - VRAM_access_write = true; + if (STAT.Bit(3)) { HBL_INT = true; } + } + } break; case 9: @@ -902,6 +909,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk case 17: read_case--; break; + case 18: + // end of rendering + break; } internal_cycle++; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs index 42bb4ecb8d..79e80ba43b 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/MemoryMap.cs @@ -58,13 +58,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { return RAM[addr - 0xE000]; } + if (addr >= 0xF000 && addr < 0xFE00) { return RAM[(RAM_Bank * 0x1000) + (addr - 0xF000)]; } - if (addr >= 0xFE00 && addr < 0xFEA0 && ppu.DMA_OAM_access) + + if (addr >= 0xFE00 && addr < 0xFEA0) { - return OAM[addr - 0xFE00]; + if (ppu.DMA_OAM_access) + { + return OAM[addr - 0xFE00]; + } + else + { + return 0xFF; + } } if (addr >= 0xFF00 && addr < 0xFF80) // The game GOAL! Requires Hardware Regs to be accessible @@ -127,7 +136,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } if (ppu.pixel_counter == 160) - { + { return ppu.bus_return; } return 0xFF; @@ -323,14 +332,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { return RAM[addr - 0xE000]; } + if (addr >= 0xF000 && addr < 0xFE00) { return RAM[(RAM_Bank * 0x1000) + (addr - 0xF000)]; } - if (addr >= 0xFE00 && addr < 0xFEA0 && ppu.DMA_OAM_access) + if (addr >= 0xFE00 && addr < 0xFEA0) { - return OAM[addr - 0xFE00]; + if (ppu.DMA_OAM_access) + { + return OAM[addr - 0xFE00]; + } + else + { + return 0xFF; + } } if (addr >= 0xFF00 && addr < 0xFF80) // The game GOAL! Requires Hardware Regs to be accessible