Example #1
0
        public override void Undo(BHAV bhav, UIBHAVEditor editor)
        {
            var tree = editor.GetSavableTree();

            if (TrueBranch)
            {
                if (InstUI.Instruction != null)
                {
                    InstUI.Instruction.TruePointer = (OldDestUI == null) ? (byte)253 : OldDestUI.InstPtr;
                }
                InstUI.TrueUI = OldDestUI;
                InstUI.TreeBox.TruePointer = (OldDestUI == null) ? (short)-1 : OldDestUI.TreeBox.InternalID;
            }
            else
            {
                if (InstUI.Instruction != null)
                {
                    InstUI.Instruction.FalsePointer = (OldDestUI == null) ? (byte)253 : OldDestUI.InstPtr;
                }
                InstUI.FalseUI = OldDestUI;
                InstUI.TreeBox.FalsePointer = (OldDestUI == null) ? (short)-1 : OldDestUI.TreeBox.InternalID;
            }

            if (InstUI.Type == TREEBoxType.Label)
            {
                editor.BHAVView.UpdateLabelPointers(InstUI.TreeBox.InternalID);
            }

            Content.Content.Get().Changes.ChunkChanged(bhav);
            FSO.SimAntics.VM.BHAVChanged(bhav);
            Content.Content.Get().Changes.ChunkChanged(tree);
        }
Example #2
0
        public virtual VMRoutine Assemble(BHAV bhav)
        {
            var routine = new VMRoutine();

            PopulateRoutineFields(bhav, routine);
            return(routine);
        }
Example #3
0
        private void SelectStackFrame(int forceFrame)
        {
            if (forceFrame == -1 && StackView.SelectedItems.Count == 0)
            {
                return;
            }
            var frame = DebugEntity.Thread.Stack[(forceFrame != -1) ? forceFrame:StackView.Items.IndexOf(StackView.SelectedItems[0])];

            if (bhav != null && bhav.ChunkID == frame.Routine.Chunk.ChunkID && frame == Editor.DebugFrame)
            {
                return;
            }
            SetActivePrimitive(null);
            this.bhav          = frame.Routine.Chunk;
            Scope              = new EditorScope(frame.CodeOwner, frame.Routine.Chunk);
            Scope.CallerObject = DebugEntity.Object;
            Scope.StackObject  = (frame.StackObject == null)?null:frame.StackObject.Object;

            EditorControl.InitBHAV(bhav, Scope, DebugEntity, frame, SelectionChanged);

            ObjectDataGrid.SelectedObject = new PropGridVMData(Scope, DebugEntity, frame, Editor);
            ObjectDataGrid.Refresh();

            PrimGroupChange(AllBtn, null);
        }
 public override void Undo(BHAV bhav, UIBHAVEditor editor)
 {
     if (Primitive.Type != TREEBoxType.Primitive)
     {
         //do nothing.
     }
     else
     {
         bhav.Instructions[0]      = Old0.Instruction;
         bhav.Instructions[OldPtr] = Primitive.Instruction;
         // TODO
         //Primitive.InstPtr = OldPtr;
         //Old0.InstPtr = 0;
         foreach (var prim in FromTrue)
         {
             prim.Instruction.TruePointer = OldPtr;
         }
         foreach (var prim in FromFalse)
         {
             prim.Instruction.FalsePointer = OldPtr;
         }
         foreach (var prim in FromTrue0)
         {
             prim.Instruction.TruePointer = 0;
         }
         foreach (var prim in FromFalse0)
         {
             prim.Instruction.FalsePointer = 0;
         }
         Content.Content.Get().Changes.ChunkChanged(bhav);
         FSO.SimAntics.VM.BHAVChanged(bhav);
     }
 }
