-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemoryGridRow.cs
202 lines (177 loc) · 3.75 KB
/
MemoryGridRow.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using System.Text.RegularExpressions;
using Avalonia.Data;
using System;
using System.ComponentModel;
/// <summary>
/// Represents row of the data grid that referrers to memory
/// But has input checks
/// </summary>
public class MemoryGridRow : INotifyPropertyChanged
{
public delegate void RowValueChangedEventHandler(int address, byte value);
public event RowValueChangedEventHandler? OnRowValueChanged;
public event PropertyChangedEventHandler? PropertyChanged;
private byte[] _memory = new byte[0x10];
public byte[] Memory => _memory;
public byte this[int i]
{
get => _memory[i];
set
{
_memory[i] = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs($"X{i.ToString("X1")}"));
}
}
public int AddressValue = 0;
public MemoryGridRow(int addressValue)
{
AddressValue = addressValue;
}
public string Address => AddressValue.ToString("X4");
private void _validate(int offset, string value)
{
if (!Regex.IsMatch(value, "^[0-9A-F]+$"))
{
throw new DataValidationException("Must only contain hex characters");
}
try
{
_memory[offset] = Convert.ToByte(value, 16);
OnRowValueChanged?.Invoke(AddressValue + offset, _memory[offset]);
}
catch (OverflowException e)
{
throw new DataValidationException("Value must be in 0 to FF range");
}
}
//yep, it's just copy paster code
//generated via c# script
public string X0
{
get => _memory[0].ToString("X2");
set
{
_validate(0, value);
}
}
public string X1
{
get => _memory[1].ToString("X2");
set
{
_validate(1, value);
}
}
public string X2
{
get => _memory[2].ToString("X2");
set
{
_validate(2, value);
}
}
public string X3
{
get => _memory[3].ToString("X2");
set
{
_validate(3, value);
}
}
public string X4
{
get => _memory[4].ToString("X2");
set
{
_validate(4, value);
}
}
public string X5
{
get => _memory[5].ToString("X2");
set
{
_validate(5, value);
}
}
public string X6
{
get => _memory[6].ToString("X2");
set
{
_validate(6, value);
}
}
public string X7
{
get => _memory[7].ToString("X2");
set
{
_validate(7, value);
}
}
public string X8
{
get => _memory[8].ToString("X2");
set
{
_validate(8, value);
}
}
public string X9
{
get => _memory[9].ToString("X2");
set
{
_validate(9, value);
}
}
public string XA
{
get => _memory[10].ToString("X2");
set
{
_validate(10, value);
}
}
public string XB
{
get => _memory[11].ToString("X2");
set
{
_validate(11, value);
}
}
public string XC
{
get => _memory[12].ToString("X2");
set
{
_validate(12, value);
}
}
public string XD
{
get => _memory[13].ToString("X2");
set
{
_validate(13, value);
}
}
public string XE
{
get => _memory[14].ToString("X2");
set
{
_validate(14, value);
}
}
public string XF
{
get => _memory[15].ToString("X2");
set
{
_validate(15, value);
}
}
}