Beispiel #1
0
 private void NextLine(InstructionInfoEventArgs e)
 {
     this.currentTextLine++;
     if (this.currentTextLine >= MaxLinesPerMessage)
     {
         GenerateNextMessage(e);
     }
 }
Beispiel #2
0
        public void projectWriter_BeforeWritingInstruction(object sender, InstructionInfoEventArgs e)
        {
            var instructionInfo = e.InstructionInfo;

            if (instructionInfo.instruction == Instruction.MSG)
            {
                string messageText = e.Text;
                //string messageText = ainFile.Messages[instructionInfo.word1];
                messageText = CombineRemainingText(messageText);
                e.Text      = messageText;
                HandleMessage(e, messageText);
            }
            else if (instructionInfo.instruction == Instruction.CALLFUNC)
            {
                var    function     = ainFile.GetFunction(instructionInfo.word1);
                string functionName = null;
                if (function != null)
                {
                    functionName = function.Name;
                }
                if (functionName == NextLineFunctionName)
                {
                    if (remainingText != "")
                    {
                        e.Handled = true;
                    }
                    else
                    {
                        NextLine(e);
                    }
                }
                else if (functionName == NextMessageFunctionName)
                {
                    if (remainingText != "")
                    {
                        while (remainingText != "")
                        {
                            e.Handled = true;
                            HandleMessage(e, remainingText);
                        }

                        GenerateNextMessage(e);
                    }
                    else
                    {
                        NextMessage();
                    }
                }
                else if (ReduceMarginFunctionNames.Contains(functionName))
                {
                    this.maxCharactersPerLine = this.MaxCharactersPerLineReduced;
                }
            }
        }
Beispiel #3
0
 void GenerateNextLine(InstructionInfoEventArgs e)
 {
     if (this.currentTextLine < MaxLinesPerMessage)
     {
         if (this.currentTextLine == MaxLinesPerMessage - 1)
         {
             e.Handled = true;
         }
         else
         {
             e.WriteText(NextLineFunctionCode);
             e.Handled = true;
         }
     }
     NextLine(e);
 }
            void writer_BeforeWritingString(object sender, InstructionInfoEventArgs e)
            {
                var instructionInfo       = e.InstructionInfo;
                var instruction           = instructionInfo.instruction;
                int indexOfStringArgument = instruction.IndexOfStringArgument();

                if (instruction.IndexOfStringArgument() >= 0)
                {
                    string originalString    = ainFile.GetString(instructionInfo.words[indexOfStringArgument]);
                    string replacementString = null;
                    if (stringDictionary != null)
                    {
                        replacementString = stringDictionary.GetOrNull(stringNumber);
                    }
                    if (replacementString != null && originalString != replacementString)
                    {
                        e.Text = replacementString;
                    }
                    stringNumber++;
                }
            }
Beispiel #5
0
 private void GenerateNextMessage(InstructionInfoEventArgs e)
 {
     e.WriteText(NextMessageFunctionCode);
     e.Handled = true;
     NextMessage();
 }
