Exemple #1
0
 /// <summary>
 /// Checks if this render state equals the specified render state.
 /// </summary>
 /// <param name="other">The other.</param>
 /// <returns></returns>
 protected bool Equals(RenderState other)
 {
     return(Equals(RenderSettings, other.RenderSettings) && TileSet.SequenceEqual(other.TileSet) &&
            BackgroundTileMap.SequenceEqual(other.BackgroundTileMap) && WindowTileMap.SequenceEqual(other.WindowTileMap) &&
            SpriteOam.SequenceEqual(other.SpriteOam) && SpriteTileSet.SequenceEqual(other.SpriteTileSet));
 }
Exemple #2
0
        /// <summary>
        /// Paints a new frame.
        /// </summary>
        private void Paint()
        {
            var renderSettings = new RenderSettings(_gpuRegisters);

            var backgroundTileMap = _tileRam.ReadBytes(renderSettings.BackgroundTileMapAddress, 0x400);
            var tileSet           = _tileRam.ReadBytes(renderSettings.TileSetAddress, 0x1000);
            var windowTileMap     = renderSettings.WindowEnabled ? _tileRam.ReadBytes(renderSettings.WindowTileMapAddress, 0x400) : new byte[0];

            byte[] spriteOam, spriteTileSet;
            if (renderSettings.SpritesEnabled)
            {
                // If the background tiles are read from the sprite pattern table then we can reuse the bytes.
                spriteTileSet = renderSettings.SpriteAndBackgroundTileSetShared ? tileSet : _tileRam.ReadBytes(0x0, 0x1000);
                spriteOam     = _spriteRam.ReadBytes(0x0, 0xa0);
            }
            else
            {
                spriteOam = spriteTileSet = new byte[0];
            }

            var renderState = new RenderState(renderSettings, tileSet, backgroundTileMap, windowTileMap, spriteOam, spriteTileSet);

            var renderStateChange = renderState.GetRenderStateChange(_lastRenderState);

            if (renderStateChange == RenderStateChange.None)
            {
                // No need to render the same frame twice.
                _frameSkip = 0;
                _framesRendered++;
                return;
            }

            _lastRenderState = renderState;

            _tileMapPointer = _tileMapPointer == null ? new TileMapPointer(renderState) : _tileMapPointer.Reset(renderState, renderStateChange);

            var bitmapPalette = _gpuRegisters.LcdMonochromePaletteRegister.Pallette;

            for (var y = 0; y < LcdHeight; y++)
            {
                for (var x = 0; x < LcdWidth; x++)
                {
                    _lcdBuffer.SetPixel(x, y, (byte)bitmapPalette[_tileMapPointer.Pixel]);

                    if (x + 1 < LcdWidth)
                    {
                        _tileMapPointer.NextColumn();
                    }
                }

                if (y + 1 < LcdHeight)
                {
                    _tileMapPointer.NextRow();
                }
            }

            _renderer.Paint(_lcdBuffer);

            _frameSkip = 0;
            _framesRendered++;
        }