mirror of
https://github.com/SourMesen/Mesen2.git
synced 2025-04-02 10:21:44 -04:00
Debugger: Tile Viewer - Make copy/paste tile compatible with all systems
This commit is contained in:
parent
e2c414de44
commit
f3590f3243
2 changed files with 30 additions and 35 deletions
|
@ -14,17 +14,6 @@ namespace Mesen.Debugger.Utilities
|
|||
{
|
||||
public static class MemCopyHelper
|
||||
{
|
||||
public static bool IsActionAllowed(MemoryType type)
|
||||
{
|
||||
return type switch {
|
||||
MemoryType.NesPpuMemory => true,
|
||||
MemoryType.NesChrRam => true,
|
||||
MemoryType.NesChrRom => true,
|
||||
MemoryType.NesPrgRom => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
public static string ToString(AddressInfo tileAddr, int len)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
@ -33,45 +22,51 @@ namespace Mesen.Debugger.Utilities
|
|||
tileAddr = DebugApi.GetAbsoluteAddress(tileAddr);
|
||||
}
|
||||
|
||||
switch(tileAddr.Type) {
|
||||
case MemoryType.NesPrgRom:
|
||||
case MemoryType.NesChrRom:
|
||||
case MemoryType.NesChrRam:
|
||||
for(int i = 0; i < len; i++) {
|
||||
if(sb.Length > 0) {
|
||||
sb.Append(" ");
|
||||
}
|
||||
sb.Append(DebugApi.GetMemoryValue(tileAddr.Type, (uint)(tileAddr.Address + i)).ToString("X2"));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return "";
|
||||
for(int i = 0; i < len; i++) {
|
||||
if(sb.Length > 0) {
|
||||
sb.Append(" ");
|
||||
}
|
||||
sb.Append(DebugApi.GetMemoryValue(tileAddr.Type, (uint)(tileAddr.Address + i)).ToString("X2"));
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static void CopyTileMem(int address, MemoryType memoryType)
|
||||
public static int GetBytesPerTile(TileFormat format)
|
||||
{
|
||||
int bitsPerPixel = format.GetBitsPerPixel();
|
||||
PixelSize tileSize = format.GetTileSize();
|
||||
int bytesPerTile = tileSize.Width * tileSize.Height * bitsPerPixel / 8;
|
||||
|
||||
return bytesPerTile;
|
||||
}
|
||||
|
||||
public static void CopyTileMem(int address, MemoryType memoryType, TileFormat format)
|
||||
{
|
||||
int bytesPerTile = GetBytesPerTile(format);
|
||||
|
||||
AddressInfo addr = new AddressInfo() { Address = address, Type = memoryType };
|
||||
string tileMem = MemCopyHelper.ToString(addr, 16);
|
||||
string tileMem = MemCopyHelper.ToString(addr, bytesPerTile);
|
||||
|
||||
if(tileMem.Length > 0) {
|
||||
ApplicationHelper.GetMainWindow()?.Clipboard?.SetTextAsync(tileMem);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PasteTileMem(int address, MemoryType memoryType)
|
||||
public static void PasteTileMem(int address, MemoryType memoryType, TileFormat format)
|
||||
{
|
||||
var clipboard = ApplicationHelper.GetMainWindow()?.Clipboard;
|
||||
if(clipboard != null) {
|
||||
string? text = Task.Run(() => clipboard?.GetTextAsync()).GetAwaiter().GetResult();
|
||||
if(text != null) {
|
||||
text = text.Replace("\n", "").Replace("\r", "").Replace(" ", "");
|
||||
if(Regex.IsMatch(text, "^[A-F0-9]{32}$", RegexOptions.IgnoreCase)) {
|
||||
int bytesPerTile = GetBytesPerTile(format);
|
||||
int charsPerTile = bytesPerTile * 2;
|
||||
string pattern = $"^[A-F0-9]{{{charsPerTile}}}$";
|
||||
|
||||
if(Regex.IsMatch(text, pattern, RegexOptions.IgnoreCase)) {
|
||||
byte[] pastedData = HexUtilities.HexToArray(text);
|
||||
for(int i = 0; i < 16; i++) {
|
||||
for(int i = 0; i < bytesPerTile; i++) {
|
||||
DebugApi.SetMemoryValue(memoryType, (uint)(address + i), (byte)pastedData[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ namespace Mesen.Debugger.ViewModels
|
|||
}
|
||||
}
|
||||
},
|
||||
new ContextMenuSeparator() { IsVisible = () => CpuType == CpuType.Nes },
|
||||
new ContextMenuSeparator(),
|
||||
new ContextMenuAction() {
|
||||
ActionType = ActionType.CopyToHdPackFormat,
|
||||
IsVisible = () => CpuType == CpuType.Nes,
|
||||
|
@ -200,23 +200,23 @@ namespace Mesen.Debugger.ViewModels
|
|||
},
|
||||
new ContextMenuAction() {
|
||||
ActionType = ActionType.CopyTileMemory,
|
||||
IsVisible = () => CpuType == CpuType.Nes,
|
||||
Shortcut = () => ConfigManager.Config.Debug.Shortcuts.Get(DebuggerShortcut.Copy),
|
||||
IsEnabled = () => GetSelectedTileAddress() >= 0,
|
||||
OnClick = () => {
|
||||
int address = GetSelectedTileAddress();
|
||||
if(address >= 0) {
|
||||
MemCopyHelper.CopyTileMem(address, Config.Source);
|
||||
MemCopyHelper.CopyTileMem(address, Config.Source, Config.Format);
|
||||
}
|
||||
}
|
||||
},
|
||||
new ContextMenuAction() {
|
||||
ActionType = ActionType.PasteTileMemory,
|
||||
IsVisible = () => CpuType == CpuType.Nes,
|
||||
Shortcut = () => ConfigManager.Config.Debug.Shortcuts.Get(DebuggerShortcut.Paste),
|
||||
IsEnabled = () => GetSelectedTileAddress() >= 0,
|
||||
OnClick = () => {
|
||||
int address = GetSelectedTileAddress();
|
||||
if(address >= 0) {
|
||||
MemCopyHelper.PasteTileMem(address, Config.Source);
|
||||
MemCopyHelper.PasteTileMem(address, Config.Source, Config.Format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue