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
|
namespace Q1.core.Arch.Constants;
public static class ChipRegisters
{
public const u8 GENERIC_REGISTER_COUNT = 64;
public const u8 AX = 0x40;
public const u8 AH = 0x41;
public const u8 AL = 0x42;
public const u8 DX = 0x44;
public const u8 DH = 0x45;
public const u8 DL = 0x46;
public const u8 LX = 0x48;
public const u8 PC = 0x4C;
public const u8 SP = 0x4D;
public static u8? GetRegisterIndex(string name)
{
return name switch
{
"AX" => AX,
"AH" => AH,
"AL" => AL,
"DX" => DX,
"DH" => DH,
"DL" => DL,
"LX" => LX,
"PC" => PC,
"SP" => SP,
_ when name.StartsWith("V") && byte.TryParse(name[1..], out u8 index) && index < GENERIC_REGISTER_COUNT => index,
_ => null
};
}
public static string? GetRegisterName(u8 index)
{
return index switch
{
AX => "AX",
AH => "AH",
AL => "AL",
DX => "DX",
DH => "DH",
DL => "DL",
LX => "LX",
PC => "PC",
SP => "SP",
_ when index < GENERIC_REGISTER_COUNT => $"V{index}",
_ => null
};
}
}
|