Skip to content

Commit

Permalink
Debugger: Memory Viewer - Allow editing multiple bytes at once
Browse files Browse the repository at this point in the history
  • Loading branch information
SourMesen committed Jan 5, 2024
1 parent 3196bfd commit 0fa90d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 6 additions & 8 deletions UI/Debugger/Controls/HexEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,13 @@ protected override void OnTextInput(TextInputEventArgs e)
char c = e.Text[0];

if(_inStringView) {
SelectionLength = 0;
NewByteValue = DataProvider.ConvertCharToByte(c);
CommitByteChanges();
MoveCursor(1);
MoveCursor(SelectionLength == 0 ? 1 : SelectionLength);
} else {
if((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
int keyValue = Int32.Parse(c.ToString(), System.Globalization.NumberStyles.HexNumber);

SelectionLength = 0;

if(NewByteValue < 0) {
NewByteValue = DataProvider.GetByte(SelectionStart).Value;
}
Expand All @@ -364,7 +361,7 @@ protected override void OnTextInput(TextInputEventArgs e)
NewByteValue &= 0xF0;
NewByteValue |= keyValue;
CommitByteChanges();
MoveCursor(1);
MoveCursor(SelectionLength == 0 ? 1 : SelectionLength);
} else {
NewByteValue &= 0x0F;
NewByteValue |= (keyValue << 4);
Expand Down Expand Up @@ -432,7 +429,7 @@ public void SelectAll()
private void CommitByteChanges()
{
if(NewByteValue >= 0) {
RequestByteUpdate(_cursorPosition, (byte)NewByteValue);
RequestByteUpdate(SelectionStart, (byte)NewByteValue);
LastNibble = false;
NewByteValue = -1;
}
Expand All @@ -441,7 +438,7 @@ private void CommitByteChanges()
private void RequestByteUpdate(int position, byte value)
{
if(position < DataProvider.Length) {
ByteUpdated?.Invoke(this, new ByteUpdatedEventArgs() { ByteOffset = position, Value = value });
ByteUpdated?.Invoke(this, new ByteUpdatedEventArgs() { ByteOffset = position, Length = SelectionLength == 0 ? 1 : SelectionLength, Value = value });
}
}

Expand Down Expand Up @@ -714,7 +711,7 @@ public override void Render(DrawingContext context)
ByteInfo byteInfo = dataProvider.GetByte(position);
byteInfo.Selected = selectionLength > 0 && position >= selectionStart && position < selectionStart + selectionLength;

if(position == SelectionStart && NewByteValue >= 0) {
if(((SelectionLength == 0 && position == SelectionStart) || (SelectionLength > 0 && position >= SelectionStart && position < SelectionStart + SelectionLength)) && NewByteValue >= 0) {
//About to draw the selected byte, draw anything that's pending, and then the current byte
byteInfo.ForeColor = Colors.DarkOrange;
byteInfo.Value = (byte)NewByteValue;
Expand Down Expand Up @@ -814,6 +811,7 @@ public struct GridPoint
public class ByteUpdatedEventArgs : EventArgs
{
public int ByteOffset;
public int Length;
public byte Value;
}

Expand Down
4 changes: 3 additions & 1 deletion UI/Debugger/Windows/MemoryToolsWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ private void editor_PointerMoved(object? sender, PointerEventArgs e)

private void editor_ByteUpdated(object? sender, ByteUpdatedEventArgs e)
{
DebugApi.SetMemoryValue(_model.Config.MemoryType, (uint)e.ByteOffset, e.Value);
for(int i = 0; i < e.Length; i++) {
DebugApi.SetMemoryValue(_model.Config.MemoryType, (uint)(e.ByteOffset+i), e.Value);
}
}

private void InitializeActions()
Expand Down

0 comments on commit 0fa90d6

Please sign in to comment.