added more instructuioins
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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})";
|
||||
|
||||
@@ -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
|
||||
|
||||
+87
-68
@@ -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);
|
||||
while (pointer < lines.Length)
|
||||
|
||||
// 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.
Reference in New Issue
Block a user