Example #5
0
        public override void Undo(BHAV bhav, UIBHAVEditor editor)
        {
            var tree = editor.GetSavableTree();

            if (NewPrimitive.Type != TREEBoxType.Primitive)
            {
                if (NewPrimitive.TreeBox.InternalID != -1)
                {
                    tree.DeleteBox(NewPrimitive.TreeBox);
                }
                editor.BHAVView.Primitives.Remove(NewPrimitive);
                editor.BHAVView.Remove(NewPrimitive);
            }
            else
            {
                //primitive we added should be at the end
                var newInst = new BHAVInstruction[bhav.Instructions.Length - 1];
                for (int i = 0; i < newInst.Length; i++)
                {
                    newInst[i] = bhav.Instructions[i];
                }

                bhav.Instructions = newInst;
                editor.BHAVView.RemovePrimitive(NewPrimitive);
                Content.Content.Get().Changes.ChunkChanged(bhav);
                FSO.SimAntics.VM.BHAVChanged(bhav);
            }
            Content.Content.Get().Changes.ChunkChanged(tree);
        }
Example #6
0
        public void Load(VMQueuedActionMarshal input, VMContext context)
        {
            CodeOwner = FSO.Content.Content.Get().WorldObjects.Get(input.CodeOwnerGUID);

            BHAV bhav = null;

            if (input.RoutineID >= 8192)
            {
                bhav = CodeOwner.Resource.SemiGlobal.Get <BHAV>(input.RoutineID);
            }
            else if (input.RoutineID >= 4096)
            {
                bhav = CodeOwner.Resource.Get <BHAV>(input.RoutineID);
            }
            else
            {
                bhav = context.Globals.Resource.Get <BHAV>(input.RoutineID);
            }
            Routine = context.VM.Assemble(bhav);

            Callee            = context.VM.GetObjectById(input.Callee);
            StackObject       = context.VM.GetObjectById(input.StackObject);
            IconOwner         = context.VM.GetObjectById(input.IconOwner);
            Name              = input.Name;
            Args              = input.Args;
            InteractionNumber = input.InteractionNumber;
            Cancelled         = input.Cancelled;
            Priority          = input.Priority;
            Mode              = input.Mode;
            Flags             = input.Flags;
            UID      = input.UID;
            Callback = (input.Callback == null)?null:new VMActionCallback(input.Callback, context);
        }
Example #7
0
        public override void Execute(BHAV bhav, UIBHAVEditor editor)
        {
            if (NewPrimitive.Type != PrimBoxType.Primitive)
            {
                editor.BHAVView.Primitives.Add(NewPrimitive);
                editor.BHAVView.Add(NewPrimitive);
            }
            else
            {
                var newInst = new BHAVInstruction[bhav.Instructions.Length + 1];
                for (int i = 0; i < bhav.Instructions.Length; i++)
                {
                    newInst[i] = bhav.Instructions[i];
                }
                newInst[newInst.Length - 1] = NewPrimitive.Instruction;
                NewPrimitive.InstPtr        = (byte)(newInst.Length - 1);

                bhav.Instructions = newInst;
                editor.BHAVView.AddPrimitive(NewPrimitive);
                NewPrimitive.UpdateDisplay();

                Content.GameContent.Get.Changes.ChunkChanged(bhav);

                SimAntics.VM.BHAVChanged(bhav);
            }
        }
Example #8
0
 public override void Execute(BHAV bhav, UIBHAVEditor editor)
 {
     Prim.Instruction.Operand = NewOp;
     Prim.UpdateDisplay();
     Content.GameContent.Get.Changes.ChunkChanged(bhav);
     SimAntics.VM.BHAVChanged(bhav);
 }
Example #9
0
 public ChangeBHAVCommand(BHAV target, EditorScope scope, VMStackFrame frame, BHAVPrimSelect callback)
 {
     Target         = target;
     TargetScope    = scope;
     Frame          = frame;
     SelectCallback = callback;
 }
