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

@ -26,7 +26,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
public DatacorderDevice()
{
}
/// <summary>
@ -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
/// <summary>
/// Internal counter used to trigger tape buzzer output
/// </summary>
private int counter = 0;
/// <summary>
/// The index of the current tape data block that is loaded
/// </summary>
@ -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
/// <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>
/// 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);

View File

@ -39,6 +39,11 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
public IBeeperDevice BuzzerDevice { get; set; }
/// <summary>
/// A second beeper for the tape
/// </summary>
public IBeeperDevice TapeBuzzer { get; set; }
/// <summary>
/// Device representing the AY-3-8912 chip found in the 128k and up spectrums
/// </summary>
@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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<ISoundProvider>(SoundMixer);