Exemplo n.º 1
0
        public override GR.Memory.ByteBuffer Compile()
        {
            _LastError = "";
            GR.Memory.ByteBuffer result = new GR.Memory.ByteBuffer();

            // C64-TAPE-RAW
            result.AppendHex("4336342D544150452D524157");
            // version (0 or 1)
            result.AppendU8(0);
            // reserved
            result.AppendU8(0);
            result.AppendU8(0);
            result.AppendU8(0);
            // size
            result.AppendU32(0);


            foreach (FileEntry file in TapFiles)
            {
                AppendFile(result, file);
            }

            result.SetU32At(16, result.Length - 20);
            return(result);
        }
        public bool ExportToBuffer(out GR.Memory.ByteBuffer CharData, out GR.Memory.ByteBuffer ColorData, out GR.Memory.ByteBuffer CharSetData, int X, int Y, int Width, int Height, bool RowByRow)
        {
            CharData  = new GR.Memory.ByteBuffer();
            ColorData = new GR.Memory.ByteBuffer();

            CharSetData = new GR.Memory.ByteBuffer(CharSet.CharacterData());

            int numBytesPerChar = Lookup.NumBytesOfSingleCharacter(Lookup.TextCharModeFromTextMode(Mode));

            if (RowByRow)
            {
                // row by row
                for (int i = 0; i < Height; ++i)
                {
                    for (int x = 0; x < Width; ++x)
                    {
                        byte   newColor = (byte)((Chars[(Y + i) * ScreenWidth + X + x] & 0xff0000) >> 16);
                        ushort newChar  = (ushort)(Chars[(Y + i) * ScreenWidth + X + x] & 0xffff);

                        if (numBytesPerChar == 2)
                        {
                            CharData.AppendU16(newChar);
                        }
                        else
                        {
                            CharData.AppendU8((byte)newChar);
                        }
                        if (Lookup.TextModeUsesColor(Mode))
                        {
                            ColorData.AppendU8(newColor);
                        }
                    }
                }
            }
            else
            {
                for (int x = 0; x < Width; ++x)
                {
                    for (int i = 0; i < Height; ++i)
                    {
                        byte   newColor = (byte)((Chars[(Y + i) * ScreenWidth + X + x] & 0xff0000) >> 16);
                        ushort newChar  = (ushort)(Chars[(Y + i) * ScreenWidth + X + x] & 0xffff);

                        if (numBytesPerChar == 2)
                        {
                            CharData.AppendU16(newChar);
                        }
                        else
                        {
                            CharData.AppendU8((byte)newChar);
                        }
                        if (Lookup.TextModeUsesColor(Mode))
                        {
                            ColorData.AppendU8(newColor);
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        internal void ExportTilesAsBuffer(bool RowByRow, out GR.Memory.ByteBuffer TileData)
        {
            TileData = new GR.Memory.ByteBuffer();

            foreach (Formats.MapProject.Tile tile in Tiles)
            {
                if (RowByRow)
                {
                    for (int j = 0; j < tile.Chars.Height; ++j)
                    {
                        for (int i = 0; i < tile.Chars.Width; ++i)
                        {
                            TileData.AppendU8((byte)tile.Chars[i, j].Character);
                            TileData.AppendU8((byte)tile.Chars[i, j].Color);
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < tile.Chars.Width; ++i)
                    {
                        for (int j = 0; j < tile.Chars.Height; ++j)
                        {
                            TileData.AppendU8((byte)tile.Chars[i, j].Character);
                            TileData.AppendU8((byte)tile.Chars[i, j].Color);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 void AppendEOD(GR.Memory.ByteBuffer Buffer)
 {
     _LastError = "";
     // end of data marker
     Buffer.AppendU8(0x56);
     Buffer.AppendU8(0x30);
 }
Exemplo n.º 5
0
        public GR.Memory.ByteBuffer ExportAsTiles()
        {
            GR.Memory.ByteBuffer tileData = new GR.Memory.ByteBuffer();

            // find max tile size
            int tileW = 1;
            int tileH = 1;

            foreach (var tile in Tiles)
            {
                if (tile.Chars.Width > tileW)
                {
                    tileW = tile.Chars.Width;
                }
                if (tile.Chars.Height > tileH)
                {
                    tileH = tile.Chars.Height;
                }
            }

            for (int j = 0; j < tileH; ++j)
            {
                for (int i = 0; i < tileW; ++i)
                {
                    foreach (Formats.MapProject.Tile tile in Tiles)
                    {
                        if ((i < tile.Chars.Width) &&
                            (j < tile.Chars.Height))
                        {
                            tileData.AppendU8((byte)tile.Chars[i, j].Character);
                        }
                        else
                        {
                            tileData.AppendU8(0);
                        }
                        if ((i < tile.Chars.Width) &&
                            (j < tile.Chars.Height))
                        {
                            tileData.AppendU8((byte)tile.Chars[i, j].Color);
                        }
                        else
                        {
                            tileData.AppendU8(0);
                        }
                    }
                }
            }
            return(tileData);
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            DiskName = Util.ToFilename(editDiskName.Text);

            while ((DiskName.Length > 0) &&
                   (DiskName.ByteAt((int)DiskName.Length - 1) == 32))
            {
                DiskName.Truncate(1);
            }
            while (DiskName.Length < 16)
            {
                DiskName.AppendU8(0xa0);
            }

            DiskID = Util.ToFilename(editDiskID.Text);

            while ((DiskID.Length > 0) &&
                   (DiskID.ByteAt((int)DiskName.Length - 1) == 32))
            {
                DiskID.Truncate(1);
            }
            while (DiskID.Length < 16)
            {
                DiskID.AppendU8(0xa0);
            }

            DialogResult = DialogResult.OK;
            Close();
        }
        public override bool HandleExport(ExportCharsetInfo Info, TextBox EditOutput, DocumentInfo DocInfo)
        {
            int    wrapByteCount = GetExportWrapCount();
            string prefix        = editPrefix.Text;

            GR.Memory.ByteBuffer charSet = new GR.Memory.ByteBuffer();
            foreach (int index in Info.ExportIndices)
            {
                charSet.Append(Info.Charset.Characters[index].Tile.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 Info.ExportIndices)
                {
                    colorData.AppendU8((byte)Info.Charset.Characters[index].Tile.CustomColor);
                }
                resultText += Util.ToASMData(colorData, wrapData, wrapByteCount, prefixRes ? prefix : "");
            }

            EditOutput.Text = resultText;
            return(true);
        }
Exemplo n.º 8
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 (Types.ConstantData.PETSCII.ContainsKey(Name[i]))
         {
             bufName.AppendU8(Types.ConstantData.PETSCII[Name[i]]);
         }
         else
         {
             bufName.AppendU8((byte)Name[i]);
         }
     }
     return(bufName);
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        private GR.Memory.ByteBuffer PadString(GR.Memory.ByteBuffer Text, int Digits, byte fillChar)
        {
            GR.Memory.ByteBuffer result = new GR.Memory.ByteBuffer();

            int useCharCount = Digits;

            if (Text.Length < useCharCount)
            {
                useCharCount = (int)Text.Length;
            }
            for (int i = 0; i < useCharCount; ++i)
            {
                result.AppendU8(Text.ByteAt(i));
            }
            while (result.Length < Digits)
            {
                result.AppendU8(fillChar);
            }
            return(result);
        }
Exemplo n.º 12
0
        public GR.Memory.ByteBuffer GenerateTableData()
        {
            GR.Memory.ByteBuffer exportData = new GR.Memory.ByteBuffer();

            foreach (var entry in ValueTable.Values)
            {
                exportData.AppendU8(GR.Convert.ToU8(entry));
            }

            return(exportData);
        }
Exemplo n.º 13
0
        /*
         *  Koalafile http://www.c64-wiki.de/index.php?title=Koala_Painter#Koala-Dateiformat
         *  Koalaformat has an Loading address (first two bytes) [00 60]
         *  ====================================================================
         *  Offset (hex): Content
         *  --------------------------------------------------------------------
         *  0000 - 1F3F : Bitmap 8000 Bytes
         *  1F40 - 2327 : Screen-RAM 1000 Bytes
         *  2328 - 270F : Color-RAM 1000 Bytes
         *  2710        : Background 1 Byte
         *
         *
         *  C64 MC Mode http://www.c64-wiki.de/index.php/Multicolor
         *  ====================================================================
         *  Color-Bits	Corresponding-Color	                        Address
         *  --------------------------------------------------------------------
         *  00	        Background	                                53281
         *  01	        Upper (four Bits/Nibble)...                 1024-2023
         *  10	        Lower (four Bits/Nibble) of Screen-RAM	    1024-2023
         *  11	        Color-RAM                                   55296-56295
         */


        public static GR.Memory.ByteBuffer KoalaFromBitmap(GR.Memory.ByteBuffer BitmapData, GR.Memory.ByteBuffer ScreenRAM, GR.Memory.ByteBuffer ColorRAM, byte BackgroundColor)
        {
            GR.Memory.ByteBuffer result = new GR.Memory.ByteBuffer();
            result.AppendU16(0x6000);
            result.Append(BitmapData);
            result.Append(ScreenRAM);
            result.Append(ColorRAM);
            result.AppendU8(BackgroundColor);

            return(result);
        }
Exemplo n.º 14
0
        private void AppendByte(GR.Memory.ByteBuffer Data, byte Value)
        {
            // new data marker
            Data.AppendU8(0x56);
            Data.AppendU8(0x42);

            byte checkBit = 1;

            for (int i = 0; i < 8; ++i)
            {
                if ((Value & (1 << i)) != 0)
                {
                    // bit set
                    Data.AppendU8(0x42);
                    Data.AppendU8(0x30);

                    checkBit ^= 1;
                }
                else
                {
                    Data.AppendU8(0x30);
                    Data.AppendU8(0x42);
                    checkBit ^= 0;
                }
            }

            if (checkBit == 1)
            {
                // bit set
                Data.AppendU8(0x42);
                Data.AppendU8(0x30);
            }
            else
            {
                Data.AppendU8(0x30);
                Data.AppendU8(0x42);
            }
            CheckSum ^= Value;
        }
Exemplo n.º 15
0
        public bool ExportToBuffer(out GR.Memory.ByteBuffer CharData, out GR.Memory.ByteBuffer ColorData, out GR.Memory.ByteBuffer CharSetData, int X, int Y, int Width, int Height, bool RowByRow)
        {
            CharData  = new GR.Memory.ByteBuffer();
            ColorData = new GR.Memory.ByteBuffer();

            CharSetData = new GR.Memory.ByteBuffer(CharSet.CharacterData());

            if (RowByRow)
            {
                // row by row
                for (int i = 0; i < Height; ++i)
                {
                    for (int x = 0; x < Width; ++x)
                    {
                        byte newColor = (byte)((Chars[(Y + i) * ScreenWidth + X + x] & 0xff00) >> 8);
                        byte newChar  = (byte)(Chars[(Y + i) * ScreenWidth + X + x] & 0xff);

                        CharData.AppendU8(newChar);
                        ColorData.AppendU8(newColor);
                    }
                }
            }
            else
            {
                for (int x = 0; x < Width; ++x)
                {
                    for (int i = 0; i < Height; ++i)
                    {
                        byte newColor = (byte)((Chars[(Y + i) * ScreenWidth + X + x] & 0xff00) >> 8);
                        byte newChar  = (byte)(Chars[(Y + i) * ScreenWidth + X + x] & 0xff);

                        CharData.AppendU8(newChar);
                        ColorData.AppendU8(newColor);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 16
0
            public GR.Memory.ByteBuffer SubBuffer(int iIndex)
            {
                GR.Memory.ByteBuffer bbResult = new GR.Memory.ByteBuffer();

                if (iIndex >= Length)
                {
                    return(bbResult);
                }
                for (int i = iIndex; i < Length; ++i)
                {
                    bbResult.AppendU8(ByteAt(i));
                }
                return(bbResult);
            }
Exemplo n.º 17
0
        public GR.Memory.ByteBuffer SaveToBuffer()
        {
            GR.Memory.ByteBuffer projectFile = new GR.Memory.ByteBuffer();

            // version
            projectFile.AppendU32(1);
            // Name
            projectFile.AppendString(Name);
            // Value table
            // number of entries
            projectFile.AppendI32(ValueTable.Values.Count);
            foreach (var entry in ValueTable.Values)
            {
                projectFile.AppendString(entry);
            }
            projectFile.AppendString(ValueTable.Formula);
            projectFile.AppendString(ValueTable.StartValue);
            projectFile.AppendString(ValueTable.EndValue);
            projectFile.AppendString(ValueTable.StepValue);
            projectFile.AppendU8((byte)(ValueTable.GenerateDeltas ? 1 : 0));

            return(projectFile);
        }
Exemplo n.º 18
0
        public bool ExportTilesAsElements(out string TileData, string LabelPrefix, bool WrapData, int WrapByteCount, string DataByteDirective)
        {
            GR.Memory.ByteBuffer tileDataW = new GR.Memory.ByteBuffer();
            GR.Memory.ByteBuffer tileDataH = new GR.Memory.ByteBuffer();

            StringBuilder sbTileCharLo  = new StringBuilder();
            StringBuilder sbTileCharHi  = new StringBuilder();
            StringBuilder sbTileColorLo = new StringBuilder();
            StringBuilder sbTileColorHi = new StringBuilder();
            StringBuilder sbTileChars   = new StringBuilder();
            StringBuilder sbTileColors  = new StringBuilder();

            GR.Memory.ByteBuffer tileDataChars = new GR.Memory.ByteBuffer();
            GR.Memory.ByteBuffer tileDataHi    = new GR.Memory.ByteBuffer();

            foreach (Formats.MapProject.Tile tile in Tiles)
            {
                tileDataW.AppendU8((byte)tile.Chars.Width);
                tileDataH.AppendU8((byte)tile.Chars.Height);

                sbTileCharLo.Append(DataByteDirective);
                sbTileCharLo.Append(" <" + LabelPrefix + "TILE_CHAR_" + tile.Name.ToUpper() + Environment.NewLine);
                sbTileCharHi.Append(DataByteDirective);
                sbTileCharHi.Append(" >" + LabelPrefix + "TILE_CHAR_" + tile.Name.ToUpper() + Environment.NewLine);

                sbTileColorLo.Append(DataByteDirective);
                sbTileColorLo.Append(" <" + LabelPrefix + "TILE_COLOR_" + tile.Name.ToUpper() + Environment.NewLine);
                sbTileColorHi.Append(DataByteDirective);
                sbTileColorHi.Append(" >" + LabelPrefix + "TILE_COLOR_" + tile.Name.ToUpper() + Environment.NewLine);

                sbTileChars.Append(LabelPrefix + "TILE_CHAR_" + tile.Name.ToUpper() + Environment.NewLine);

                var tileCharData = new GR.Memory.ByteBuffer();
                for (int j = 0; j < tile.Chars.Height; ++j)
                {
                    for (int i = 0; i < tile.Chars.Width; ++i)
                    {
                        tileCharData.AppendU8(tile.Chars[i, j].Character);
                    }
                }
                sbTileChars.AppendLine(Util.ToASMData(tileCharData, WrapData, WrapByteCount, DataByteDirective));


                sbTileColors.Append(LabelPrefix + "TILE_COLOR_" + tile.Name.ToUpper() + Environment.NewLine);

                var tileColorData = new GR.Memory.ByteBuffer();
                for (int j = 0; j < tile.Chars.Height; ++j)
                {
                    for (int i = 0; i < tile.Chars.Width; ++i)
                    {
                        tileColorData.AppendU8(tile.Chars[i, j].Color);
                    }
                }
                sbTileColors.AppendLine(Util.ToASMData(tileColorData, WrapData, WrapByteCount, DataByteDirective));
            }
            TileData = LabelPrefix + "NUM_TILES = " + Tiles.Count + System.Environment.NewLine
                       + LabelPrefix + "TILE_WIDTH" + System.Environment.NewLine + Util.ToASMData(tileDataW, WrapData, WrapByteCount, DataByteDirective) + System.Environment.NewLine
                       + LabelPrefix + "TILE_HEIGHT" + System.Environment.NewLine + Util.ToASMData(tileDataH, WrapData, WrapByteCount, DataByteDirective) + System.Environment.NewLine
                       + LabelPrefix + "TILE_CHARS_LO" + System.Environment.NewLine
                       + sbTileCharLo.ToString() + System.Environment.NewLine
                       + LabelPrefix + "TILE_CHARS_HI" + System.Environment.NewLine
                       + sbTileCharHi.ToString() + System.Environment.NewLine
                       + LabelPrefix + "TILE_COLORS_LO" + System.Environment.NewLine
                       + sbTileColorLo.ToString() + System.Environment.NewLine
                       + LabelPrefix + "TILE_COLORS_HI" + System.Environment.NewLine
                       + sbTileColorHi.ToString() + System.Environment.NewLine
                       + sbTileChars.ToString() + System.Environment.NewLine
                       + sbTileColors.ToString() + System.Environment.NewLine;
            return(true);
        }
Exemplo n.º 19
0
        public override GR.Memory.ByteBuffer Compile()
        {
            _LastError = "";

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

            // Tape Header
            // 0 32 DOS tape description + EOF (for type)
            // 32 2 tape version ($0200)
            // 34 2 number of directory entries
            // 36 2 number of used entries (can be 0 in my loader)
            // 38 2 free
            // 40 24 user description as displayed in tape menu
            int usedEntries = 0;

            for (int i = 0; i < 30; ++i)
            {
                // File Header
                // Offset Size Description
                // 0 1 entry type (see below)
                // 1 1 C64 file type
                // 2 2 start address
                // 4 2 end address
                // 6 2 free
                // 8 4 offset of file contents start within T64 file
                // 12 4 free
                // 16 16 C64 file name
                if ((i >= FileRecords.Count) ||
                    (FileRecords[i].EntryType == 0))
                {
                }
                else
                {
                    ++usedEntries;
                }
            }

            result.Append(PadString(TapeInfo.Description + (char)0x1a, 32, 0x2e));
            result.AppendU16(TapeInfo.Version);
            result.AppendU16(30);
            result.AppendU16((ushort)usedEntries);
            result.AppendU16(0);
            result.Append(PadString(TapeInfo.UserDescription, 24, 0x20));

            int completeOffset = 64 + 30 * 32;

            for (int i = 0; i < 30; ++i)
            {
                // File Header
                // Offset Size Description
                // 0 1 entry type (see below)
                // 1 1 C64 file type
                // 2 2 start address
                // 4 2 end address
                // 6 2 free
                // 8 4 offset of file contents start within T64 file
                // 12 4 free
                // 16 16 C64 file name
                if ((i >= FileRecords.Count) ||
                    (FileRecords[i].EntryType == 0))
                {
                    GR.Memory.ByteBuffer dummy = new GR.Memory.ByteBuffer(32);
                    result.Append(dummy);
                }
                else
                {
                    result.AppendU8((byte)FileRecords[i].EntryType);
                    result.AppendU8((byte)FileRecords[i].C64FileType);
                    result.AppendU16(FileRecords[i].StartAddress);
                    result.AppendU16((ushort)(FileRecords[i].StartAddress + FileDatas[i].Length));
                    result.AppendU16(0);
                    result.AppendU32((uint)completeOffset);
                    result.AppendU32(0);
                    result.Append(PadString(FileRecords[i].Filename, 16, 0x20));

                    completeOffset += (int)FileDatas[i].Length;
                }
            }
            for (int i = 0; i < FileRecords.Count; ++i)
            {
                result.Append(FileDatas[i]);
            }
            return(result);
        }
        private int HandleCharscreenFile(GR.Text.ArgumentParser ArgParser)
        {
            if (!ValidateExportType("charscreen file", ArgParser.Parameter("TYPE"), new string[] { "CHARS", "CHARSCOLORS", "COLORS" }))
            {
                return(1);
            }

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

            var charScreenProject = new RetroDevStudio.Formats.CharsetScreenProject();

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

            int x      = 0;
            int y      = 0;
            int width  = -1;
            int height = -1;

            if (ArgParser.IsParameterSet("AREA"))
            {
                string   rangeInfo  = ArgParser.Parameter("AREA");
                string[] rangeParts = rangeInfo.Split(',');
                if (rangeParts.Length != 4)
                {
                    System.Console.WriteLine("AREA is invalid, expected four values separated by comma: x,y,width,height");
                    return(1);
                }
                x      = GR.Convert.ToI32(rangeParts[0]);
                y      = GR.Convert.ToI32(rangeParts[1]);
                width  = GR.Convert.ToI32(rangeParts[2]);
                height = GR.Convert.ToI32(rangeParts[3]);

                if ((width <= 0) ||
                    (height <= 0) ||
                    (x < 0) ||
                    (y < 0) ||
                    (x + width > charScreenProject.ScreenWidth) ||
                    (y + height > charScreenProject.ScreenHeight))
                {
                    System.Console.WriteLine("AREA values are out of bounds or invalid, expected four values separated by comma: x,y,width,height");
                    return(1);
                }
            }
            else
            {
                width  = charScreenProject.ScreenWidth;
                height = charScreenProject.ScreenHeight;
            }

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

            if (ArgParser.Parameter("TYPE").Contains("CHARS"))
            {
                for (int j = y; j < y + height; ++j)
                {
                    for (int i = x; i < x + width; ++i)
                    {
                        resultingData.AppendU8((byte)charScreenProject.Chars[i + j * charScreenProject.ScreenWidth]);
                    }
                }
            }
            if (ArgParser.Parameter("TYPE").Contains("COLORS"))
            {
                for (int j = y; j < y + height; ++j)
                {
                    for (int i = x; i < x + width; ++i)
                    {
                        resultingData.AppendU8((byte)(charScreenProject.Chars[i + j * charScreenProject.ScreenWidth] >> 8));
                    }
                }
            }
            if (!GR.IO.File.WriteAllBytes(ArgParser.Parameter("EXPORT"), resultingData))
            {
                Console.WriteLine("Could not write to file " + ArgParser.Parameter("EXPORT"));
                return(1);
            }
            return(0);
        }
Exemplo n.º 21
0
        public GR.Memory.ByteBuffer CreateHDIBAsBuffer()
        {
            GR.Memory.ByteBuffer result = new GR.Memory.ByteBuffer();
            BITMAPINFOHEADER     bi     = new BITMAPINFOHEADER();
            int    dwLen;
            IntPtr hDIB;

            if ((BitsPerPixel != 1) &&
                (BitsPerPixel != 2) &&
                (BitsPerPixel != 4) &&
                (BitsPerPixel != 8) &&
                (BitsPerPixel != 15) &&
                (BitsPerPixel != 16) &&
                (BitsPerPixel != 24) &&
                (BitsPerPixel != 32))
            {
                // not supported depth
                return(null);
            }

            bi.biSize     = System.Runtime.InteropServices.Marshal.SizeOf(bi);
            bi.biWidth    = Width;
            bi.biHeight   = Height;
            bi.biPlanes   = 1;
            bi.biBitCount = (short)BitsPerPixel;
            if (bi.biBitCount == 15)
            {
                bi.biBitCount = 16;
            }
            bi.biCompression = (int)BitmapCompression.BI_RGB;

            bi.biSizeImage     = (int)(((((uint)bi.biWidth * bi.biBitCount) + 31) / 32 * 4) * bi.biHeight);
            bi.biXPelsPerMeter = 0;
            bi.biYPelsPerMeter = 0;
            bi.biClrUsed       = 0;
            bi.biClrImportant  = 0;

            // calculate size of memory block required to store BITMAPINFO
            dwLen = bi.biSize + PaletteSize(bi) + bi.biSizeImage;

            hDIB = System.Runtime.InteropServices.Marshal.AllocHGlobal(dwLen);
            if (hDIB == IntPtr.Zero)
            {
                // uh oh
                return(null);
            }
            unsafe
            {
                // lock memory block and get pointer to it
                BITMAPINFOHEADER *lpbi = (BITMAPINFOHEADER *)GlobalLock(hDIB);

                // Daten in den Puffer kopieren
                *lpbi = bi;

                // Bild-Daten kopieren
                switch (bi.biBitCount)
                {
                case 1:
                {
                    // Palette in DC setzen
                    if (PaletteEntryCount > 0)
                    {
                        RGBQUAD *bmiColor;

                        bmiColor = (RGBQUAD *)((byte *)lpbi + lpbi->biSize);

                        for (int i = 0; i < 2; i++)
                        {
                            bmiColor[i].rgbRed      = PaletteRed(i);
                            bmiColor[i].rgbGreen    = PaletteGreen(i);
                            bmiColor[i].rgbBlue     = PaletteBlue(i);
                            bmiColor[i].rgbReserved = 0;
                        }
                    }

                    byte *pData = (byte *)lpbi + lpbi->biSize + PaletteSize(bi);

                    int iLO = Width / 8;
                    if ((Width & 7) != 0)
                    {
                        iLO++;
                    }
                    if ((iLO % 4) != 0)
                    {
                        iLO += 4 - (iLO % 4);
                    }

                    /*
                     * GR::Graphic::ContextDescriptor    cdImage( Image );
                     * GR::Graphic::ContextDescriptor    cdTarget;
                     *
                     * cdTarget.Attach( cdImage.Width(), cdImage.Height(), iLO, cdImage.ImageFormat(), pData );
                     *
                     * for ( int j = 0; j < Image.Height(); j++ )
                     * {
                     * cdTarget.HLine( 0, cdTarget.Width() - 1, j, 1 );
                     * cdTarget.HLine( 1, cdTarget.Width() - 2, j, 0 );
                     * }*/
                }
                break;

                case 4:
                {
                    // Palette in DC setzen
                    if (PaletteEntryCount > 0)
                    {
                        RGBQUAD *bmiColor = (RGBQUAD *)((byte *)lpbi + lpbi->biSize);

                        for (int i = 0; i < 16; i++)
                        {
                            bmiColor[i].rgbRed      = PaletteRed(i);
                            bmiColor[i].rgbGreen    = PaletteGreen(i);
                            bmiColor[i].rgbBlue     = PaletteBlue(i);
                            bmiColor[i].rgbReserved = 0;
                        }
                    }

                    byte *pData = (byte *)lpbi + lpbi->biSize + PaletteSize(bi);

                    int iLO = Width / 2;
                    if ((Width & 1) != 0)
                    {
                        iLO++;
                    }
                    if ((iLO % 4) != 0)
                    {
                        iLO += 4 - (iLO % 4);
                    }
                    for (int j = 0; j < Height; j++)
                    {
                        for (int i = 0; i < Width; i++)
                        {
                            ((byte *)pData)[i + (Height - j - 1) * iLO] = (byte)GetPixel(i, j);
                        }
                    }

                    /*
                     * GR::Graphic::ContextDescriptor    cdImage( Image );
                     * GR::Graphic::ContextDescriptor    cdTarget;
                     *
                     * cdTarget.Attach( cdImage.Width(), cdImage.Height(), iLO, cdImage.ImageFormat(), pData );
                     *
                     * for ( int j = 0; j < Image.Height(); j++ )
                     * {
                     * cdImage.CopyLine( 0, j, cdImage.Width(), 0, cdImage.Height() - j - 1, &cdTarget );
                     * }*/
                }
                break;

                case 8:
                {
                    // Palette in DC setzen
                    if (PaletteEntryCount > 0)
                    {
                        RGBQUAD *bmiColor;

                        bmiColor = (RGBQUAD *)((byte *)lpbi + lpbi->biSize);

                        for (int i = 0; i < 256; i++)
                        {
                            bmiColor[i].rgbRed      = PaletteRed(i);
                            bmiColor[i].rgbGreen    = PaletteGreen(i);
                            bmiColor[i].rgbBlue     = PaletteBlue(i);
                            bmiColor[i].rgbReserved = 0;
                        }
                    }

                    byte *pData = (byte *)lpbi + lpbi->biSize + PaletteSize(bi);

                    int iLO = Width;
                    if ((iLO % 4) != 0)
                    {
                        iLO += 4 - (iLO % 4);
                    }
                    for (int j = 0; j < Height; j++)
                    {
                        for (int i = 0; i < Width; i++)
                        {
                            ((byte *)pData)[i + (Height - j - 1) * iLO] = (byte)GetPixel(i, j);
                        }
                    }
                }
                break;

                case 16:
                {
                    byte *pData = (byte *)lpbi + lpbi->biSize + PaletteSize(bi);

                    int iLO = Width * 2;
                    if ((iLO % 4) != 0)
                    {
                        iLO += 4 - (iLO % 4);
                    }
                    for (int j = 0; j < Height; j++)
                    {
                        for (int i = 0; i < Width; i++)
                        {
                            ((ushort *)pData)[i + (Height - j - 1) * iLO / 2] = (ushort)GetPixel(i, j);
                        }
                    }
                }
                break;

                /*
                 * case 24:
                 * {
                 * byte    *pData = (byte*)lpbi + lpbi->biSize + PaletteSize( bi );
                 *
                 * int iLO = Width * 3;
                 * if ( ( iLO % 4 ) != 0 )
                 * {
                 *  iLO += 4 - ( iLO % 4 );
                 * }
                 * for ( int j = 0; j < Height; j++ )
                 * {
                 *  for ( int i = 0; i < Width; i++ )
                 *  {
                 *    ( (byte*)pData )[3 * i + ( Height - j - 1 ) * iLO] = (byte)*( (byte*)Image.Data() + 3 * ( i + j * Image.Width() ) );
                 *    ( (byte*)pData )[3 * i + ( Height - j - 1 ) * iLO + 1] = (byte)*( (byte*)Image.Data() + 3 * ( i + j * Image.Width() ) + 1 );
                 *    ( (byte*)pData )[3 * i + ( Height - j - 1 ) * iLO + 2] = (byte)*( (byte*)Image.Data() + 3 * ( i + j * Image.Width() ) + 2 );
                 *  }
                 * }
                 * }
                 * break;*/
                case 32:
                {
                    byte *pData = (byte *)lpbi + lpbi->biSize + PaletteSize(bi);

                    int iLO = Width;
                    for (int j = 0; j < Height; j++)
                    {
                        for (int i = 0; i < Width; i++)
                        {
                            ((uint *)pData)[i + (Height - j - 1) * iLO] = GetPixel(i, j);
                        }
                    }
                }
                break;

                default:
                    Debug.Log("CreateHDIBAsBuffer unsupported depth " + bi.biBitCount);
                    break;
                }

                byte *pDIBData = (byte *)lpbi;
                for (int i = 0; i < bi.biSize + PaletteSize(bi) + bi.biSizeImage; ++i)
                {
                    result.AppendU8(pDIBData[i]);
                }

                //bi = *lpbi;
                GlobalUnlock(hDIB);

                System.Runtime.InteropServices.Marshal.FreeHGlobal(hDIB);
            }

            return(result);
        }
        public GR.Memory.ByteBuffer SaveToBuffer()
        {
            GR.Memory.ByteBuffer projectFile = new GR.Memory.ByteBuffer();

            // version
            projectFile.AppendU32(1);
            // Name
            projectFile.AppendString(System.IO.Path.GetFileNameWithoutExtension(Name));
            // charset Filename
            projectFile.AppendString(System.IO.Path.GetFileNameWithoutExtension(Name));

            for (int i = 0; i < 256; ++i)
            {
                projectFile.AppendI32(Characters[i].Color);
            }
            for (int i = 0; i < 256; ++i)
            {
                projectFile.AppendU8(Characters[i].Multicolor ? (byte)1 : (byte)0);
            }
            projectFile.AppendI32(BackgroundColor);
            projectFile.AppendI32(MultiColor1);
            projectFile.AppendI32(MultiColor2);

            for (int i = 0; i < 256; ++i)
            {
                // Tile colors
                projectFile.AppendI32(0);
                projectFile.AppendI32(0);
                projectFile.AppendI32(0);
                projectFile.AppendI32(0);
                // Tile chars
                projectFile.AppendI32(0);
                projectFile.AppendI32(0);
                projectFile.AppendI32(0);
                projectFile.AppendI32(0);
            }

            // generic multi color
            projectFile.AppendI32(0);

            // test bed
            projectFile.Append(new GR.Memory.ByteBuffer(64));

            // charset data
            for (int i = 0; i < 256; ++i)
            {
                projectFile.Append(Characters[i].Data);
            }

            // used tiles
            projectFile.AppendU32(UsedTiles);

            // export name
            projectFile.AppendString(ExportFilename);
            // export path block table
            projectFile.AppendString("");
            // export path charset
            projectFile.AppendString("");
            // export path editor tiles
            projectFile.AppendString("");
            // categories
            projectFile.AppendI32(Categories.Count);
            foreach (System.Collections.Generic.KeyValuePair <int, string> category in Categories)
            {
                projectFile.AppendI32(category.Key);
                projectFile.AppendString(category.Value);
            }
            for (int i = 0; i < 256; ++i)
            {
                projectFile.AppendI32(Characters[i].Category);
            }
            return(projectFile);
        }
Exemplo n.º 23
0
        public GR.Memory.ByteBuffer SaveToBuffer()
        {
            GR.Memory.ByteBuffer projectFile = new GR.Memory.ByteBuffer();

            // version
            projectFile.AppendU32(1);
            // Name
            projectFile.AppendString(System.IO.Path.GetFileNameWithoutExtension(Name));
            // charset Filename
            projectFile.AppendString(System.IO.Path.GetFileNameWithoutExtension(Name));

            for (int i = 0; i < 256; ++i)
            {
                projectFile.AppendI32(Characters[i].Color);
            }
            for (int i = 0; i < 256; ++i)
            {
                projectFile.AppendU8((byte)Characters[i].Mode);
            }
            projectFile.AppendI32(BackgroundColor);
            projectFile.AppendI32(MultiColor1);
            projectFile.AppendI32(MultiColor2);

            for (int i = 0; i < 256; ++i)
            {
                // Tile colors
                projectFile.AppendI32(0);
                projectFile.AppendI32(0);
                projectFile.AppendI32(0);
                projectFile.AppendI32(0);
                // Tile chars
                projectFile.AppendI32(0);
                projectFile.AppendI32(0);
                projectFile.AppendI32(0);
                projectFile.AppendI32(0);
            }

            // generic multi color
            projectFile.AppendI32(0);

            // test bed
            projectFile.Append(new GR.Memory.ByteBuffer(64));

            // charset data
            for (int i = 0; i < 256; ++i)
            {
                projectFile.Append(Characters[i].Data);
            }

            // used tiles
            projectFile.AppendU32(UsedTiles);

            // export name
            projectFile.AppendString(ExportFilename);
            // export path block table
            projectFile.AppendString("");
            // export path charset
            projectFile.AppendString("");
            // export path editor tiles
            projectFile.AppendString("");
            // categories
            projectFile.AppendI32(Categories.Count);
            for (int i = 0; i < Categories.Count; ++i)
            {
                projectFile.AppendI32(i);
                projectFile.AppendString(Categories[i]);
            }
            for (int i = 0; i < 256; ++i)
            {
                projectFile.AppendI32(Characters[i].Category);
            }
            projectFile.AppendI32(NumCharacters);
            projectFile.AppendI32(ShowGrid ? 1 : 0);
            projectFile.AppendI32(StartCharacter);
            projectFile.AppendI32(BGColor4);

            // playground
            projectFile.AppendI32(16); // w
            projectFile.AppendI32(16); // h

            for (int i = 0; i < PlaygroundChars.Count; ++i)
            {
                projectFile.AppendU16(PlaygroundChars[i]);
            }
            return(projectFile);
        }
Exemplo n.º 24
0
        public GR.Memory.ByteBuffer SaveToBuffer()
        {
            GR.Memory.ByteBuffer projectFile = new GR.Memory.ByteBuffer();

            // version
            projectFile.AppendU32(1);
            projectFile.AppendI32(Sprites.Count);
            // Name
            projectFile.AppendString(Name);
            for (int i = 0; i < Sprites.Count; ++i)
            {
                projectFile.AppendI32(Sprites[i].Color);
            }
            for (int i = 0; i < Sprites.Count; ++i)
            {
                projectFile.AppendU8(Sprites[i].Multicolor ? (byte)1 : (byte)0);
            }
            projectFile.AppendI32(BackgroundColor);
            projectFile.AppendI32(MultiColor1);
            projectFile.AppendI32(MultiColor2);
            // generic MC
            projectFile.AppendU32(0);
            for (int i = 0; i < Sprites.Count; ++i)
            {
                projectFile.Append(Sprites[i].Data);
                projectFile.AppendU8((byte)Sprites[i].Color);
            }
            projectFile.AppendU32(UsedSprites);

            // export name
            projectFile.AppendString(ExportFilename);

            // exportpath
            projectFile.AppendString("");

            // desc
            for (int i = 0; i < Sprites.Count; ++i)
            {
                projectFile.AppendString("");
            }

            // testbed (not used anymore, write 0 as number of sprites)
            projectFile.AppendI32(0);


            foreach (var layer in SpriteLayers)
            {
                GR.IO.FileChunk chunkLayer = new GR.IO.FileChunk(Types.FileChunk.SPRITESET_LAYER);

                GR.IO.FileChunk chunkLayerInfo = new GR.IO.FileChunk(Types.FileChunk.SPRITESET_LAYER_INFO);
                chunkLayerInfo.AppendString(layer.Name);
                chunkLayerInfo.AppendU8((byte)layer.BackgroundColor);
                chunkLayer.Append(chunkLayerInfo.ToBuffer());

                foreach (var sprite in layer.Sprites)
                {
                    GR.IO.FileChunk chunkLayerSprite = new GR.IO.FileChunk(Types.FileChunk.SPRITESET_LAYER_ENTRY);
                    chunkLayerSprite.AppendI32(sprite.Index);
                    chunkLayerSprite.AppendU8((byte)sprite.Color);
                    chunkLayerSprite.AppendI32(sprite.X);
                    chunkLayerSprite.AppendI32(sprite.Y);
                    chunkLayerSprite.AppendU8((byte)(sprite.ExpandX ? 1 : 0));
                    chunkLayerSprite.AppendU8((byte)(sprite.ExpandY ? 1 : 0));

                    chunkLayer.Append(chunkLayerSprite.ToBuffer());
                }
                projectFile.Append(chunkLayer.ToBuffer());
            }

            /*
             * int spriteTestCount = memIn.ReadInt32();
             * for ( int i = 0; i < spriteTestCount; ++i )
             * {
             * int spriteIndex = memIn.ReadInt32();
             * byte spriteColor = memIn.ReadUInt8();
             * bool spriteMultiColor = ( memIn.ReadUInt8() != 0 );
             * int spriteX = memIn.ReadInt32();
             * int spriteY = memIn.ReadInt32();
             * }*/
            return(projectFile);
        }