Example #10
0
        private void ExecuteSubRoutine(VMStackFrame frame, BHAV bhav, GameIffResource codeOwner, VMSubRoutineOperand args)
        {
            if (bhav == null)
            {
                Pop(VMPrimitiveExitCode.ERROR);
                return;
            }
            System.Diagnostics.Debug.WriteLine("Invoke: " + bhav.ChunkLabel);
            System.Diagnostics.Debug.WriteLine("");

            var routine    = frame.VM.Assemble(bhav);
            var childFrame = new VMStackFrame
            {
                Routine     = routine,
                Caller      = frame.Caller,
                Callee      = frame.Callee,
                CodeOwner   = codeOwner,
                StackObject = frame.StackObject
            };

            childFrame.Args = new short[routine.Arguments];
            for (var i = 0; i < childFrame.Args.Length; i++)
            {
                var argValue = args.Arguments[i];
                if (argValue == -1)
                {
                    /** TODO: Is this the right rule? Maybe a flag decides when to copy from temp? **/
                    argValue = TempRegisters[i];
                }
                childFrame.Args[i] = argValue;
            }
            Push(childFrame);
        }
Example #11
0
        public virtual VMRoutine Assemble(BHAV bhav, GameIffResource res)
        {
            var routine = new VMRoutine();

            PopulateRoutineFields(bhav, routine);
            return(routine);
        }
Example #12
0
        public void ExecuteSubRoutine(VMStackFrame frame, BHAV bhav, GameObject codeOwner, VMSubRoutineOperand args)
        {
            if (bhav == null)
            {
                Pop(VMPrimitiveExitCode.ERROR);
                return;
            }

            var routine    = Context.VM.Assemble(bhav);
            var childFrame = new VMStackFrame
            {
                Routine     = routine,
                Caller      = frame.Caller,
                Callee      = frame.Callee,
                CodeOwner   = codeOwner,
                StackObject = frame.StackObject,
                ActionTree  = frame.ActionTree
            };

            childFrame.Args = new short[(routine.Arguments > 4) ? routine.Arguments : 4];
            for (var i = 0; i < childFrame.Args.Length; i++)
            {
                short argValue = (i > 3) ? (short)-1 : args.Arguments[i];
                if (argValue == -1 && args.UseTemp0)
                {
                    argValue = TempRegisters[i];
                }
                childFrame.Args[i] = argValue;
            }
            Push(childFrame);
        }
Example #13
0
        public void ExecuteSubRoutine(VMStackFrame frame, BHAV bhav, GameIffResource codeOwner, VMSubRoutineOperand args)
        {
            if (bhav == null)
            {
                Pop(VMPrimitiveExitCode.ERROR);
                return;
            }

            var routine    = frame.VM.Assemble(bhav);
            var childFrame = new VMStackFrame
            {
                Routine     = routine,
                Caller      = frame.Caller,
                Callee      = frame.Callee,
                CodeOwner   = codeOwner,
                StackObject = frame.StackObject
            };

            childFrame.Args = new short[4];
            for (var i = 0; i < childFrame.Args.Length; i++)
            {
                var argValue = args.Arguments[i];
                if (argValue == -1)
                {
                    argValue = TempRegisters[i];
                }
                childFrame.Args[i] = argValue;
            }
            Push(childFrame);
        }
Example #14
0
 public override void Execute(BHAV bhav, UIBHAVEditor editor)
 {
     if (Primitive.Type != PrimBoxType.Primitive)
     {
         //do nothing.
     }
     else
     {
         bhav.Instructions[0]      = Primitive.Instruction;
         bhav.Instructions[OldPtr] = Old0.Instruction;
         Primitive.InstPtr         = 0;
         Old0.InstPtr = OldPtr;
         foreach (var prim in FromTrue)
         {
             prim.Instruction.TruePointer = 0;
         }
         foreach (var prim in FromFalse)
         {
             prim.Instruction.FalsePointer = 0;
         }
         foreach (var prim in FromTrue0)
         {
             prim.Instruction.TruePointer = OldPtr;
         }
         foreach (var prim in FromFalse0)
         {
             prim.Instruction.FalsePointer = OldPtr;
         }
         Content.GameContent.Get.Changes.ChunkChanged(bhav);
         SimAntics.VM.BHAVChanged(bhav);
     }
 }
Example #15
0
        public virtual void Load(VMStackFrameMarshal input, VMContext context)
        {
            CodeOwner = FSO.Content.Content.Get().WorldObjects.Get(input.CodeOwnerGUID);

            BHAV bhav = null;

            if (input.RoutineID >= 8192)
            {
                bhav = ScopeResource.SemiGlobal.Get <BHAV>(input.RoutineID);
            }
            else if (input.RoutineID >= 4096)
            {
                bhav = ScopeResource.Get <BHAV>(input.RoutineID);
            }
            else
            {
                bhav = Global.Resource.Get <BHAV>(input.RoutineID);
            }
            Routine = VM.Assemble(bhav);

            InstructionPointer = input.InstructionPointer;
            Caller             = context.VM.GetObjectById(input.Caller);
            Callee             = context.VM.GetObjectById(input.Callee);
            StackObject        = context.VM.GetObjectById(input.StackObject);
            Locals             = input.Locals;
            Args = input.Args;
        }
Example #16
0
        public BHAVEditor OpenEditor(BHAV bhav, GameObject srcobj)
        {
            if (bhav == null)
            {
                return(null);
            }
            BHAVEditor window;

            if (Editors.ContainsKey(bhav))
            {
                window = Editors[bhav];
                var form = (Form)window;
                if (form.WindowState == FormWindowState.Minimized)
                {
                    form.WindowState = FormWindowState.Normal;
                }
                window.Activate();
                return(window);
            }

            window = new BHAVEditor(bhav, new EditorComponent.EditorScope(srcobj, bhav));
            window.Show();
            window.Activate();
            Editors.Add(bhav, window);
            return(window);
        }
Example #17
0
        private void ExecuteInstruction(VMStackFrame frame)
        {
            var instruction = frame.GetCurrentInstruction();
            var opcode      = instruction.Opcode;

            if (opcode >= 256)
            {
                BHAV bhav = null;

                GameObject CodeOwner;
                if (opcode >= 8192)
                {
                    // Semi-Global sub-routine call
                    bhav = frame.ScopeResource.SemiGlobal.Get <BHAV>(opcode);
                }
                else if (opcode >= 4096)
                {
                    // Private sub-routine call
                    bhav = frame.ScopeResource.Get <BHAV>(opcode);
                }
                else
                {
                    // Global sub-routine call
                    //CodeOwner = frame.Global.Resource;
                    bhav = frame.Global.Resource.Get <BHAV>(opcode);
                }

                CodeOwner = frame.CodeOwner;

                var operand = (VMSubRoutineOperand)instruction.Operand;
                ExecuteSubRoutine(frame, bhav, CodeOwner, operand);
                if (Stack.LastOrDefault().GetCurrentInstruction().Breakpoint || ThreadBreak == VMThreadBreakMode.StepIn)
                {
                    Breakpoint(frame);
                    ContinueExecution = false;
                }
                else
                {
                    ContinueExecution = true;
                }
                return;
            }


            var primitive = Context.Primitives[opcode];

            if (primitive == null)
            {
                //throw new Exception("Unknown primitive!");
                HandleResult(frame, instruction, VMPrimitiveExitCode.GOTO_TRUE);
                return;
                //Pop(VMPrimitiveExitCode.ERROR);
            }

            VMPrimitiveHandler handler = primitive.GetHandler();
            var result = handler.Execute(frame, instruction.Operand);

            HandleResult(frame, instruction, result);
        }
Example #18
0
 public override void Undo(BHAV bhav, UIBHAVEditor editor)
 {
     Prim.Instruction.Operand = OldOp;
     Prim.RefreshOperand();
     Prim.UpdateDisplay();
     Content.GameContent.Get.Changes.ChunkChanged(bhav);
     SimAntics.VM.BHAVChanged(bhav);
 }
Example #19
0
        public override void Undo(BHAV bhav, UIBHAVEditor editor)
        {
            var tree = editor.GetSavableTree();

            Box.SetComment(OldComment);
            Box.ApplyBoxPositionCentered();
            NotifyGotos();
            Content.Content.Get().Changes.ChunkChanged(tree);
        }
