예제 #1
0
 public static GR.Memory.ByteBuffer ToFilename(string Name)
 {
     GR.Memory.ByteBuffer bufName = new GR.Memory.ByteBuffer();
     for (int i = 0; i < 16; ++i)
     {
         if (i < Name.Length)
         {
             /*
              * if ( ConstantData.PETSCII.ContainsKey( Name[i] ) )
              * {
              * bufName.AppendU8( ConstantData.PETSCII[Name[i]] );
              * }*/
             var potChar = ConstantData.PetSCIIToChar.Values.FirstOrDefault(v => v.CharValue == Name[i]);
             if (potChar != null)
             {
                 bufName.AppendU8(potChar.PetSCIIValue);
             }
             else
             {
                 bufName.AppendU8((byte)Name[i]);
             }
         }
         else
         {
             bufName.AppendU8(0xa0);
         }
     }
     return(bufName);
 }
        private int HandleMapProject(GR.Text.ArgumentParser ArgParser)
        {
            if (!ValidateExportType("map project file", ArgParser.Parameter("TYPE"), new string[] { "MAPDATA", "MAPDATAASM" }))
            {
                return(1);
            }

            GR.Memory.ByteBuffer data = GR.IO.File.ReadAllBytes(ArgParser.Parameter("MAPPROJECT"));
            if (data == null)
            {
                System.Console.WriteLine("Couldn't read binary char file " + ArgParser.Parameter("MAPPROJECT"));
                return(1);
            }

            var mapProject = new RetroDevStudio.Formats.MapProject();

            if (!mapProject.ReadFromBuffer(data))
            {
                System.Console.WriteLine("Couldn't read map project from file " + ArgParser.Parameter("MAPPROJECT"));
                return(1);
            }

            GR.Memory.ByteBuffer resultingData = new GR.Memory.ByteBuffer();

            if (ArgParser.Parameter("TYPE").Contains("MAPDATAASM"))
            {
                foreach (var map in mapProject.Maps)
                {
                    var mapData = new ByteBuffer((uint)(map.Tiles.Width * map.Tiles.Height));

                    for (int j = 0; j < 0 + map.Tiles.Height; ++j)
                    {
                        for (int i = 0; i < 0 + map.Tiles.Width; ++i)
                        {
                            mapData.SetU8At(i + j * map.Tiles.Width, (byte)map.Tiles[i, j]);
                        }
                    }
                    resultingData.Append(Encoding.ASCII.GetBytes("MAP_" + map.Name + "\n!hex \"" + mapData.ToString() + "\"\n"));
                }
            }
            else if (ArgParser.Parameter("TYPE").Contains("MAPDATA"))
            {
                foreach (var map in mapProject.Maps)
                {
                    for (int j = 0; j < 0 + map.Tiles.Height; ++j)
                    {
                        for (int i = 0; i < 0 + map.Tiles.Width; ++i)
                        {
                            resultingData.AppendU8((byte)map.Tiles[i, j]);
                        }
                    }
                }
            }
            if (!GR.IO.File.WriteAllBytes(ArgParser.Parameter("EXPORT"), resultingData))
            {
                Console.WriteLine("Could not write to file " + ArgParser.Parameter("EXPORT"));
                return(1);
            }
            return(0);
        }
예제 #3
0
 public static GR.Memory.ByteBuffer ToPETSCII(string Name)
 {
     GR.Memory.ByteBuffer bufName = new GR.Memory.ByteBuffer();
     for (int i = 0; i < Name.Length; ++i)
     {
         if (ConstantData.PETSCII.ContainsKey(Name[i]))
         {
             bufName.AppendU8(ConstantData.PETSCII[Name[i]]);
         }
         else
         {
             bufName.AppendU8((byte)Name[i]);
         }
     }
     return(bufName);
 }
