Esempio n. 1
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. 2
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. 3
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. 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 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. 6
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. 7
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. 8
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. 9
0
        public List <string> ExtractArgs(OPCodes.Codes code)
        {
            List <string> args = new List <string>();
            List <int>    read = new List <int>();

            if (!Args.ContainsKey(code))
            {
                args.Add("Unknown OP code");
            }

            ArgumentType[] toExtract = Args.ContainsKey(code) ? Args[code] : new ArgumentType[] {};

            foreach (ArgumentType i in toExtract)
            {
                int    size  = 0;
                byte[] bytes = null;

                if (i.IsStatic())
                {
                    bytes = Reader.NextArray(i.Size);
                    size  = i.Size;

                    try
                    {
                        read.Add(BitConverter.ToInt32(bytes));
                    }
                    catch (Exception e)
                    {
                        read.Add(-1);
                    }
                }
                else
                {
                    bytes = Reader.NextArray(read[i.Idx]);
                    size  = read[i.Idx];
                    read.Add(size);
                }



                if (i is Int)
                {
                    args.Add("INT[" + BitConverter.ToInt32(bytes) + "]");
                }

                if (i is Ptr)
                {
                    args.Add("PTR[" + BitConverter.ToInt32(bytes) + "]");
                }

                if (i is Array)
                {
                    List <string> strs = new List <string>();

                    foreach (byte b in bytes)
                    {
                        strs.Add(b.ToString());
                    }

                    args.Add("ARRAY[" + String.Join(", ", strs) + "]");
                }

                if (i is CharArray)
                {
                    List <byte> strs = new List <byte>();

                    foreach (byte b in bytes)
                    {
                        strs.Add(b);
                    }

                    args.Add("STRING[" + Encoding.ASCII.GetString(strs.ToArray()) + "]");
                }

                if (i is ConditionFlag)
                {
                    args.Add(i.As <ConditionFlag>().GetFlag(BitConverter.ToInt32(bytes)));
                }

                if (i is TypeFlag)
                {
                    args.Add(i.As <TypeFlag>().GetFlag(BitConverter.ToInt32(bytes)));
                }

                if (i is TargetFlag)
                {
                    args.Add(i.As <TargetFlag>().GetFlag(bytes[0]));
                }
            }

            return(args);
        }