Exemple #1
0
        private Dialect ReadBASICDialect(string File)
        {
            var dialect = new Dialect();

            using (var reader = new GR.IO.BinaryReader(File))
            {
                string line;
                bool   firstLine = true;
                int    lineIndex = 0;
                bool   exOpcodes = false;

                while (reader.ReadLine(out line))
                {
                    ++lineIndex;
                    line = line.Trim();
                    if ((string.IsNullOrEmpty(line)) ||
                        (line.StartsWith("#")))
                    {
                        continue;
                    }
                    // skip header
                    if (firstLine)
                    {
                        firstLine = false;
                        continue;
                    }

                    if (line == "ExOpcodes")
                    {
                        exOpcodes = true;
                        continue;
                    }

                    string[] parts = line.Split(';');
                    if (parts.Length != 3)
                    {
                        Core.AddToOutput("Invalid BASIC format file '" + File + "', expected three columns in line " + lineIndex + System.Environment.NewLine);
                        return(null);
                    }
                    if (exOpcodes)
                    {
                        dialect.AddExOpcode(parts[0], GR.Convert.ToI32(parts[1], 16));
                    }
                    else
                    {
                        dialect.AddOpcode(parts[0], GR.Convert.ToI32(parts[1], 16), parts[2]);
                    }
                }
            }
            dialect.Name = System.IO.Path.GetFileNameWithoutExtension(File);
            BASICDialects.Add(dialect.Name, dialect);

            return(dialect);
        }
Exemple #2
0
        private Dialect ReadDialectFromFile(string File)
        {
            var dialect = new Dialect();

            using (var reader = new GR.IO.BinaryReader(File))
            {
                string line;
                bool   firstLine = true;
                int    lineIndex = 0;

                while (reader.ReadLine(out line))
                {
                    ++lineIndex;
                    line = line.Trim();
                    if ((string.IsNullOrEmpty(line)) ||
                        (line.StartsWith("#")))
                    {
                        continue;
                    }
                    // skip header
                    if (firstLine)
                    {
                        firstLine = false;
                        continue;
                    }

                    string[] parts = line.Split(';');
                    if (parts.Length != 3)
                    {
                        return(null);
                    }

                    /*
                     * if ( ( parts[1].Length % 1 ) == 1 )
                     * {
                     * parts[1] = "0" + parts[1];
                     * }*/
                    dialect.AddOpcode(parts[0], GR.Convert.ToI32(parts[1], 16), parts[2]);
                }
            }
            dialect.Name = System.IO.Path.GetFileNameWithoutExtension(File);

            return(dialect);
        }
Exemple #3
0
        private Dialect ReadBASICDialect(string File)
        {
            var dialect = new Dialect();

            using (var reader = new GR.IO.BinaryReader(File))
            {
                string line;
                bool   firstLine = true;
                int    lineIndex = 0;
                bool   exOpcodes = false;

                while (reader.ReadLine(out line))
                {
                    ++lineIndex;
                    line = line.Trim();
                    if ((string.IsNullOrEmpty(line)) ||
                        (line.StartsWith("#")))
                    {
                        continue;
                    }
                    if (line.StartsWith("StartAddress="))
                    {
                        dialect.DefaultStartAddress = line.Substring(13);
                        continue;
                    }
                    else if (line.StartsWith("SafeLineLength="))
                    {
                        dialect.SafeLineLength = GR.Convert.ToI32(line.Substring(15));
                        continue;
                    }

                    // skip header
                    if (firstLine)
                    {
                        firstLine = false;
                        continue;
                    }


                    if (line == "ExOpcodes")
                    {
                        exOpcodes = true;
                        continue;
                    }

                    string[] parts = line.Split(';');
                    if ((parts.Length != 3) &&
                        (parts.Length != 4))
                    {
                        Core.AddToOutput("Invalid BASIC format file '" + File + "', expected three or four columns in line " + lineIndex + System.Environment.NewLine);
                        return(null);
                    }
                    if (exOpcodes)
                    {
                        dialect.AddExOpcode(parts[0], GR.Convert.ToI32(parts[1], 16));
                    }
                    else
                    {
                        var opCode = dialect.AddOpcode(parts[0], GR.Convert.ToI32(parts[1], 16), parts[2]);

                        if (parts.Length == 4)
                        {
                            string[] extraInfo = parts[3].Split(',');

                            for (int i = 0; i < extraInfo.Length; ++i)
                            {
                                if (string.Compare(extraInfo[i], "COMMENT", true) == 0)
                                {
                                    opCode.IsComment = true;
                                }
                            }
                        }
                    }
                }
            }
            dialect.Name = System.IO.Path.GetFileNameWithoutExtension(File);
            BASICDialects.Add(dialect.Name, dialect);

            return(dialect);
        }