/// <summary> /// Runs a Machine's core for a certain number of ticks, and optionally stopping on an audio overrun. /// </summary> /// <param name="machine">The machine whose core should be run.</param> /// <param name="ticks">The number of ticks to run the machine for.</param> /// <returns>The total number of ticks that the machine ran for. Note this may be slightly larger than <c>ticks</c>, since Z80 instructions take at least 4 ticks.</returns> static public UInt64 Run(IMachine machine, UInt64 ticks) { UInt64 beforeTicks = machine.Core.Ticks; ManualResetEvent e = new ManualResetEvent(false); machine.Core.IdleRequest = () => { e.Set(); return(null); }; machine.Core.PushRequest(CoreRequest.RunUntil(machine.Ticks + ticks)); machine.Core.Start(); while (!e.WaitOne(10)) { machine.AdvancePlayback(48000); } machine.Core.Stop(); machine.Core.IdleRequest = null; return(machine.Core.Ticks - beforeTicks); }