Clean up peeking for Hex Editor's N64 Matrix view

This commit is contained in:
James Groom 2023-12-22 01:17:02 +10:00 committed by GitHub
parent 0d5b0ac964
commit cae739a826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 13 deletions

View File

@ -2232,28 +2232,24 @@ namespace BizHawk.Client.EmuHawk
private void viewN64MatrixToolStripMenuItem_Click(object sender, EventArgs e) private void viewN64MatrixToolStripMenuItem_Click(object sender, EventArgs e)
{ {
static double Wat(uint n)
=> unchecked((int) n) / 65536.0;
if (_highlightedAddress is null) return; if (_highlightedAddress is null) return;
bool bigEndian = true;
var addr = _highlightedAddress.Value & ~0b11L; var addr = _highlightedAddress.Value & ~0b11L;
//ushort = _domain.PeekWord(addr, bigEndian);
const int SIZE = 4; const int SIZE = 4;
var matVals = new float[SIZE, SIZE]; var raw = new ushort[2 * SIZE * SIZE];
for (int i = 0; i < 4; i++) _domain.BulkPeekUshort(addr.RangeTo(addr + (SIZE * SIZE * sizeof(float) - 1)), bigEndian: true, raw);
{
for (int j = 0; j < 4; j++)
{
ushort hi = _domain.PeekUshort(((addr+(i<<3)+(j<<1) )^0x0), bigEndian);
ushort lo = _domain.PeekUshort(((addr+(i<<3)+(j<<1) + 32)^0x0), bigEndian);
matVals[i,j] = ((hi << 16) | lo) / 65536.0f;
}
}
List<List<string>> strings = new(); List<List<string>> strings = new();
for (var y = 0; y < SIZE; y++) for (var y = 0; y < SIZE; y++)
{ {
strings.Add(new()); strings.Add(new());
for (var x = 0; x < SIZE; x++) for (var x = 0; x < SIZE; x++)
{ {
strings[y].Add(matVals[y, x].ToString(CultureInfo.InvariantCulture)); // was going to right-pad, as the previous code did (poorly), but I realised that's not necessary and not really helpful, as well as being hard to get right --yoshi var i = y * SIZE + x;
uint n = raw[i];
n <<= 16;
n |= raw[SIZE * SIZE + i];
strings[y].Add(((float) Wat(n)).ToString(CultureInfo.InvariantCulture)); // was going to right-pad, as the previous code did (poorly), but I realised that's not necessary and not really helpful, as well as being hard to get right --yoshi
} }
} }
using N64MatrixDisplayDialog dialog = new(strings); using N64MatrixDisplayDialog dialog = new(strings);