Esempio n. 1
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. 2
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. 3
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. 4
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. 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 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. 7
0
        public void Print(ProgramReader reader)
        {
            Pointer ptr = new Pointer(Processor.MMU)
            {
                Value = reader.NextPtr()
            };

            string str = ptr.GetString();

            Console.WriteLine(str);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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. 10
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. 11
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());
        }