ZXHawk: Started tapedevice independence implementation

This commit is contained in:
Asnivor 2018-03-27 14:12:51 +01:00
parent 3b9835274a
commit 86dd0b4a06
7 changed files with 71 additions and 8 deletions

View File

@ -37,13 +37,20 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
_machine = machine; _machine = machine;
_cpu = _machine.CPU; _cpu = _machine.CPU;
_buzzer = machine.BuzzerDevice; _buzzer = machine.TapeBuzzer;
} }
#endregion #endregion
#region State Information #region State Information
/// <summary>
/// Internal counter used to trigger tape buzzer output
/// </summary>
private int counter = 0;
/// <summary> /// <summary>
/// The index of the current tape data block that is loaded /// The index of the current tape data block that is loaded
/// </summary> /// </summary>
@ -146,6 +153,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
//if (TapeIsPlaying && AutoPlay) //if (TapeIsPlaying && AutoPlay)
//FlashLoad(); //FlashLoad();
_buzzer.ProcessPulseValue(true, currentState);
} }
#endregion #endregion
@ -160,7 +169,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
if (_tapeIsPlaying) if (_tapeIsPlaying)
return; return;
_machine.BuzzerDevice.SetTapeMode(true); _buzzer.SetTapeMode(true);
_machine.Spectrum.OSD_TapePlaying(); _machine.Spectrum.OSD_TapePlaying();
@ -215,7 +224,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
if (!_tapeIsPlaying) if (!_tapeIsPlaying)
return; return;
_machine.BuzzerDevice.SetTapeMode(false); _buzzer.SetTapeMode(false);
_machine.Spectrum.OSD_TapeStopped(); _machine.Spectrum.OSD_TapeStopped();
@ -377,6 +386,27 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
#region Tape Device Methods #region Tape Device Methods
/// <summary>
/// Runs every frame
/// </summary>
public void TapeCycle()
{
if (TapeIsPlaying)
{
counter++;
if (counter > 50)
{
counter = 0;
bool state = GetEarBit(_machine.CPU.TotalExecutedCycles);
_buzzer.ProcessPulseValue(false, state);
}
}
}
/// <summary> /// <summary>
/// Simulates the spectrum 'EAR' input reading data from the tape /// Simulates the spectrum 'EAR' input reading data from the tape
/// </summary> /// </summary>
@ -534,7 +564,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
_lastCycle = cpuCycle - (long)cycles; _lastCycle = cpuCycle - (long)cycles;
// play the buzzer // play the buzzer
_buzzer.ProcessPulseValue(false, currentState); //_buzzer.ProcessPulseValue(false, currentState);
return currentState; return currentState;
} }
@ -898,6 +928,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
public void SyncState(Serializer ser) public void SyncState(Serializer ser)
{ {
ser.BeginSection("DatacorderDevice"); ser.BeginSection("DatacorderDevice");
ser.Sync("counter", ref counter);
ser.Sync("_currentDataBlockIndex", ref _currentDataBlockIndex); ser.Sync("_currentDataBlockIndex", ref _currentDataBlockIndex);
ser.Sync("_position", ref _position); ser.Sync("_position", ref _position);
ser.Sync("_tapeIsPlaying", ref _tapeIsPlaying); ser.Sync("_tapeIsPlaying", ref _tapeIsPlaying);

View File

@ -39,6 +39,11 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary> /// </summary>
public IBeeperDevice BuzzerDevice { get; set; } public IBeeperDevice BuzzerDevice { get; set; }
/// <summary>
/// A second beeper for the tape
/// </summary>
public IBeeperDevice TapeBuzzer { get; set; }
/// <summary> /// <summary>
/// Device representing the AY-3-8912 chip found in the 128k and up spectrums /// Device representing the AY-3-8912 chip found in the 128k and up spectrums
/// </summary> /// </summary>
@ -142,6 +147,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
if (_renderSound) if (_renderSound)
{ {
BuzzerDevice.StartFrame(); BuzzerDevice.StartFrame();
TapeBuzzer.StartFrame();
if (AYDevice != null) if (AYDevice != null)
AYDevice.StartFrame(); AYDevice.StartFrame();
} }
@ -155,6 +161,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// run a single CPU instruction // run a single CPU instruction
CPU.ExecuteOne(); CPU.ExecuteOne();
// cycle the tape device
TapeDevice.TapeCycle();
} }
// we have reached the end of a frame // we have reached the end of a frame
@ -165,7 +174,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
ULADevice.UpdateScreenBuffer(ULADevice.FrameLength); ULADevice.UpdateScreenBuffer(ULADevice.FrameLength);
if (_renderSound) if (_renderSound)
{
BuzzerDevice.EndFrame(); BuzzerDevice.EndFrame();
TapeBuzzer.EndFrame();
}
if (AYDevice != null) if (AYDevice != null)
AYDevice.EndFrame(); AYDevice.EndFrame();
@ -329,6 +341,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
RomData.SyncState(ser); RomData.SyncState(ser);
KeyboardDevice.SyncState(ser); KeyboardDevice.SyncState(ser);
BuzzerDevice.SyncState(ser); BuzzerDevice.SyncState(ser);
TapeBuzzer.SyncState(ser);
ULADevice.SyncState(ser); ULADevice.SyncState(ser);
if (AYDevice != null) if (AYDevice != null)
@ -337,7 +350,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
((AYChip)AYDevice as AYChip).PanningConfiguration = Spectrum.Settings.AYPanConfig; ((AYChip)AYDevice as AYChip).PanningConfiguration = Spectrum.Settings.AYPanConfig;
} }
ser.Sync("tapeMediaIndex", ref tapeMediaIndex); ser.Sync("tapeMediaIndex", ref tapeMediaIndex);
TapeMediaIndex = tapeMediaIndex; TapeMediaIndex = tapeMediaIndex;

