public void RefreshViewer() { if (_layerBpp[_state.Ppu.BgMode, _options.Layer] == 0) { _options.Layer = 0; } if (_isGameboyMode) { DebugApi.GetGameboyTilemap(_vram, _state.Gameboy.Ppu, (ushort)(_options.Layer == 0 ? 0x1800 : 0x1C00), _tilemapData); } else { DebugApi.GetTilemap(_options, _state.Ppu, _vram, _cgram, _tilemapData); } int mapWidth = GetWidth(); int mapHeight = GetHeight(); if (_tilemapImage.Width != mapWidth || _tilemapImage.Height != mapHeight) { _tilemapImage = new Bitmap(mapWidth, mapHeight, PixelFormat.Format32bppPArgb); ctrlImagePanel.Image = _tilemapImage; } using (Graphics g = Graphics.FromImage(_tilemapImage)) { GCHandle handle = GCHandle.Alloc(_tilemapData, GCHandleType.Pinned); Bitmap source = new Bitmap(mapWidth, mapHeight, 4 * 1024, PixelFormat.Format32bppPArgb, handle.AddrOfPinnedObject()); g.DrawImage(source, 0, 0); handle.Free(); } btnLayer1.BackColor = _options.Layer == 0 ? SystemColors.GradientActiveCaption : Color.Empty; btnLayer2.BackColor = _options.Layer == 1 ? SystemColors.GradientActiveCaption : Color.Empty; btnLayer3.BackColor = _options.Layer == 2 ? SystemColors.GradientActiveCaption : Color.Empty; btnLayer4.BackColor = _options.Layer == 3 ? SystemColors.GradientActiveCaption : Color.Empty; btnLayer1.Enabled = _layerBpp[_state.Ppu.BgMode, 0] > 0; btnLayer2.Enabled = _layerBpp[_state.Ppu.BgMode, 1] > 0; btnLayer3.Enabled = _layerBpp[_state.Ppu.BgMode, 2] > 0; btnLayer4.Enabled = _layerBpp[_state.Ppu.BgMode, 3] > 0; btnLayer1.Text = _isGameboyMode ? "BG" : "1"; btnLayer2.Text = _isGameboyMode ? "Window" : "2"; btnLayer2.Width = _isGameboyMode ? 64 : 32; btnLayer3.Visible = !_isGameboyMode; btnLayer4.Visible = !_isGameboyMode; lblMap.Visible = !_isGameboyMode; txtMapNumber.Visible = !_isGameboyMode; lblValue.Visible = !_isGameboyMode; txtValue.Visible = !_isGameboyMode; ctrlImagePanel.ImageSize = new Size(GetWidth(), GetHeight()); ctrlImagePanel.Selection = new Rectangle(_selectedColumn * 8, _selectedRow * 8, IsLargeTileWidth ? 16 : 8, IsLargeTileHeight ? 16 : 8); ctrlImagePanel.GridSizeX = chkShowTileGrid.Checked ? (IsLargeTileWidth ? 16 : 8): 0; ctrlImagePanel.GridSizeY = chkShowTileGrid.Checked ? (IsLargeTileHeight ? 16 : 8): 0; if (chkShowScrollOverlay.Checked) { if (_isGameboyMode) { if (_options.Layer == 0) { GbPpuState ppu = _state.Gameboy.Ppu; ctrlImagePanel.Overlay = new Rectangle(ppu.ScrollX, ppu.ScrollY, 160, 144); } else { //Hide for window, doesn't make sense to show this ctrlImagePanel.Overlay = Rectangle.Empty; } } else { LayerConfig layer = _state.Ppu.Layers[_options.Layer]; int hScroll = _state.Ppu.BgMode == 7 ? (int)_state.Ppu.Mode7.HScroll : layer.HScroll; int vScroll = _state.Ppu.BgMode == 7 ? (int)_state.Ppu.Mode7.VScroll : layer.VScroll; int height = _state.Ppu.OverscanMode ? 239 : 224; ctrlImagePanel.Overlay = new Rectangle(hScroll, vScroll, IsDoubleWidthScreen ? 512 : 256, IsDoubleHeightScreen ? height * 2 : height); } } else { ctrlImagePanel.Overlay = Rectangle.Empty; } ctrlImagePanel.Refresh(); if (_isGameboyMode) { UpdateGameboyFields(); } else { UpdateFields(); } }