Exemple #1
0
 public static int DebugPrint(QDVMthread thr)
 {
     CheckLowStack(thr.st, 1);
     Console.Write("[{0}]", StkQDVM.ThrId);
     Console.WriteLine(GetStrArg(thr));
     return(0);
 }
Exemple #2
0
        static int EraseStar(QDVMthread thr)
        {
            int y = thr.st.Pop();
            int x = thr.st.Pop();

            frm.ErasePix(x, y);
            return(0);
        }
Exemple #3
0
        public static int KickThread(QDVMthread thr)
        {
            CheckLowStack(thr.st, 1);
            int i = thr.st.Pop();

            StkQDVM.Threads[i].Kick();
            return(0);
        }
Exemple #4
0
        public static int Sleep(QDVMthread thr)
        {
            CheckLowStack(thr.st, 1);
            int SleepTime = thr.st.Pop();

            System.Threading.Thread.Sleep(SleepTime);
            return(0);
        }
Exemple #5
0
        public void Init(string dir)
        {
            BaseDir = dir;
            QDVMthread tr0 = new QDVMthread();

            tr0.Load("main.qdm");
            Threads[0] = tr0;
            tr0.Kick();
        }
Exemple #6
0
 public static int DoEvents(QDVMthread thr)
 {
     System.Windows.Forms.Application.DoEvents();
     if (System.Windows.Forms.Application.OpenForms.Count < 1)
     {
         return(1);
     }
     return(0);
 }
Exemple #7
0
        static int DrawStar(QDVMthread thr)
        {
            int y     = thr.st.Pop();
            int x     = thr.st.Pop();
            int stage = thr.st.Pop();

            frm.DrawPix3(x, y, stage);
            frm.Refresh();
            return(0);
        }
Exemple #8
0
        protected static string GetStrArg(QDVMthread thr)
        {
            int    addr = thr.st.Pop();
            String str  = "";

            while (thr.code[addr] != 0)
            {
                str += Convert.ToChar(thr.code[addr++]);
            }
            return(str);
        }
Exemple #9
0
        public static int KillThread(QDVMthread thr)
        {
            CheckLowStack(thr.st, 1);
            int ThrID = thr.st.Pop();

            if (StkQDVM.Threads[ThrID] != null)
            {
                StkQDVM.Threads[ThrID] = null;
            }
            return(0);
        }
Exemple #10
0
        public static int NameThread(QDVMthread thr)
        {
            CheckLowStack(thr.st, 2);
            int i = thr.st.Pop();

            if (StkQDVM.Threads[i] == null)
            {
                throw new Exception("Dead thread id was given into a syscall");
            }
            StkQDVM.Threads[i].id = GetStrArg(thr);
            return(0);
        }
Exemple #11
0
 public static int CreateThread(QDVMthread thr)
 {
     CheckLowStack(thr.st, 1);
     for (int i = 0; i < QDVMdef.MAX_THRD_COUNT; i++)
     {
         if (StkQDVM.Threads[i] == null)
         {
             StkQDVM.Threads[i] = new QDVMthread();
             String CodeFile = GetStrArg(thr);
             StkQDVM.Threads[i].Load(CodeFile);
             return(i);
         }
     }
     return(-1);
 }
Exemple #12
0
        public static int SendMessage(QDVMthread thr)
        {
            CheckLowStack(thr.st, 3);
            int     addr  = thr.st.Pop();
            int     MsgID = thr.st.Pop();
            int     ThrID = thr.st.Pop();
            QDVMmsg msg   = new QDVMmsg();

            msg.ThrID = ThrID;
            msg.MsgID = MsgID;
            for (int i = 0; i < QDVMdef.MSG_DATA_SIZE; i++, addr++)
            {
                msg.Data[i] = thr.code[addr];
            }
            StkQDVM.Messages.Add(msg);
            return(0);
        }
Exemple #13
0
 public void Run()
 {
     do
     {
         for (ThrId = 0; ThrId < QDVMdef.MAX_THRD_COUNT; ThrId++)
         {
             CurThr = Threads[ThrId];
             if (CurThr == null)
             {
                 continue;
             }
             if (CurThr.state == QDThrState.NEW)
             {
                 continue;
             }
             CurThr.state = QDThrState.RUN;
             for (int c = 0; c < QDVMdef.FRAME_TICKS; c++)
             {
                 Executor(CurThr);
                 if (PrintStack)
                 {
                     Console.Write("[{0}]:", ThrId);
                     foreach (int num in CurThr.st)
                     {
                         Console.Write("{0}->", num);
                     }
                     Console.WriteLine();
                     //Console.ReadLine();
                 }
                 if (CurThr.state != QDThrState.RUN)
                 {
                     break;
                 }
             }
             if (CurThr.state == QDThrState.FROZEN)
             {
                 CurThr.state = QDThrState.WAIT;
             }
         }
         if (Threads[0] == null)
         {
             break;
         }
     }while (true);
 }
Exemple #14
0
        public static int FindThread(QDVMthread thr)
        {
            CheckLowStack(thr.st, 1);
            String Name = GetStrArg(thr);

            for (int i = 0; i < QDVMdef.MAX_THRD_COUNT; i++)
            {
                if (StkQDVM.Threads[i] == null)
                {
                    continue;
                }
                if (StkQDVM.Threads[i].id.Equals(Name))
                {
                    return(i);
                }
            }
            return(-1);
        }
