public override bool HandleImport(CharsetScreenProject CharScreen, CharsetScreenEditor Editor)
        {
            Parser.ASMFileParser asmParser = new RetroDevStudio.Parser.ASMFileParser();

            Parser.CompileConfig config = new Parser.CompileConfig();
            config.TargetType = Types.CompileTargetType.PLAIN;
            config.OutputFile = "temp.bin";
            config.Assembler  = Types.AssemblerType.C64_STUDIO;

            string temp = "* = $0801\n" + editInput.Text;

            if ((asmParser.Parse(temp, null, config, null)) &&
                (asmParser.Assemble(config)))
            {
                GR.Memory.ByteBuffer charData = asmParser.AssembledOutput.Assembly;

                int charsToImport = (int)charData.Length / 8;
                if (charsToImport > CharScreen.CharSet.TotalNumberOfCharacters)
                {
                    charsToImport = CharScreen.CharSet.TotalNumberOfCharacters;
                }

                for (int i = 0; i < charsToImport; ++i)
                {
                    charData.CopyTo(CharScreen.CharSet.Characters[i].Tile.Data, i * 8, 8);
                    Editor.RebuildCharImage(i);
                }

                return(true);
            }
            return(false);
        }
 public UndoCharscreenValuesChange(CharsetScreenProject Project, CharsetScreenEditor Editor)
 {
     this.Project    = Project;
     this.Editor     = Editor;
     BackgroundColor = Project.CharSet.Colors.BackgroundColor;
     Multicolor1     = Project.CharSet.Colors.MultiColor1;
     Multicolor2     = Project.CharSet.Colors.MultiColor2;
     BGColor4        = Project.CharSet.Colors.BGColor4;
     Mode            = Project.Mode;
 }
