Exemple #1
0
        private bool PreprocessRows()
        {
            Z80Preprocessor preprocessor = new Z80Preprocessor(m_ProgramText, IncludeDirectories, m_FileName);

            if (!preprocessor.Preprocess())
            {
                m_StatusMessage.AppendLine(preprocessor.StatusMessage);
                WrongLineNumber = preprocessor.WrongLineNumber;
                return(false);
            }

            InterPretedAssemblyRows.AddRange(preprocessor.PreprocessedProgramLines);
            m_SkippedLineNumbers.AddRange(preprocessor.SkippedLineNumbers);
            return(true);
        }
Exemple #2
0
        private bool BuildAssemblyRows()
        {
            do
            {
                foreach (AssemblyRow row in InterPretedAssemblyRows)
                {
                    switch (row.Instruction.Type)
                    {
                    case InstructionType.AssemblerInstruction:
                    {
                        if (!ResolveAssemblerInstruction(row))
                        {
                            return(false);
                        }
                    }
                    break;

                    case InstructionType.ProcessorInstruction:
                    {
                        if (!BuildProcessorInstruction(row))
                        {
                            return(false);
                        }
                    }
                    break;
                    }
                    if (!string.IsNullOrEmpty(row.Label))
                    {
                        Symbol addressSymbol = AssembledProgram.SymbolTable.FirstOrDefault(s => s.Key == row.Label && s.Value.Type == SymbolType.Address).Value;
                        if (addressSymbol != null && addressSymbol.State == SymbolState.Unresolved)
                        {
                            addressSymbol.Value = AssembledProgram.SymbolTable[AssemblerConstans.LocationCounterSymbol].Value;
                        }
                    }
                    if (row.InstructionBytes.Count > 0)
                    {
                        row.Address = AssembledProgram.SymbolTable[AssemblerConstans.LocationCounterSymbol].Value;
                        ushort newLocationCounter = AssembledProgram.SymbolTable[AssemblerConstans.LocationCounterSymbol].Value;
                        newLocationCounter += (ushort)row.InstructionBytes.Count;
                        AssembledProgram.SymbolTable[AssemblerConstans.LocationCounterSymbol].Value = newLocationCounter;
                    }
                }

                // The program is not closed with the 'END' assembler instruction, in this case the last row is handled as latest
                if (m_CurrentProgramSection != null)
                {
                    m_CurrentProgramSection.SectionLength =
                        (ushort)(AssembledProgram.SymbolTable[AssemblerConstans.LocationCounterSymbol].Value - m_CurrentProgramSection.ProgramStartAddress);
                    AssembledProgram.ProgramSections.Add(m_CurrentProgramSection);
                    m_CurrentProgramSection = null;
                }
            } while (InterPretedAssemblyRows.Any(row => row.State == AssemblyRowState.ContainsFutureSymbol));

            if (AssembledProgram.ProgramSections.Count == 0)
            {
                m_StatusMessage.AppendLine(@"A program nem tartalmaz 'ORG' utasítást!");
                WrongLineNumber = 1;
                return(false);
            }
            return(true);
        }