Example #20
0
 public override void Execute(BHAV bhav, UIBHAVEditor editor)
 {
     Old      = editor.BHAVView.EditTarget;
     OldScope = editor.BHAVView.Scope;
     OldFrame = editor.DebugFrame;
     editor.BHAVView.OnSelectedChanged -= SelectCallback;
     editor.SwitchBHAV(Target, TargetScope, Frame);
     editor.BHAVView.OnSelectedChanged += SelectCallback;
 }
Example #21
0
        public BHAVContainer(BHAV target, EditorScope scope)
        {
            Scope          = scope;
            EditTarget     = target;
            EditTargetTree = scope.ActiveTree;

            Init();
            HitTest = ListenForMouse(new Rectangle(Int32.MinValue / 2, Int32.MinValue / 2, Int32.MaxValue, Int32.MaxValue), new UIMouseEvent(DragMouseEvents));
        }
Example #22
0
        public void UpdateListing()
        {
            InteractionList.Items.Clear();
            TTAToListIndex = new Dictionary <int, int>();
            int i = 0;

            foreach (var entry in ActiveTTAB.Interactions)
            {
                BHAV test   = GetBHAV(entry.TestFunction);
                BHAV action = GetBHAV(entry.ActionFunction);
                InteractionList.Items.Add(
                    new ListViewItem(new string[] { entry.TTAIndex.ToString(),
                                                    (test == null)?"---":test.ChunkLabel,
                                                    (action == null)?"---":action.ChunkLabel }));
                TTAToListIndex.Add((int)entry.TTAIndex, i++);
            }

            var                sortActions = ActiveTTAB.Interactions.OrderBy(x => GetTTA(x.TTAIndex));
            int                prevDepth   = 0;
            TreeNode           curNode     = null;
            TreeNodeCollection curDepth    = PieView.Nodes;
            string             category    = "";

            curDepth.Clear();
            PieToInteraction = new Dictionary <TreeNode, int>();
            foreach (var entry in sortActions)
            {
                BHAV test   = GetBHAV(entry.TestFunction);
                BHAV action = GetBHAV(entry.ActionFunction);
                var  name   = GetTTA(entry.TTAIndex);
                var  split  = name.Split('/');
                var  node   = new TreeNode(split[split.Length - 1] + " (" + entry.TTAIndex.ToString() + " / " +
                                           ((test == null) ? "---" : test.ChunkLabel) + " / " +
                                           ((action == null) ? "---" : action.ChunkLabel) + ")");
                PieToInteraction.Add(node, (int)entry.TTAIndex);

                while (split.Length - 1 < prevDepth || (prevDepth > 0 && category != split[prevDepth - 1]))
                {
                    curNode  = curNode.Parent;
                    category = (curNode == null) ? "" : curNode.Text;
                    curDepth = (curNode == null) ? PieView.Nodes : curNode.Nodes;
                    prevDepth--;
                }

                while (split.Length - 1 > prevDepth)
                {
                    var newName = split[prevDepth++];
                    var newNode = new TreeNode(newName); //add new category
                    category = newName;
                    curDepth.Add(newNode);
                    curNode  = newNode;
                    curDepth = newNode.Nodes;
                }

                curDepth.Add(node);
            }
        }
        public override void Execute(BHAV bhav, UIBHAVEditor editor)
        {
            var tree = editor.GetSavableTree();

            Box.TreeBox.X      = (short)AfterPos.X;
            Box.TreeBox.Y      = (short)AfterPos.Y;
            Box.TreeBox.Width  = (short)AfterSize.X;
            Box.TreeBox.Height = (short)AfterSize.Y;
            Content.Content.Get().Changes.ChunkChanged(tree);
        }