Exemplo n.º 3
0
        public override bool HandleImport(CharsetScreenProject CharScreen, CharsetScreenEditor Editor)
        {
            switch (comboImportFromDefault.SelectedIndex)
            {
            case 0:
                for (int i = 0; i < 256; ++i)
                {
                    for (int j = 0; j < 8; ++j)
                    {
                        CharScreen.CharSet.Characters[i].Tile.Data.SetU8At(j, ConstantData.UpperCaseCharsetC64.ByteAt(i * 8 + j));
                    }
                    CharScreen.CharSet.Characters[i].Tile.CustomColor = 1;
                }
                Editor.CharsetChanged();
                return(true);

            case 1:
                for (int i = 0; i < 256; ++i)
                {
                    for (int j = 0; j < 8; ++j)
                    {
                        CharScreen.CharSet.Characters[i].Tile.Data.SetU8At(j, ConstantData.LowerCaseCharsetC64.ByteAt(i * 8 + j));
                    }
                    CharScreen.CharSet.Characters[i].Tile.CustomColor = 1;
                }
                Editor.CharsetChanged();
                return(true);

            case 2:
                for (int i = 0; i < 256; ++i)
                {
                    for (int j = 0; j < 8; ++j)
                    {
                        CharScreen.CharSet.Characters[i].Tile.Data.SetU8At(j, ConstantData.UpperCaseCharsetViC20.ByteAt(i * 8 + j));
                    }
                    CharScreen.CharSet.Characters[i].Tile.CustomColor = 1;
                }
                Editor.CharsetChanged();
                return(true);

            case 3:
                for (int i = 0; i < 256; ++i)
                {
                    for (int j = 0; j < 8; ++j)
                    {
                        CharScreen.CharSet.Characters[i].Tile.Data.SetU8At(j, ConstantData.LowerCaseCharsetViC20.ByteAt(i * 8 + j));
                    }
                    CharScreen.CharSet.Characters[i].Tile.CustomColor = 1;
                }
                Editor.CharsetChanged();
                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
        public UndoCharscreenSizeChange(CharsetScreenProject Project, CharsetScreenEditor Editor, int Width, int Height)
        {
            this.Width   = Width;
            this.Height  = Height;
            this.Editor  = Editor;
            this.Project = Project;

            ChangedData.Resize(Width, Height);

            for (int i = 0; i < Width; ++i)
            {
                for (int j = 0; j < Height; ++j)
                {
                    ChangedData[i, j] = Project.Chars[i + j * Width];
                }
            }
        }
Exemplo n.º 5
0
        public UndoCharscreenCharsetChange(CharsetScreenProject Project, CharsetScreenEditor Editor)
        {
            this.Project = Project;
            this.Editor  = Editor;

            CharsetData = new List <CharData>();
            for (int i = 0; i < Project.CharSet.ExportNumCharacters; ++i)
            {
                var Char = new CharData();
                Char.Tile.Data        = new GR.Memory.ByteBuffer(Project.CharSet.Characters[i].Tile.Data);
                Char.Tile.CustomColor = Project.CharSet.Characters[i].Tile.CustomColor;
                Char.Category         = Project.CharSet.Characters[i].Category;
                Char.Index            = i;

                CharsetData.Add(Char);
            }
        }
        public UndoCharscreenCharChange(CharsetScreenProject Project, CharsetScreenEditor Editor, int X, int Y, int Width, int Height)
        {
            this.X       = X;
            this.Y       = Y;
            this.Width   = Width;
            this.Height  = Height;
            this.Editor  = Editor;
            this.Project = Project;

            ChangedData.Resize(Width, Height);

            for (int i = 0; i < Width; ++i)
            {
                for (int j = 0; j < Height; ++j)
                {
                    ChangedData[i, j] = Project.Chars[X + i + (Y + j) * Project.ScreenWidth];
                }
            }
        }
        public override bool HandleImport(CharsetScreenProject CharScreen, CharsetScreenEditor Editor)
        {
            string filename;

            if (Editor.OpenFile("Open Charpad project, Marq's PETSCII editor files or binary data", Constants.FILEFILTER_CHARSET_CHARPAD + Constants.FILEFILTER_MARQS_PETSCII + Constants.FILEFILTER_ALL, out filename))
            {
                if (System.IO.Path.GetExtension(filename).ToUpper() == ".CTM")
                {
                    // a charpad project file
                    GR.Memory.ByteBuffer projectFile = GR.IO.File.ReadAllBytes(filename);

                    Formats.CharpadProject cpProject = new RetroDevStudio.Formats.CharpadProject();
                    if (!cpProject.LoadFromFile(projectFile))
                    {
                        return(false);
                    }

                    CharScreen.CharSet.Colors.BackgroundColor = cpProject.BackgroundColor;
                    CharScreen.CharSet.Colors.MultiColor1     = cpProject.MultiColor1;
                    CharScreen.CharSet.Colors.MultiColor2     = cpProject.MultiColor2;
                    CharScreen.CharSet.Colors.BGColor4        = cpProject.BackgroundColor4;

                    int maxChars = cpProject.NumChars;
                    if (maxChars > CharScreen.CharSet.TotalNumberOfCharacters)
                    {
                        maxChars = CharScreen.CharSet.TotalNumberOfCharacters;
                    }

                    CharScreen.CharSet.ExportNumCharacters = maxChars;
                    for (int charIndex = 0; charIndex < CharScreen.CharSet.ExportNumCharacters; ++charIndex)
                    {
                        CharScreen.CharSet.Characters[charIndex].Tile.Data        = cpProject.Characters[charIndex].Data;
                        CharScreen.CharSet.Characters[charIndex].Tile.CustomColor = cpProject.Characters[charIndex].Color;

                        Editor.RebuildCharImage(charIndex);
                    }

                    // import tiles
                    var mapProject = new MapProject();
                    mapProject.MultiColor1 = cpProject.MultiColor1;
                    mapProject.MultiColor2 = cpProject.MultiColor2;

                    for (int i = 0; i < cpProject.NumTiles; ++i)
                    {
                        Formats.MapProject.Tile tile = new Formats.MapProject.Tile();

                        tile.Name = "Tile " + (i + 1).ToString();
                        tile.Chars.Resize(cpProject.TileWidth, cpProject.TileHeight);
                        tile.Index = i;

                        for (int y = 0; y < tile.Chars.Height; ++y)
                        {
                            for (int x = 0; x < tile.Chars.Width; ++x)
                            {
                                tile.Chars[x, y].Character = (byte)cpProject.Tiles[i].CharData.UInt16At(2 * (x + y * tile.Chars.Width));
                                tile.Chars[x, y].Color     = cpProject.Tiles[i].ColorData.ByteAt(x + y * tile.Chars.Width);
                            }
                        }
                        mapProject.Tiles.Add(tile);
                    }

                    var map = new Formats.MapProject.Map();
                    map.Tiles.Resize(cpProject.MapWidth, cpProject.MapHeight);
                    for (int j = 0; j < cpProject.MapHeight; ++j)
                    {
                        for (int i = 0; i < cpProject.MapWidth; ++i)
                        {
                            map.Tiles[i, j] = cpProject.MapData.ByteAt(i + j * cpProject.MapWidth);
                        }
                    }
                    map.TileSpacingX = cpProject.TileWidth;
                    map.TileSpacingY = cpProject.TileHeight;
                    mapProject.Maps.Add(map);

                    Editor.comboBackground.SelectedIndex  = mapProject.Charset.Colors.BackgroundColor;
                    Editor.comboMulticolor1.SelectedIndex = mapProject.Charset.Colors.MultiColor1;
                    Editor.comboMulticolor2.SelectedIndex = mapProject.Charset.Colors.MultiColor2;
                    Editor.comboBGColor4.SelectedIndex    = mapProject.Charset.Colors.BGColor4;
                    Editor.comboCharsetMode.SelectedIndex = (int)cpProject.DisplayModeFile;

                    GR.Memory.ByteBuffer charData  = new GR.Memory.ByteBuffer((uint)(map.Tiles.Width * map.TileSpacingX * map.Tiles.Height * map.TileSpacingY));
                    GR.Memory.ByteBuffer colorData = new GR.Memory.ByteBuffer((uint)(map.Tiles.Width * map.TileSpacingX * map.Tiles.Height * map.TileSpacingY));

                    for (int y = 0; y < map.Tiles.Height; ++y)
                    {
                        for (int x = 0; x < map.Tiles.Width; ++x)
                        {
                            int tileIndex = map.Tiles[x, y];
                            if (tileIndex < mapProject.Tiles.Count)
                            {
                                // a real tile
                                var tile = mapProject.Tiles[tileIndex];

                                for (int j = 0; j < tile.Chars.Height; ++j)
                                {
                                    for (int i = 0; i < tile.Chars.Width; ++i)
                                    {
                                        charData.SetU8At(x * map.TileSpacingX + i + (y * map.TileSpacingY + j) * (map.Tiles.Width * map.TileSpacingX), tile.Chars[i, j].Character);
                                        colorData.SetU8At(x * map.TileSpacingX + i + (y * map.TileSpacingY + j) * (map.Tiles.Width * map.TileSpacingX), tile.Chars[i, j].Color);
                                    }
                                }
                            }
                        }
                    }

                    if (cpProject.MapColorData != null)
                    {
                        // this charpad project has alternative color data
                        for (int i = 0; i < cpProject.MapHeight; ++i)
                        {
                            for (int j = 0; j < cpProject.MapWidth; ++j)
                            {
                                colorData.SetU8At(j + i * cpProject.MapWidth, cpProject.MapColorData.ByteAt(j + i * cpProject.MapWidth));
                            }
                        }
                    }

                    Editor.ImportFromData(map.TileSpacingX * map.Tiles.Width,
                                          map.TileSpacingY * map.Tiles.Height,
                                          charData, colorData, CharScreen.CharSet);
                }
                else if (System.IO.Path.GetExtension(filename).ToUpper() == ".C")
                {
                    string cData = GR.IO.File.ReadAllText(filename);
                    if (!string.IsNullOrEmpty(cData))
                    {
                        int dataStart = cData.IndexOf('{');
                        if (dataStart == -1)
                        {
                            return(false);
                        }

                        /*
                         * int     dataEnd = cData.IndexOf( '}', dataStart );
                         * if ( dataEnd == -1 )
                         * {
                         * return false;
                         * }
                         * string  actualData = cData.Substring( dataStart + 1, dataEnd - dataStart - 2 );
                         */
                        string actualData = cData.Substring(dataStart + 1);

                        var screenData = new ByteBuffer();

                        var    dataLines = actualData.Split('\n');
                        string dataType  = "";
                        for (int i = 0; i < dataLines.Length; ++i)
                        {
                            var dataLine = dataLines[i].Trim();
                            if (dataLine.StartsWith("//"))
                            {
                                if (dataLine.Contains("META:"))
                                {
                                    int metaPos = dataLine.IndexOf("META:");

                                    // META: 16 25 DIRART upper
                                    string[] parms = dataLine.Substring(metaPos + 5).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                                    if (parms.Length >= 2)
                                    {
                                        int newWidth  = GR.Convert.ToI32(parms[0]);
                                        int newHeight = GR.Convert.ToI32(parms[1]);

                                        if ((newWidth > 0) &&
                                            (newHeight > 0))
                                        {
                                            Editor.SetScreenSize(newWidth, newHeight);
                                        }
                                    }
                                    if (parms.Length >= 3)
                                    {
                                        dataType = parms[2].ToUpper();
                                    }
                                }
                                continue;
                            }
                            int pos      = 0;
                            int commaPos = -1;

                            while (pos < dataLine.Length)
                            {
                                commaPos = dataLine.IndexOf(',', pos);
                                if (commaPos == -1)
                                {
                                    // end of line
                                    byte byteValue = GR.Convert.ToU8(dataLine.Substring(pos));

                                    screenData.AppendU8(byteValue);
                                    break;
                                }
                                else
                                {
                                    byte byteValue = GR.Convert.ToU8(dataLine.Substring(pos, commaPos - pos));

                                    screenData.AppendU8(byteValue);
                                    pos = commaPos + 1;
                                }
                            }
                        }
                        // border and BG first

                        if (dataType != "DIRART")
                        {
                            CharScreen.CharSet.Colors.BackgroundColor = screenData.ByteAt(1);
                            screenData = screenData.SubBuffer(2);
                        }

                        Editor.ImportFromData(screenData);
                    }
                }
                else
                {
                    GR.Memory.ByteBuffer data = GR.IO.File.ReadAllBytes(filename);

                    Editor.ImportFromData(data);
                }
            }

            return(true);
        }
 public virtual bool HandleImport(CharsetScreenProject CharScreen, CharsetScreenEditor Editor)
 {
     return(false);
 }
 public override bool HandleImport(CharsetScreenProject CharScreen, CharsetScreenEditor Editor)
 {
     return(Editor.OpenExternalCharset());
 }
        public override bool HandleImport(CharsetScreenProject CharScreen, CharsetScreenEditor Editor)
        {
            var settings = new RetroDevStudio.Parser.BasicFileParser.ParserSettings();

            settings.StripREM     = true;
            settings.StripSpaces  = true;
            settings.BASICDialect = C64Models.BASIC.Dialect.BASICV2;

            var parser = new RetroDevStudio.Parser.BasicFileParser(settings);

            string[] lines          = editInput.Text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            int      lastLineNumber = -1;

            int  cursorX     = 0;
            int  cursorY     = 0;
            byte curColor    = 14;
            bool reverseMode = false;

            foreach (var line in lines)
            {
                var cleanLine = line.Trim();

                var lineInfo = parser.TokenizeLine(cleanLine, 1, ref lastLineNumber);

                for (int i = 0; i < lineInfo.Tokens.Count; ++i)
                {
                    var token = lineInfo.Tokens[i];

                    if ((token.TokenType == Parser.BasicFileParser.Token.Type.BASIC_TOKEN) &&
                        (token.ByteValue == 0x99))
                    {
                        // a PRINT statement
                        bool hasSemicolonAtEnd = false;
                        while ((i + 1 < lineInfo.Tokens.Count) &&
                               (lineInfo.Tokens[i + 1].Content != ":"))
                        {
                            ++i;

                            var nextToken = lineInfo.Tokens[i];

                            if (nextToken.TokenType == Parser.BasicFileParser.Token.Type.STRING_LITERAL)
                            {
                                // handle incoming PETSCII plus control codes!
                                bool hadError     = false;
                                var  actualString = Parser.BasicFileParser.ReplaceAllMacrosBySymbols(nextToken.Content.Substring(1, nextToken.Content.Length - 2), out hadError);
                                foreach (var singleChar in actualString)
                                {
                                    var key = ConstantData.AllPhysicalKeyInfos.Find(x => x.CharValue == singleChar);
                                    if (key != null)
                                    {
                                        if ((key.Type == KeyType.GRAPHIC_SYMBOL) ||
                                            (key.Type == KeyType.NORMAL))
                                        {
                                            if (reverseMode)
                                            {
                                                Editor.SetCharacter(cursorX, cursorY, (ushort)(key.ScreenCodeValue + 128), curColor);
                                            }
                                            else
                                            {
                                                Editor.SetCharacter(cursorX, cursorY, key.ScreenCodeValue, curColor);
                                            }
                                            ++cursorX;
                                            if (cursorX >= CharScreen.ScreenWidth)
                                            {
                                                cursorX = 0;
                                                ++cursorY;
                                            }
                                        }
                                        else if (key.Type == KeyType.CONTROL_CODE)
                                        {
                                            switch (key.PetSCIIValue)
                                            {
                                            case 5:
                                                curColor = 1;
                                                break;

                                            case 17:
                                                ++cursorY;
                                                break;

                                            case 18:
                                                reverseMode = true;
                                                break;

                                            case 28:
                                                curColor = 2;
                                                break;

                                            case 29:
                                                ++cursorX;
                                                break;

                                            case 30:
                                                curColor = 5;
                                                break;

                                            case 31:
                                                curColor = 6;
                                                break;

                                            case 129:
                                                curColor = 8;
                                                break;

                                            case 144:
                                                curColor = 0;
                                                break;

                                            case 145:
                                                --cursorY;
                                                break;

                                            case 146:
                                                reverseMode = false;
                                                break;

                                            case 149:
                                                curColor = 9;
                                                break;

                                            case 150:
                                                curColor = 10;
                                                break;

                                            case 151:
                                                curColor = 11;
                                                break;

                                            case 152:
                                                curColor = 12;
                                                break;

                                            case 153:
                                                curColor = 13;
                                                break;

                                            case 154:
                                                curColor = 14;
                                                break;

                                            case 155:
                                                curColor = 15;
                                                break;

                                            case 156:
                                                curColor = 4;
                                                break;

                                            case 157:
                                                --cursorX;
                                                if (cursorX < 0)
                                                {
                                                    cursorX += CharScreen.ScreenWidth;
                                                    --cursorY;
                                                }
                                                break;

                                            case 158:
                                                curColor = 7;
                                                break;

                                            case 159:
                                                curColor = 3;
                                                break;
                                            }
                                        }
                                    }
                                }
                                continue;
                            }
                            else if (nextToken.Content == ";")
                            {
                                hasSemicolonAtEnd = true;
                            }
                            else
                            {
                                hasSemicolonAtEnd = false;
                                reverseMode       = false;
                            }
                        }
                        if (!hasSemicolonAtEnd)
                        {
                            cursorX = 0;
                            ++cursorY;

                            // TODO - Scroll up
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 11
0
 public override bool HandleImport(CharsetScreenProject CharScreen, CharsetScreenEditor Editor)
 {
     return(Editor.ImportFromData(Util.FromASMData(editInput.Text)));
 }