diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs index 1988ff98fa..7b70954462 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBC_PPU.cs @@ -120,6 +120,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } STAT = (byte)((value & 0xF8) | (STAT & 7) | 0x80); + + if (!STAT.Bit(6)) { LYC_INT = false; } + if (!STAT.Bit(4)) { VBL_INT = false; } break; case 0xFF42: // SCY scroll_y = value; @@ -360,20 +363,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk LY_inc = 1; Core.in_vblank = false; - /* - VBL_INT = false; - if (STAT.Bit(3)) { HBL_INT = true; } - - STAT &= 0xFC; - */ // special note here, the y coordiate of the window is kept if the window is deactivated // meaning it will pick up where it left off if re-enabled later // so we don't reset it in the scanline loop window_y_tile = 0; window_y_tile_inc = 0; window_started = false; - if (!LCDC.Bit(5)) { window_is_reset = true; } - + if (!LCDC.Bit(5)) { window_is_reset = true; } } // Automatically restore access to VRAM at this time (force end drawing) @@ -424,6 +420,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk HBL_INT = false; + // there is an edge case where a VBL INT is triggered if STAT bit 5 is set + if (STAT.Bit(5)) { VBL_INT = true; } + // set STAT mode to 1 (VBlank) and interrupt flag if it is enabled STAT &= 0xFC; STAT |= 0x01; @@ -432,12 +431,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk Core.REG_FF0F |= 0x01; } - if ((LY >= 144) && (cycle == 4)) - { - // a special case of OAM mode 2 IRQ assertion, even though PPU Mode still is 1 - //if (STAT.Bit(5)) { OAM_INT = true; } - } - if ((LY == 153) && (cycle == 6)) { LY = 0; @@ -501,7 +494,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { if (cycle == 2) { - if (LY != 0) { if (STAT.Bit(5)) { OAM_INT = true; } } + if (LY != 0) + { + HBL_INT = false; + if (STAT.Bit(5)) { OAM_INT = true; } + } } else if (cycle == 4) { @@ -512,12 +509,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk STAT &= 0xFC; STAT |= 0x2; - 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 - // (This is important for Wacky Racers and Altered Space) - VBL_INT = false; + if (LY == 0) + { + VBL_INT = false; + if (STAT.Bit(5)) { OAM_INT = true; } + } } // here OAM scanning is performed @@ -555,12 +551,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk STAT |= 0x04; if (STAT.Bit(6)) { LYC_INT = true; } } - - // also a special case of OAM mode 2 IRQ assertion, even though PPU Mode still is 1 - //if (STAT.Bit(5)) { OAM_INT = true; } } - - //if (cycle == 92) { OAM_INT = false; } } // here LY=LYC will be asserted or cleared (but only if LY isnt 0 as that's a special case) @@ -571,7 +562,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk LYC_INT = false; STAT &= 0xFB; } - } else if ((cycle == 4) && (LY != 0)) { diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs index 255cbf9d1b..1cae78cc21 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GB_PPU.cs @@ -61,6 +61,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } STAT = (byte)((value & 0xF8) | (STAT & 7) | 0x80); + + if (!STAT.Bit(6)) { LYC_INT = false; } + if (!STAT.Bit(4)) { VBL_INT = false; } break; case 0xFF42: // SCY scroll_y = value; @@ -136,9 +139,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk LY_inc = 1; Core.in_vblank = false; - VBL_INT = false; - if (STAT.Bit(3)) { HBL_INT = true; } - STAT &= 0xFC; // special note here, the y coordiate of the window is kept if the window is deactivated @@ -198,6 +198,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk HBL_INT = false; + // there is an edge case where a VBL INT is triggered if STAT bit 5 is set + if (STAT.Bit(5)) { VBL_INT = true; } + // set STAT mode to 1 (VBlank) and interrupt flag if it is enabled STAT &= 0xFC; STAT |= 0x01; @@ -206,12 +209,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk Core.REG_FF0F |= 0x01; } - if ((LY >= 144) && (cycle == 4)) - { - // a special case of OAM mode 2 IRQ assertion, even though PPU Mode still is 1 - if (STAT.Bit(5)) { OAM_INT = true; } - } - if ((LY == 153) && (cycle == 6)) { LY = 0; @@ -275,8 +272,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk if (cycle < 80) { if (cycle == 2) - { - if (LY != 0) { if (STAT.Bit(5)) { OAM_INT = true; } } + { + if (LY != 0) + { + HBL_INT = false; + if (STAT.Bit(5)) { OAM_INT = true; } + } } else if (cycle == 4) { @@ -287,9 +288,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk STAT &= 0xFC; STAT |= 0x2; - if (LY == 0) { if (STAT.Bit(5)) { OAM_INT = true; } } - - HBL_INT = false; + if (LY == 0) + { + VBL_INT = false; + if (STAT.Bit(5)) { OAM_INT = true; } + } } // here OAM scanning is performed @@ -326,12 +329,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk STAT |= 0x04; if (STAT.Bit(6)) { LYC_INT = true; } } - - // also a special case of OAM mode 2 IRQ assertion, even though PPU Mode still is 1 - if (STAT.Bit(5)) { OAM_INT = true; } } - - if (cycle == 92) { OAM_INT = false; } } // here LY=LYC will be asserted or cleared (but only if LY isnt 0 as that's a special case)