AxibugEmuOnline/AxibugEmuOnline.Client/Assets/VirtualNes.Core/ApuEX/APU_FDS.cs

136 lines
4.1 KiB
C#
Raw Normal View History

2024-07-26 17:52:33 +08:00
using System;
namespace VirtualNes.Core
{
public class APU_FDS : APU_INTERFACE
{
private FDSSOUND fds = new FDSSOUND();
private FDSSOUND fds_sync = new FDSSOUND();
public APU_FDS()
{
fds.ZeroMemory();
fds_sync.ZeroMemory();
}
2024-07-26 17:52:33 +08:00
public override void Reset(float fClock, int nRate)
{
2024-07-30 11:57:09 +08:00
//todo : 实现
2024-07-26 17:52:33 +08:00
}
public override void Setup(float fClock, int nRate)
{
2024-07-30 11:57:09 +08:00
//todo : 实现
2024-07-26 17:52:33 +08:00
}
public override void Write(ushort addr, byte data)
{
2024-07-30 11:57:09 +08:00
//todo : 实现
2024-07-26 17:52:33 +08:00
}
public override int Process(int channel)
{
2024-07-30 11:57:09 +08:00
//todo : 实现
return 0;
2024-07-26 17:52:33 +08:00
}
internal void SyncWrite(ushort addr, byte data)
{
WriteSub(addr, data, fds_sync, 1789772.5d);
}
private void WriteSub(ushort addr, byte data, FDSSOUND ch, double rate)
{
2024-07-30 11:57:09 +08:00
//todo : 实现
2024-07-26 17:52:33 +08:00
}
2024-08-05 11:52:43 +08:00
internal byte SyncRead(ushort addr)
{
byte data = (byte)(addr >> 8);
if (addr >= 0x4040 && addr <= 0x407F)
{
data = (byte)(fds_sync.main_wavetable[addr & 0x3F] | 0x40);
}
else
if (addr == 0x4090)
{
data = (byte)((fds_sync.volenv_gain & 0x3F) | 0x40);
}
else
if (addr == 0x4092)
{
data = (byte)((fds_sync.swpenv_gain & 0x3F) | 0x40);
}
return data;
}
2024-07-26 17:52:33 +08:00
private class FDSSOUND
{
2024-08-05 11:52:43 +08:00
public byte[] reg = new byte[0x80];
public byte volenv_mode; // Volume Envelope
public byte volenv_gain;
public byte volenv_decay;
public double volenv_phaseacc;
public byte swpenv_mode; // Sweep Envelope
public byte swpenv_gain;
public byte swpenv_decay;
public double swpenv_phaseacc;
// For envelope unit
public byte envelope_enable; // $4083 bit6
public byte envelope_speed; // $408A
// For $4089
public byte wave_setup; // bit7
public int master_volume; // bit1-0
// For Main unit
public int[] main_wavetable = new int[64];
public byte main_enable;
public int main_frequency;
public int main_addr;
// For Effector(LFO) unit
public byte[] lfo_wavetable = new byte[64];
public byte lfo_enable; // 0:Enable 1:Wavetable setup
public int lfo_frequency;
public int lfo_addr;
public double lfo_phaseacc;
// For Sweep unit
public int sweep_bias;
// Misc
public int now_volume;
public int now_freq;
public int output;
public void ZeroMemory()
{
Array.Clear(reg, 0, reg.Length);
volenv_mode = 0;
volenv_gain = 0;
volenv_decay = 0;
volenv_phaseacc = 0.0;
swpenv_mode = 0;
swpenv_gain = 0;
swpenv_decay = 0;
swpenv_phaseacc = 0.0;
envelope_enable = 0;
envelope_speed = 0;
wave_setup = 0;
master_volume = 0;
Array.Clear(main_wavetable, 0, main_wavetable.Length);
main_enable = 0;
main_frequency = 0;
main_addr = 0;
Array.Clear(lfo_wavetable, 0, lfo_wavetable.Length);
lfo_enable = 0;
lfo_frequency = 0;
lfo_addr = 0;
lfo_phaseacc = 0.0;
sweep_bias = 0;
now_volume = 0;
now_freq = 0;
output = 0;
}
2024-07-26 17:52:33 +08:00
}
}
}