Esempio n. 1
0
        private void Update_(int cyclesThisIteration)
        {
            while (cyclesThisIteration > 0)
            {
                var next_seq_ticks =
                    Apu.NextModulo_(this.syncTicks_, FRAME_SEQUENCER_TICKS);
                if (next_seq_ticks == FRAME_SEQUENCER_TICKS)
                {
                    this.frame_ = (byte)((this.frame_ + 1) % FRAME_SEQUENCER_COUNT);

                    var updateSweep   = this.frame_ == 2 || this.frame_ == 6;
                    var updateLengths =
                        updateSweep || this.frame_ == 0 || this.frame_ == 4;
                    var updateEnvelopes = updateLengths || this.frame_ == 7;

                    if (updateSweep)
                    {
                        this.UpdateSweep_();
                    }

                    if (updateLengths)
                    {
                        this.UpdateLengths_();
                    }

                    if (updateEnvelopes)
                    {
                        this.UpdateEnvelopes_();
                    }
                }
                var ticks = Math.Min(next_seq_ticks, cyclesThisIteration);
                this.UpdateChannels_(ticks / APU_TICKS);
                cyclesThisIteration -= ticks;
            }
        }