View File

@ -31,6 +31,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
BuzzerDevice = new Buzzer(this); BuzzerDevice = new Buzzer(this);
BuzzerDevice.Init(44100, ULADevice.FrameLength); BuzzerDevice.Init(44100, ULADevice.FrameLength);
TapeBuzzer = new Buzzer(this);
TapeBuzzer.Init(44100, ULADevice.FrameLength);
AYDevice = new AYChip(this); AYDevice = new AYChip(this);
AYDevice.Init(44100, ULADevice.FrameLength); AYDevice.Init(44100, ULADevice.FrameLength);

View File

@ -31,6 +31,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
BuzzerDevice = new Buzzer(this); BuzzerDevice = new Buzzer(this);
BuzzerDevice.Init(44100, ULADevice.FrameLength); BuzzerDevice.Init(44100, ULADevice.FrameLength);
TapeBuzzer = new Buzzer(this);
TapeBuzzer.Init(44100, ULADevice.FrameLength);
AYDevice = new AYChip(this); AYDevice = new AYChip(this);
AYDevice.Init(44100, ULADevice.FrameLength); AYDevice.Init(44100, ULADevice.FrameLength);

View File

@ -31,6 +31,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
BuzzerDevice = new Buzzer(this); BuzzerDevice = new Buzzer(this);
BuzzerDevice.Init(44100, ULADevice.FrameLength); BuzzerDevice.Init(44100, ULADevice.FrameLength);
TapeBuzzer = new Buzzer(this);
TapeBuzzer.Init(44100, ULADevice.FrameLength);
AYDevice = new AYChip(this); AYDevice = new AYChip(this);
AYDevice.Init(44100, ULADevice.FrameLength); AYDevice.Init(44100, ULADevice.FrameLength);

View File

@ -26,6 +26,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
BuzzerDevice = new Buzzer(this); BuzzerDevice = new Buzzer(this);
BuzzerDevice.Init(44100, ULADevice.FrameLength); BuzzerDevice.Init(44100, ULADevice.FrameLength);
TapeBuzzer = new Buzzer(this);
TapeBuzzer.Init(44100, ULADevice.FrameLength);
KeyboardDevice = new StandardKeyboard(this); KeyboardDevice = new StandardKeyboard(this);
InitJoysticks(joysticks); InitJoysticks(joysticks);

View File

@ -101,6 +101,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
SoundMixer = new SoundProviderMixer((int)(32767 / 10), (ISoundProvider)_machine.BuzzerDevice); SoundMixer = new SoundProviderMixer((int)(32767 / 10), (ISoundProvider)_machine.BuzzerDevice);
if (_machine.AYDevice != null) if (_machine.AYDevice != null)
SoundMixer.AddSource(_machine.AYDevice); SoundMixer.AddSource(_machine.AYDevice);
if (_machine.TapeBuzzer != null)
SoundMixer.AddSource((ISoundProvider)_machine.TapeBuzzer);
//SoundMixer.Stereo = ((ZXSpectrumSettings)settings as ZXSpectrumSettings).StereoSound; //SoundMixer.Stereo = ((ZXSpectrumSettings)settings as ZXSpectrumSettings).StereoSound;
if (_machine.AYDevice != null && _machine.AYDevice.GetType() == typeof(AYChip)) 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; ((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<ISoundProvider>(SoundMixer); ser.Register<ISoundProvider>(SoundMixer);