Example #24
0
        public static VMRoutine Assemble(VM vm, BHAV bhav)
        {
            var context = vm.Context;

            var routine = new VMRoutine();

            routine.Locals    = bhav.Locals;
            routine.Arguments = bhav.Args;
            routine.Type      = bhav.Type;
            routine.ID        = bhav.ChunkID;
            routine.Chunk     = bhav;
            routine.VM        = vm;
            routine.Rti       = new VMFunctionRTI {
                Name = bhav.ChunkLabel
            };

            VMInstruction[] instructions = new VMInstruction[bhav.Instructions.Length];
            for (var i = 0; i < bhav.Instructions.Length; i++)
            {
                var bhavInstruction = bhav.Instructions[i];
                var instruction     = new VMInstruction();

                instruction.Index        = (byte)i;
                instruction.Opcode       = bhavInstruction.Opcode;
                instruction.Operand      = null;
                instruction.FalsePointer = bhavInstruction.FalsePointer;
                instruction.TruePointer  = bhavInstruction.TruePointer;
                instruction.Breakpoint   = bhavInstruction.Breakpoint;
                instruction.Function     = routine;

                /** Routine call **/
                if (instruction.Opcode >= 256)
                {
                    var operand = new VMSubRoutineOperand();
                    operand.Read(bhavInstruction.Operand);
                    instruction.Operand = operand;
                }
                else
                {
                    var primitive = context.Primitives[instruction.Opcode];
                    if (primitive != null)
                    {
                        if (primitive.OperandModel != null)
                        {
                            VMPrimitiveOperand operand = (VMPrimitiveOperand)Activator.CreateInstance(primitive.OperandModel);
                            operand.Read(bhavInstruction.Operand);
                            instruction.Operand = operand;
                        }
                    }
                }
                instructions[i] = instruction;
            }
            routine.Instructions = instructions;
            return(routine);
        }
        public override void Undo(BHAV bhav, UIBHAVEditor editor)
        {
            var tree = editor.GetSavableTree();

            Box.TreeBox.X      = (short)BeforePos.X;
            Box.TreeBox.Y      = (short)BeforePos.Y;
            Box.TreeBox.Width  = (short)BeforeSize.X;
            Box.TreeBox.Height = (short)BeforeSize.Y;
            Box.ApplyBoxPositionCentered();
            Content.Content.Get().Changes.ChunkChanged(tree);
        }
Example #26
0
 public static void BHAVChanged(BHAV bhav)
 {
     lock (_Assembled)
     {
         bhav.RuntimeVer++;
         if (_Assembled.ContainsKey(bhav))
         {
             _Assembled.Remove(bhav);
         }
     }
     OnBHAVChange?.Invoke();
 }
Example #27
0
 public VMRoutine Assemble(BHAV bhav)
 {
     lock (_Assembled)
     {
         if (_Assembled.ContainsKey(bhav))
         {
             return(_Assembled[bhav]);
         }
         var routine = VMTranslator.Assemble(this, bhav);
         _Assembled.Add(bhav, routine);
         return(routine);
     }
 }
Example #28
0
        public override void Undo(BHAV bhav, UIBHAVEditor editor)
        {
            if (Primitive.Type != PrimBoxType.Primitive)
            {
                editor.BHAVView.Primitives.Add(Primitive);
                editor.BHAVView.Add(Primitive);
            }
            else
            {
                var  newInst = new BHAVInstruction[bhav.Instructions.Length + 1];
                byte index   = 0;
                for (int i = 0; i < newInst.Length; i++)
                {
                    if (i == Primitive.InstPtr)
                    {
                        newInst[i] = Primitive.Instruction;
                    }
                    else
                    {
                        var inst = bhav.Instructions[index++];
                        newInst[i] = inst;
                        if (inst.TruePointer < 252 && inst.TruePointer >= Primitive.InstPtr)
                        {
                            inst.TruePointer++;
                        }
                        if (inst.FalsePointer < 252 && inst.FalsePointer >= Primitive.InstPtr)
                        {
                            inst.FalsePointer++;
                        }
                    }
                }

                bhav.Instructions = newInst;
                editor.BHAVView.AddPrimitive(Primitive);
            }

            foreach (var prim in FromTrue)
            {
                prim.TrueUI = Primitive;
                prim.Instruction.TruePointer = Primitive.InstPtr;
            }

            foreach (var prim in FromFalse)
            {
                prim.FalseUI = Primitive;
                prim.Instruction.FalsePointer = Primitive.InstPtr;
            }

            Content.GameContent.Get.Changes.ChunkChanged(bhav);
            SimAntics.VM.BHAVChanged(bhav);
        }
