Skip to content

Commit

Permalink
Merge branch 'initialization-rework'
Browse files Browse the repository at this point in the history
  • Loading branch information
irusanov committed Jan 10, 2022
2 parents 908a446 + 06e1bfc commit 15d2217
Show file tree
Hide file tree
Showing 19 changed files with 511 additions and 2,500 deletions.
71 changes: 13 additions & 58 deletions PowerTableMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZenStates;
using ZenStates.Core;

namespace ZenStatesDebugTool
{
public partial class PowerTableMonitor : Form
{
private readonly PowerTable PowerTable;
private uint dramBaseAddress = 0;
private readonly UIntPtr dramPtr;
private readonly Ops OPS;
private readonly uint[] table = new uint[PowerTable.tableSize / 4];
private readonly Cpu CPU;
readonly Timer PowerCfgTimer = new Timer();
private readonly BindingList<PowerMonitorItem> list = new BindingList<PowerMonitorItem>();
private class PowerMonitorItem
Expand All @@ -26,61 +22,27 @@ private class PowerMonitorItem
public string Value { get; set; }
}

private void ReadPowerConfig()
private void FillInData(float[] table)
{
if (dramBaseAddress > 0)
{
try
{
uint data = 0;

if (OPS.TransferTableToDram() != SMU.Status.OK)
OPS.TransferTableToDram(); // retry

for (int i = 0; i < table.Length; ++i)
{
NativeMethods.GetPhysLong(dramPtr + (i * 0x4), out data);
table[i] = data;
}

if (table.Any(v => v != 0))
PowerTable.Table = table;
}
catch (EntryPointNotFoundException ex)
{
throw new ApplicationException(ex.Message);
}
catch (DllNotFoundException ex)
{
throw new ApplicationException(ex.Message);
}
}
}

private void FillInData(uint[] table)
{

list.Clear();

for (var i = 0; i < table.Length; i++)
{
var bytes = BitConverter.GetBytes(table[i]);
list.Add(new PowerMonitorItem {
Index = $"{i:D4}",
Offset = $"0x{(i*4):X4}",
Value = $"{BitConverter.ToSingle(bytes, 0):F6}"
Value = $"{table[i]:F6}"
});;
}
}

private void RefreshData(uint[] table)
private void RefreshData(float[] table)
{
int index = 0;

foreach (var item in list)
{
var bytes = BitConverter.GetBytes(table[index]);
item.Value = $"{BitConverter.ToSingle(bytes, 0):F6}";
item.Value = $"{table[index]:F6}";
index++;
}

Expand All @@ -90,30 +52,23 @@ private void RefreshData(uint[] table)
private void PowerCfgTimer_Tick(object sender, EventArgs e)
{
Console.WriteLine("refreshing");
ReadPowerConfig();
RefreshData(PowerTable.Table);
if (CPU.RefreshPowerTable() == SMU.Status.OK)
RefreshData(CPU.powerTable.Table);
}

public PowerTableMonitor(Ops ops)
public PowerTableMonitor(Cpu cpu)
{
OPS = ops;
PowerTable = new PowerTable(OPS.Smu.SMU_TYPE);
CPU = cpu;
PowerCfgTimer.Interval = 2000;
PowerCfgTimer.Tick += new EventHandler(PowerCfgTimer_Tick);

InitializeComponent();

dataGridView1.DataSource = list;

// Get first base address
dramBaseAddress = (uint)(OPS.GetDramBaseAddress() & 0xFFFFFFFF);
if (dramBaseAddress > 0)
{
dramPtr = new UIntPtr(dramBaseAddress);
ReadPowerConfig();
}

FillInData(PowerTable.Table);
cpu.RefreshPowerTable();

FillInData(cpu.powerTable.Table);
}

private void PowerTableMonitor_FormClosing(object sender, FormClosingEventArgs e)
Expand Down
Binary file added Prebuilt/ZenStates-Core.dll
Binary file not shown.
15 changes: 8 additions & 7 deletions SMUMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
using ZenStates;
using ZenStates.Core;

namespace ZenStatesDebugTool
{
public partial class SMUMonitor : Form
{
private readonly Ops OPS;
private readonly Cpu CPU;
readonly System.Windows.Forms.Timer MonitorTimer = new System.Windows.Forms.Timer();
private readonly BindingList<SmuMonitorItem> list = new BindingList<SmuMonitorItem>();
private uint prevCmdValue;
Expand All @@ -23,9 +23,9 @@ private class SmuMonitorItem
public string Rsp { get; set; }
}

public SMUMonitor(Ops ops, uint addrMsg, uint addrArg, uint addrRsp)
public SMUMonitor(Cpu cpu, uint addrMsg, uint addrArg, uint addrRsp)
{
OPS = ops;
CPU = cpu;
SMU_ADDR_MSG = addrMsg;
SMU_ADDR_ARG = addrArg;
SMU_ADDR_RSP = addrRsp;
Expand All @@ -47,13 +47,14 @@ private void AddLine()
uint rsp = 0;
uint arg = 0;

OPS.SmuReadReg(SMU_ADDR_MSG, ref msg);
msg = CPU.ReadDword(SMU_ADDR_MSG);

if (msg != prevCmdValue)
{
prevCmdValue = msg;
if (OPS.SmuReadReg(SMU_ADDR_RSP, ref rsp))
OPS.SmuReadReg(SMU_ADDR_ARG, ref arg);
rsp = CPU.ReadDword(SMU_ADDR_RSP);
if (rsp != 0)
arg = CPU.ReadDword(SMU_ADDR_ARG);

new Thread(() => {
list.Add(new SmuMonitorItem
Expand Down
Loading

0 comments on commit 15d2217

Please sign in to comment.