Exemple #15
0
        public static int GetMessage(QDVMthread thr)
        {
            CheckLowStack(thr.st, 2);
            int     AddrData  = thr.st.Pop();
            int     AddrMsgID = thr.st.Pop();
            QDVMmsg msg       = StkQDVM.Messages.Find(delegate(QDVMmsg mess)
            {
                return(mess.ThrID == StkQDVM.ThrId);
            });

            if (msg == null)
            {
                return(0);
            }
            thr.code[AddrData] = (byte)msg.MsgID;
            for (int i = 0; i < QDVMdef.MSG_DATA_SIZE; i++, AddrMsgID++)
            {
                thr.code[AddrMsgID] = msg.Data[i];
            }
            return(1);
        }
Exemple #16
0
        void Executor(QDVMthread thr)
        {
            byte[] opcodes;
            opcodes = thr.code;

            try {
                switch (opcodes[thr.ip++])
                {
                case QDVMoc.VM_NOP: break;

                case QDVMoc.VM_LDB: QDVMoc.LDb(thr.st, opcodes, opcodes[thr.ip++]); break;

                case QDVMoc.VM_LDI: QDVMoc.LDi(thr.st, opcodes, opcodes[thr.ip++]); break;

                case QDVMoc.VM_LSB: thr.st.Push(opcodes[thr.ip++]); break;

                case QDVMoc.VM_LSI: QDVMoc.LDi(thr.st, opcodes, thr.ip); thr.ip += 4; break;

                case QDVMoc.VM_LDV: QDVMoc.LDv(thr.st, thr.vars, opcodes[thr.ip++]); break;

                case QDVMoc.VM_STV: QDVMoc.STv(thr.st, thr.vars, opcodes[thr.ip++]); break;

                case QDVMoc.VM_ADD: QDVMoc.Add(thr.st); break;

                case QDVMoc.VM_SUB: QDVMoc.Sub(thr.st); break;

                case QDVMoc.VM_MUL: QDVMoc.Mul(thr.st); break;

                case QDVMoc.VM_DIV: QDVMoc.Div(thr.st); break;

                case QDVMoc.VM_MOD: QDVMoc.Mod(thr.st); break;

                case QDVMoc.VM_INC: thr.st.Push(1); QDVMoc.Add(thr.st); break;

                case QDVMoc.VM_DEC: thr.st.Push(1); QDVMoc.Sub(thr.st); break;

                case QDVMoc.VM_JEQ:
                case QDVMoc.VM_JNE:
                case QDVMoc.VM_JGE:
                case QDVMoc.VM_JGR:
                case QDVMoc.VM_JLE:
                case QDVMoc.VM_JLS:
                case QDVMoc.VM_JMP:
                case QDVMoc.VM_JZ:
                case QDVMoc.VM_JNZ:
                    thr.ip = QDVMoc.GetJump(thr.st, opcodes, thr.ip);
                    break;

                case QDVMoc.VM_RND: QDVMoc.GetRandom(thr.st); break;

                case QDVMoc.VM_CLK: thr.st.Push((int)(DateTime.Now.ToFileTime() / 10000L)); break;

                case QDVMoc.VM_HLT: thr.state = QDThrState.FROZEN; break;

                case QDVMoc.VM_POP: thr.st.Pop(); break;

                case QDVMoc.VM_DUP: thr.st.Push(thr.st.Peek()); break;

                case QDVMoc.VM_SWP: int a, b;
                    a = thr.st.Pop(); b = thr.st.Pop();
                    thr.st.Push(a); thr.st.Push(b); break;

                case QDVMoc.VM_SCL: thr.st.Push(Syscalls[opcodes[thr.ip++]](thr)); break;

                case QDVMoc.VM_CAL: int addr = QDVMhlp.GetJmpAddr(opcodes[thr.ip], opcodes[thr.ip + 1]);
                    thr.rs.Push(thr.ip + 2);
                    thr.ip = addr;
                    break;

                case QDVMoc.VM_RET: if (thr.rs.Count > 0)
                    {
                        thr.ip = thr.rs.Pop();
                    }
                    else
                    {
                        if (thr.state == QDThrState.NEW)
                        {
                            thr.state = QDThrState.FROZEN;
                        }
                        else
                        {
                            thr.state = QDThrState.DEAD;
                        }
                    } break;

                default: throw new Exception(String.Format("Opcode {0} not implemented", opcodes[thr.ip - 1]));
                }
            } catch (Exception ex) {
                //Console.Out.WriteLine(ex.StackTrace);
                throw new Exception(String.Format("{0} at [{1}]:{2}", ex.Message, ThrId, thr.ip - 1));
            }
            if (thr.state == QDThrState.DEAD)
            {
                Threads[ThrId] = null;
            }
        }
Exemple #17
0
 static int GetBounds(QDVMthread thr)
 {
     thr.st.Push(Screen.PrimaryScreen.Bounds.Width);
     thr.st.Push(Screen.PrimaryScreen.Bounds.Height);
     return(0);
 }