Example #29
0
        public BHAVContainer(BHAV target, EditorScope scope)
        {
            Scope      = scope;
            EditTarget = target;

            Selected   = new List <PrimitiveBox>();
            Primitives = new List <PrimitiveBox>();
            RealPrim   = new List <PrimitiveBox>();

            byte i = 0;

            foreach (var inst in EditTarget.Instructions)
            {
                var ui = new PrimitiveBox(inst, i++, this);
                Primitives.Add(ui);
                RealPrim.Add(ui);
                this.Add(ui);
            }

            var RealPrims = new List <PrimitiveBox>(Primitives);

            foreach (var prim in RealPrims)
            {
                if (prim.Instruction.FalsePointer > 252 && prim.Returns != PrimitiveReturnTypes.Done)
                {
                    var dest = new PrimitiveBox((prim.Instruction.FalsePointer == 254) ? PrimBoxType.True : PrimBoxType.False, this);
                    Primitives.Add(dest);
                    this.Add(dest);
                    prim.FalseUI = dest;
                }
                else if (prim.Instruction.FalsePointer < RealPrim.Count)
                {
                    prim.FalseUI = RealPrim[prim.Instruction.FalsePointer];
                }

                if (prim.Instruction.TruePointer > 252)
                {
                    var dest = new PrimitiveBox((prim.Instruction.TruePointer == 254) ? PrimBoxType.True : PrimBoxType.False, this);
                    Primitives.Add(dest);
                    this.Add(dest);
                    prim.TrueUI = dest;
                }
                else if (prim.Instruction.TruePointer < RealPrim.Count)
                {
                    prim.TrueUI = RealPrim[prim.Instruction.TruePointer];
                }
            }
            CleanPosition();

            HitTest = ListenForMouse(new Rectangle(Int32.MinValue / 2, Int32.MinValue / 2, Int32.MaxValue, Int32.MaxValue), new UIMouseEvent(DragMouseEvents));
        }
Example #30
0
        private void ExecuteInstruction(VMStackFrame frame)
        {
            var instruction = frame.GetCurrentInstruction();
            var opcode      = instruction.Opcode;

            if (opcode >= 256)
            {
                BHAV bhav = null;

                GameIffResource CodeOwner;
                if (opcode >= 8192)
                {
                    CodeOwner = frame.Callee.SemiGlobal.Resource;
                    bhav      = frame.Callee.SemiGlobal.Resource.Get <BHAV>(opcode);
                }
                else if (opcode >= 4096)
                {
                    /** Private sub-routine call **/
                    CodeOwner = frame.CalleePrivate;
                    bhav      = frame.CalleePrivate.Get <BHAV>(opcode);
                }
                else
                {
                    /** Global sub-routine call **/
                    CodeOwner = frame.Global.Resource;
                    bhav      = frame.Global.Resource.Get <BHAV>(opcode);
                }

                var operand = frame.GetCurrentOperand <VMSubRoutineOperand>();
                ExecuteSubRoutine(frame, bhav, CodeOwner, operand);
                NextInstruction();
                return;
            }


            var primitive = Context.GetPrimitive(opcode);

            if (primitive == null)
            {
                throw new Exception("Unknown primitive!");
                //HandleResult(frame, instruction, VMPrimitiveExitCode.GOTO_TRUE);
                //return;
                //Pop(VMPrimitiveExitCode.ERROR);
            }

            VMPrimitiveHandler handler = primitive.GetHandler();
            var result = handler.Execute(frame);

            HandleResult(frame, instruction, result);
        }