From 7bd469d51435f493d77b45d99ad3606e99c96c7b Mon Sep 17 00:00:00 2001 From: saxxonpike Date: Tue, 13 Nov 2012 22:40:54 +0000 Subject: [PATCH] commodore64: add SyncSoundProvider for SID, placeholder for 1541 disk drive and VIA I/O chip --- BizHawk.Emulation/BizHawk.Emulation.csproj | 2 + .../Computers/Commodore64/1541.cs | 32 ++++++++++++++++ .../Computers/Commodore64/C64.cs | 2 +- .../Computers/Commodore64/SidSoundProvider.cs | 34 +++++++++++++++++ .../Computers/Commodore64/Via.cs | 37 +++++++++++++++++++ 5 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 BizHawk.Emulation/Computers/Commodore64/1541.cs create mode 100644 BizHawk.Emulation/Computers/Commodore64/Via.cs diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj index 9147b2aa70..935d06b09f 100644 --- a/BizHawk.Emulation/BizHawk.Emulation.csproj +++ b/BizHawk.Emulation/BizHawk.Emulation.csproj @@ -79,6 +79,7 @@ VersionInfo.cs + @@ -92,6 +93,7 @@ + diff --git a/BizHawk.Emulation/Computers/Commodore64/1541.cs b/BizHawk.Emulation/Computers/Commodore64/1541.cs new file mode 100644 index 0000000000..1b1721f6d2 --- /dev/null +++ b/BizHawk.Emulation/Computers/Commodore64/1541.cs @@ -0,0 +1,32 @@ +using BizHawk.Emulation.CPUs.M6502; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BizHawk.Emulation.Computers.Commodore64 +{ + public class Drive1541 + { + // the 1541 drive: + // + // 2kb ram, mapped 0000-07FF + // two 6522 VIA chips, mapped at 1800 (communication to C64) and 1C00 (drive mechanics) + + public MOS6502X cpu; + public Via via0; + public Via via1; + + public Drive1541() + { + HardReset(); + } + + public void HardReset() + { + cpu = new MOS6502X(); + via0 = new Via(); + via1 = new Via(); + } + } +} diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.cs b/BizHawk.Emulation/Computers/Commodore64/C64.cs index 07d87e0842..e6753d4801 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.cs @@ -45,7 +45,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 } /*TODO*/ - public ISyncSoundProvider SyncSoundProvider { get { return null; } } //TODO + public ISyncSoundProvider SyncSoundProvider { get { return new SidSyncSoundProvider(sid); ; } } public bool StartAsyncSound() { return true; } //TODO public void EndAsyncSound() { } //TODO public bool DeterministicEmulation { get; set; } //TODO diff --git a/BizHawk.Emulation/Computers/Commodore64/SidSoundProvider.cs b/BizHawk.Emulation/Computers/Commodore64/SidSoundProvider.cs index ff1ef5c64f..e15b07d3c4 100644 --- a/BizHawk.Emulation/Computers/Commodore64/SidSoundProvider.cs +++ b/BizHawk.Emulation/Computers/Commodore64/SidSoundProvider.cs @@ -19,6 +19,19 @@ namespace BizHawk.Emulation.Computers.Commodore64 ResetBuffer(); } + public short[] GetAllSamples() + { + List samples = new List(); + while (sampleBufferReadIndex != sampleBufferIndex) + { + samples.Add(sampleBuffer[sampleBufferReadIndex]); + sampleBufferReadIndex++; + if (sampleBufferReadIndex == sampleBufferCapacity) + sampleBufferReadIndex = 0; + } + return samples.ToArray(); + } + public void GetSamples(short[] samples) { int count = samples.Length; @@ -87,4 +100,25 @@ namespace BizHawk.Emulation.Computers.Commodore64 sampleCounter--; } } + + public class SidSyncSoundProvider : ISyncSoundProvider + { + private Sid sid; + + public SidSyncSoundProvider(Sid source) + { + sid = source; + } + + public void DiscardSamples() + { + sid.DiscardSamples(); + } + + public void GetSamples(out short[] samples, out int nsamp) + { + samples = sid.GetAllSamples(); + nsamp = samples.Length / 2; + } + } } diff --git a/BizHawk.Emulation/Computers/Commodore64/Via.cs b/BizHawk.Emulation/Computers/Commodore64/Via.cs new file mode 100644 index 0000000000..811cf3384d --- /dev/null +++ b/BizHawk.Emulation/Computers/Commodore64/Via.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BizHawk.Emulation.Computers.Commodore64 +{ + // MOS Technologies VIA 6522 + // register count: 16 + // IO port count: 2 + + public class ViaRegs + { + public int ACR; + public int IER; + public int IFR; + public int PCR; + public int SR; + public int[] TC; + public int[] TL; + } + + public class Via + { + public ViaRegs regs; + + public Via() + { + HardReset(); + } + + public void HardReset() + { + regs = new ViaRegs(); + } + } +}