///////////////////////////////////////////////////////////// public bool FindFunction(int Module, int Function, out XRomCode OpCode) { OpCode = null; int Index = XRomCodeList.BinarySearch(new XRomCode(String.Empty, (short)Module, (short)Function), MneComparer); if (Index < 0) { return(false); } OpCode = XRomCodeList[Index]; return(true); }
///////////////////////////////////////////////////////////// public bool FindMnemonic(String Mnemonic, out XRomCode OpCode) { OpCode = null; int Index = XRomCodeList.BinarySearch(new XRomCode(Mnemonic, 0, 0), MneComparer); if (Index < 0) { return(false); } OpCode = XRomCodeList[Index]; return(true); }
///////////////////////////////////////////////////////////// public void AddMnemonicsFromFile(string filename) { const int RegexIdxAll = 0; const int RegexIdxEmpty = 1; const int RegexIdxComment = 2; const int RegexIdxXRomDefinition = 3; const int RegexIdxFctNameQuoted = 6; const int RegexIdxFctName = 7; const int RegexIdxXRomNr = 8; const int RegexIdxFctNr = 9; try { StreamReader xromStream = new StreamReader(filename, System.Text.Encoding.ASCII); int lineNr = 0; Regex Parser = new Regex(@"(^\s*$)|(\s*;)|(\s*((""(.+)"")|(.+))\s*,\s*(\d+)\s*,\s*(\d+)\s*(;|$))", RegexOptions.IgnoreCase); string line = xromStream.ReadLine(); while (line != null) { Match match = Parser.Match(line); line = xromStream.ReadLine(); lineNr++; if (match.Groups[RegexIdxComment].Success) { //comment, do nothing } else if (match.Groups[RegexIdxEmpty].Success) { //empty line, do nothing } else if (match.Groups[RegexIdxXRomDefinition].Success) { string fctName; if (match.Groups[RegexIdxFctNameQuoted].Success) { fctName = match.Groups[RegexIdxFctNameQuoted].Value; } else { fctName = match.Groups[RegexIdxFctName].Value; } string rom = match.Groups[RegexIdxXRomNr].Value; string fct = match.Groups[RegexIdxFctNr].Value; int romInt; if (fctName.Length > 7) { Console.WriteLine("Error in XRom file line {0}: wrong ROM name format", lineNr); continue; } if (!int.TryParse(rom, out romInt)) { Console.WriteLine("Error in XRom file line {0}: wrong ROM number format", lineNr); continue; } if (romInt < 0 || romInt >= 32) { Console.WriteLine("Error in XRom file line {0}: ROM number out of range", lineNr); continue; } int fctInt; if (!int.TryParse(fct, out fctInt)) { Console.WriteLine("Error in XRom file line {0}: wrong function number format", lineNr); continue; } if (fctInt < 0 || fctInt >= 64) { Console.WriteLine("Error in XRom file line {0}: function number out of range", lineNr); continue; } var newXrom = new XRomCode(fctName, (short)romInt, (short)fctInt); XRomCodeList.Add(newXrom); } else { Console.WriteLine("Error in XRom file line {0}: syntax error", lineNr); } } xromStream.Close(); XRomCodeList.Sort(MneComparer); } catch (Exception e) { } }