예제 #4
0
        internal static ByteBuffer FromBASICHex(string Text)
        {
            string[] lines = Text.Split(new char[] { '\n' });

            GR.Memory.ByteBuffer resultData = new GR.Memory.ByteBuffer();

            for (int i = 0; i < lines.Length; ++i)
            {
                string cleanLine = lines[i].Trim().ToUpper();

                int dataPos = cleanLine.IndexOf("DATA");
                if (dataPos != -1)
                {
                    int commaPos     = -1;
                    int byteStartPos = dataPos + 4;

                    do
                    {
                        commaPos = cleanLine.IndexOf(',', byteStartPos);
                        if (commaPos == -1)
                        {
                            commaPos = cleanLine.Length;
                        }
                        int value = GR.Convert.ToI32(cleanLine.Substring(byteStartPos, commaPos - byteStartPos).Trim(), 16);
                        resultData.AppendU8((byte)value);

                        byteStartPos = commaPos + 1;
                    }while (commaPos < cleanLine.Length);
                }
            }
            return(resultData);
        }
예제 #5
0
        private void btnFromBASIC_Click(object sender, EventArgs e)
        {
            string[] lines = textBinaryData.Text.Split(new char[] { '\n' });

            GR.Memory.ByteBuffer resultData = new GR.Memory.ByteBuffer();

            for (int i = 0; i < lines.Length; ++i)
            {
                string cleanLine = lines[i].Trim().ToUpper();

                int dataPos = cleanLine.IndexOf("DATA");
                if (dataPos != -1)
                {
                    int commaPos     = -1;
                    int byteStartPos = dataPos + 4;

                    do
                    {
                        commaPos = cleanLine.IndexOf(',', byteStartPos);
                        if (commaPos == -1)
                        {
                            commaPos = cleanLine.Length;
                        }
                        int value = GR.Convert.ToI32(cleanLine.Substring(byteStartPos, commaPos - byteStartPos).Trim());
                        resultData.AppendU8((byte)value);

                        byteStartPos = commaPos + 1;
                    }while (commaPos < cleanLine.Length);
                }
            }

            SetHexData(resultData);
        }
예제 #6
0
        public GR.Memory.ByteBuffer ToBuffer()
        {
            GR.Memory.ByteBuffer result = new GR.Memory.ByteBuffer();

            result.AppendI32(Width);
            result.AppendI32(Height);
            result.AppendU32((uint)PixelFormat);

            result.AppendI32(PaletteEntryCount);
            for (int i = 0; i < PaletteEntryCount; ++i)
            {
                result.AppendU8(PaletteRed(i));
                result.AppendU8(PaletteGreen(i));
                result.AppendU8(PaletteBlue(i));
            }
            result.Append(m_ImageData);
            return(result);
        }
예제 #7
0
        private void btnExportCharsetToData_Click(object sender, EventArgs e)
        {
            int wrapByteCount = GR.Convert.ToI32(editWrapByteCount.Text);

            if (wrapByteCount <= 0)
            {
                wrapByteCount = 8;
            }
            string prefix = editPrefix.Text;

            List <int> exportIndices = ListOfExportIndices();

            GR.Memory.ByteBuffer charSet = new GR.Memory.ByteBuffer();
            foreach (int index in exportIndices)
            {
                charSet.Append(m_Charset.Characters[index].Data);
            }

            bool wrapData  = checkExportToDataWrap.Checked;
            bool prefixRes = checkExportToDataIncludeRes.Checked;

            string resultText = "CHARS" + System.Environment.NewLine;

            resultText += Util.ToASMData(charSet, wrapData, wrapByteCount, prefixRes ? prefix : "");
            if (checkIncludeColor.Checked)
            {
                resultText += System.Environment.NewLine + "COLORS" + System.Environment.NewLine;

                GR.Memory.ByteBuffer colorData = new GR.Memory.ByteBuffer();
                foreach (int index in exportIndices)
                {
                    colorData.AppendU8((byte)m_Charset.Characters[index].Color);
                }
                resultText += Util.ToASMData(colorData, wrapData, wrapByteCount, prefixRes ? prefix : "");
            }

            editDataExport.Text = resultText;
        }