Esempio n. 1
0
        public static int FunctionStart(Processor proc, ProgramReader reader)
        {
            proc.Stack.Push(proc.FunctionToCall);
            proc.FunctionToCall = null;

            return(reader.Elapsed());
        }
Esempio n. 2
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. 3
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. 4
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. 5
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. 6
0
        public static int FunctionPop(Processor proc, ProgramReader reader)
        {
            StackContainer c = proc.Stack.Peek();

            proc.MMU.Free(c.Memory);
            proc.Stack.Pop();

            return(reader.Elapsed());
        }
Esempio n. 7
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. 8
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. 9
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. 10
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. 11
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. 12
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. 13
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. 14
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. 15
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. 16
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. 17
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. 18
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. 19
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. 20
0
 public static int Brk(Processor proc, ProgramReader reader)
 {
     return(reader.Elapsed());
 }
Esempio n. 21
0
 public static int ModulusConst(Processor proc, ProgramReader reader)
 {
     throw new NotImplementedException();
     return(reader.Elapsed());
 }
Esempio n. 22
0
        public static int AssignPtrCarry(Processor proc, ProgramReader reader)
        {
            proc.Registers.PtrCarry = true;

            return(reader.Elapsed());
        }
Esempio n. 23
0
        public static int Exit(Processor proc, ProgramReader reader)
        {
            proc.Running = false;

            return(reader.Elapsed());
        }