Debugger: Improved tile viewer performance

This commit is contained in:
Sour 2019-03-30 12:20:52 -04:00
parent 2100ddb712
commit d7b2d3af6a
6 changed files with 33 additions and 47 deletions

View file

@ -187,9 +187,6 @@ struct GetTileViewOptions
TileFormat Format;
int32_t Width;
int32_t Palette;
SnesMemoryType MemoryType;
int32_t AddressOffset;
bool ShowTileGrid;
};

View file

@ -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;

View file

@ -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);

View file

@ -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); }

View file

@ -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,7 +121,6 @@ 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 {
@ -120,7 +129,6 @@ namespace Mesen.GUI.Debugger
handle.Free();
}
}
}
UpdateMapSize();
picTilemap.Invalidate();
@ -165,9 +173,9 @@ namespace Mesen.GUI.Debugger
private void cboMemoryType_SelectedIndexChanged(object sender, EventArgs e)
{
_options.MemoryType = cboMemoryType.GetEnumValue<SnesMemoryType>();
_memoryType = cboMemoryType.GetEnumValue<SnesMemoryType>();
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);
}
}
}

View file

@ -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;
}