コード例 #1
0
        public void DrawTiles()
        {
            ushort tileBaseAddress    = DisFuncs.GetTileBaseAddress(_state.TileBase);
            ushort tileMapBaseAddress = DisFuncs.GetTileMapBaseAddress(_state.TileMap);

            for (int tileY = 0; tileY < 18; ++tileY)
            {
                for (int tileX = 0; tileX < 20; ++tileX)
                {
                    int tileOffset;
                    if (_state.NoTileMap)
                    {
                        tileOffset = 16 * tileY + tileX;
                    }
                    else
                    {
                        tileOffset = DisFuncs.GetTileOffset(_disDef, _memory, tileMapBaseAddress,
                                                            _state.TileBase, tileX, tileY);
                    }
                    byte[] tileData = DisFuncs.GetTileData(_disDef, _memory, tileBaseAddress, tileOffset, false);

                    DrawFuncs.DrawTile(_pixelLookupTable,
                                       _disDef, _debugInternalTargets[(int)DebugTargets.Tiles],
                                       _tempPixelBuffer,
                                       _disDef.ScreenPixelCountX, tileData,
                                       8 * tileX, 8 * tileY,
                                       256, 256);
                }
            }
        }
コード例 #2
0
        internal void StartFrame()
        {
            _state.CurrentLine = 0;
            _state.CurrentWY   = _state.WY;

            if (!_state.Enabled)
            {
                return;
            }

            // WINDOW TRANSPARENCY
            if (_updateDebugTargets[(int)DebugTargets.Window])
            {
                DrawFuncs.DrawTransparency(_disDef, _debugInternalTargets[(int)DebugTargets.Window],
                                           _disDef.ScreenPixelCountX,
                                           0, 0,
                                           _disDef.ScreenPixelCountX, _disDef.ScreenPixelCountY);
            }

            // SPRITES TRANSPARENCY
            if (_updateDebugTargets[(int)DebugTargets.SpriteLayer])
            {
                DrawFuncs.DrawTransparency(_disDef, _debugInternalTargets[(int)DebugTargets.SpriteLayer],
                                           _disDef.ScreenPixelCountX,
                                           0, 0,
                                           _disDef.ScreenPixelCountX, _disDef.ScreenPixelCountY);
            }
        }
コード例 #3
0
        internal void DrawTiming()
        {
            // This probably means an empty step (breakpoint)
            if (_state.PrevTickCount == _state.CurrentLineTickCount)
            {
                return;
            }

            int beginX = (int)(pixelsPerTick * _state.PrevTickCount);
            int endX   = (int)(pixelsPerTick * _state.CurrentLineTickCount);

            if (beginX >= 256 || endX >= 256)
            {
                return;
            }

            if ((_state.CurrentLine == 0) &&
                ((endX <= beginX) || firstRun))
            {
                //DisplayFunctions.DrawTransparency(disDef, displayTimingBmpData, 0, 0, 256, 154);
                DrawFuncs.DrawRectangle(_disDef, _debugInternalTargets[(int)DebugTargets.DisplayTiming],
                                        _disDef.TimingPixelCountX,
                                        0, 0,
                                        _disDef.TimingPixelCountX, _disDef.TimingPixelCountY,
                                        0xFF000000, true);
            }

            byte mode  = (byte)_state.DisplayMode;
            uint color = 0xFFFFFF00;

            if (mode == 1)
            {
                color = 0xFFFF0000;
            }
            if (mode == 2)
            {
                color = 0xFF00FF00;
            }
            if (mode == 3)
            {
                color = 0xFF0000FF;
            }

            int rowIndex = _state.CurrentLine * _disDef.TimingPixelCountX;

            for (int i = beginX; i < endX; ++i)
            {
                _debugInternalTargets[(int)DebugTargets.DisplayTiming][rowIndex + i] = color;
            }
        }
コード例 #4
0
        internal void DrawSprite(uint[] spriteData, int spriteCode, int pX, int pY)
        {
            DrawFuncs.DrawTransparency(_disDef, spriteData, 8, 0, 0, 8, 16);

            if (_state.LCDCBits[2])
            {
                spriteCode = spriteCode & 0xFE; // We remove the last bit
            }

            // We draw the top part
            byte[] pixels = DisFuncs.GetTileData(_disDef, _memory, 0x8000, spriteCode, _state.LCDCBits[2]);
            DrawFuncs.DrawTile(_pixelLookupTable,
                               _disDef, spriteData, _tempPixelBuffer,
                               8, pixels, pX, pY,
                               _disDef.ScreenPixelCountX, _disDef.ScreenPixelCountY);
        }
コード例 #5
0
        internal void EndFrame()
        {
            if (_state.Enabled)
            {
                if (_updateDebugTargets[(int)DebugTargets.Background])
                {
                    DrawFuncs.DrawRectangle(_disDef, _debugInternalTargets[(int)DebugTargets.Background],
                                            _disDef.FramePixelCountX,
                                            _state.SCX, _state.SCY,
                                            _disDef.ScreenPixelCountX, _disDef.ScreenPixelCountY,
                                            _disDef.RectangleColor);
                }

                if (_updateDebugTargets[(int)DebugTargets.Tiles])
                {
                    DrawTiles();
                }
            }
        }
