Beispiel #1
0
        public void ExecuteCommand(Word word)
        {
            string command = word.Value.Substring(0, 2);
            string operand = "";
            if (word.Value.Length != 3)
            {
                operand = word.Value.Substring(2, word.Value.Length - 2);
            }

            switch (command)
            {
                case "AD":
                    {
                        this.AX = this.AX + this.CX;
                        break;
                    }
                case "SU":
                    {
                        this.AX = this.AX - this.CX;
                        break;
                    }
                case "CM":
                    {
                        if (this.AX > this.CX)
                            this.SF = 0;
                        if (this.AX < this.CX)
                            this.SF = 2;
                        if (Word.HexToInt(this.AX.Value) == Word.HexToInt(this.CX.Value))
                            this.SF = 1;
                        break;
                    }
                case "SA":
                    {
                        this.memory[Convert.ToInt32(operand[0].ToString(), 16), Convert.ToInt32(operand[1].ToString(), 16)].Value = this.AX.Value;
                        break;
                    }
                case "LA":
                    {
                        this.AX.Value = this.memory[Convert.ToInt32(operand[0].ToString(), 16), Convert.ToInt32(operand[1].ToString(), 16)].Value;
                        break;
                    }
                case "SC":
                    {
                        this.memory[Convert.ToInt32(operand[0].ToString(), 16), Convert.ToInt32(operand[1].ToString(), 16)].Value = this.CX.Value;
                        break;
                    }
                case "LC":
                    {
                        this.CX.Value = this.memory[Convert.ToInt32(operand[0].ToString(), 16), Convert.ToInt32(operand[1].ToString(), 16)].Value;
                        break;
                    }
                case "JM":
                    {
                        this.PC = Convert.ToInt16(operand, 16);
                        break;
                    }
                case "JE":
                    {
                        if (this.SF == 1)
                            this.PC = Convert.ToInt16(operand, 16);
                        else this.PC++;
                        break;
                    }
                case "JN":
                    {
                        if (this.SF != 1)
                            this.PC = Convert.ToInt16(operand, 16);
                        else this.PC++;
                        break;
                    }
                case "JA":
                    {
                        if (this.SF == 0)
                            this.PC = Convert.ToInt16(operand, 16);
                        else this.PC++;
                        break;
                    }
                case "JB":
                    {
                        if (this.SF == 2)
                            this.PC = Convert.ToInt16(operand, 16);
                        else this.PC++;
                        break;
                    }
                case "JG":
                    {
                        if (this.SF == 0 || this.SF == 1)
                            this.PC = Convert.ToInt16(operand, 16);
                        else this.PC++;
                        break;
                    }
                case "JL":
                    {
                        if (this.SF == 1 || this.SF == 2)
                            this.PC = Convert.ToInt16(operand, 16);
                        else this.PC++;
                        break;
                    }
                case "GD": //TO DO: everything
                    {
                        //memory.Write(operand);
                        memory.Write(operand, vm.Io.Buffer);
                        vm.Io.Flush();
                        break;
                    }
                case "PD":
                    {
                        string buf = string.Empty;
                        int block = Word.HexToInt(operand[0].ToString());
                        for (int i = 0; i < memory.WordCount; i++)
                        {
                            if (memory[block, i].Value != "----")
                                buf += memory[block, i].Value;
                        }
                        vm.Io.Buffer = buf;
                        vm.Io.WriteBuffer();
                        vm.Io.Flush();
                        break;
                    }
                case "--":
                    {
                        break;
                    }
                case "$E":
                    {

                        break;
                    }
                default:
                    {
                        throw new ArgumentException("Unknown command: " + word.Value);
                    }
            }
        }