Example #1
0
        static void Main(string[] args)
        {
            // Initalize definitions
            InstructionDefinition.Initalize();
            FunctionDefinition.Initalize();

            // Parse arguments
            Program.Arguments = GetArguments(args);
            for (int i = 0; i < Program.Arguments.Length; i++)
            {
                switch (Program.Arguments[i])
                {
                case "-game": {
                    Program.GameLocation = Program.Arguments[++i];
                    break;
                }
                }
            }

            if (Program.GameLocation == null)
            {
                if (args.Length == 1 && File.Exists(args[0]) == true)
                {
                    Program.GameLocation = args[0];
                }
                else
                {
                    Program.GameLocation = Path.GetDirectoryName(Program.Arguments[0]) + "\\data.win";
                }
            }

            // Check existence
            if (File.Exists(Program.GameLocation) == false)
            {
                // NOTE: Runner.exe will display a file selection dialogue if no -game argument is provided
                //       but I don't really think we need to replicate the same behaviour.
                MessageBox.Show("Could not find specified game file: \"" + Program.GameLocation + "\"", "An error has occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Load game
            Program.GameData = new IFF(Program.GameLocation, new Game());
            Program.GameData.Parse(delegate(Game _game) {
                _game.Initalize(false);
            });
        }
Example #2
0
        private Instruction ParseInstruction(string[] parts, bool resolveNames)
        {
            var conditional     = default(Parameter);
            var conditionalZero = false;
            var skip            = 0;

            if (parts[0] == "IFZ" || parts[0] == "IFNZ")
            {
                conditionalZero = parts[0] == "IFZ";
                conditional     = this.ParseParameter(parts[1], resolveNames);
                skip           += 2;
            }

            var def = InstructionDefinition.Find(parts[skip++]);

            if (def == null)
            {
                throw new InvalidInstructionException();
            }

            return(new Instruction(def.Code, parts.Skip(skip).Select(p => this.ParseParameter(p, resolveNames)).ToList(), conditional, conditionalZero));
        }
Example #3
0
        private void Tick()
        {
            var execute = true;

            this.WriteRegister(Register.RIP, this.executingAddress + this.CurrentInstruction.Length);

            if (this.CurrentInstruction.ConditionalParameter != null)
            {
                var value = this.GetValue(this.CurrentInstruction.ConditionalParameter);

                execute = (this.CurrentInstruction.ConditionalZero && value == 0) || (!this.CurrentInstruction.ConditionalZero && value != 0);
            }

            if (execute)
            {
                if (InstructionDefinition.IsCodeValid(this.CurrentInstruction.Code))
                {
                    this.LoadParameters(this.operandA, this.operandB, this.operandC);

                    this.Execute(this.CurrentInstruction.Code, this.operandA, this.operandB, this.operandC);

                    this.SaveParameters(this.operandA, this.operandB, this.operandC);
                }
                else
                {
                    this.RaiseInterrupt(Interrupt.InvalidInstruction, this.CurrentInstruction.Code, this.executingAddress);
                }
            }

            this.executingAddress = this.ReadRegister(Register.RIP);

            if (this.interruptsEnabled && !this.inIsr && this.InterruptController.PendingCount != 0)
            {
                this.EnterInterrupt(this.InterruptController.Dequeue());
            }

            this.SetNextInstruction();
        }
Example #4
0
 public Instruction(uint position, InstructionDefinition instructionDefinition, params Operand[] operands) : base(position)
 {
     InstructionDefinition = instructionDefinition;
     Operands = operands;
 }
Example #5
0
 public uint CreateMachineCode()
 {
     return(InstructionDefinition.CreateMachineCode(Operands));
 }