From d322c3c00fab8b75c74454e3c9d8b1ed56f94c8f Mon Sep 17 00:00:00 2001 From: beirich Date: Sun, 29 Apr 2012 01:40:38 +0000 Subject: [PATCH] Fix some bugs responsible for out-of-bounds array access crash on ym2612 --- BizHawk.Emulation/CPUs/Z80/Z80A.cs | 11 ++++++++++- .../Consoles/Sega/Genesis/MemoryMap.68000.cs | 4 ++-- BizHawk.Emulation/Sound/YM2612.cs | 5 +++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/BizHawk.Emulation/CPUs/Z80/Z80A.cs b/BizHawk.Emulation/CPUs/Z80/Z80A.cs index 158c0a3fd7..056b802c2a 100644 --- a/BizHawk.Emulation/CPUs/Z80/Z80A.cs +++ b/BizHawk.Emulation/CPUs/Z80/Z80A.cs @@ -3,7 +3,7 @@ using System.Globalization; using System.IO; // This Z80 emulator is a modified version of Ben Ryves 'Brazil' emulator. -// It is MIT licensed (not public domain). (See Licenses) +// It is MIT licensed. namespace BizHawk.Emulation.CPUs.Z80 { @@ -33,6 +33,15 @@ namespace BizHawk.Emulation.CPUs.Z80 TotalExecutedCycles = 0; } + /// + /// Reset the Z80 to its initial state, but don't modify cycle counters. For use where Z80 may be reset + /// + public void SoftReset() + { + ResetRegisters(); + ResetInterrupts(); + } + // Memory Access public Func ReadMemory; diff --git a/BizHawk.Emulation/Consoles/Sega/Genesis/MemoryMap.68000.cs b/BizHawk.Emulation/Consoles/Sega/Genesis/MemoryMap.68000.cs index 5ae8761eda..434df79a89 100644 --- a/BizHawk.Emulation/Consoles/Sega/Genesis/MemoryMap.68000.cs +++ b/BizHawk.Emulation/Consoles/Sega/Genesis/MemoryMap.68000.cs @@ -116,7 +116,7 @@ namespace BizHawk.Emulation.Consoles.Sega { Z80Reset = (value & 1) == 0; if (Z80Reset) - SoundCPU.Reset(); + SoundCPU.SoftReset(); //Console.WriteLine("z80 reset: " + Z80Reset); return; } @@ -182,7 +182,7 @@ namespace BizHawk.Emulation.Consoles.Sega { Z80Reset = (value & 0x100) == 0; if (Z80Reset) - SoundCPU.Reset(); + SoundCPU.SoftReset(); //Console.WriteLine("z80 reset: " + Z80Reset); return; } diff --git a/BizHawk.Emulation/Sound/YM2612.cs b/BizHawk.Emulation/Sound/YM2612.cs index 8edc963898..129dd7d473 100644 --- a/BizHawk.Emulation/Sound/YM2612.cs +++ b/BizHawk.Emulation/Sound/YM2612.cs @@ -28,6 +28,11 @@ namespace BizHawk.Emulation.Sound public void BeginFrame(int clock) { frameStartClock = clock; + while (commands.Count > 0) + { + var cmd = commands.Dequeue(); + WriteCommand(cmd); + } } public void EndFrame(int clock)