public static int FunctionStart(Processor proc, ProgramReader reader) { proc.Stack.Push(proc.FunctionToCall); proc.FunctionToCall = null; return(reader.Elapsed()); }
public static int Cast(Processor proc, ProgramReader reader) { TypeFlag returnType = (TypeFlag)reader.NextInt(); uint addr = reader.NextPtr(); object v1 = BytesToNative(proc.Registers.TypeRegisters[0], proc.Registers.OperationRegisters[0]); byte[] b = null; switch (returnType) { case TypeFlag.Char: v1 = Conversions.ToChar(v1); break; case TypeFlag.Int: v1 = Conversions.ToInteger(v1); break; case TypeFlag.Float: v1 = Conversions.ToSingle(v1); break; } b = Convert(v1, returnType); MemoryWriter w = MemoryWriter.GetWriter(2, proc, addr); w.Write(b); return(reader.Elapsed()); }
public void ReadInt(ProgramReader reader) { string str = Console.ReadLine(); int value = Int32.Parse(str); Processor.Registers.SetReturnCarry(value); }
public static int Jump(Processor proc, ProgramReader reader) { int addr = reader.NextInt(); proc.ActiveStackContainer.ProgramCounter = addr; proc.Registers.JumpCarry = true; return(0); }
public static int AssignTypeRegister(Processor proc, ProgramReader reader) { int id = reader.NextInt(); int flag = reader.NextInt(); proc.Registers.TypeRegisters[id] = (TypeFlag)flag; return(reader.Elapsed()); }
public static int AssignTargetRegister(Processor proc, ProgramReader reader) { int id = reader.NextInt(); byte flag = reader.NextByte(); proc.Registers.TargetRegisters[id] = (TargetFlag)flag; return(reader.Elapsed()); }
public void Rand(ProgramReader reader) { int min = reader.NextInt(); int max = reader.NextInt(); min = GetRand().Next(min, max + 1); Processor.Registers.SetReturnCarry(min); }
public void Test(ProgramReader reader) { int a = reader.NextInt(); int b = reader.NextInt(); int c = reader.NextInt(); a = a + b + c; LibraryHandler.GetResource <Processor>().Registers.SetReturnCarry(a); }
public static int FunctionPop(Processor proc, ProgramReader reader) { StackContainer c = proc.Stack.Peek(); proc.MMU.Free(c.Memory); proc.Stack.Pop(); return(reader.Elapsed()); }
public static int AssignConditionRegister(Processor proc, ProgramReader reader) { int id = reader.NextInt(); uint ptr = reader.NextPtr(); Array.Copy(proc.ActiveStackContainer.Memory.Memory, ptr, proc.Registers.ConditionRegisters[id], 0, Defines.SIZE_INT); return(reader.Elapsed()); }
public static int AssignReturnCarry(Processor proc, ProgramReader reader) { uint ptr = reader.NextPtr(); int size = reader.NextInt(); Array.Copy(proc.Registers.ReturnCarry, 0, proc.ActiveStackContainer.Memory.Memory, ptr, size); return(reader.Elapsed()); }
public static int SetReturnCarry(Processor proc, ProgramReader reader) { int size = reader.NextInt(); byte[] value = reader.NextArray(size); Array.Copy(value, 0, proc.Registers.ReturnCarry, 0, size); return(reader.Elapsed()); }
public static int AssignStaticConditionRegister(Processor proc, ProgramReader reader) { int id = reader.NextInt(); byte[] value = reader.NextArray(Defines.SIZE_INT); Array.Copy(value, 0, proc.Registers.ConditionRegisters[id], 0, Defines.SIZE_INT); return(reader.Elapsed()); }
public void Decompile(byte[] program, string output) { Reader = new ProgramReader(program, 0); ReadFunctionTable(); ReadSymbolsTable(); ReadProgram(); Output.WriteFile(output); }
public static int FunctionCall(Processor proc, ProgramReader reader) { int fctId = reader.NextInt(); int idx = proc.Functions[fctId]; int size = proc.GetFunctionStackSize(fctId); proc.FunctionToCall = new StackContainer(proc.MMU.Alloc(size), idx + Defines.SIZE_INT); return(reader.Elapsed()); }
public static int AssignConstOperationRegister(Processor proc, ProgramReader reader) { int id = reader.NextInt(); int size = reader.NextInt(); byte[] value = reader.NextArray(size); proc.Registers.OperationRegisters[id] = value; return(reader.Elapsed()); }
public static int VarConstCopy(Processor proc, ProgramReader reader) { int size = reader.NextInt(); byte[] from = reader.NextArray(size); uint to = reader.NextPtr(); Array.Copy(from, 0, proc.FunctionToCall.Memory.Memory, to, size); return(reader.Elapsed()); }
public static int VarFctCopy(Processor proc, ProgramReader reader) { int size = reader.NextInt(); uint from = reader.NextPtr(); uint to = reader.NextPtr(); StackContainer c = proc.Stack.Peek(); Array.Copy(c.Memory.Memory, from, proc.FunctionToCall.Memory.Memory, to, size); return(reader.Elapsed()); }
public void Print(ProgramReader reader) { Pointer ptr = new Pointer(Processor.MMU) { Value = reader.NextPtr() }; string str = ptr.GetString(); Console.WriteLine(str); }
public void run() { Console.WriteLine("0.0.1V use with caution..."); while (!exit) { Console.Write("RMCMD>"); string[] t = (Console.ReadLine()).Split(' '); if (File.Exists(t[0])) { if (t.Length > 1) { if (t[1] == "d") { cpu.setDebug(true); } else { cpu.setDebug(false); } } else { cpu.setDebug(false); } cpu.resetVM(); ProgramReader tmp = new ProgramReader(t[0], 16 * 16); cpu.getMemory().newPaging(tmp.getMemory()); VirtualMachine vm = new VirtualMachine(cpu, cpu.getDebug()); vm.run(); } else if (t[0] == "exit") { exit = true; } else if (t[0] == "cls" || t[0] == "clear") { Console.Clear(); } else if (t[0] == "pm") { cpu.memory.printMemory(); } else if (t[0] == "alloc" && t.Length > 1) { cpu.memory.allocateBlock(Convert.ToInt32(t[1])); } else { Console.WriteLine("File/Command \"" + t[0] + "\" not found!"); } } }
public static int Set(Processor proc, ProgramReader reader) { int sourceSize = reader.NextInt(); byte[] source = reader.NextArray(sourceSize); uint dest = reader.NextPtr(); MemoryReader r = MemoryReader.GetReader(0, proc, source, sourceSize); MemoryWriter w = MemoryWriter.GetWriter(1, proc, dest); w.Write(r.Data); return(reader.Elapsed()); }
public static int LibCall(Processor proc, ProgramReader reader) { int size = reader.NextInt(); int libNameSize = reader.NextInt(); int fctNameSize = reader.NextInt(); byte[] lib = reader.NextArray(libNameSize); byte[] fct = reader.NextArray(fctNameSize); string l = Encoding.ASCII.GetString(lib); string f = Encoding.ASCII.GetString(fct); proc.FunctionToCall = new LibStackContainer(l, f, proc.MMU.Alloc(size)); return(reader.Elapsed()); }
public static int AssignOperationRegister(Processor proc, ProgramReader reader) { int id = reader.NextInt(); int size = reader.NextInt(); byte[] ptr = reader.NextArray(Defines.SIZE_PTR); byte[] reg = new byte[size]; MemoryReader r = MemoryReader.GetReader(id, proc, ptr, Defines.SIZE_PTR); Array.Copy(r.Data, 0, reg, 0, size); proc.Registers.OperationRegisters[id] = reg; return(reader.Elapsed()); }
public static int AssignToPointer(Processor proc, ProgramReader reader) { uint source = reader.NextPtr(); int size = reader.NextInt(); uint dest = reader.NextPtr(); byte[] toCopy = new byte[size]; dest = proc.MMU.ReadPtr(dest); Array.Copy(proc.ActiveStackContainer.Memory.Memory, source, toCopy, 0, size); proc.MMU.WriteBytes(toCopy, dest); return(reader.Elapsed()); }
public static int If(Processor proc, ProgramReader reader) { ConditionFlag flag = (ConditionFlag)reader.NextInt(); uint address = reader.NextPtr(); int a = BitConverter.ToInt32(proc.Registers.ConditionRegisters[0]); int b = BitConverter.ToInt32(proc.Registers.ConditionRegisters[1]); bool result = ConditionChecker(flag, a, b); if (result) { proc.ActiveStackContainer.ProgramCounter = (int)address; proc.Registers.JumpCarry = true; return(0); } return(reader.Elapsed()); }
public static int AssignStatic(Processor proc, ProgramReader reader) { uint ptr = reader.NextPtr(); int size = reader.NextInt(); byte[] toCopy = reader.NextArray(size); if (proc.Registers.PtrCarry) { int a = BitConverter.ToInt32(toCopy) + proc.ActiveStackContainer.Memory.Start; toCopy = BitConverter.GetBytes(a); proc.Registers.PtrCarry = false; } Array.Copy(toCopy, 0, proc.ActiveStackContainer.Memory.Memory, ptr, size); return(reader.Elapsed()); }
public void FormatString(ProgramReader reader) { Pointer ptr = new Pointer(Processor.MMU) { Value = reader.NextPtr() }; string str = ptr.GetString(); Regex r = new Regex(@"\{%[d,s,f]}"); MatchCollection matches = r.Matches(str); foreach (Match match in matches) { object obj = null; if (match.Value == "{%d}") { obj = reader.NextInt(); } if (match.Value == "{%f}") { obj = reader.NextFloat(); } if (match.Value == "{%s}") { obj = new Pointer(Processor.MMU) { Value = reader.NextPtr() }.GetString(); } str = ReplaceFirst(str, match.Value, obj.ToString()); } RangeContainer c = Processor.MMU.Alloc(str.Length + 1); c.Write(str); Processor.Registers.SetReturnCarry(c.Start); }
public void Invoke(ProgramReader reader, string method) { StackReader = reader; Methods[method](reader); }
public void Invoke(ProgramReader reader, string lib, string method) { LoadedLibraries.First(i => i.Library.Name == lib).Invoke(reader, method); }
public static int AssignPtrCarry(Processor proc, ProgramReader reader) { proc.Registers.PtrCarry = true; return(reader.Elapsed()); }