/// <summary> /// Goes to a label (Arg1). /// </summary> /// <param name="Args">An int that specifies the address to go to.</param> public static void Goto(ref ScriptArguments Args) { var Thread = Args.GetThread(); int Arg1 = Args.GetIntParameter(0); Thread.ProgramCounter = (uint)(Arg1 < 0 ? Thread.BaseAddress - Arg1 : Arg1); }
/// <summary> /// Waits for a specified number of millisecs. /// Opcode: 0001 /// </summary> /// <param name="Args">An instance of ScriptArguments.</param> public static void Wait(ref ScriptArguments Args) { int Time = Args.GetIntParameter(0); Debug.Assert(Time >= 0, "negative wait time is not supported"); var Thread = Args.GetThread(); // Scripts use wait 0 to yield Thread.WakeCounter = Time > 0 ? Time : -1; }
/// <summary> /// Starts a new thread on the ScriptMachine. /// </summary> /// <param name="Args">A ScriptArguments instance.</param> public static void StartThread(ref ScriptArguments Args) { Args.GetVM().StartThread((uint)Args.GetIntParameter(0), false); var Threads = Args.GetVM().GetThreads(); SCMThread Thread = Threads[Threads.Count - 1]; var Locals = Thread.Locals.ToArray(); // Copy arguments to locals for (var i = 1u; i < Args.GetParameters().Count; ++i) { if (Args[i].Type == SCMType.EndOfArgList) { break; } /**reinterpret_cast<ScriptInt*>(Thread.Locals.ToArray() + * sizeof(int) * (i - 1)) = args[i].integerValue();*/ byte[] SrcInt = BitConverter.GetBytes(Args[i].IntegerValue()); Array.Copy(SrcInt, 0, Locals, sizeof(int) * (i - 1), SrcInt.Length - 1); Thread.Locals.AddRange(Locals); } }