Exemplo n.º 1
0
 public Op(int idx)
 {
     Index    = idx;
     Opcode   = Opcode.Nop;
     Operand1 = Operand.None;
     Operand2 = Operand.None;
     Length   = 1;
     Code     = String.Empty;
     PcMod    = PcMod.Length;
 }
Exemplo n.º 2
0
 public Op(int idx, Opcode opcode, Operand operand1, Operand operand2, int length, string code, PcMod pcMod)
 {
     Index    = idx;
     Opcode   = opcode;
     Operand1 = operand1;
     Operand2 = operand2;
     Length   = length;
     Code     = code;
     PcMod    = pcMod;
 }
Exemplo n.º 3
0
        public static List <Op> GenerateOpcodes(String path)
        {
            List <Op> ops = new List <Op>(256);

            for (int ii = 0; ii < 256; ii++)
            {
                ops.Add(new Op(ii));
            }


            String[] lines   = System.IO.File.ReadAllLines(path);
            int      nextIdx = 0;

            for (int ii = 0; ii < lines.Length; ii++)
            {
                String line = lines[ii];
                if (LineStartsWith_OP(line) == false)
                {
                    continue;
                }

                Match match = Regex.Match(line, @"OP\(\s*(\w+)\s*,\s*(\w+)\s*,\s*Opf_(\w+)\s*,\s*Pcm_(\w+)\s*,\s*(\d)\s*,\s*(.*)", RegexOptions.IgnoreCase);

                if (match.Success)
                {
                    string name     = match.Groups[1].Value;
                    string operands = match.Groups[2].Value;
                    string format   = match.Groups[3].Value;
                    string pcmod    = match.Groups[4].Value;
                    string time     = match.Groups[5].Value;
                    string code     = match.Groups[6].Value;

                    int     idx = nextIdx++;
                    Opcode  op = (Opcode)Enum.Parse(typeof(Opcode), name);
                    Operand operand1 = Operand.None, operand2 = Operand.None;
                    PcMod   pcMod = pcmod == "Set" ? PcMod.Set : PcMod.Length;

                    int length = 1;

                    if (operands.Length == 1)
                    {
                        switch (operands[0])
                        {
                        case 'x': operand1 = Operand.X; break;

                        case 'y': operand1 = Operand.Y; break;

                        case 'z': operand1 = Operand.Z; break;

                        case 'w': operand1 = Operand.W; break;

                        case 'a': operand1 = Operand.A; break;

                        case 'i': operand1 = Operand.I; break;

                        case 'j': operand1 = Operand.J; break;

                        case 'A': operand1 = Operand.Address; break;

                        case 'W': operand1 = Operand.Address; break;

                        case 'B': operand1 = Operand.Byte; break;

                        case 'P': operand1 = Operand.Pc; break;

                        case 'F': operand1 = Operand.F; break;
                        }
                    }
                    else if (operands.Length == 2)
                    {
                        switch (operands[0])
                        {
                        case 'x': operand1 = Operand.X; break;

                        case 'y': operand1 = Operand.Y; break;

                        case 'z': operand1 = Operand.Z; break;

                        case 'w': operand1 = Operand.W; break;

                        case 'a': operand1 = Operand.A; break;

                        case 'i': operand1 = Operand.I; break;

                        case 'j': operand1 = Operand.J; break;

                        case 'W': operand1 = Operand.Address; break;

                        case 'A': operand1 = Operand.Address; break;

                        case 'B': operand1 = Operand.Byte; break;

                        case 'P': operand1 = Operand.Pc; break;

                        case 'F': operand1 = Operand.F; break;
                        }
                        switch (operands[1])
                        {
                        case 'x': operand2 = Operand.X; break;

                        case 'y': operand2 = Operand.Y; break;

                        case 'z': operand2 = Operand.Z; break;

                        case 'w': operand2 = Operand.W; break;

                        case 'i': operand2 = Operand.I; break;

                        case 'j': operand2 = Operand.J; break;

                        case 'a': operand2 = Operand.A; break;

                        case 'W': operand2 = Operand.Address; break;

                        case 'A': operand2 = Operand.Address; break;

                        case 'B': operand2 = Operand.Byte; break;

                        case 'P': operand2 = Operand.Pc; break;

                        case 'F': operand2 = Operand.F; break;
                        }
                    }

                    if (format == "Address" || format == "Word")
                    {
                        length = 3;
                    }
                    else if (format == "Byte")
                    {
                        length = 2;
                    }

                    ops[idx] = new Op(idx, op, operand1, operand2, length, code, pcMod);
                }
                else
                {
                    Debug.LogErrorFormat("Unknown Syntax: {0}", line);
                    nextIdx++; // Reserve this, so don't break the chain.
                }
            }


            return(ops);
        }