mirror of
https://github.com/SourMesen/Mesen2.git
synced 2025-04-02 10:21:44 -04:00
Merge f3590f3243
into 7267e28e21
This commit is contained in:
commit
212ec029be
4 changed files with 108 additions and 1 deletions
|
@ -853,6 +853,12 @@ namespace Mesen.Debugger.Utilities
|
|||
|
||||
[IconFile("HdPack")]
|
||||
CopyToHdPackFormat,
|
||||
|
||||
[IconFile("CheatCode")]
|
||||
CopyTileMemory,
|
||||
|
||||
[IconFile("Paste")]
|
||||
PasteTileMemory,
|
||||
|
||||
[IconFile("Find")]
|
||||
CheatDatabase,
|
||||
|
|
77
UI/Debugger/Utilities/MemCopyHelper.cs
Normal file
77
UI/Debugger/Utilities/MemCopyHelper.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
using Avalonia;
|
||||
using Mesen.Interop;
|
||||
using Mesen.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Tmds.DBus;
|
||||
|
||||
namespace Mesen.Debugger.Utilities
|
||||
{
|
||||
public static class MemCopyHelper
|
||||
{
|
||||
public static string ToString(AddressInfo tileAddr, int len)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if(tileAddr.Type == MemoryType.NesPpuMemory) {
|
||||
tileAddr = DebugApi.GetAbsoluteAddress(tileAddr);
|
||||
}
|
||||
|
||||
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 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, bytesPerTile);
|
||||
|
||||
if(tileMem.Length > 0) {
|
||||
ApplicationHelper.GetMainWindow()?.Clipboard?.SetTextAsync(tileMem);
|
||||
}
|
||||
}
|
||||
|
||||
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(" ", "");
|
||||
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 < bytesPerTile; i++) {
|
||||
DebugApi.SetMemoryValue(memoryType, (uint)(address + i), (byte)pastedData[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -169,7 +169,7 @@ namespace Mesen.Debugger.ViewModels
|
|||
}
|
||||
}
|
||||
},
|
||||
new ContextMenuSeparator() { IsVisible = () => CpuType == CpuType.Nes },
|
||||
new ContextMenuSeparator(),
|
||||
new ContextMenuAction() {
|
||||
ActionType = ActionType.CopyToHdPackFormat,
|
||||
IsVisible = () => CpuType == CpuType.Nes,
|
||||
|
@ -180,6 +180,28 @@ namespace Mesen.Debugger.ViewModels
|
|||
HdPackCopyHelper.CopyToHdPackFormat(address, Config.Source, RawPalette, SelectedPalette, false);
|
||||
}
|
||||
}
|
||||
},
|
||||
new ContextMenuAction() {
|
||||
ActionType = ActionType.CopyTileMemory,
|
||||
Shortcut = () => ConfigManager.Config.Debug.Shortcuts.Get(DebuggerShortcut.Copy),
|
||||
IsEnabled = () => GetSelectedTileAddress() >= 0,
|
||||
OnClick = () => {
|
||||
int address = GetSelectedTileAddress();
|
||||
if(address >= 0) {
|
||||
MemCopyHelper.CopyTileMem(address, Config.Source, Config.Format);
|
||||
}
|
||||
}
|
||||
},
|
||||
new ContextMenuAction() {
|
||||
ActionType = ActionType.PasteTileMemory,
|
||||
Shortcut = () => ConfigManager.Config.Debug.Shortcuts.Get(DebuggerShortcut.Paste),
|
||||
IsEnabled = () => GetSelectedTileAddress() >= 0,
|
||||
OnClick = () => {
|
||||
int address = GetSelectedTileAddress();
|
||||
if(address >= 0) {
|
||||
MemCopyHelper.PasteTileMem(address, Config.Source, Config.Format);
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
|
|
|
@ -3651,6 +3651,8 @@ E
|
|||
<Value ID="ResetAccessCounters">Reset access stats</Value>
|
||||
|
||||
<Value ID="CopyToHdPackFormat">Copy tile (HD pack format)</Value>
|
||||
<Value ID="CopyTileMemory">Copy tile (memory)</Value>
|
||||
<Value ID="PasteTileMemory">Paste tile (memory)</Value>
|
||||
<Value ID="CheatDatabase">Cheat database</Value>
|
||||
<Value ID="ToggleBilinearInterpolation">Use bilinear interpolation</Value>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue