From d6a9d69f7e65a582417ec6955f211b8feaf35626 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Fri, 25 May 2018 15:00:16 -0400 Subject: [PATCH] GBHawk: Fix Pinball Fantasies --- .../CPUs/LR35902/Interrupts.cs | 2 +- .../Consoles/Nintendo/GBHawk/GBC_PPU.cs | 29 +++++++++++------- .../Consoles/Nintendo/GBHawk/GB_PPU.cs | 30 ++++++++++++------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/BizHawk.Emulation.Cores/CPUs/LR35902/Interrupts.cs b/BizHawk.Emulation.Cores/CPUs/LR35902/Interrupts.cs index 6ee944e95d..12979e363d 100644 --- a/BizHawk.Emulation.Cores/CPUs/LR35902/Interrupts.cs +++ b/BizHawk.Emulation.Cores/CPUs/LR35902/Interrupts.cs @@ -12,8 +12,8 @@ namespace BizHawk.Emulation.Common.Components.LR35902 IDLE, WR, SPl, SPh, PCh, IDLE, - INT_GET, W,// NOTE: here is where we check for a cancelled IRQ DEC16, SPl, SPh, + INT_GET, W,// NOTE: here is where we check for a cancelled IRQ WR, SPl, SPh, PCl, IDLE, IDLE, diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs index f27a8221c3..6d85069d24 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs @@ -352,12 +352,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk cycle = 0; LY += LY_inc; Core.cpu.LY = LY; - // here is where LY = LYC gets cleared (but only if LY isnt 0 as that's a special case) - if (LY_inc == 1) - { - LYC_INT = false; - STAT &= 0xFB; - } no_scan = false; @@ -444,7 +438,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk //if (STAT.Bit(5)) { OAM_INT = true; } } - if ((LY == 153) && (cycle == 8)) + if ((LY == 153) && (cycle == 6)) { LY = 0; LY_inc = 0; @@ -505,7 +499,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { if (cycle < 80) { - if (cycle == 4) + if (cycle == 2) + { + if (LY != 0) { if (STAT.Bit(5)) { OAM_INT = true; } } + } + else if (cycle == 4) { // apparently, writes can make it to OAM one cycle longer then reads OAM_access_write = false; @@ -514,7 +512,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk STAT &= 0xFC; STAT |= 0x2; - if (STAT.Bit(5)) { OAM_INT = true; } + if (LY == 0) { if (STAT.Bit(5)) { OAM_INT = true; } } HBL_INT = false; // DMG exits VBlank into mode 0, but not GBC, so this line is needed @@ -565,8 +563,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk //if (cycle == 92) { OAM_INT = false; } } - // here LY=LYC will be asserted - if ((cycle == 4) && (LY != 0)) + // here LY=LYC will be asserted or cleared (but only if LY isnt 0 as that's a special case) + if ((cycle == 2) && (LY != 0)) + { + if (LY_inc == 1) + { + LYC_INT = false; + STAT &= 0xFB; + } + + } + else if ((cycle == 4) && (LY != 0)) { if ((LY == LYC) && !STAT.Bit(2)) { diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs index b1b38d71b3..535844ebc3 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs @@ -128,12 +128,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk LY += LY_inc; Core.cpu.LY = LY; - // here is where LY = LYC gets cleared (but only if LY isnt 0 as that's a special case) - if (LY_inc == 1) - { - LYC_INT = false; - STAT &= 0xFB; - } no_scan = false; @@ -218,7 +212,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk if (STAT.Bit(5)) { OAM_INT = true; } } - if ((LY == 153) && (cycle == 8)) + if ((LY == 153) && (cycle == 6)) { LY = 0; LY_inc = 0; @@ -280,7 +274,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { if (cycle < 80) { - if (cycle == 4) + if (cycle == 2) + { + if (LY != 0) { if (STAT.Bit(5)) { OAM_INT = true; } } + } + else if (cycle == 4) { // apparently, writes can make it to OAM one cycle longer then reads OAM_access_write = false; @@ -288,7 +286,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk // here mode 2 will be set to true and interrupts fired if enabled STAT &= 0xFC; STAT |= 0x2; - if (STAT.Bit(5)) { OAM_INT = true; } + + if (LY == 0) { if (STAT.Bit(5)) { OAM_INT = true; } } HBL_INT = false; } @@ -335,8 +334,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk if (cycle == 92) { OAM_INT = false; } } - // here LY=LYC will be asserted - if ((cycle == 4) && (LY != 0)) + // here LY=LYC will be asserted or cleared (but only if LY isnt 0 as that's a special case) + if ((cycle == 2) && (LY != 0)) + { + if (LY_inc == 1) + { + LYC_INT = false; + STAT &= 0xFB; + } + + } + else if ((cycle == 4) && (LY != 0)) { if ((LY == LYC) && !STAT.Bit(2)) {