Beispiel #6
0
        private void HandleMessage(InstructionInfoEventArgs e, string messageText)
        {
            int indentSize        = GetIndentSize(messageText);
            int realSplitPosition = FindCharacterIndexOfRightMargin(messageText, maxCharactersPerLine);

            if (realSplitPosition < messageText.Length || e.Handled == true)
            {
                e.Handled = true;
                while (realSplitPosition < messageText.Length)
                {
                    int position = FindSplitPoint(messageText, realSplitPosition);
                    if (position <= indentSize)
                    {
                        //for really long lines - split them at the wrap position instead of an infinite loop
                        position = realSplitPosition;
                    }

                    string line = messageText.Substring(0, position);

                    e.WriteLine(" " + AssemblerProjectWriter.EscapeAndQuoteMessage(line) + " ");
                    GenerateNextLine(e);
                    e.WriteLine("");

                    messageText = messageText.Substring(position);

                    //eat spaces
                    position = 0;
                    while (position < messageText.Length && messageText[position] == ' ')
                    {
                        position++;
                    }
                    if (position > 0)
                    {
                        messageText = messageText.Substring(position);
                    }

                    //add indent if enabled
                    if (MaintainIndentation)
                    {
                        if (indentSize > 0)
                        {
                            messageText = "".PadLeft(indentSize, ' ') + messageText;
                        }
                    }

                    //find next split
                    realSplitPosition = FindCharacterIndexOfRightMargin(messageText, maxCharactersPerLine);
                }

                //remaining text is set to something if this is a "next message" call, so output any leftover text at that time.
                //Otherwise, if we have the leftover text feature disabled, output it now.
                if (!this.RemoveLineBreaksIfWordWrapping || this.remainingText != "")
                {
                    e.WriteText(" " + AssemblerProjectWriter.EscapeAndQuoteMessage(messageText) + " ");
                    this.remainingText = "";
                }
                else
                {
                    this.remainingText = messageText;
                }
            }
        }
            void writer_BeforeWritingInstruction(object sender, InstructionInfoEventArgs e)
            {
                var instructionInfo = e.InstructionInfo;
                var instruction     = instructionInfo.instruction;
                int word1           = instructionInfo.word1;

                if (InsideFunction)
                {
                    if (!hasOutputFunction)
                    {
                        if (this.CodePatches.ContainsKey(currentFunctionName))
                        {
                            var codePatch = this.CodePatches[currentFunctionName];
                            e.WriteLine(codePatch);
                        }
                        hasOutputFunction = true;
                    }

                    if (instruction == Instruction.FUNC || instruction == Instruction.ENDFUNC || instruction == Instruction.EOF)
                    {
                        //will emit the ENDFUNC or next FUNC instruction
                        InsideFunction     = false;
                        e.StopEmittingCode = false;
                    }
                    else
                    {
                        e.Handled          = true;
                        e.StopEmittingCode = true;
                        return;
                    }
                }


                if (instruction == Instruction.FUNC)
                {
                    int functionNumber = instructionInfo.word1;
                    var function       = ainFile.GetFunction(functionNumber);
                    if (function != null)
                    {
                        stringNumber        = 0;
                        messageNumber       = 0;
                        currentFunctionName = function.Name;
                        stringDictionary    = stringEntries.GetOrNull(currentFunctionName);
                        messageDictionary   = messageEntries.GetOrNull(currentFunctionName);

                        if (this.CodePatches.ContainsKey(currentFunctionName))
                        {
                            //var codePatch = this.CodePatches[currentFunctionName];
                            //e.WriteLine(codePatch);
                            e.Handled          = false;
                            e.StopEmittingCode = false;
                            //will emit the FUNC instruction, but then not the rest
                            this.InsideFunction    = true;
                            this.hasOutputFunction = false;
                        }
                    }
                }
                else /*if (stringDictionary != null || messageDictionary != null)*/
                {
                    if (instruction == Instruction.MSG)
                    {
                        string originalMessage = originalAinFile.GetMessage(word1);
                        string newMessage      = null;
                        if (messageDictionary != null)
                        {
                            newMessage = messageDictionary.GetOrNull(messageNumber);
                        }

                        if (newMessage != null && newMessage != originalMessage)
                        {
                            e.Text = newMessage;
                        }

                        if (this.WordWrap)
                        {
                            if (this.wordWrapper.HasRemainingText == false && e.Text == originalMessage)
                            {
                                //don't wrap text because we match the original and don't have remaining text
                            }
                            else
                            {
                                wordWrapper.projectWriter_BeforeWritingInstruction(sender, e);
                            }
                        }
                        if (e.Dirty && !e.Handled)
                        {
                            //recheck this!
                            newMessage = e.Text;
                            e.WriteLine("\tMSG " + AssemblerProjectWriter.EscapeAndQuoteMessage(newMessage));
                            e.Handled = true;
                        }
                        messageNumber++;
                    }
                    //string instructions are handled by writer_BeforeWritingString
                    else if (instruction == Instruction.CALLFUNC)
                    {
                        //for text wrapping (to do later)
                        if (this.WordWrap)
                        {
                            wordWrapper.projectWriter_BeforeWritingInstruction(sender, e);
                        }
                    }
                }
            }