diff --git a/Core/DebugTypes.h b/Core/DebugTypes.h index 1908052..4c80767 100644 --- a/Core/DebugTypes.h +++ b/Core/DebugTypes.h @@ -187,9 +187,6 @@ struct GetTileViewOptions TileFormat Format; int32_t Width; int32_t Palette; - SnesMemoryType MemoryType; - int32_t AddressOffset; - bool ShowTileGrid; }; diff --git a/Core/PpuTools.cpp b/Core/PpuTools.cpp index e31a64c..a167263 100644 --- a/Core/PpuTools.cpp +++ b/Core/PpuTools.cpp @@ -74,10 +74,10 @@ uint32_t PpuTools::GetRgbPixelColor(uint8_t* cgram, uint8_t colorIndex, uint8_t return ToArgb(paletteColor); } -void PpuTools::GetTileView(GetTileViewOptions options, uint32_t *outBuffer) +void PpuTools::GetTileView(GetTileViewOptions options, uint8_t *source, uint32_t srcSize, uint8_t *cgram, uint32_t *outBuffer) { - uint8_t* ram; - uint32_t ramMask; + uint8_t* ram = source; + uint32_t ramMask = srcSize - 1; uint8_t bpp; bool directColor = false; @@ -102,25 +102,6 @@ void PpuTools::GetTileView(GetTileViewOptions options, uint32_t *outBuffer) default: bpp = 8; break; } - switch(options.MemoryType) { - default: - case SnesMemoryType::VideoRam: - ramMask = Ppu::VideoRamSize - 1; - ram = _ppu->GetVideoRam(); - break; - - case SnesMemoryType::PrgRom: - ramMask = _console->GetCartridge()->DebugGetPrgRomSize() - 1; - ram = _console->GetCartridge()->DebugGetPrgRom(); - break; - - case SnesMemoryType::WorkRam: - ramMask = MemoryManager::WorkRamSize - 1; - ram = _console->GetMemoryManager()->DebugGetWorkRam(); - break; - } - - uint8_t* cgram = _ppu->GetCgRam(); int bytesPerTile = 64 * bpp / 8; int tileCount = 0x10000 / bytesPerTile; @@ -133,7 +114,7 @@ void PpuTools::GetTileView(GetTileViewOptions options, uint32_t *outBuffer) if(options.Format == TileFormat::Mode7 || options.Format == TileFormat::Mode7DirectColor) { for(int row = 0; row < rowCount; row++) { - uint32_t baseOffset = row * bytesPerTile * options.Width + options.AddressOffset; + uint32_t baseOffset = row * bytesPerTile * options.Width; for(int column = 0; column < options.Width; column++) { uint32_t addr = baseOffset + bytesPerTile * column; @@ -159,7 +140,7 @@ void PpuTools::GetTileView(GetTileViewOptions options, uint32_t *outBuffer) } } else { for(int row = 0; row < rowCount; row++) { - uint32_t baseOffset = row * bytesPerTile * options.Width + options.AddressOffset; + uint32_t baseOffset = row * bytesPerTile * options.Width; for(int column = 0; column < options.Width; column++) { uint32_t addr = baseOffset + bytesPerTile * column; diff --git a/Core/PpuTools.h b/Core/PpuTools.h index e124ca4..37ede53 100644 --- a/Core/PpuTools.h +++ b/Core/PpuTools.h @@ -22,7 +22,7 @@ private: public: PpuTools(Console *console, Ppu *ppu); - void GetTileView(GetTileViewOptions options, uint32_t *outBuffer); + void GetTileView(GetTileViewOptions options, uint8_t *source, uint32_t srcSize, uint8_t *cgram, uint32_t *outBuffer); void GetTilemap(GetTilemapOptions options, uint8_t* vram, uint8_t* cgram, uint32_t *outBuffer); void SetViewerUpdateTiming(uint32_t viewerId, uint16_t scanline, uint16_t cycle); diff --git a/InteropDLL/DebugApiWrapper.cpp b/InteropDLL/DebugApiWrapper.cpp index e0a44ed..b8d9c18 100644 --- a/InteropDLL/DebugApiWrapper.cpp +++ b/InteropDLL/DebugApiWrapper.cpp @@ -70,7 +70,7 @@ extern "C" DllExport void __stdcall GetCdlData(uint32_t offset, uint32_t length, SnesMemoryType memoryType, uint8_t* cdlData) { GetDebugger()->GetCodeDataLogger()->GetCdlData(offset, length, memoryType, cdlData); } DllExport void __stdcall GetTilemap(GetTilemapOptions options, uint8_t *vram, uint8_t *cgram, uint32_t *buffer) { GetDebugger()->GetPpuTools()->GetTilemap(options, vram, cgram, buffer); } - DllExport void __stdcall GetTileView(GetTileViewOptions options, uint32_t *buffer) { GetDebugger()->GetPpuTools()->GetTileView(options, buffer); } + DllExport void __stdcall GetTileView(GetTileViewOptions options, uint8_t *source, uint32_t srcSize, uint8_t *cgram, uint32_t *buffer) { GetDebugger()->GetPpuTools()->GetTileView(options, source, srcSize, cgram, buffer); } DllExport void __stdcall SetViewerUpdateTiming(uint32_t viewerId, uint16_t scanline, uint16_t cycle) { GetDebugger()->GetPpuTools()->SetViewerUpdateTiming(viewerId, scanline, cycle); } DllExport void __stdcall GetDebugEvents(DebugEventInfo *infoArray, uint32_t &maxEventCount, bool getPreviousFrameData) { GetDebugger()->GetEventManager()->GetEvents(infoArray, maxEventCount, getPreviousFrameData); } diff --git a/UI/Debugger/PpuViewer/frmTileViewer.cs b/UI/Debugger/PpuViewer/frmTileViewer.cs index c7b5e96..7a6de96 100644 --- a/UI/Debugger/PpuViewer/frmTileViewer.cs +++ b/UI/Debugger/PpuViewer/frmTileViewer.cs @@ -18,8 +18,12 @@ namespace Mesen.GUI.Debugger private NotificationListener _notifListener; private GetTileViewOptions _options; private byte[] _tileData; + private byte[] _cgram; + private byte[] _tileSource; private Bitmap _tileImage; private bool _zoomed; + private SnesMemoryType _memoryType = SnesMemoryType.VideoRam; + private int _addressOffset = 0; public frmTileViewer() { @@ -92,14 +96,20 @@ namespace Mesen.GUI.Debugger private void RefreshData() { _options.Palette = ctrlPaletteViewer.SelectedPalette; - lock(_tileData) { - DebugApi.GetTileView(_options, _tileData); - } + _cgram = DebugApi.GetMemoryState(SnesMemoryType.CGRam); + + byte[] source = DebugApi.GetMemoryState(_memoryType); + int size = Math.Min(source.Length - _addressOffset, 0x10000); + _tileSource = new byte[0x10000]; + Array.Copy(source, _addressOffset, _tileSource, 0, size); + ctrlPaletteViewer.RefreshData(); } private void RefreshViewer() { + DebugApi.GetTileView(_options, _tileSource, _tileSource.Length, _cgram, _tileData); + int tileCount = 0x10000 / GetBytesPerTile(); int mapWidth = _options.Width * 8; @@ -111,14 +121,12 @@ namespace Mesen.GUI.Debugger } using(Graphics g = Graphics.FromImage(_tileImage)) { - lock(_tileData) { - GCHandle handle = GCHandle.Alloc(_tileData, GCHandleType.Pinned); - Bitmap source = new Bitmap(mapWidth, mapHeight, 4 * mapWidth, PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject()); - try { - g.DrawImage(source, 0, 0); - } finally { - handle.Free(); - } + GCHandle handle = GCHandle.Alloc(_tileData, GCHandleType.Pinned); + Bitmap source = new Bitmap(mapWidth, mapHeight, 4 * mapWidth, PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject()); + try { + g.DrawImage(source, 0, 0); + } finally { + handle.Free(); } } @@ -165,9 +173,9 @@ namespace Mesen.GUI.Debugger private void cboMemoryType_SelectedIndexChanged(object sender, EventArgs e) { - _options.MemoryType = cboMemoryType.GetEnumValue(); + _memoryType = cboMemoryType.GetEnumValue(); - bool isVram = _options.MemoryType == SnesMemoryType.VideoRam; + bool isVram = _memoryType == SnesMemoryType.VideoRam; nudOffset.Visible = !isVram; nudBank.Visible = !isVram; lblOffset.Visible = !isVram; @@ -176,6 +184,8 @@ namespace Mesen.GUI.Debugger nudBank.Value = 0; nudOffset.Value = 0; } + + nudBank.Maximum = Math.Max(1, (DebugApi.GetMemorySize(_memoryType) / 0x10000) - 1); } private void cboBpp_SelectedIndexChanged(object sender, EventArgs e) @@ -199,12 +209,12 @@ namespace Mesen.GUI.Debugger private void nudBank_ValueChanged(object sender, EventArgs e) { - _options.AddressOffset = (int)(nudBank.Value * 0x10000 + nudOffset.Value); + _addressOffset = (int)(nudBank.Value * 0x10000 + nudOffset.Value); } private void nudOffset_ValueChanged(object sender, EventArgs e) { - _options.AddressOffset = (int)(nudBank.Value * 0x10000 + nudOffset.Value); + _addressOffset = (int)(nudBank.Value * 0x10000 + nudOffset.Value); } } } diff --git a/UI/Interop/DebugApi.cs b/UI/Interop/DebugApi.cs index 4a90176..2483843 100644 --- a/UI/Interop/DebugApi.cs +++ b/UI/Interop/DebugApi.cs @@ -72,7 +72,7 @@ namespace Mesen.GUI } [DllImport(DllPath)] public static extern void GetTilemap(GetTilemapOptions options, byte[] vram, byte[] cgram, [In, Out] byte[] buffer); - [DllImport(DllPath)] public static extern void GetTileView(GetTileViewOptions options, [In, Out] byte[] buffer); + [DllImport(DllPath)] public static extern void GetTileView(GetTileViewOptions options, byte[] source, int srcSize, byte[] cgram, [In, Out] byte[] buffer); [DllImport(DllPath)] public static extern void SetViewerUpdateTiming(Int32 viewerId, Int32 scanline, Int32 cycle); @@ -345,8 +345,6 @@ namespace Mesen.GUI public TileFormat Format; public Int32 Width; public Int32 Palette; - public SnesMemoryType MemoryType; - public Int32 AddressOffset; [MarshalAs(UnmanagedType.I1)] public bool ShowTileGrid; }