Ejemplo n.º 1
0
        public CallerInformation CheckValidCall(CalcLocation location)
        {
            CallerInformation info = GetCallInfo(location);

            if (location.IsRam || info != null)
            {
                return(info);
            }

            for (byte page = 0; page < 0x20; page++)
            {
                if (page == location.Page)
                {
                    continue;
                }

                location = new CalcLocation(location.Address, page, false);
                info     = GetCallInfo(location);
                if (info != null)
                {
                    return(info);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public void ParseListFile(string listFileContents)
        {
            var               calcToFile         = new Dictionary <CalcLocation, DocumentLocation>(700000);
            var               fileToCalc         = new Dictionary <DocumentLocation, CalcLocation>(700000);
            var               callerInfo         = new Dictionary <CalcLocation, CallerInformation>();
            FcreateFile       currentFcreateFile = null;
            FilePath          currentFile        = new FilePath(string.Empty);
            var               lines          = listFileContents.Split('\n');
            var               fcreateForFile = new Dictionary <FilePath, FcreateFile>();
            CallerInformation callInfoToAdd  = null;

            for (int i = 0; i < lines.Length; i++)
            {
                var line = lines[i];
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                Match fileMatch = FileRegex.Match(line);
                if (fileMatch.Success)
                {
                    string file = fileMatch.Groups["file"].Value.Trim();
                    if (file == "fcreate")
                    {
                        if (!fcreateForFile.TryGetValue(currentFile, out currentFcreateFile))
                        {
                            currentFcreateFile          = new FcreateFile();
                            fcreateForFile[currentFile] = currentFcreateFile;
                        }
                        currentFile = new FilePath(currentFile + ".fcreate");
                    }
                    else
                    {
                        currentFile        = new FilePath(file);
                        currentFcreateFile = null;
                    }
                }
                else
                {
                    Match listingMatch = ListingRegex.Match(line);
                    if (!listingMatch.Success)
                    {
                        continue;
                    }

                    string stringLineNumber = listingMatch.Groups["lineNum"].Value.Trim();
                    int    lineNumber       = int.Parse(stringLineNumber);
                    ushort address          = ushort.Parse(listingMatch.Groups["addr"].Value, NumberStyles.HexNumber);
                    byte   page             = byte.Parse(listingMatch.Groups["page"].Value, NumberStyles.HexNumber);
                    string codeLine         = listingMatch.Groups["line"].Value;

                    // correction for ram pages
                    if (page == 0 && address >= 0x8000 && address < 0xC000)
                    {
                        page = 1;
                    }

                    if (currentFcreateFile != null)
                    {
                        lineNumber += currentFcreateFile.Lines;
                        currentFcreateFile.Builder.AppendLine(listingMatch.Groups["line"].Value.TrimEnd());
                        currentFcreateFile.Lines++;
                    }

                    if (listingMatch.Groups["byte1"].Value.Contains("-") || string.IsNullOrWhiteSpace(listingMatch.Groups["byte1"].Value))
                    {
                        continue;
                    }

                    DocumentLocation key   = new DocumentLocation(currentFile, lineNumber);
                    CalcLocation     value = new CalcLocation(address, page, address >= 0x8000);

                    do
                    {
                        line         = lines[i + 1];
                        listingMatch = ListingContRegex.Match(line);
                        if (!listingMatch.Success)
                        {
                            continue;
                        }

                        i++;
                        codeLine = listingMatch.Groups["line"].Value;
                    } while (listingMatch.Success);

                    if (callInfoToAdd != null)
                    {
                        callerInfo.Add(value, callInfoToAdd);
                    }

                    callInfoToAdd = ParseCallLine(codeLine, key);

                    if (!calcToFile.ContainsKey(value))
                    {
                        calcToFile.Add(value, key);
                    }

                    if (!fileToCalc.ContainsKey(key))
                    {
                        fileToCalc.Add(key, value);
                    }
                }
            }

            foreach (var file in fcreateForFile)
            {
                var filePath = new FilePath(file.Key + ".fcreate");
                using (var writer = new StreamWriter(filePath))
                {
                    writer.Write(file.Value.Builder.ToString());
                }
            }

            _fileToCalc        = fileToCalc;
            _calcToFile        = calcToFile;
            _callerInformation = callerInfo;
        }