Beispiel #1
0
        public void Tick()
        {
            if (!_enabled)
            {
                return;
            }

            for (var i = 0; i < _allModes.Length; i++)
            {
                var abstractSoundMode = _allModes[i];
                var channel           = abstractSoundMode.Tick();
                _channels[i] = channel;
            }

            var selection = _ram.GetByte(0xff25);
            var left      = 0;
            var right     = 0;

            for (var i = 0; i < 4; i++)
            {
                if (!_overridenEnabled[i])
                {
                    continue;
                }

                if ((selection & (1 << i + 4)) != 0)
                {
                    left += _channels[i];
                }

                if ((selection & (1 << i)) != 0)
                {
                    right += _channels[i];
                }
            }

            left  /= 4;
            right /= 4;

            var volumes = _ram.GetByte(0xff24);

            left  *= ((volumes >> 4) & 0b111);
            right *= (volumes & 0b111);

            _output.Play((byte)left, (byte)right);
        }
Beispiel #2
0
        public override int GetByte(int address)
        {
            if (!_waveRam.Accepts(address))
            {
                return(base.GetByte(address));
            }

            if (!IsEnabled())
            {
                return(_waveRam.GetByte(address));
            }

            if (_waveRam.Accepts(_lastReadAddress) && (Gbc || _ticksSinceRead < 2))
            {
                return(_waveRam.GetByte(_lastReadAddress));
            }

            return(0xff);
        }