Esempio n. 1
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());
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void Rand(ProgramReader reader)
        {
            int min = reader.NextInt();
            int max = reader.NextInt();

            min = GetRand().Next(min, max + 1);

            Processor.Registers.SetReturnCarry(min);
        }
Esempio n. 4
0
        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());
        }
Esempio n. 5
0
        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());
        }
Esempio n. 6
0
        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());
        }
Esempio n. 7
0
        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());
        }
Esempio n. 8
0
        public static int Jump(Processor proc, ProgramReader reader)
        {
            int addr = reader.NextInt();

            proc.ActiveStackContainer.ProgramCounter = addr;
            proc.Registers.JumpCarry = true;
            return(0);
        }
Esempio n. 9
0
        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());
        }
Esempio n. 10
0
        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());
        }
Esempio n. 11
0
        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());
        }
Esempio n. 12
0
        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());
        }
Esempio n. 13
0
        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());
        }
Esempio n. 14
0
        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());
        }
Esempio n. 15
0
        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());
        }
Esempio n. 16
0
        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());
        }
Esempio n. 17
0
        public void ReadProgram()
        {
            int fctId = 0;

            while (!Reader.IsOver())
            {
                int idx        = Reader.GetCounter();
                int checkIndex = Reader.GetCounter() - (Defines.SIZE_INT * (FuncsIdx.Count + 1));

                if (FuncsIdx.Contains(checkIndex))
                {
                    Output.OutputFunctionStart(idx - Defines.SIZE_INT * (FuncsIdx.Count + 1), fctId++, Reader.NextInt());
                }
                else
                {
                    OPCodes.Codes code = (OPCodes.Codes)Reader.NextInt();
                    List <string> args = ExtractArgs(code);

                    Output.OutputInstruction(idx - Defines.SIZE_INT * (FuncsIdx.Count + 1), code, args);
                }
            }
        }
Esempio n. 18
0
        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());
        }
Esempio n. 19
0
        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());
        }
Esempio n. 20
0
        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());
        }
Esempio n. 21
0
        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());
        }
Esempio n. 22
0
        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);
        }