broken-neees
Version:
A really broken NEEES emulator that introduces glitches and random bugs on purpose!
35 lines (32 loc) • 986 B
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
const APU_MIN_TIMER = 8;
const APU_MAX_TIMER = 0x7ff;
class FrequencySweep {
constructor(channel) {
this.channel = channel;
// input
this.startFlag = false;
// output
this.dividerCount = 0;
this.mute = false;
}
clock() {
const register = this.channel.registers.sweep;
if (register.enabledFlag && register.shiftCount > 0 && this.dividerCount === 0 && !this.mute) {
const sweepDelta = this.channel.timer >> register.shiftCount;
this.channel.timer += sweepDelta * (register.negateFlag ? -1 : 1);
}
if (this.dividerCount === 0 || this.startFlag) {
this.dividerCount = register.dividerPeriodMinusOne + 1;
this.startFlag = false;
} else this.dividerCount--;
}
muteIfNeeded() {
this.mute = this.channel.timer < APU_MIN_TIMER || this.channel.timer > APU_MAX_TIMER;
}
}
exports.default = FrequencySweep;