Hi.
Fairly recently I asked for some help with understanding the NES APU.
Blargg posted the following code (which has been extremely helpful. Thanks ):
It seems that whilst the timer still has time left (> 0), the same value is generated and sent to the mixer. When the timer runs out of time (<= 0), a new output value is generated and output to the mixer periodically until the timer runs out again.
Assuming that the above is correct (I hope), the way I understand it is that the noise and triangle channel behave in a very similar way. Although the output values are obviously different, it still outputs a particular generated value (taken from a sequence for the triangle and using a shift register to generate pseudo-random values for noise) for a time then generates a new value, continuing like this.
Would this seem correct? (ignoring the additional components which work on the channels, like the envelope generator etc).
Thank you very much.
Fairly recently I asked for some help with understanding the NES APU.
Blargg posted the following code (which has been extremely helpful. Thanks ):
Code:
#include <stdio.h>
static int r4000, r4002, r4003; // APU registers
static int timer; // divider connected to 1.79 MHz clock
static int phase; // position in 8-step wave sequence
static const int waves [4] [8] = {
{0,1,0,0,0,0,0,0},
{0,1,1,0,0,0,0,0},
{0,1,1,1,1,0,0,0},
{1,0,0,1,1,1,1,1}
};
int next_clock()
{
if ( --timer <= 0 )
{
int raw = (r4003 & 7) << 8 | r4002;
timer = (raw + 1) * 2;
phase = (phase + 1) & 7;
}
return waves [r4000 >> 6 & 3] [phase];
}
int main()
{
int n;
printf( "One digit = 1/1789773 of a second\n" );
// change these values and see what happens
r4000 = 0x40; // duty = 25%
r4002 = 1; // clocks between duty step = 4
r4003 = 0;
for ( n = 1000; n--; )
printf( "%d", next_clock() );
return 0;
}
static int r4000, r4002, r4003; // APU registers
static int timer; // divider connected to 1.79 MHz clock
static int phase; // position in 8-step wave sequence
static const int waves [4] [8] = {
{0,1,0,0,0,0,0,0},
{0,1,1,0,0,0,0,0},
{0,1,1,1,1,0,0,0},
{1,0,0,1,1,1,1,1}
};
int next_clock()
{
if ( --timer <= 0 )
{
int raw = (r4003 & 7) << 8 | r4002;
timer = (raw + 1) * 2;
phase = (phase + 1) & 7;
}
return waves [r4000 >> 6 & 3] [phase];
}
int main()
{
int n;
printf( "One digit = 1/1789773 of a second\n" );
// change these values and see what happens
r4000 = 0x40; // duty = 25%
r4002 = 1; // clocks between duty step = 4
r4003 = 0;
for ( n = 1000; n--; )
printf( "%d", next_clock() );
return 0;
}
It seems that whilst the timer still has time left (> 0), the same value is generated and sent to the mixer. When the timer runs out of time (<= 0), a new output value is generated and output to the mixer periodically until the timer runs out again.
Assuming that the above is correct (I hope), the way I understand it is that the noise and triangle channel behave in a very similar way. Although the output values are obviously different, it still outputs a particular generated value (taken from a sequence for the triangle and using a shift register to generate pseudo-random values for noise) for a time then generates a new value, continuing like this.
Would this seem correct? (ignoring the additional components which work on the channels, like the envelope generator etc).
Thank you very much.