From f6f55c09de56a7cf850d9961e3152876866dbd78 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Fri, 25 Aug 2017 11:28:19 -0400 Subject: [PATCH] A7800Hawk: refactor sound for pokey --- .../Atari/A7800Hawk/A7800Hawk.IEmulator.cs | 42 ++++++++++++++++++- .../Atari/A7800Hawk/A7800Hawk.IStatable.cs | 1 + .../Consoles/Atari/A7800Hawk/A7800Hawk.cs | 4 +- .../Consoles/Atari/A7800Hawk/Pokey.cs | 2 + 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IEmulator.cs index 9157297326..31eb7b9345 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IEmulator.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; namespace BizHawk.Emulation.Cores.Atari.A7800Hawk { - public partial class A7800Hawk : IEmulator, IVideoProvider + public partial class A7800Hawk : IEmulator, IVideoProvider, ISoundProvider { public IEmulatorServiceProvider ServiceProvider { get; } @@ -351,5 +351,45 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk }; #endregion + + #region Sound provider + + private int _spf; + + public bool CanProvideAsync => false; + + public void SetSyncMode(SyncSoundMode mode) + { + if (mode != SyncSoundMode.Sync) + { + throw new InvalidOperationException("Only Sync mode is supported."); + } + } + + public SyncSoundMode SyncMode => SyncSoundMode.Sync; + + public void GetSamplesSync(out short[] samples, out int nsamp) + { + short[] ret = new short[_spf * 2]; + nsamp = _spf; + tia.GetSamples(ret); + // add pokey samples here + + + samples = ret; + } + + public void GetSamplesAsync(short[] samples) + { + throw new NotSupportedException("Async is not available"); + } + + public void DiscardSamples() + { + tia.AudioClocks = 0; + } + + #endregion + } } diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IStatable.cs index 3e49e1b5bd..1a698d4b9d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IStatable.cs @@ -62,6 +62,7 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk ser.Sync("A7800_control_register", ref A7800_control_register); ser.Sync("_isPAL", ref _isPAL); + ser.Sync("_spf", ref _spf); ser.Sync("Maria_regs", ref Maria_regs, false); ser.Sync("RAM", ref RAM, false); diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.cs b/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.cs index 2c87fa28f0..9a15b34da5 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.cs @@ -227,7 +227,7 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk pokey.Core = this; ser.Register(this); - ser.Register(tia); + ser.Register(this); ServiceProvider = ser; _tracer = new TraceBuffer { Header = cpu.TraceHeader }; @@ -262,6 +262,8 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk cpu_cycle = 0; _vidbuffer = new int[VirtualWidth * VirtualHeight]; + + _spf = (_frameHz > 55) ? 740 : 880; } private void ExecFetch(ushort addr) diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/Pokey.cs b/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/Pokey.cs index 50ba9dedc7..c103f3d728 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/Pokey.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/Pokey.cs @@ -46,6 +46,8 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk public void WriteReg(int reg, byte value) { Regs[reg] = value; + + } public void Tick()