added more instructuioins
This commit is contained in:
+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++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user