From e951439bedec86d90df8022c52691101d234b197 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Sun, 3 Dec 2017 19:09:33 -0500 Subject: [PATCH] GBHawk: Implement frame draw delay --- .../Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs | 15 +++++++++++++-- .../Consoles/Nintendo/GBHawk/PPU.cs | 11 +++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs index af6cc525d9..ec2ea73c89 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IEmulator.cs @@ -116,7 +116,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } - while (!vblank_rise && (ticker < 100000)) + while (!vblank_rise) { audio.tick(); timer.tick_1(); @@ -133,7 +133,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { vblank_rise = true; } + ticker++; + if (ticker > 10000000) { throw new Exception("ERROR: Unable to Resolve Frame"); } + in_vblank_old = in_vblank; } @@ -183,7 +186,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk public int[] GetVideoBuffer() { - return _vidbuffer; + if (ppu.blank_frame) + { + for (int i = 0; i < _vidbuffer.Length; i++) + { + _vidbuffer[i] = (int)color_palette[0]; + } + ppu.blank_frame = false; + } + return _vidbuffer; } public int VirtualWidth => 160; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/PPU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/PPU.cs index aa741aaf84..41531f005b 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/PPU.cs @@ -79,6 +79,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk public int index_used; public int sprite_ordered_index; public int bottom_index; + public bool blank_frame; // windowing state public int window_counter; @@ -126,6 +127,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk OAM_access_write = true; } + if (!LCDC.Bit(7) && value.Bit(7)) + { + // don't draw for one frame after turning on + blank_frame = true; + } + LCDC = value; break; case 0xFF41: // STAT @@ -176,7 +183,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk case 0xFF4B: // WX window_x = value; break; - } + } } public void tick() @@ -233,7 +240,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } } - cycle = 0; LY += LY_inc; //Console.WriteLine(Core.cpu.TotalExecutedCycles); @@ -1232,6 +1238,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk ser.Sync("index_used", ref index_used); ser.Sync("sprite_ordered_index", ref sprite_ordered_index); ser.Sync("bottom_index", ref bottom_index); + ser.Sync("blank_frame", ref blank_frame); ser.Sync("window_counter", ref window_counter); ser.Sync("window_pre_render", ref window_pre_render);