예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #4
0
        public bool ReadFromBuffer(GR.Memory.ByteBuffer SettingsData)
        {
            IgnoredWarnings.Clear();

            GR.IO.BinaryReader binReader = new GR.IO.BinaryReader(SettingsData.MemoryStream());

            GR.IO.FileChunk chunkData = new GR.IO.FileChunk();

            while (chunkData.ReadFromStream(binReader))
            {
                switch (chunkData.Type)
                {
                case Types.FileChunk.SETTINGS_TOOL:
                {
                    ToolInfo tool = new ToolInfo();

                    tool.FromChunk(chunkData);

                    // sanitize args
                    tool.CartArguments = tool.CartArguments.Replace("$(BuildTargetFilename)", "$(RunFilename)");
                    tool.PRGArguments  = tool.PRGArguments.Replace("$(BuildTargetFilename)", "$(RunFilename)");
                    tool.WorkPath      = tool.WorkPath.Replace("$(FilePath)", "$(RunPath)");

                    if (string.IsNullOrEmpty(tool.TrueDriveOnArguments))
                    {
                        tool.TrueDriveOnArguments  = "-truedrive +virtualdev";
                        tool.TrueDriveOffArguments = "+truedrive -virtualdev";
                    }
                    if (tool.PRGArguments.Contains("-truedrive "))
                    {
                        tool.PRGArguments = tool.PRGArguments.Replace("-truedrive ", "");
                    }
                    if (tool.PRGArguments.Contains(" -truedrive"))
                    {
                        tool.PRGArguments = tool.PRGArguments.Replace(" -truedrive", "");
                    }
                    ToolInfos.AddLast(tool);
                }
                break;

                case Types.FileChunk.SETTINGS_ACCELERATOR:
                {
                    AcceleratorKey key = new AcceleratorKey();

                    key.FromChunk(chunkData);

                    Accelerators.Add(key.Key, key);
                }
                break;

                case Types.FileChunk.SETTINGS_DPS_LAYOUT:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    uint size = binIn.ReadUInt32();
                    GR.Memory.ByteBuffer tempData = new GR.Memory.ByteBuffer();
                    binIn.ReadBlock(tempData, size);
                    SetLayoutFromData(tempData);
                }
                break;

                case Types.FileChunk.SETTINGS_SOUND:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    PlaySoundOnSuccessfulBuild   = (binIn.ReadUInt8() != 0);
                    PlaySoundOnBuildFailure      = (binIn.ReadUInt8() != 0);
                    PlaySoundOnSearchFoundNoItem = (binIn.ReadUInt8() != 0);
                }
                break;

                case Types.FileChunk.SETTINGS_WINDOW:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    MainWindowPlacement = binIn.ReadString();
                }
                break;

                case Types.FileChunk.SETTINGS_TABS:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    TabSize = binIn.ReadInt32();
                    if ((TabSize <= 0) ||
                        (TabSize >= 100))
                    {
                        TabSize = 2;
                    }
                    AllowTabs          = (binIn.ReadUInt8() != 0);
                    TabConvertToSpaces = (binIn.ReadUInt8() != 0);
                }
                break;

                case Types.FileChunk.SETTINGS_FONT:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    SourceFontFamily = binIn.ReadString();
                    SourceFontSize   = (float)binIn.ReadInt32();

                    BASICUseNonC64Font    = (binIn.ReadUInt8() != 0);
                    BASICSourceFontFamily = binIn.ReadString();
                    BASICSourceFontSize   = (float)binIn.ReadInt32();
                    if (BASICSourceFontSize <= 0)
                    {
                        BASICSourceFontSize = 9.0f;
                    }
                }
                break;

                case Types.FileChunk.SETTINGS_SYNTAX_COLORING:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    Types.SyntaxElement element = (C64Studio.Types.SyntaxElement)binIn.ReadUInt32();

                    Types.SyntaxColor color = new C64Studio.Types.SyntaxColor(GR.EnumHelper.GetDescription(element));
                    color.FGColor     = binIn.ReadUInt32();
                    color.BGColor     = binIn.ReadUInt32();
                    color.BGColorAuto = (binIn.ReadUInt32() != 0);

                    SyntaxColoring.Add(element, color);
                }
                break;

                case Types.FileChunk.SETTINGS_UI:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    ToolbarActiveMain     = (binIn.ReadUInt8() == 1);
                    ToolbarActiveDebugger = (binIn.ReadUInt8() == 1);
                }
                break;

                case Types.FileChunk.SETTINGS_RUN_EMULATOR:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    TrueDriveEnabled = (binIn.ReadUInt8() != 0);
                }
                break;

                case Types.FileChunk.SETTINGS_DEFAULTS:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    DefaultProjectBasePath = binIn.ReadString();
                }
                break;

                case Types.FileChunk.SETTINGS_FIND_REPLACE:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    LastFindIgnoreCase = (binIn.ReadUInt8() == 1);
                    LastFindWholeWord  = (binIn.ReadUInt8() == 1);
                    LastFindRegexp     = (binIn.ReadUInt8() == 1);
                    LastFindWrap       = (binIn.ReadUInt8() == 1);
                    LastFindTarget     = binIn.ReadUInt8();

                    int numFindArguments = binIn.ReadInt32();
                    for (int i = 0; i < numFindArguments; ++i)
                    {
                        FindArguments.Add(binIn.ReadString());
                    }
                    int numReplaceArguments = binIn.ReadInt32();
                    for (int i = 0; i < numReplaceArguments; ++i)
                    {
                        ReplaceArguments.Add(binIn.ReadString());
                    }
                }
                break;

                case Types.FileChunk.SETTINGS_IGNORED_WARNINGS:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    int numIgnoredWarnings = binIn.ReadInt32();

                    for (int i = 0; i < numIgnoredWarnings; ++i)
                    {
                        IgnoredWarnings.Add((C64Studio.Types.ErrorCode)binIn.ReadInt32());
                    }
                }
                break;

                case Types.FileChunk.SETTINGS_PANEL_DISPLAY_DETAILS:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    string toolName = binIn.ReadString();

                    if (GenericTools.ContainsKey(toolName))
                    {
                        uint length = binIn.ReadUInt32();
                        GR.Memory.ByteBuffer data = new GR.Memory.ByteBuffer();

                        binIn.ReadBlock(data, length);
                        GenericTools[toolName].ApplyDisplayDetails(data);
                    }
                }
                break;

                case Types.FileChunk.SETTINGS_BASIC_KEYMAP:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    int numEntries = binIn.ReadInt32();

                    uint neutralLang = (uint)(System.Globalization.CultureInfo.CurrentCulture.KeyboardLayoutId & 0xff);

                    if ((neutralLang != 7) &&
                        (neutralLang != 9))
                    {
                        neutralLang = 9;
                    }

                    for (int i = 0; i < numEntries; ++i)
                    {
                        Keys key = (Keys)binIn.ReadUInt32();
                        Types.KeyboardKey cmdKey = (C64Studio.Types.KeyboardKey)binIn.ReadInt32();

                        var keyMapEntry = new KeymapEntry();

                        foreach (var entry in BASICKeyMap.DefaultKeymaps[neutralLang])
                        {
                            if (entry.Value.KeyboardKey == cmdKey)
                            {
                                BASICKeyMap.Keymap[key] = entry.Value;
                                break;
                            }
                        }
                    }
                }
                break;

                case Types.FileChunk.SETTINGS_ASSEMBLER_EDITOR:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    ASMHideLineNumbers = (binIn.ReadUInt8() != 0);
                }
                break;

                case Types.FileChunk.SETTINGS_BASIC_PARSER:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    BASICStripSpaces = (binIn.ReadUInt8() != 0);
                }
                break;

                case Types.FileChunk.SETTINGS_ENVIRONMENT:
                {
                    GR.IO.IReader binIn = chunkData.MemoryReader();

                    AutoOpenLastSolution = (binIn.ReadUInt8() != 0);
                }
                break;
                }
            }
            return(true);
        }