2015-11-16 08:38:05 +00:00
|
|
|
auto APU::Square::run() -> void {
|
2012-04-06 04:29:50 +00:00
|
|
|
if(period && --period == 0) {
|
2013-12-10 12:12:54 +00:00
|
|
|
period = 2 * (2048 - frequency);
|
2012-04-06 04:29:50 +00:00
|
|
|
phase++;
|
|
|
|
switch(duty) {
|
|
|
|
case 0: signal = (phase == 6); break; //_____-_
|
|
|
|
case 1: signal = (phase >= 6); break; //______--
|
|
|
|
case 2: signal = (phase >= 4); break; //____----
|
|
|
|
case 3: signal = (phase <= 5); break; //------__
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint4 sample = volume;
|
|
|
|
if(enable == false || signal == false) sample = 0;
|
|
|
|
output = sample;
|
|
|
|
}
|
|
|
|
|
2015-11-16 08:38:05 +00:00
|
|
|
auto APU::Square::clocklength() -> void {
|
2012-04-06 04:29:50 +00:00
|
|
|
if(enable && counter) {
|
|
|
|
if(++length == 0) enable = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 08:38:05 +00:00
|
|
|
auto APU::Square::clockenvelope() -> void {
|
2012-04-06 04:29:50 +00:00
|
|
|
if(enable && envelope.frequency && --envelope.period == 0) {
|
|
|
|
envelope.period = envelope.frequency;
|
|
|
|
if(envelope.direction == 0 && volume > 0) volume--;
|
|
|
|
if(envelope.direction == 1 && volume < 15) volume++;
|
|
|
|
}
|
|
|
|
}
|