Ejemplo n.º 1
0
        public void ExecuteCommand(string line)
        {
            var type = ParseCommandType(line);

            (int, int)duoParams;
            int    singleParam;
            string stringParam;

            switch (type)
            {
            case CommandType.ADD:
                m_cpu.ADD();
                break;

            case CommandType.SUB:
                m_cpu.SUB();
                break;

            case CommandType.MUL:
                m_cpu.MUL();
                break;

            case CommandType.DIV:
                m_cpu.DIV();
                break;

            case CommandType.CMP:
                m_cpu.CMP();
                break;

            case CommandType.LA:
                duoParams = ParseParams(line);
                m_cpu.LA(duoParams.Item1, duoParams.Item2);
                break;

            case CommandType.SA:
                duoParams = ParseParams(line);
                m_cpu.SA(duoParams.Item1, duoParams.Item2);
                break;

            case CommandType.PRAX:
                m_cpu.PRAX();
                break;

            case CommandType.PR:
                duoParams = ParseParams(line);
                m_cpu.PR(duoParams.Item1, duoParams.Item2);
                break;

            case CommandType.PA:
                duoParams = ParseParams(line);
                m_cpu.PA(duoParams.Item1, duoParams.Item2);
                break;

            case CommandType.RDAX:
                m_cpu.RDAX();
                break;

            case CommandType.RD:
                duoParams = ParseParams(line);
                m_cpu.RD(duoParams.Item1, duoParams.Item2);
                break;

            case CommandType.RDA:
                singleParam = ParseSingleParam(line);
                m_cpu.RDA(singleParam);
                break;

            case CommandType.SWAP:
                m_cpu.SWAP();
                break;

            case CommandType.JP:
                duoParams = ParseParams(line);
                m_cpu.JP(duoParams.Item1, duoParams.Item2);
                break;

            case CommandType.JM:
                duoParams = ParseParams(line);
                m_cpu.JM(duoParams.Item1, duoParams.Item2);
                break;

            case CommandType.JL:
                duoParams = ParseParams(line);
                m_cpu.JL(duoParams.Item1, duoParams.Item2);
                break;

            case CommandType.JE:
                duoParams = ParseParams(line);
                m_cpu.JE(duoParams.Item1, duoParams.Item2);
                break;

            case CommandType.JN:
                duoParams = ParseParams(line);
                m_cpu.JN(duoParams.Item1, duoParams.Item2);
                break;

            case CommandType.JX:
                duoParams = ParseParams(line);
                m_cpu.JX(duoParams.Item1, duoParams.Item2);
                break;

            case CommandType.JY:
                duoParams = ParseParams(line);
                m_cpu.JY(duoParams.Item1, duoParams.Item2);
                break;

            case CommandType.HALT:
                m_cpu.HALT();
                break;

            case CommandType.SD:
                duoParams   = ParseParams(line);
                stringParam = ParseStringData(line);
                m_cpu.SD(duoParams.Item1, duoParams.Item2, stringParam);
                break;

            case CommandType.ERROR:
                Console.WriteLine("Bad command, no exception for now");
                break;

            case CommandType.PRBX:
                m_cpu.PRBX();
                break;

            case CommandType.RDBX:
                m_cpu.RDBX();
                break;

            case CommandType.MINT:
                m_cpu.MINT();
                break;

            case CommandType.MCHR:
                m_cpu.MCHR();
                break;

            case CommandType.CHDR:
                stringParam = ParseStringData(line);
                m_cpu.CHDR(stringParam);
                break;

            case CommandType.SDIR:
                m_cpu.SDIR();
                break;

            default:
                throw new NotImplementedException($"Command type: {type} is not implemented");
            }
        }