http://wiki.nesdev.com/w/index.php/APU_Pulse
I am trying to emulate the duty cycles.
I read this:
This is my approach:
($4003, $4007 writes set dutyCounter=7 currently.)
By counting backward, it will effectively output:
00000001
00000011
00001111
11111100
Which looks nice, but I'm not sure if that's the intention or not.
But if you really mean we should be outputting LITERALLY:
01000000
01100000
01111000
10011111
Then why mention the decrementing thing? It's just confusing. If the counter is supposed to decrement, then store the table as if you're decrementing the counter (like my first example) and say you should decrement. If the counter is supposed to increment, then store the table in that order (like the second table) and don't talk about decrementing. Really, it's not a great code simplification to turn a decrement into an increment, in return for making the table look like hot garbage. >_>
Any help would be appreciated. I'd try to emulate this by ear but I cannot tell the difference at all between either way.
I am trying to emulate the duty cycles.
I read this:
Quote:
Duty Cycle Sequences
Duty Waveform sequence
0 0 1 0 0 0 0 0 0 (12.5%)
1 0 1 1 0 0 0 0 0 (25%)
2 0 1 1 1 1 0 0 0 (50%)
3 1 0 0 1 1 1 1 1 (25% negated)
The reason for these odd sequences is that the sequence counter is initialized to zero but counts downward rather than upward
Duty Waveform sequence
0 0 1 0 0 0 0 0 0 (12.5%)
1 0 1 1 0 0 0 0 0 (25%)
2 0 1 1 1 1 0 0 0 (50%)
3 1 0 0 1 1 1 1 1 (25% negated)
The reason for these odd sequences is that the sequence counter is initialized to zero but counts downward rather than upward
This is my approach:
Code:
auto APU::Pulse::clock() -> uint8 {
if(!sweep.checkPeriod()) return 0;
if(lengthCounter == 0) return 0;
static const uint dutyTable[4][8] = {
{0, 1, 0, 0, 0, 0, 0, 0}, //12.5%
{0, 1, 1, 0, 0, 0, 0, 0}, //25.0%
{0, 1, 1, 1, 1, 0, 0, 0}, //50.0%
{1, 0, 0, 1, 1, 1, 1, 1}, //25.0% (inverted)
};
uint8 result = dutyTable[duty][dutyCounter] ? envelope.volume() : 0;
if(sweep.pulsePeriod < 0x008) result = 0;
if(--periodCounter == 0) {
periodCounter = (sweep.pulsePeriod + 1) * 2;
dutyCounter--; //note this is a uint3 type. If the value is zero, dutyCounter-- becomes 7.
}
return result;
}
if(!sweep.checkPeriod()) return 0;
if(lengthCounter == 0) return 0;
static const uint dutyTable[4][8] = {
{0, 1, 0, 0, 0, 0, 0, 0}, //12.5%
{0, 1, 1, 0, 0, 0, 0, 0}, //25.0%
{0, 1, 1, 1, 1, 0, 0, 0}, //50.0%
{1, 0, 0, 1, 1, 1, 1, 1}, //25.0% (inverted)
};
uint8 result = dutyTable[duty][dutyCounter] ? envelope.volume() : 0;
if(sweep.pulsePeriod < 0x008) result = 0;
if(--periodCounter == 0) {
periodCounter = (sweep.pulsePeriod + 1) * 2;
dutyCounter--; //note this is a uint3 type. If the value is zero, dutyCounter-- becomes 7.
}
return result;
}
($4003, $4007 writes set dutyCounter=7 currently.)
By counting backward, it will effectively output:
00000001
00000011
00001111
11111100
Which looks nice, but I'm not sure if that's the intention or not.
But if you really mean we should be outputting LITERALLY:
01000000
01100000
01111000
10011111
Then why mention the decrementing thing? It's just confusing. If the counter is supposed to decrement, then store the table as if you're decrementing the counter (like my first example) and say you should decrement. If the counter is supposed to increment, then store the table in that order (like the second table) and don't talk about decrementing. Really, it's not a great code simplification to turn a decrement into an increment, in return for making the table look like hot garbage. >_>
Any help would be appreciated. I'd try to emulate this by ear but I cannot tell the difference at all between either way.