A few people might have seen my other thread about struggling with generating some NES-audio. I'm trying to cleanup this mess and thought about trying to generate some psuedo-code to hopefully make things more clear. I'm not sure this is a good idea or not, we'll see. I don't understand all of the documentation that's available but I'm hoping some talented people (I know there are many around here) perhaps wants to help out?
Feel free to make comments about adjustements and I'll update this post. Or if you have a better idea, feel free to let me know.
Currently I'm focusing on understanding the squarewave channel 0 (below) but it's obviously not complete at the moment.
EDIT: Ignore this psuedo-code below, check the posts from Disch instead.
Feel free to make comments about adjustements and I'll update this post. Or if you have a better idea, feel free to let me know.
Currently I'm focusing on understanding the squarewave channel 0 (below) but it's obviously not complete at the moment.
EDIT: Ignore this psuedo-code below, check the posts from Disch instead.
Code:
$4000:
Set DutyType to (bit 6-7)
if bit 5 = 1 (?????)
if VolumeMode=Decay
if bit 4 = 1
DecayLooping=true, restart at 0x0F;
else
DecayLooping=false, stay at 0
LenghtCounterClock = Disabled
if bit 4 = 0
VolumeMode=Decay
Set Volume to 0x0F
Set EnvelopeReloadValue to (bit 3-0)
else
VolumeMode=Fixed
Set volume to (bit 3-0)
$4001: SWEEP
$4002
WaveLength (lowest 8 bits) = value
$4003
WaveLength (upper 3 bits) = bit 2-0
CurrentWaveLength=WaveLength
LengtCounter=Bit 7-3 (5 bits)
LenghtCounter=DurationTable[LengthCounter]
LenghtCounterClock = enabled (if LengthCounter>0)
$Vertical blank:
if LengthCounterClock is enabled
LengthCounter--
if LenghtCounter==0
SilenceChannel()
Set DutyType to (bit 6-7)
if bit 5 = 1 (?????)
if VolumeMode=Decay
if bit 4 = 1
DecayLooping=true, restart at 0x0F;
else
DecayLooping=false, stay at 0
LenghtCounterClock = Disabled
if bit 4 = 0
VolumeMode=Decay
Set Volume to 0x0F
Set EnvelopeReloadValue to (bit 3-0)
else
VolumeMode=Fixed
Set volume to (bit 3-0)
$4001: SWEEP
$4002
WaveLength (lowest 8 bits) = value
$4003
WaveLength (upper 3 bits) = bit 2-0
CurrentWaveLength=WaveLength
LengtCounter=Bit 7-3 (5 bits)
LenghtCounter=DurationTable[LengthCounter]
LenghtCounterClock = enabled (if LengthCounter>0)
$Vertical blank:
if LengthCounterClock is enabled
LengthCounter--
if LenghtCounter==0
SilenceChannel()