summaryrefslogtreecommitdiff
path: root/Q1.core/Arch
diff options
context:
space:
mode:
Diffstat (limited to 'Q1.core/Arch')
-rw-r--r--Q1.core/Arch/Constants/ChipRegisters.cs36
-rw-r--r--Q1.core/Arch/Lookups/InstructionSet.cs25
2 files changed, 61 insertions, 0 deletions
diff --git a/Q1.core/Arch/Constants/ChipRegisters.cs b/Q1.core/Arch/Constants/ChipRegisters.cs
index 042ce32..40caf6a 100644
--- a/Q1.core/Arch/Constants/ChipRegisters.cs
+++ b/Q1.core/Arch/Constants/ChipRegisters.cs
@@ -16,4 +16,40 @@ public static class ChipRegisters
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
+ };
+ }
} \ No newline at end of file
diff --git a/Q1.core/Arch/Lookups/InstructionSet.cs b/Q1.core/Arch/Lookups/InstructionSet.cs
index 2ea20fc..ad81f2e 100644
--- a/Q1.core/Arch/Lookups/InstructionSet.cs
+++ b/Q1.core/Arch/Lookups/InstructionSet.cs
@@ -20,6 +20,31 @@ public static class InstructionSet
throw new ArgumentException($"Instruction '{instructionName}' not found in the instruction set.");
}
+ public static u8 GetOpcodeWithIndex(string instructionName, out u8 index)
+ {
+ for (u8 opcode = 0; opcode < InstructionSet.Lookup.Length; opcode++)
+ {
+ var group = InstructionSet.Lookup[opcode];
+ if (group.Implicit.Name == instructionName ||
+ group.SimpleAddressing.Name == instructionName ||
+ group.ExtendedImplicit.Name == instructionName ||
+ group.ExtendedAddressing.Name == instructionName)
+ {
+ if (group.Implicit.Name == instructionName)
+ index = 0;
+ else if (group.SimpleAddressing.Name == instructionName)
+ index = 1;
+ else if (group.ExtendedImplicit.Name == instructionName)
+ index = 2;
+ else
+ index = 3;
+
+ return opcode;
+ }
+ }
+ throw new ArgumentException($"Instruction '{instructionName}' not found in the instruction set.");
+ }
+
static InstructionSet()
{
var nop = new ImplicitInstruction { Name = "NOP", Execute = InstructionSet.Nop };