AxibugEmuOnline/AxibugEmuOnline.Client/Assets/MyNes.Core/MMC5Pcm.cs

87 lines
1.6 KiB
C#
Raw Normal View History

2024-07-03 18:15:28 +08:00
using System.IO;
2024-07-03 18:22:22 +08:00
namespace MyNes.Core
2024-07-03 18:15:28 +08:00
{
2024-07-03 18:22:22 +08:00
internal class MMC5Pcm
{
internal byte output;
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
internal bool Outputable;
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
private bool readMode;
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
private bool PCMIRQenable;
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
private bool irqTrip;
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
internal void HardReset()
{
output = 0;
readMode = false;
PCMIRQenable = false;
irqTrip = false;
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
internal void SoftReset()
{
HardReset();
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
internal void Write5010(byte data)
{
readMode = (data & 1) == 1;
PCMIRQenable = (data & 0x80) == 128;
if (PCMIRQenable && irqTrip)
{
NesEmu.IRQFlags |= 8;
}
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
internal byte Read5010()
{
byte result = (byte)((irqTrip & PCMIRQenable) ? 128 : 0);
irqTrip = false;
NesEmu.IRQFlags &= -9;
return result;
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
internal void Write5011(byte data)
{
if (readMode)
{
return;
}
if (data == 0)
{
irqTrip = true;
}
else
{
irqTrip = false;
if (Outputable)
{
output = data;
}
}
if (PCMIRQenable && irqTrip)
{
NesEmu.IRQFlags |= 8;
}
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
internal void SaveState(ref BinaryWriter stream)
{
stream.Write(readMode);
stream.Write(PCMIRQenable);
stream.Write(irqTrip);
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
internal void LoadState(ref BinaryReader stream)
{
readMode = stream.ReadBoolean();
PCMIRQenable = stream.ReadBoolean();
irqTrip = stream.ReadBoolean();
}
}
2024-07-03 15:40:13 +08:00
}