Hex Editor - lots of cleanups

This commit is contained in:
adelikat 2019-11-03 10:46:45 -06:00
parent 39586a5bf0
commit 9fb8499ffe
2 changed files with 163 additions and 212 deletions

View File

@ -111,7 +111,6 @@
this.HexMenuStrip.Size = new System.Drawing.Size(584, 24); this.HexMenuStrip.Size = new System.Drawing.Size(584, 24);
this.HexMenuStrip.TabIndex = 1; this.HexMenuStrip.TabIndex = 1;
this.HexMenuStrip.Text = "menuStrip1"; this.HexMenuStrip.Text = "menuStrip1";
this.HexMenuStrip.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.HexMenuStrip_ItemClicked);
// //
// FileSubMenu // FileSubMenu
// //

View File

@ -50,10 +50,9 @@ namespace BizHawk.Client.EmuHawk
[RequiredService] [RequiredService]
private IEmulator Emulator { get; set; } private IEmulator Emulator { get; set; }
private int fontWidth; private readonly int _fontWidth;
private int fontHeight; private readonly int _fontHeight;
private readonly List<ToolStripMenuItem> _domainMenuItems = new List<ToolStripMenuItem>();
private readonly char[] _nibbles = { 'G', 'G', 'G', 'G', 'G', 'G', 'G', 'G' }; // G = off 0-9 & A-F are acceptable values private readonly char[] _nibbles = { 'G', 'G', 'G', 'G', 'G', 'G', 'G', 'G' }; // G = off 0-9 & A-F are acceptable values
private readonly List<long> _secondaryHighlightedAddresses = new List<long>(); private readonly List<long> _secondaryHighlightedAddresses = new List<long>();
@ -104,8 +103,8 @@ namespace BizHawk.Client.EmuHawk
// character so we'll see how much the width increases on the second character. // character so we'll see how much the width increases on the second character.
var fontSize1 = TextRenderer.MeasureText("0", font); var fontSize1 = TextRenderer.MeasureText("0", font);
var fontSize2 = TextRenderer.MeasureText("00", font); var fontSize2 = TextRenderer.MeasureText("00", font);
fontWidth = fontSize2.Width - fontSize1.Width; _fontWidth = fontSize2.Width - fontSize1.Width;
fontHeight = fontSize1.Height; _fontHeight = fontSize1.Height;
InitializeComponent(); InitializeComponent();
AddressesLabel.BackColor = Color.Transparent; AddressesLabel.BackColor = Color.Transparent;
@ -131,20 +130,11 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private WatchSize WatchSize private WatchSize WatchSize => (WatchSize)DataSize;
{
get
{
return (WatchSize)DataSize;
}
}
#region API #region API
public bool UpdateBefore public bool UpdateBefore => false;
{
get { return false; }
}
public bool AskSaveChanges() public bool AskSaveChanges()
{ {
@ -411,17 +401,15 @@ namespace BizHawk.Client.EmuHawk
return false; return false;
} }
using (var file = new HawkFile()) using var file = new HawkFile();
file.Open(path);
if (!file.Exists)
{ {
file.Open(path); return false;
if (!file.Exists)
{
return false;
}
return file.IsArchive;
} }
return file.IsArchive;
} }
private static byte[] GetRomBytes() private static byte[] GetRomBytes()
@ -432,23 +420,21 @@ namespace BizHawk.Client.EmuHawk
return new byte[] { 0xFF }; return new byte[] { 0xFF };
} }
using (var file = new HawkFile()) using var file = new HawkFile();
file.Open(path);
if (!file.Exists)
{ {
file.Open(path); return null;
if (!file.Exists)
{
return null;
}
if (file.IsArchive)
{
var stream = file.GetStream();
return stream.ReadAllBytes();
}
return File.ReadAllBytes(path);
} }
if (file.IsArchive)
{
var stream = file.GetStream();
return stream.ReadAllBytes();
}
return File.ReadAllBytes(path);
} }
private static int GetNumDigits(long i) private static int GetNumDigits(long i)
@ -568,24 +554,21 @@ namespace BizHawk.Client.EmuHawk
{ {
if (_addr + j + DataSize <= _domain.Size) if (_addr + j + DataSize <= _domain.Size)
{ {
int t_val = 0; int tVal = 0;
int t_next = 0;
bool is_cht;
for (int k = 0; k < DataSize; k++) for (int k = 0; k < DataSize; k++)
{ {
t_next = MakeValue(1, _addr + j + k, out is_cht); int tNext = MakeValue(1, _addr + j + k);
if (SwapBytes) if (SwapBytes)
{ {
t_val += (t_next << (k * 8)); tVal += (tNext << (k * 8));
} }
else else
{ {
t_val += (t_next << ((DataSize - k - 1) * 8)); tVal += (tNext << ((DataSize - k - 1) * 8));
} }
} }
rowStr.AppendFormat(_digitFormatString, t_val); rowStr.AppendFormat(_digitFormatString, tVal);
} }
else else
{ {
@ -624,15 +607,8 @@ namespace BizHawk.Client.EmuHawk
: _domain.PeekByte(address); : _domain.PeekByte(address);
} }
private int MakeValue(int dataSize, long address, out bool is_cheat) private int MakeValue(int dataSize, long address)
{ {
if (Global.CheatList.IsActive(_domain, address))
{
is_cheat = true;
return Global.CheatList.GetCheatValue(_domain, address, (WatchSize)dataSize ).Value;
}
is_cheat = false;
switch (dataSize) switch (dataSize)
{ {
default: default:
@ -647,20 +623,14 @@ namespace BizHawk.Client.EmuHawk
private int MakeValue(long address) private int MakeValue(long address)
{ {
bool temp; return MakeValue(DataSize, address);
return MakeValue(DataSize, address, out temp);
} }
private void SetMemoryDomain(string name) private void SetMemoryDomain(string name)
{ {
if (name == _romDomain.Name) _domain = name == _romDomain.Name
{ ? _romDomain
_domain = _romDomain; : MemoryDomains[name];
}
else
{
_domain = MemoryDomains[name];
}
SwapBytes = false; SwapBytes = false;
BigEndian = _domain.EndianType == MemoryDomain.Endian.Big; BigEndian = _domain.EndianType == MemoryDomain.Endian.Big;
@ -671,14 +641,9 @@ namespace BizHawk.Client.EmuHawk
HexScrollBar.Value = 0; HexScrollBar.Value = 0;
} }
if (_domain.CanPoke()) AddressesLabel.ForeColor = _domain.CanPoke()
{ ? SystemColors.ControlText
AddressesLabel.ForeColor = SystemColors.ControlText; : SystemColors.ControlDarkDark;
}
else
{
AddressesLabel.ForeColor = SystemColors.ControlDarkDark;
}
if (HighlightedAddress >= _domain.Size if (HighlightedAddress >= _domain.Size
|| (_secondaryHighlightedAddresses.Any() && _secondaryHighlightedAddresses.Max() >= _domain.Size)) || (_secondaryHighlightedAddresses.Any() && _secondaryHighlightedAddresses.Max() >= _domain.Size))
@ -768,7 +733,7 @@ namespace BizHawk.Client.EmuHawk
Text += " - Editing Address 0x" + string.Format(_numDigitsStr, _addressHighlighted); Text += " - Editing Address 0x" + string.Format(_numDigitsStr, _addressHighlighted);
if (_secondaryHighlightedAddresses.Any()) if (_secondaryHighlightedAddresses.Any())
{ {
Text += $" (Selected 0x{_secondaryHighlightedAddresses.Count() + (_secondaryHighlightedAddresses.Contains(_addressHighlighted) ? 0 : 1):X})"; Text += $" (Selected 0x{_secondaryHighlightedAddresses.Count + (_secondaryHighlightedAddresses.Contains(_addressHighlighted) ? 0 : 1):X})";
} }
} }
} }
@ -817,11 +782,11 @@ namespace BizHawk.Client.EmuHawk
{ {
default: default:
case 1: case 1:
return Watch.GenerateWatch(_domain, address, WatchSize.Byte, Client.Common.DisplayType.Hex, BigEndian, ""); return Watch.GenerateWatch(_domain, address, WatchSize.Byte, Common.DisplayType.Hex, BigEndian);
case 2: case 2:
return Watch.GenerateWatch(_domain, address, WatchSize.Word, Client.Common.DisplayType.Hex, BigEndian, ""); return Watch.GenerateWatch(_domain, address, WatchSize.Word, Common.DisplayType.Hex, BigEndian);
case 4: case 4:
return Watch.GenerateWatch(_domain, address, WatchSize.DWord, Client.Common.DisplayType.Hex, BigEndian, ""); return Watch.GenerateWatch(_domain, address, WatchSize.DWord, Common.DisplayType.Hex, BigEndian);
} }
} }
@ -850,7 +815,7 @@ namespace BizHawk.Client.EmuHawk
_domain, _domain,
address, address,
WatchSize, WatchSize,
Client.Common.DisplayType.Hex, Common.DisplayType.Hex,
BigEndian); BigEndian);
Global.CheatList.Add(new Cheat( Global.CheatList.Add(new Cheat(
@ -868,7 +833,7 @@ namespace BizHawk.Client.EmuHawk
_domain, _domain,
address, address,
WatchSize, WatchSize,
Client.Common.DisplayType.Hex, Common.DisplayType.Hex,
BigEndian); BigEndian);
cheats.Add(new Cheat( cheats.Add(new Cheat(
@ -889,12 +854,10 @@ namespace BizHawk.Client.EmuHawk
private void SaveFileBinary(string path) private void SaveFileBinary(string path)
{ {
var file = new FileInfo(path); var file = new FileInfo(path);
using (var binWriter = new BinaryWriter(File.Open(file.FullName, FileMode.Create))) using var binWriter = new BinaryWriter(File.Open(file.FullName, FileMode.Create));
for (var i = 0; i < _domain.Size; i++)
{ {
for (var i = 0; i < _domain.Size; i++) binWriter.Write(_domain.PeekByte(i));
{
binWriter.Write(_domain.PeekByte(i));
}
} }
} }
@ -903,7 +866,6 @@ namespace BizHawk.Client.EmuHawk
if (_domain.Name == "File on Disk") if (_domain.Name == "File on Disk")
{ {
var extension = Path.GetExtension(RomName); var extension = Path.GetExtension(RomName);
return $"Binary (*{extension})|*{extension}|All Files|*.*"; return $"Binary (*{extension})|*{extension}|All Files|*.*";
} }
@ -955,22 +917,16 @@ namespace BizHawk.Client.EmuHawk
{ {
using var sfd = new SaveFileDialog using var sfd = new SaveFileDialog
{ {
Filter = GetSaveFileFilter(), Filter = GetSaveFileFilter()
RestoreDirectory = true, , RestoreDirectory = true
InitialDirectory = RomDirectory , InitialDirectory = RomDirectory
, FileName =
_domain.Name == "File on Disk"
? RomName
: PathManager.FilesystemSafeName(Global.Game)
}; };
if (_domain.Name == "File on Disk")
{
sfd.FileName = RomName;
}
else
{
sfd.FileName = PathManager.FilesystemSafeName(Global.Game);
}
var result = sfd.ShowHawkDialog(); var result = sfd.ShowHawkDialog();
return result == DialogResult.OK ? sfd.FileName : ""; return result == DialogResult.OK ? sfd.FileName : "";
} }
@ -978,22 +934,15 @@ namespace BizHawk.Client.EmuHawk
{ {
using var sfd = new SaveFileDialog using var sfd = new SaveFileDialog
{ {
Filter = "Text (*.txt)|*.txt|All Files|*.*", Filter = "Text (*.txt)|*.txt|All Files|*.*"
RestoreDirectory = true, , RestoreDirectory = true
InitialDirectory = RomDirectory , InitialDirectory = RomDirectory
, FileName = _domain.Name == "File on Disk"
? $"{Path.GetFileNameWithoutExtension(RomName)}.txt"
: PathManager.FilesystemSafeName(Global.Game)
}; };
if (_domain.Name == "File on Disk")
{
sfd.FileName = $"{Path.GetFileNameWithoutExtension(RomName)}.txt";
}
else
{
sfd.FileName = PathManager.FilesystemSafeName(Global.Game);
}
var result = sfd.ShowHawkDialog(); var result = sfd.ShowHawkDialog();
return result == DialogResult.OK ? sfd.FileName : ""; return result == DialogResult.OK ? sfd.FileName : "";
} }
@ -1006,7 +955,7 @@ namespace BizHawk.Client.EmuHawk
private void SetUpScrollBar() private void SetUpScrollBar()
{ {
_rowsVisible = (MemoryViewerBox.Height - (fontHeight * 2) - (fontHeight / 2)) / fontHeight; _rowsVisible = (MemoryViewerBox.Height - (_fontHeight * 2) - (_fontHeight / 2)) / _fontHeight;
var totalRows = (int)((_domain.Size + 15) / 16); var totalRows = (int)((_domain.Size + 15) / 16);
if (totalRows < _rowsVisible) if (totalRows < _rowsVisible)
@ -1027,17 +976,17 @@ namespace BizHawk.Client.EmuHawk
// Scroll value determines the first row // Scroll value determines the first row
long i = HexScrollBar.Value; long i = HexScrollBar.Value;
var rowoffset = y / fontHeight; var rowOffset = y / _fontHeight;
i += rowoffset; i += rowOffset;
int colWidth = DataSize * 2 + 1; int colWidth = DataSize * 2 + 1;
var column = x / (fontWidth * colWidth); var column = x / (_fontWidth * colWidth);
var innerOffset = AddressesLabel.Location.X - AddressLabel.Location.X + AddressesLabel.Margin.Left; var innerOffset = AddressesLabel.Location.X - AddressLabel.Location.X + AddressesLabel.Margin.Left;
var start = GetTextOffset() - innerOffset; var start = GetTextOffset() - innerOffset;
if (x > start) if (x > start)
{ {
column = (x - start) / (fontWidth * DataSize); column = (x - start) / (_fontWidth * DataSize);
} }
if (i >= 0 && i <= _maxRow && column >= 0 && column < (16 / DataSize)) if (i >= 0 && i <= _maxRow && column >= 0 && column < (16 / DataSize))
@ -1094,13 +1043,13 @@ namespace BizHawk.Client.EmuHawk
private Point GetAddressCoordinates(long address) private Point GetAddressCoordinates(long address)
{ {
var extra = (address % DataSize) * fontWidth * 2; var extra = (address % DataSize) * _fontWidth * 2;
var xOffset = AddressesLabel.Location.X + fontWidth / 2 - 2; var xOffset = AddressesLabel.Location.X + _fontWidth / 2 - 2;
var yOffset = AddressesLabel.Location.Y; var yOffset = AddressesLabel.Location.Y;
return new Point( return new Point(
(int)((((address % 16) / DataSize) * (fontWidth * (DataSize * 2 + 1))) + xOffset + extra), (int)((((address % 16) / DataSize) * (_fontWidth * (DataSize * 2 + 1))) + xOffset + extra),
(int)((((address / 16) - HexScrollBar.Value) * fontHeight) + yOffset) (int)((((address / 16) - HexScrollBar.Value) * _fontHeight) + yOffset)
); );
} }
@ -1112,15 +1061,15 @@ namespace BizHawk.Client.EmuHawk
private int GetTextOffset() private int GetTextOffset()
{ {
int start = (16 / DataSize) * fontWidth * (DataSize * 2 + 1); int start = (16 / DataSize) * _fontWidth * (DataSize * 2 + 1);
start += AddressesLabel.Location.X + fontWidth / 2; start += AddressesLabel.Location.X + _fontWidth / 2;
start += fontWidth * 2; start += _fontWidth * 2;
return start; return start;
} }
private long GetTextX(long address) private long GetTextX(long address)
{ {
return GetTextOffset() + ((address % 16) * fontWidth); return GetTextOffset() + ((address % 16) * _fontWidth);
} }
private bool HasNibbles() private bool HasNibbles()
@ -1355,17 +1304,18 @@ namespace BizHawk.Client.EmuHawk
}; };
var result = sfd.ShowHawkDialog(); var result = sfd.ShowHawkDialog();
if(result != System.Windows.Forms.DialogResult.OK) return; if (result != DialogResult.OK)
{
return;
}
var path = sfd.FileName; var path = sfd.FileName;
using (var inf = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)) using var inf = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
long todo = Math.Min(inf.Length, _domain.Size);
for (long i = 0; i < todo; i++)
{ {
long todo = Math.Min(inf.Length, _domain.Size); _domain.PokeByte(i, (byte)inf.ReadByte());
for (long i = 0; i < todo; i++)
{
_domain.PokeByte(i, (byte)inf.ReadByte());
}
} }
} }
@ -1375,42 +1325,34 @@ namespace BizHawk.Client.EmuHawk
if (!string.IsNullOrWhiteSpace(path)) if (!string.IsNullOrWhiteSpace(path))
{ {
var file = new FileInfo(path); var file = new FileInfo(path);
using (var sw = new StreamWriter(file.FullName)) using var sw = new StreamWriter(file.FullName);
var sb = new StringBuilder();
for (var i = 0; i < _domain.Size / 16; i++)
{ {
var sb = new StringBuilder(); for (var j = 0; j < 16; j++)
for (var i = 0; i < _domain.Size / 16; i++)
{ {
for (var j = 0; j < 16; j++) sb.Append($"{_domain.PeekByte((i * 16) + j):X2} ");
{
sb.Append($"{_domain.PeekByte((i * 16) + j):X2} ");
}
sb.AppendLine();
} }
sw.WriteLine(sb); sb.AppendLine();
} }
sw.WriteLine(sb);
} }
} }
private void LoadTableFileMenuItem_Click(object sender, EventArgs e) private void LoadTableFileMenuItem_Click(object sender, EventArgs e)
{ {
string romName; string initialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.ToolsPathFragment, null);
string intialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.ToolsPathFragment, null); var romName = Global.Config.RecentRoms.MostRecent.Contains('|')
if (Global.Config.RecentRoms.MostRecent.Contains('|')) ? Global.Config.RecentRoms.MostRecent.Split('|').Last()
{ : Global.Config.RecentRoms.MostRecent;
romName = Global.Config.RecentRoms.MostRecent.Split('|').Last();
}
else
{
romName = Global.Config.RecentRoms.MostRecent;
}
using var ofd = new OpenFileDialog using var ofd = new OpenFileDialog
{ {
FileName = $"{Path.GetFileNameWithoutExtension(romName)}.tbl", FileName = $"{Path.GetFileNameWithoutExtension(romName)}.tbl",
InitialDirectory = intialDirectory, InitialDirectory = initialDirectory,
Filter = "Text Table files (*.tbl)|*.tbl|All Files|*.*", Filter = "Text Table files (*.tbl)|*.tbl|All Files|*.*",
RestoreDirectory = false RestoreDirectory = false
}; };
@ -1475,28 +1417,35 @@ namespace BizHawk.Client.EmuHawk
string MakeCopyExportString(bool export) string MakeCopyExportString(bool export)
{ {
//make room for an array with _secondaryHighlightedAddresses and optionally HighlightedAddress // make room for an array with _secondaryHighlightedAddresses and optionally HighlightedAddress
long[] addresses = new long[_secondaryHighlightedAddresses.Count + (HighlightedAddress.HasValue ? 1 : 0)]; long[] addresses = new long[_secondaryHighlightedAddresses.Count + (HighlightedAddress.HasValue ? 1 : 0)];
//if there was actually nothing to do, return // if there was actually nothing to do, return
if (addresses.Length == 0) if (addresses.Length == 0)
{
return null; return null;
}
//fill the array with _secondaryHighlightedAddresses // fill the array with _secondaryHighlightedAddresses
for (int i = 0; i < _secondaryHighlightedAddresses.Count; i++) for (int i = 0; i < _secondaryHighlightedAddresses.Count; i++)
{
addresses[i] = _secondaryHighlightedAddresses[i]; addresses[i] = _secondaryHighlightedAddresses[i];
//and add HighlightedAddress if present }
if (HighlightedAddress.HasValue)
addresses[addresses.Length - 1] = HighlightedAddress.Value;
//these need to be sorted. it's not just for HighlightedAddress, _secondaryHighlightedAddresses can even be jumbled // and add HighlightedAddress if present
if (HighlightedAddress.HasValue)
{
addresses[addresses.Length - 1] = HighlightedAddress.Value;
}
// these need to be sorted. it's not just for HighlightedAddress, _secondaryHighlightedAddresses can even be jumbled
Array.Sort(addresses); Array.Sort(addresses);
//find the maximum length of the exported string // find the maximum length of the exported string
int maximumLength = addresses.Length * (export ? 3 : 2) + 8; int maximumLength = addresses.Length * (export ? 3 : 2) + 8;
StringBuilder sb = new StringBuilder(maximumLength); var sb = new StringBuilder(maximumLength);
//generate it differently for export (as you see it) or copy (raw bytes) // generate it differently for export (as you see it) or copy (raw bytes)
if (export) if (export)
for (int i = 0; i < addresses.Length; i++) for (int i = 0; i < addresses.Length; i++)
{ {
@ -1506,13 +1455,15 @@ namespace BizHawk.Client.EmuHawk
} }
else else
{ {
for (int i = 0; i < addresses.Length; i++) foreach (var addr in addresses)
{ {
long start = addresses[i]; long start = addr;
long end = addresses[i] + DataSize -1 ; long end = addr + DataSize -1 ;
bool temp;
for(long a = start;a<=end;a++) for (long a = start; a <= end; a++)
sb.AppendFormat("{0:X2}", MakeValue(1,a, out temp)); {
sb.AppendFormat("{0:X2}", MakeValue(1, a));
}
} }
} }
@ -1523,22 +1474,28 @@ namespace BizHawk.Client.EmuHawk
{ {
var value = MakeCopyExportString(true); var value = MakeCopyExportString(true);
if (!string.IsNullOrEmpty(value)) if (!string.IsNullOrEmpty(value))
{
Clipboard.SetDataObject(value); Clipboard.SetDataObject(value);
}
} }
private void CopyMenuItem_Click(object sender, EventArgs e) private void CopyMenuItem_Click(object sender, EventArgs e)
{ {
var value = MakeCopyExportString(false); var value = MakeCopyExportString(false);
if (!string.IsNullOrEmpty(value)) if (!string.IsNullOrEmpty(value))
{
Clipboard.SetDataObject(value); Clipboard.SetDataObject(value);
}
} }
private void PasteMenuItem_Click(object sender, EventArgs e) private void PasteMenuItem_Click(object sender, EventArgs e)
{ {
var data = Clipboard.GetDataObject(); var data = Clipboard.GetDataObject();
if (data != null && !data.GetDataPresent(DataFormats.Text)) if (data == null || !data.GetDataPresent(DataFormats.Text))
{
return; return;
}
var clipboardRaw = (string)data.GetData(DataFormats.Text); var clipboardRaw = (string)data.GetData(DataFormats.Text);
var hex = clipboardRaw.OnlyHex(); var hex = clipboardRaw.OnlyHex();
@ -1558,7 +1515,7 @@ namespace BizHawk.Client.EmuHawk
UpdateValues(); UpdateValues();
} }
private bool _lastSearchWasText = false; private bool _lastSearchWasText;
private void SearchTypeChanged(bool isText) private void SearchTypeChanged(bool isText)
{ {
_lastSearchWasText = isText; _lastSearchWasText = isText;
@ -1770,7 +1727,7 @@ namespace BizHawk.Client.EmuHawk
_domain, _domain,
address, address,
(WatchSize)DataSize, (WatchSize)DataSize,
Client.Common.DisplayType.Hex, Common.DisplayType.Hex,
BigEndian)); BigEndian));
poke.SetWatch(watches); poke.SetWatch(watches);
@ -2251,11 +2208,11 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private Pen _blackPen = new Pen(Color.Black); private readonly Pen _blackPen = new Pen(Color.Black);
private SolidBrush _freezeBrush = new SolidBrush(Global.Config.HexFreezeColor); private readonly SolidBrush _freezeBrush = new SolidBrush(Global.Config.HexFreezeColor);
private SolidBrush _freezeHighlightBrush = new SolidBrush(Global.Config.HexHighlightFreezeColor); private readonly SolidBrush _freezeHighlightBrush = new SolidBrush(Global.Config.HexHighlightFreezeColor);
private SolidBrush _highlightBrush = new SolidBrush(Global.Config.HexHighlightColor); private readonly SolidBrush _highlightBrush = new SolidBrush(Global.Config.HexHighlightColor);
private SolidBrush _secondaryHighlightBrush = new SolidBrush(Color.FromArgb(0x44, Global.Config.HexHighlightColor)); private readonly SolidBrush _secondaryHighlightBrush = new SolidBrush(Color.FromArgb(0x44, Global.Config.HexHighlightColor));
private void MemoryViewerBox_Paint(object sender, PaintEventArgs e) private void MemoryViewerBox_Paint(object sender, PaintEventArgs e)
{ {
@ -2275,9 +2232,9 @@ namespace BizHawk.Client.EmuHawk
if (gaps < 0) { gaps = 0; } if (gaps < 0) { gaps = 0; }
var width = (fontWidth * 2 * (int)cheat.Size) + (gaps * fontWidth); var width = (_fontWidth * 2 * (int)cheat.Size) + (gaps * _fontWidth);
var rect = new Rectangle(GetAddressCoordinates(cheat.Address ?? 0), new Size(width, fontHeight)); var rect = new Rectangle(GetAddressCoordinates(cheat.Address ?? 0), new Size(width, _fontHeight));
e.Graphics.DrawRectangle(_blackPen, rect); e.Graphics.DrawRectangle(_blackPen, rect);
_freezeBrush.Color = Global.Config.HexFreezeColor; _freezeBrush.Color = Global.Config.HexFreezeColor;
e.Graphics.FillRectangle(_freezeBrush, rect); e.Graphics.FillRectangle(_freezeBrush, rect);
@ -2290,24 +2247,24 @@ namespace BizHawk.Client.EmuHawk
// Create a slight offset to increase rectangle sizes // Create a slight offset to increase rectangle sizes
var point = GetAddressCoordinates(_addressHighlighted); var point = GetAddressCoordinates(_addressHighlighted);
var textX = (int)GetTextX(_addressHighlighted); var textX = (int)GetTextX(_addressHighlighted);
var textpoint = new Point(textX, point.Y); var textPoint = new Point(textX, point.Y);
var rect = new Rectangle(point, new Size(fontWidth * 2 * DataSize + (NeedsExtra(_addressHighlighted) ? fontWidth : 0) + 2, fontHeight)); var rect = new Rectangle(point, new Size(_fontWidth * 2 * DataSize + (NeedsExtra(_addressHighlighted) ? _fontWidth : 0) + 2, _fontHeight));
e.Graphics.DrawRectangle(_blackPen, rect); e.Graphics.DrawRectangle(_blackPen, rect);
var textrect = new Rectangle(textpoint, new Size(fontWidth * DataSize, fontHeight)); var textRect = new Rectangle(textPoint, new Size(_fontWidth * DataSize, _fontHeight));
if (Global.CheatList.IsActive(_domain, _addressHighlighted)) if (Global.CheatList.IsActive(_domain, _addressHighlighted))
{ {
_freezeHighlightBrush.Color = Global.Config.HexHighlightFreezeColor; _freezeHighlightBrush.Color = Global.Config.HexHighlightFreezeColor;
e.Graphics.FillRectangle(_freezeHighlightBrush, rect); e.Graphics.FillRectangle(_freezeHighlightBrush, rect);
e.Graphics.FillRectangle(_freezeHighlightBrush, textrect); e.Graphics.FillRectangle(_freezeHighlightBrush, textRect);
} }
else else
{ {
_highlightBrush.Color = Global.Config.HexHighlightColor; _highlightBrush.Color = Global.Config.HexHighlightColor;
e.Graphics.FillRectangle(_highlightBrush, rect); e.Graphics.FillRectangle(_highlightBrush, rect);
e.Graphics.FillRectangle(_highlightBrush, textrect); e.Graphics.FillRectangle(_highlightBrush, textRect);
} }
} }
@ -2317,24 +2274,24 @@ namespace BizHawk.Client.EmuHawk
{ {
var point = GetAddressCoordinates(address); var point = GetAddressCoordinates(address);
var textX = (int)GetTextX(address); var textX = (int)GetTextX(address);
var textpoint = new Point(textX, point.Y); var textPoint = new Point(textX, point.Y);
var rect = new Rectangle(point, new Size(fontWidth * 2 * DataSize + 2, fontHeight)); var rect = new Rectangle(point, new Size(_fontWidth * 2 * DataSize + 2, _fontHeight));
e.Graphics.DrawRectangle(_blackPen, rect); e.Graphics.DrawRectangle(_blackPen, rect);
var textrect = new Rectangle(textpoint, new Size(fontWidth * DataSize, fontHeight)); var textRect = new Rectangle(textPoint, new Size(_fontWidth * DataSize, _fontHeight));
if (Global.CheatList.IsActive(_domain, address)) if (Global.CheatList.IsActive(_domain, address))
{ {
_freezeHighlightBrush.Color = Global.Config.HexHighlightFreezeColor; _freezeHighlightBrush.Color = Global.Config.HexHighlightFreezeColor;
e.Graphics.FillRectangle(_freezeHighlightBrush, rect); e.Graphics.FillRectangle(_freezeHighlightBrush, rect);
e.Graphics.FillRectangle(_freezeHighlightBrush, textrect); e.Graphics.FillRectangle(_freezeHighlightBrush, textRect);
} }
else else
{ {
_secondaryHighlightBrush.Color = Color.FromArgb(0x44, Global.Config.HexHighlightColor); _secondaryHighlightBrush.Color = Color.FromArgb(0x44, Global.Config.HexHighlightColor);
e.Graphics.FillRectangle(_secondaryHighlightBrush, rect); e.Graphics.FillRectangle(_secondaryHighlightBrush, rect);
e.Graphics.FillRectangle(_secondaryHighlightBrush, textrect); e.Graphics.FillRectangle(_secondaryHighlightBrush, textRect);
} }
} }
} }
@ -2426,11 +2383,6 @@ namespace BizHawk.Client.EmuHawk
#endregion #endregion
private void HexMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
#endregion #endregion
private void viewN64MatrixToolStripMenuItem_Click(object sender, EventArgs e) private void viewN64MatrixToolStripMenuItem_Click(object sender, EventArgs e)
@ -2438,9 +2390,9 @@ namespace BizHawk.Client.EmuHawk
if (!HighlightedAddress.HasValue) if (!HighlightedAddress.HasValue)
return; return;
bool bigend = true; bool bigEndian = true;
long addr = HighlightedAddress.Value; long addr = HighlightedAddress.Value;
//ushort = _domain.PeekWord(addr,bigend); //ushort = _domain.PeekWord(addr, bigEndian);
float[,] matVals = new float[4,4]; float[,] matVals = new float[4,4];
@ -2448,28 +2400,28 @@ namespace BizHawk.Client.EmuHawk
{ {
for (int j = 0; j < 4; j++) for (int j = 0; j < 4; j++)
{ {
ushort hi = _domain.PeekUshort(((addr+(i<<3)+(j<<1) )^0x0),bigend); ushort hi = _domain.PeekUshort(((addr+(i<<3)+(j<<1) )^0x0), bigEndian);
ushort lo = _domain.PeekUshort(((addr+(i<<3)+(j<<1) + 32)^0x0),bigend); ushort lo = _domain.PeekUshort(((addr+(i<<3)+(j<<1) + 32)^0x0), bigEndian);
matVals[i,j] = (int)(((hi << 16) | lo)) / 65536.0f; matVals[i,j] = (int)(((hi << 16) | lo)) / 65536.0f;
} }
} }
//if needed // if needed
//var mat = new SlimDX.Matrix(); ////var mat = new SlimDX.Matrix();
//mat.M11 = matVals[0, 0]; mat.M12 = matVals[0, 1]; mat.M13 = matVals[0, 2]; mat.M14 = matVals[0, 3]; ////mat.M11 = matVals[0, 0]; mat.M12 = matVals[0, 1]; mat.M13 = matVals[0, 2]; mat.M14 = matVals[0, 3];
//mat.M21 = matVals[1, 0]; mat.M22 = matVals[1, 1]; mat.M23 = matVals[1, 2]; mat.M24 = matVals[1, 3]; ////mat.M21 = matVals[1, 0]; mat.M22 = matVals[1, 1]; mat.M23 = matVals[1, 2]; mat.M24 = matVals[1, 3];
//mat.M31 = matVals[2, 0]; mat.M32 = matVals[2, 1]; mat.M33 = matVals[2, 2]; mat.M34 = matVals[2, 3]; ////mat.M31 = matVals[2, 0]; mat.M32 = matVals[2, 1]; mat.M33 = matVals[2, 2]; mat.M34 = matVals[2, 3];
//mat.M41 = matVals[3, 0]; mat.M42 = matVals[3, 1]; mat.M43 = matVals[3, 2]; mat.M44 = matVals[3, 3]; ////mat.M41 = matVals[3, 0]; mat.M42 = matVals[3, 1]; mat.M43 = matVals[3, 2]; mat.M44 = matVals[3, 3];
//MessageBox.Show(mat.ToString()); ////MessageBox.Show(mat.ToString());
using var sw = new StringWriter(); using var sw = new StringWriter();
for(int i=0;i<4;i++) for (int i = 0; i < 4; i++)
sw.WriteLine("{0,18:0.00000} {1,18:0.00000} {2,18:0.00000} {3,18:0.00000}", matVals[i, 0], matVals[i, 1], matVals[i, 2], matVals[i, 3]); {
sw.WriteLine("{0,18:0.00000} {1,18:0.00000} {2,18:0.00000} {3,18:0.00000}", matVals[i, 0], matVals[i, 1], matVals[i, 2], matVals[i, 3]);
}
var str = sw.ToString(); var str = sw.ToString();
MessageBox.Show(str); MessageBox.Show(str);
} }
} }
} }