diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Datacorder/DatacorderDevice.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Datacorder/DatacorderDevice.cs index 37f82f5f52..c67ce41ee4 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Datacorder/DatacorderDevice.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Datacorder/DatacorderDevice.cs @@ -26,7 +26,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public DatacorderDevice() { - + } /// @@ -37,13 +37,20 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { _machine = machine; _cpu = _machine.CPU; - _buzzer = machine.BuzzerDevice; + _buzzer = machine.TapeBuzzer; } + + #endregion #region State Information + /// + /// Internal counter used to trigger tape buzzer output + /// + private int counter = 0; + /// /// The index of the current tape data block that is loaded /// @@ -145,7 +152,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum public void StartFrame() { //if (TapeIsPlaying && AutoPlay) - //FlashLoad(); + //FlashLoad(); + + _buzzer.ProcessPulseValue(true, currentState); } #endregion @@ -160,7 +169,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum if (_tapeIsPlaying) return; - _machine.BuzzerDevice.SetTapeMode(true); + _buzzer.SetTapeMode(true); _machine.Spectrum.OSD_TapePlaying(); @@ -215,7 +224,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum if (!_tapeIsPlaying) return; - _machine.BuzzerDevice.SetTapeMode(false); + _buzzer.SetTapeMode(false); _machine.Spectrum.OSD_TapeStopped(); @@ -376,6 +385,27 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum #endregion #region Tape Device Methods + + + + + /// + /// Runs every frame + /// + public void TapeCycle() + { + if (TapeIsPlaying) + { + counter++; + + if (counter > 50) + { + counter = 0; + bool state = GetEarBit(_machine.CPU.TotalExecutedCycles); + _buzzer.ProcessPulseValue(false, state); + } + } + } /// /// Simulates the spectrum 'EAR' input reading data from the tape @@ -534,7 +564,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum _lastCycle = cpuCycle - (long)cycles; // play the buzzer - _buzzer.ProcessPulseValue(false, currentState); + //_buzzer.ProcessPulseValue(false, currentState); return currentState; } @@ -898,6 +928,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum public void SyncState(Serializer ser) { ser.BeginSection("DatacorderDevice"); + ser.Sync("counter", ref counter); ser.Sync("_currentDataBlockIndex", ref _currentDataBlockIndex); ser.Sync("_position", ref _position); ser.Sync("_tapeIsPlaying", ref _tapeIsPlaying); diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs index a1e44356d1..af68ff0587 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs @@ -39,6 +39,11 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public IBeeperDevice BuzzerDevice { get; set; } + /// + /// A second beeper for the tape + /// + public IBeeperDevice TapeBuzzer { get; set; } + /// /// Device representing the AY-3-8912 chip found in the 128k and up spectrums /// @@ -142,6 +147,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum if (_renderSound) { BuzzerDevice.StartFrame(); + TapeBuzzer.StartFrame(); if (AYDevice != null) AYDevice.StartFrame(); } @@ -154,7 +160,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum ULADevice.CheckForInterrupt(CurrentFrameCycle); // run a single CPU instruction - CPU.ExecuteOne(); + CPU.ExecuteOne(); + + // cycle the tape device + TapeDevice.TapeCycle(); } // we have reached the end of a frame @@ -165,7 +174,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum ULADevice.UpdateScreenBuffer(ULADevice.FrameLength); if (_renderSound) + { BuzzerDevice.EndFrame(); + TapeBuzzer.EndFrame(); + } if (AYDevice != null) AYDevice.EndFrame(); @@ -329,6 +341,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum RomData.SyncState(ser); KeyboardDevice.SyncState(ser); BuzzerDevice.SyncState(ser); + TapeBuzzer.SyncState(ser); ULADevice.SyncState(ser); if (AYDevice != null) @@ -336,7 +349,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum AYDevice.SyncState(ser); ((AYChip)AYDevice as AYChip).PanningConfiguration = Spectrum.Settings.AYPanConfig; } - ser.Sync("tapeMediaIndex", ref tapeMediaIndex); TapeMediaIndex = tapeMediaIndex; diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128K/ZX128.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128K/ZX128.cs index 3ea955ddca..0494585323 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128K/ZX128.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128K/ZX128.cs @@ -31,6 +31,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum BuzzerDevice = new Buzzer(this); BuzzerDevice.Init(44100, ULADevice.FrameLength); + TapeBuzzer = new Buzzer(this); + TapeBuzzer.Init(44100, ULADevice.FrameLength); + AYDevice = new AYChip(this); AYDevice.Init(44100, ULADevice.FrameLength); diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128KPlus2a/ZX128Plus2a.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128KPlus2a/ZX128Plus2a.cs index 3cd1f695d5..c2eb1cb85b 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128KPlus2a/ZX128Plus2a.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128KPlus2a/ZX128Plus2a.cs @@ -31,6 +31,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum BuzzerDevice = new Buzzer(this); BuzzerDevice.Init(44100, ULADevice.FrameLength); + TapeBuzzer = new Buzzer(this); + TapeBuzzer.Init(44100, ULADevice.FrameLength); + AYDevice = new AYChip(this); AYDevice.Init(44100, ULADevice.FrameLength); diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128KPlus3/ZX128Plus3.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128KPlus3/ZX128Plus3.cs index 916232bcb6..d9cf36a106 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128KPlus3/ZX128Plus3.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128KPlus3/ZX128Plus3.cs @@ -31,6 +31,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum BuzzerDevice = new Buzzer(this); BuzzerDevice.Init(44100, ULADevice.FrameLength); + TapeBuzzer = new Buzzer(this); + TapeBuzzer.Init(44100, ULADevice.FrameLength); + AYDevice = new AYChip(this); AYDevice.Init(44100, ULADevice.FrameLength); diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum48K/ZX48.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum48K/ZX48.cs index 9dacc597f3..20618d7f1b 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum48K/ZX48.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum48K/ZX48.cs @@ -26,6 +26,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum BuzzerDevice = new Buzzer(this); BuzzerDevice.Init(44100, ULADevice.FrameLength); + TapeBuzzer = new Buzzer(this); + TapeBuzzer.Init(44100, ULADevice.FrameLength); + KeyboardDevice = new StandardKeyboard(this); InitJoysticks(joysticks); diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.cs index fab7424edf..cd4eabe7ba 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.cs @@ -101,6 +101,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum SoundMixer = new SoundProviderMixer((int)(32767 / 10), (ISoundProvider)_machine.BuzzerDevice); if (_machine.AYDevice != null) SoundMixer.AddSource(_machine.AYDevice); + if (_machine.TapeBuzzer != null) + SoundMixer.AddSource((ISoundProvider)_machine.TapeBuzzer); //SoundMixer.Stereo = ((ZXSpectrumSettings)settings as ZXSpectrumSettings).StereoSound; if (_machine.AYDevice != null && _machine.AYDevice.GetType() == typeof(AYChip)) @@ -115,6 +117,12 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum ((Buzzer)_machine.BuzzerDevice as Buzzer).EarVolume = ((ZXSpectrumSettings)settings as ZXSpectrumSettings).EarVolume; } + if (_machine.TapeBuzzer != null) + { + ((Buzzer)_machine.TapeBuzzer as Buzzer).TapeVolume = ((ZXSpectrumSettings)settings as ZXSpectrumSettings).TapeVolume; + //((Buzzer)_machine.TapeBuzzer as Buzzer).EarVolume = ((ZXSpectrumSettings)settings as ZXSpectrumSettings).EarVolume; + } + ser.Register(SoundMixer);