added more instructuioins

This commit is contained in:
2026-09-09 13:41:49 -05:00
parent a71d73e19d
commit 0decb483fe
18 changed files with 320 additions and 111 deletions
+8
View File
@@ -18,14 +18,22 @@ namespace Core
STX, // Stores X into accumulator
STY, // Stores Y into accumulator
SEA, // Sets accumulator
ADD, // Adds X + Y then stores in Accumulator
SUB, // Subtracts X - Y then stores in Accumulator
MUL, // Multiplies X * Y then stores in Accumulator
DIV, // Divides X / Y then stores in Accumulator
JZE, // Jumps to a pointer in the program on zero flag
JNZE,// Jumps to a pouinter on not zero floag
JIE,
JMP, // Jumps to a pointer in the program
SFG, // Sets a flag to true
RFG, // Sets a flag to false
GIE, // Gets if X is equal to Y
PRA, // Prints accumulator
PRX, // Prints X
PRY, // Prints Y
+5
View File
@@ -120,6 +120,11 @@ public class DebugDumper
comment = $"Set flag '{tokens[1]}' to false";
break;
// misc
case "GIE":
comment = $"Get if X ({x}) is equal to Y ({y})";
break;
// Debug
case "PRA":
comment = $"Print Accumulator ({accumulator})";
+11
View File
@@ -4,6 +4,7 @@ X, Y registers
Memory (8kb)
:: Flags
Z; Zero
E; Is Equal
:: Helpers
NVAR <name>, <value>; Sets new a variable and its value
@@ -27,10 +28,20 @@ DIV; Divides X / Y then stores in Accumulator
:: Commands (flow control)
JZE <pointer>; Jumps to a pointer in the program on zero flag
JNZE <pointer>; Jumps to a pointer if is not zero
JIE <pointer>; Jumps if is equal
JMP <pointer>; Jumps to a pointer in the program
SFG <flag>; Sets a flag to true
RFG <flag; Sets a flag to false
:: Extra shite
GIE; Gets if X is equal to Y
GIG; Gets if X is greater than Y
GIL; Gets if X is less than Y
GIGE; Gets if X is greater than or equal to Y
GILE; Gets if X is less than or equal to Y
:: Commands (Debug)
PRA; Prints accumulator
PRX; Prints X
+85 -66
View File
@@ -8,7 +8,6 @@ namespace Core
{
public class Operations
{
public Operations(int pixBufSize) => WindowSize = pixBufSize;
public Dictionary<string, int> Variables = new Dictionary<string, int>();
public static int WindowSize;
public int Accumulator = 0;
@@ -17,9 +16,24 @@ namespace Core
public int[] Memory = new int[256];
public string Filename;
public int pointer = 0;
public int[] PixBufferR = new int[WindowSize];
public int[] PixBufferG = new int[WindowSize];
public int[] PixBufferB = new int[WindowSize];
// Declare them here without `new int[WindowSize]`
public int[] PixBufferR;
public int[] PixBufferG;
public int[] PixBufferB;
public int f_IsEqu;
public int f_IsZer;
public Operations(int pixBufSize)
{
WindowSize = pixBufSize;
// Initialize them here so they use the correct WindowSize
PixBufferR = new int[WindowSize];
PixBufferG = new int[WindowSize];
PixBufferB = new int[WindowSize];
}
private int ResolveValue(string shite)
@@ -34,6 +48,8 @@ namespace Core
return StackX;
case "RAY":
return StackY;
case "f_IsEqual":
return f_IsEqu;
}
Variables.TryGetValue(shite, out int a);
return a;
@@ -45,6 +61,11 @@ namespace Core
}
}
private int booltoint(bool val)
{
return (val == true) ? 1 : 0;
}
public void ExecuteCommand(ComponentType type, string[] args)
{
@@ -96,6 +117,21 @@ namespace Core
case ComponentType.JMP:
pointer = ResolveValue(args[1]) - 1;
return;
case ComponentType.JNZE:
if (f_IsZer != 1)
{
pointer = ResolveValue(args[1]) - 1;
}
return;
case ComponentType.JIE:
if (f_IsEqu== 1)
{
pointer = ResolveValue(args[1]) - 1;
}
return;
case ComponentType.GIE:
f_IsEqu = booltoint(StackX == StackY);
return;
// math
case ComponentType.ADD:
@@ -134,87 +170,70 @@ namespace Core
public void EquParserLoop(string equ)
{
string[] lines = equ.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
// Pass 1: Collect labels with correct line tracking
for (int i = 0; i < lines.Length; i++)
{
string trimmedLine = lines[i].Trim();
if (trimmedLine.StartsWith("@"))
{
string labelName = trimmedLine.Substring(1);
Variables[labelName] = i; // Point to the line index
}
}
// Pass 2: Execution loop
while (pointer < lines.Length)
{
string[] tokens = lines[pointer].Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
string command = tokens[0];
if (tokens.Length == 0)
if (tokens.Length == 0 || tokens[0].StartsWith("@"))
{
pointer++;
continue;
}
string command = tokens[0];
switch (command)
{
default: break;
case "::":
break;
// variables
case "NVAR":
ExecuteCommand(ComponentType.NVAR, tokens);
break;
case "RVAR":
ExecuteCommand(ComponentType.RVAR, tokens);
break;
case "SVAR":
ExecuteCommand(ComponentType.SVAR, tokens);
break;
// Variables
case "NVAR": ExecuteCommand(ComponentType.NVAR, tokens); break;
case "RVAR": ExecuteCommand(ComponentType.RVAR, tokens); break;
case "SVAR": ExecuteCommand(ComponentType.SVAR, tokens); break;
// memory
case "LDA":
ExecuteCommand(ComponentType.LDA, tokens);
break;
case "STA":
ExecuteCommand(ComponentType.STA, tokens);
break;
case "LDX":
ExecuteCommand(ComponentType.LDX, tokens);
break;
case "LDY":
ExecuteCommand(ComponentType.LDY, tokens);
break;
case "STX":
ExecuteCommand(ComponentType.STX, tokens);
break;
case "STY":
ExecuteCommand(ComponentType.STY, tokens);
break;
case "SEA":
ExecuteCommand(ComponentType.SEA, tokens);
break;
// Memory
case "LDA": ExecuteCommand(ComponentType.LDA, tokens); break;
case "STA": ExecuteCommand(ComponentType.STA, tokens); break;
case "LDX": ExecuteCommand(ComponentType.LDX, tokens); break;
case "LDY": ExecuteCommand(ComponentType.LDY, tokens); break;
case "STX": ExecuteCommand(ComponentType.STX, tokens); break;
case "STY": ExecuteCommand(ComponentType.STY, tokens); break;
case "SEA": ExecuteCommand(ComponentType.SEA, tokens); break;
// flow control
case "JMP":
ExecuteCommand(ComponentType.JMP, tokens);
break;
// Flow control
case "JMP": ExecuteCommand(ComponentType.JMP, tokens); break;
case "JNZE": ExecuteCommand(ComponentType.JNZE, tokens); break;
case "JIE": ExecuteCommand(ComponentType.JIE, tokens); break;
case "GIE": ExecuteCommand(ComponentType.GIE, tokens); break;
// math
case "ADD":
ExecuteCommand(ComponentType.ADD, tokens);
break;
// Math (Added missing operations)
case "ADD": ExecuteCommand(ComponentType.ADD, tokens); break;
case "SUB": ExecuteCommand(ComponentType.SUB, tokens); break;
case "MUL": ExecuteCommand(ComponentType.MUL, tokens); break;
case "DIV": ExecuteCommand(ComponentType.DIV, tokens); break;
// debug
case "PRA":
ExecuteCommand(ComponentType.PRA, tokens);
break;
case "PRX":
ExecuteCommand(ComponentType.PRX, tokens);
break;
case "PRY":
ExecuteCommand(ComponentType.PRY, tokens);
break;
case "PRM":
ExecuteCommand(ComponentType.PRM, tokens);
break;
case "HLT":
ExecuteCommand(ComponentType.HLT, tokens);
break;
// Debug
case "PRA": ExecuteCommand(ComponentType.PRA, tokens); break;
case "PRX": ExecuteCommand(ComponentType.PRX, tokens); break;
case "PRY": ExecuteCommand(ComponentType.PRY, tokens); break;
case "PRM": ExecuteCommand(ComponentType.PRM, tokens); break;
case "HLT": ExecuteCommand(ComponentType.HLT, tokens); break;
}
pointer++;
}
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+96 -17
View File
@@ -1,25 +1,104 @@
:: variables
NVAR var1, 12
NVAR var2, 10
NVAR outcome, 0
JMP 8
:: Some insight on this
:: @meta is the metadata discriptor
::
@meta
:: Set to codepage 610
SEA 610
:: codepage always gets stored at byte 0 of mem
STA 0
:: set interupt 0 to 615 (startup)
SEA 615
:: store in mem
STA 1
JMP ready
@readyjumpback
LDA 24
JMP ACC
:: setup
SEA var1
@ready
SEA ready
LDX
SEA var2
SEA 8
LDY
ADD
SVAR outcome, ACC
SEA outcome
STA 4
PRM 4
JMP 21
STA 24
JMP RegisterModes
JMP parse
@RegisterModes
NVAR m_add, 068
NVAR m_sub, 078
NVAR m_div, 088
NVAR m_mul, 098
NVAR mode, m_mul
NVAR A, 10
NVAR B, 10
JMP readyjumpback
:: end
RVAR var1
RVAR var2
RVAR outcome
@madd
SEA A
LDX
SEA B
LDY
ADD
STA 8
JMP EOF
@msub
SEA A
LDX
SEA B
LDY
SUB
STA 8
JMP EOF
@mmul
SEA A
LDX
SEA B
LDY
MUL
STA 8
JMP EOF
@mdiv
SEA A
LDX
SEA B
LDY
DIV
STA 8
JMP EOF
@parse
SEA mode
LDX
SEA m_add
LDY
GIE
JIE madd
SEA mode
LDX
SEA m_sub
LDY
GIE
JIE msub
SEA mode
LDX
SEA m_mul
LDY
GIE
JIE mmul
SEA mode
LDX
SEA m_div
LDY
GIE
JIE mdiv
JMP EOF
@EOF
PRM 8
HLT
+104 -25
View File
@@ -1,25 +1,104 @@
[0] :: variables
[1] NVAR var1, 12 :: Create 'var1' with value of '12'
[2] NVAR var2, 10 :: Create 'var2' with value of '10'
[3] NVAR outcome, 0 :: Create 'outcome' with value of '0'
[4] JMP 8 :: Jump to line 8
[5]
[6]
[7] :: setup
[8] SEA var1 :: Set Accumulator to 'var1' (12)
[9] LDX :: Load Accumulator (12) into X
[10] SEA var2 :: Set Accumulator to 'var2' (10)
[11] LDY :: Load Accumulator (10) into Y
[12] ADD :: Add X (12) and Y (10) and store into the Accumulator (22)
[13] SVAR outcome, ACC :: Set variable 'outcome' to '0'
[14] SEA outcome :: Set Accumulator to 'outcome' (0)
[15] STA 4 :: Store the Accumulator (0) into Memory address 4
[16] PRM 4 :: Print value of memory address 4
[17] JMP 21 :: Jump to line 21
[18]
[19]
[20] :: end
[21] RVAR var1 :: Remove variable 'var1'
[22] RVAR var2 :: Remove variable 'var2'
[23] RVAR outcome :: Remove variable 'outcome'
[24] HLT :: Halt execution
[0] :: Some insight on this
[1] :: @meta is the metadata discriptor
[2] ::
[3] @meta :: Unknown command
[4] :: Set to codepage 610
[5] SEA 610 :: Set Accumulator to 610
[6] :: codepage always gets stored at byte 0 of mem
[7] STA 0 :: Store the Accumulator (610) into Memory address 0
[8] :: set interupt 0 to 615 (startup)
[9] SEA 615 :: Set Accumulator to 615
[10] :: store in mem
[11] STA 1 :: Store the Accumulator (615) into Memory address 1
[12] JMP ready :: Jump to line ready
[13]
[14] @readyjumpback :: Unknown command
[15] LDA 24 :: Load memory address 24 into Accumulator
[16] JMP ACC :: Jump to line ACC
[17]
[18] @ready :: Unknown command
[19] SEA ready :: Set Accumulator to 0
[20] LDX :: Load Accumulator (0) into X
[21] SEA 8 :: Set Accumulator to 8
[22] LDY :: Load Accumulator (8) into Y
[23] ADD :: Add X (0) and Y (8) and store into the Accumulator (8)
[24] STA 24 :: Store the Accumulator (8) into Memory address 24
[25] JMP RegisterModes :: Jump to line RegisterModes
[26] JMP parse :: Jump to line parse
[27]
[28] @RegisterModes :: Unknown command
[29] NVAR m_add, 068 :: Create 'm_add' with value of '68'
[30] NVAR m_sub, 078 :: Create 'm_sub' with value of '78'
[31] NVAR m_div, 088 :: Create 'm_div' with value of '88'
[32] NVAR m_mul, 098 :: Create 'm_mul' with value of '98'
[33] NVAR mode, m_mul :: Create 'mode' with value of '98'
[34] NVAR A, 10 :: Create 'A' with value of '10'
[35] NVAR B, 10 :: Create 'B' with value of '10'
[36] JMP readyjumpback :: Jump to line readyjumpback
[37]
[38] @madd :: Unknown command
[39] SEA A :: Set Accumulator to 'A' (10)
[40] LDX :: Load Accumulator (10) into X
[41] SEA B :: Set Accumulator to 'B' (10)
[42] LDY :: Load Accumulator (10) into Y
[43] ADD :: Add X (10) and Y (10) and store into the Accumulator (20)
[44] STA 8 :: Store the Accumulator (20) into Memory address 8
[45] JMP EOF :: Jump to line EOF
[46]
[47] @msub :: Unknown command
[48] SEA A :: Set Accumulator to 'A' (10)
[49] LDX :: Load Accumulator (10) into X
[50] SEA B :: Set Accumulator to 'B' (10)
[51] LDY :: Load Accumulator (10) into Y
[52] SUB :: Subtract Y (10) from X (10) and store into the Accumulator (0)
[53] STA 8 :: Store the Accumulator (0) into Memory address 8
[54] JMP EOF :: Jump to line EOF
[55]
[56] @mmul :: Unknown command
[57] SEA A :: Set Accumulator to 'A' (10)
[58] LDX :: Load Accumulator (10) into X
[59] SEA B :: Set Accumulator to 'B' (10)
[60] LDY :: Load Accumulator (10) into Y
[61] MUL :: Multiply X (10) and Y (10) and store into the Accumulator (100)
[62] STA 8 :: Store the Accumulator (100) into Memory address 8
[63] JMP EOF :: Jump to line EOF
[64]
[65] @mdiv :: Unknown command
[66] SEA A :: Set Accumulator to 'A' (10)
[67] LDX :: Load Accumulator (10) into X
[68] SEA B :: Set Accumulator to 'B' (10)
[69] LDY :: Load Accumulator (10) into Y
[70] DIV :: Divide X (10) by Y (10) and store into the Accumulator (1)
[71] STA 8 :: Store the Accumulator (1) into Memory address 8
[72] JMP EOF :: Jump to line EOF
[73]
[74] @parse :: Unknown command
[75] SEA mode :: Set Accumulator to 'mode' (98)
[76] LDX :: Load Accumulator (98) into X
[77] SEA m_add :: Set Accumulator to 'm_add' (68)
[78] LDY :: Load Accumulator (68) into Y
[79] GIE :: Get if X (98) is equal to Y (68)
[80] JIE madd :: Unknown command
[81] SEA mode :: Set Accumulator to 'mode' (98)
[82] LDX :: Load Accumulator (98) into X
[83] SEA m_sub :: Set Accumulator to 'm_sub' (78)
[84] LDY :: Load Accumulator (78) into Y
[85] GIE :: Get if X (98) is equal to Y (78)
[86] JIE msub :: Unknown command
[87] SEA mode :: Set Accumulator to 'mode' (98)
[88] LDX :: Load Accumulator (98) into X
[89] SEA m_mul :: Set Accumulator to 'm_mul' (98)
[90] LDY :: Load Accumulator (98) into Y
[91] GIE :: Get if X (98) is equal to Y (98)
[92] JIE mmul :: Unknown command
[93] SEA mode :: Set Accumulator to 'mode' (98)
[94] LDX :: Load Accumulator (98) into X
[95] SEA m_div :: Set Accumulator to 'm_div' (88)
[96] LDY :: Load Accumulator (88) into Y
[97] GIE :: Get if X (98) is equal to Y (88)
[98] JIE mdiv :: Unknown command
[99] JMP EOF :: Jump to line EOF
[100]
[101] @EOF :: Unknown command
[102] PRM 8 :: Print value of memory address 8
[103] HLT :: Halt execution
+9 -1
View File
@@ -1,2 +1,10 @@
:: variables
NVAR
NVAR m_add, 1
NVAR m_sub, 2
NVAR m_mul, 3
NVAR m_div, 4
NVAR mode, m_add
SEA mode
STA 0
PRM 0
HLT
Binary file not shown.
Binary file not shown.