Example #1
0
 static bool EOL(Token token)
 {
     if (token == null)
     {
         return(true);
     }
     if (token.Next != null)
     {
         if (!ErrorTable.HasErrors(currentFileName))
         {
             LogError(currentFileName, token, "Unwanted characters at end of line! " + token.Value + " " + token.Next.Value);
         }
         return(false);
     }
     return(true);
 }
Example #2
0
        static bool Pass(int pass, string source)
        {
            FirstAddress = -1;
            //LogError(currentFileName, null,"Pass" + PassNo.ToString(), -1);
            maxtext        = 0;
            sb             = new StringBuilder();
            bytes          = new List <string>();
            sourcelines    = new List <string>();
            IsTerminal     = false;
            Cancelled      = false;
            currentPass    = pass;
            terminate      = false;
            currentLine    = 0;
            ProgramCounter = 0;
            ErrorTable.Reset();
            Memory = new int[0x10000];

            for (int i = 0; i < 0x10000; i++)
            {
                Memory[i] = -1;
            }
            string[] lines;
            if (source.Contains("\r\n"))
            {
                source = source.Replace("\r", "");
            }
            //lines = source.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            lines = source.Split('\n');
            foreach (string line in lines)
            {
                if (ProgramCounter > 0xffff)
                {
                    break;
                }
                startaddress = ProgramCounter;
                currenttext  = line;
                currentLine++;
                AssembleLine(line);
                if (pass == 2)
                {
                    sourcelines.Add(currenttext);
                    int           length = ProgramCounter - startaddress;
                    StringBuilder textsb = new StringBuilder();
                    if (length > 0)
                    {
                        switch (lastTokenType)
                        {
                        case TokenType.Directive:
                        case TokenType.Preprocessor:
                            textsb.Append("    " + " ");
                            break;

                        case TokenType.Label:
                        case TokenType.Symbol:
                        case TokenType.Opcode:
                            textsb.Append(startaddress.ToString("X4") + " ");
                            break;

                        default:
                            textsb.Append(startaddress.ToString("X4") + " ");
                            break;
                        }
                        int newline = 0;
                        for (int i = 0; i < length; i++)
                        {
                            if (newline > 15)
                            {
                                sourcelines.Add("{''}");
                                currentLine++;
                                if (textsb.Length > maxtext)
                                {
                                    maxtext = textsb.Length + 1;
                                }
                                bytes.Add(textsb.ToString());
                                textsb = new StringBuilder();
                                textsb.Append((startaddress + i).ToString("X4") + " ");
                                newline = 0;
                            }
                            if (Memory[startaddress + i] != -1)
                            {
                                textsb.Append(Memory[startaddress + i].ToString("X2") + " ");
                                newline++;
                            }
                            if (textsb.Length > maxtext)
                            {
                                maxtext = textsb.Length + 1;
                            }
                        }
                    }
                    bytes.Add(textsb.ToString());
                    OnAssembledLine(null, new AssembledLineEventArgs(ProgramCounter - length, length));
                }
                //if (ErrorTable.HasErrors)                    break;
                if (IsTerminal)
                {
                    break;
                }
                if (terminate)
                {
                    break;
                }
                if (Cancelled)
                {
                    break;
                }
            }
            return(!ErrorTable.HasErrors(currentFileName));
        }