-
Notifications
You must be signed in to change notification settings - Fork 5
/
SMUMonitor.cs
99 lines (82 loc) · 3.03 KB
/
SMUMonitor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
using ZenStates.Core;
namespace ZenStatesDebugTool
{
public partial class SMUMonitor : Form
{
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;
private uint prevArgValue;
private readonly uint SMU_ADDR_MSG;
private readonly uint SMU_ADDR_ARG;
private readonly uint SMU_ADDR_RSP;
private class SmuMonitorItem
{
public string Cmd { get; set; }
public string Arg { get; set; }
public string Rsp { get; set; }
}
public SMUMonitor(Cpu cpu, uint addrMsg, uint addrArg, uint addrRsp)
{
CPU = cpu;
SMU_ADDR_MSG = addrMsg;
SMU_ADDR_ARG = addrArg;
SMU_ADDR_RSP = addrRsp;
MonitorTimer.Interval = 10;
MonitorTimer.Tick += new EventHandler(MonitorTimer_Tick);
InitializeComponent();
labelCmdAddr.Text = $"0x{addrMsg:X8}";
labelRspAddr.Text = $"0x{addrRsp:X8}";
labelArgAddr.Text = $"0x{addrArg:X8}";
dataGridView2.DataSource = list;
}
private void AddLine()
{
uint msg = 0;
uint rsp = 0;
uint arg = 0;
msg = CPU.ReadDword(SMU_ADDR_MSG);
arg = CPU.ReadDword(SMU_ADDR_ARG);
if (msg != prevCmdValue || arg != prevArgValue)
{
prevCmdValue = msg;
prevArgValue = arg;
rsp = CPU.ReadDword(SMU_ADDR_RSP);
if (rsp != 0)
arg = CPU.ReadDword(SMU_ADDR_ARG);
new Thread(() => {
list.Add(new SmuMonitorItem
{
Cmd = $"0x{msg:X2}",
Arg = $"0x{arg:X8}",
Rsp = $"0x{rsp:X2} {GetSMUStatus.GetByType((SMU.Status)rsp)}"
});
dataGridView2.FirstDisplayedScrollingRowIndex = list.Count - 1;
}).Start();
}
}
private void MonitorTimer_Tick(object sender, EventArgs e) => AddLine();
private void SMUMonitor_FormClosing(object sender, FormClosingEventArgs e) => MonitorTimer.Stop();
private void ButtonClear_Click(object sender, EventArgs e) => list.Clear();
private void SMUMonitor_Shown(object sender, EventArgs e) => MonitorTimer.Start();
private void ButtonApply_Click(object sender, EventArgs e)
{
if (MonitorTimer.Enabled)
{
MonitorTimer.Stop();
buttonStartStop.Text = "Start";
}
else
{
prevCmdValue = 0;
MonitorTimer.Start();
buttonStartStop.Text = "Stop";
}
}
}
}