コード例 #6
0
        public void DrawFrame(int rowBegin, int rowEnd)
        {
            if (!_state.Enabled)
            {
                return;
            }
            if (rowBegin > 143)
            {
                return;
            }

            #region BACKGROUND

            bool drawBackground = _state.LCDCBits[0];
            // We copy the information from the background tile to the effective screen
            for (int y = rowBegin; y < rowEnd; y++)
            {
                // We obtain the correct row
                int bY = (y + _state.SCY) % _disDef.FramePixelCountY;
                DisFuncs.GetRowPixels(ref _tempFrameLineBuffer,
                                      _pixelLookupTable,
                                      _disDef, _memory,
                                      _tempPixelBuffer,
                                      bY, _state.LCDCBits[3], _state.LCDCBits[4]);

                if (_updateDebugTargets[(int)DebugTargets.Background])
                {
                    // TODO(Cristian): Draw the whole debug target
                    DrawFuncs.DrawLine(_disDef, _debugInternalTargets[(int)DebugTargets.Background],
                                       _disDef.FramePixelCountX,
                                       _tempFrameLineBuffer,
                                       0, bY,
                                       0, _disDef.FramePixelCountX);
                }

                if (drawBackground)
                {
                    DrawFuncs.DrawLine(_disDef, _screenInternalBuffer,
                                       _disDef.ScreenPixelCountX,
                                       _tempFrameLineBuffer,
                                       0, y,
                                       _state.SCX, _disDef.FramePixelCountX,
                                       false, true);
                }
            }

            #endregion

            #region WINDOW

            int rWX = _state.WX - 7; // The window pos is (WX - 7, WY)

            // TODO(Cristian): If BG display is off, it actually prints white
            bool drawWindow = _state.LCDCBits[5];
            for (int row = rowBegin; row < rowEnd; row++)
            {
                if ((row >= _state.CurrentWY) && (row < 144))
                {
                    // The offset indexes represent that the window is drawn from it's beggining
                    // at (WX, WY)
                    DisFuncs.GetRowPixels(ref _tempFrameLineBuffer,
                                          _pixelLookupTable,
                                          _disDef, _memory, _tempPixelBuffer,
                                          row - _state.CurrentWY,
                                          _state.LCDCBits[6], _state.LCDCBits[4]);

                    // Independent target
                    if (_updateDebugTargets[(int)DebugTargets.Window])
                    {
                        DrawFuncs.DrawLine(_disDef, _debugInternalTargets[(int)DebugTargets.Window],
                                           _disDef.ScreenPixelCountX,
                                           _tempFrameLineBuffer,
                                           rWX, row,
                                           0, _disDef.ScreenPixelCountX - rWX);
                    }

                    // Screen target
                    if (drawWindow)
                    {
                        DrawFuncs.DrawLine(_disDef, _screenInternalBuffer,
                                           _disDef.ScreenPixelCountX,
                                           _tempFrameLineBuffer,
                                           rWX, row,
                                           0, _disDef.ScreenPixelCountX - rWX);
                    }
                }
            }

            #endregion

            #region SPRITES

            bool drawSprites = _state.LCDCBits[1];
            for (int row = rowBegin; row < rowEnd; row++)
            {
                if (_updateDebugTargets[(int)DebugTargets.SpriteLayer])
                {
                    // Independent target
                    uint[] pixels = new uint[_disDef.ScreenPixelCountX];
                    DisFuncs.GetSpriteRowPixels(_pixelLookupTable,
                                                _disDef, _memory, _spriteOAMs, pixels,
                                                _tempPixelBuffer,
                                                row, _state.LCDCBits[2],
                                                true);
                    DrawFuncs.DrawLine(_disDef, _debugInternalTargets[(int)DebugTargets.SpriteLayer],
                                       _disDef.ScreenPixelCountX,
                                       pixels,
                                       0, row,
                                       0, _disDef.ScreenPixelCountX);
                }

                // Screen Target
                if (drawSprites)
                {
                    DisFuncs.GetPixelRowFromBitmap(ref _tempFrameLineBuffer,
                                                   _disDef, _screenInternalBuffer,
                                                   row, _disDef.ScreenPixelCountX);
                    DisFuncs.GetSpriteRowPixels(_pixelLookupTable,
                                                _disDef, _memory, _spriteOAMs,
                                                _tempFrameLineBuffer, _tempPixelBuffer,
                                                row, _state.LCDCBits[2]);
                    DrawFuncs.DrawLine(_disDef, _screenInternalBuffer, _disDef.ScreenPixelCountX,
                                       _tempFrameLineBuffer,
                                       0, row,
                                       0, _disDef.ScreenPixelCountX);
                }
            }

            #endregion
        }