コード例 #1
0
ファイル: CharsetEditor.cs プロジェクト: aiSzzPL77/C64Studio
        private void btnExportCharset_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.SaveFileDialog saveDlg = new System.Windows.Forms.SaveFileDialog();

            saveDlg.FileName = m_Charset.ExportFilename;
            saveDlg.Title    = "Export Charset to";
            saveDlg.Filter   = "Charset|*.chr|All Files|*.*";
            if (DocumentInfo.Project != null)
            {
                saveDlg.InitialDirectory = DocumentInfo.Project.Settings.BasePath;
            }
            if (saveDlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            if (m_Charset.ExportFilename != saveDlg.FileName)
            {
                m_Charset.ExportFilename = saveDlg.FileName;
                Modified = true;
            }
            GR.Memory.ByteBuffer charSet = new GR.Memory.ByteBuffer();

            List <int> exportIndices = ListOfExportIndices();

            foreach (int i in exportIndices)
            {
                charSet.Append(m_Charset.Characters[i].Data);
            }
            GR.IO.File.WriteAllBytes(m_Charset.ExportFilename, charSet);
        }
コード例 #2
0
ファイル: CharsetEditor.cs プロジェクト: aiSzzPL77/C64Studio
        private void btnExportCharsetToBASICHex_Click(object sender, EventArgs e)
        {
            int startLine = GR.Convert.ToI32(editExportBASICLineNo.Text);

            if ((startLine < 0) ||
                (startLine > 63999))
            {
                startLine = 10;
            }
            int lineOffset = GR.Convert.ToI32(editExportBASICLineOffset.Text);

            if ((lineOffset < 0) ||
                (lineOffset > 63999))
            {
                startLine = 10;
            }

            List <int> exportIndices = ListOfExportIndices();

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

            string resultText = Util.ToBASICHexData(charSet, startLine, lineOffset);

            editDataExport.Text = resultText;
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public override bool HandleExport(ExportCharsetInfo Info, TextBox EditOutput, DocumentInfo DocInfo)
        {
            System.Windows.Forms.SaveFileDialog saveDlg = new System.Windows.Forms.SaveFileDialog();

            saveDlg.FileName = Info.Charset.ExportFilename;
            saveDlg.Title    = "Export Charset to";
            saveDlg.Filter   = "Charset|*.chr|All Files|*.*";
            if (DocInfo.Project != null)
            {
                saveDlg.InitialDirectory = DocInfo.Project.Settings.BasePath;
            }
            if (saveDlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return(false);
            }
            GR.Memory.ByteBuffer charSet = new GR.Memory.ByteBuffer();

            List <int> exportIndices = Info.ExportIndices;

            foreach (int i in exportIndices)
            {
                charSet.Append(Info.Charset.Characters[i].Tile.Data);
            }
            if (checkPrefixLoadAddress.Checked)
            {
                ushort address = GR.Convert.ToU16(editPrefixLoadAddress.Text, 16);

                var addressData = new ByteBuffer();
                addressData.AppendU16(address);
                charSet = addressData + charSet;
            }
            GR.IO.File.WriteAllBytes(saveDlg.FileName, charSet);
            return(true);
        }
コード例 #5
0
        private void RenderFullImage(Tiny64.Machine machine, GR.Image.MemoryImage img)
        {
            // render image
            bool vicActive = ((machine.VIC.ReadByte(0x11) & 0x10) != 0);

            if (vicActive)
            {
                int  vicBank          = (machine.CIA2.ReadByte(0) & 0x03) ^ 0x03;
                int  screenPos        = ((machine.VIC.ReadByte(0x18) & 0xf0) >> 4) * 1024 + vicBank * 16384;
                int  localCharDataPos = (machine.VIC.ReadByte(0x18) & 0x0e) * 1024;
                int  charDataPos      = localCharDataPos + vicBank * 16384;
                byte bgColor          = (byte)(machine.VIC.ReadByte(0x21) & 0x0f);

                GR.Memory.ByteBuffer charData = null;
                if (((vicBank == 0) ||
                     (vicBank == 2)) &&
                    (localCharDataPos == 0x1000))
                {
                    // use default upper case chars
                    charData = new GR.Memory.ByteBuffer();
                    charData.Append(Machine.Memory.CharacterROM, 0, 2048);
                }
                else if (((vicBank == 0) ||
                          (vicBank == 2)) &&
                         (localCharDataPos == 0x2000))
                {
                    // use default lower case chars
                    charData = new GR.Memory.ByteBuffer();
                    charData.Append(Machine.Memory.CharacterROM, 2048, 2048);
                }
                else
                {
                    // use RAM
                    charData = new GR.Memory.ByteBuffer(machine.Memory.RAM);
                    charData = charData.SubBuffer(charDataPos, 2048);
                }
                for (int y = 0; y < 25; ++y)
                {
                    for (int x = 0; x < 40; ++x)
                    {
                        byte charIndex = machine.Memory.RAM[screenPos + x + y * 40];
                        byte charColor = machine.Memory.ColorRAM[x + y * 40];

                        //CharacterDisplayer.DisplayHiResChar( charData.SubBuffer( charIndex * 8, 8 ), bgColor, charColor, img, x * 8, y * 8 );
                    }
                }

                /*
                 * DataObject dataObj = new DataObject();
                 *
                 * GR.Memory.ByteBuffer      dibData = img.CreateHDIBAsBuffer();
                 *
                 * System.IO.MemoryStream    ms = dibData.MemoryStream();
                 *
                 * // WTF - SetData requires streams, NOT global data (HGLOBAL)
                 * dataObj.SetData( "DeviceIndependentBitmap", ms );
                 * Clipboard.SetDataObject( dataObj, true );*/
            }
        }
コード例 #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 btnExport_Click(object sender, EventArgs e)
        {
            List <int> exportIndices = ListOfExportIndices();

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

            var exportInfo = new ExportCharsetInfo()
            {
                Charset       = m_Charset,
                ExportIndices = ListOfExportIndices()
            };

            editDataExport.Text = "";
            editDataExport.Font = m_DefaultOutputFont;
            m_ExportForm.HandleExport(exportInfo, editDataExport, DocumentInfo);
        }
コード例 #8
0
        protected override bool PerformSave(string FullPath)
        {
            m_Charset.Name      = DocumentInfo.DocumentFilename;
            m_Charset.UsedTiles = GR.Convert.ToU32(editCharactersFrom.Text);

            if (IsBinaryFile())
            {
                // save binary only!
                GR.Memory.ByteBuffer charSet = new GR.Memory.ByteBuffer();
                charSet.Reserve(m_Charset.TotalNumberOfCharacters * Lookup.NumBytesOfSingleCharacterBitmap(m_Charset.Mode));

                for (int i = 0; i < m_Charset.TotalNumberOfCharacters; ++i)
                {
                    charSet.Append(m_Charset.Characters[i].Tile.Data);
                }

                return(SaveDocumentData(FullPath, charSet));
            }
            GR.Memory.ByteBuffer projectFile = SaveToBuffer();

            return(SaveDocumentData(FullPath, projectFile));
        }
コード例 #9
0
ファイル: CharsetEditor.cs プロジェクト: aiSzzPL77/C64Studio
        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;
        }
コード例 #10
0
ファイル: CharsetEditor.cs プロジェクト: aiSzzPL77/C64Studio
        private bool SaveProject(bool SaveAs)
        {
            string saveFilename = DocumentInfo.FullPath;

            if ((String.IsNullOrEmpty(DocumentInfo.DocumentFilename)) ||
                (SaveAs))
            {
                System.Windows.Forms.SaveFileDialog saveDlg = new System.Windows.Forms.SaveFileDialog();

                saveDlg.Title  = "Save Charset Project as";
                saveDlg.Filter = "Charset Projects|*.charsetproject|All Files|*.*";
                if (DocumentInfo.Project != null)
                {
                    saveDlg.InitialDirectory = DocumentInfo.Project.Settings.BasePath;
                }
                if (saveDlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return(false);
                }
                if (SaveAs)
                {
                    saveFilename = saveDlg.FileName;
                }
                else
                {
                    DocumentInfo.DocumentFilename = saveDlg.FileName;
                    if (DocumentInfo.Element != null)
                    {
                        if (string.IsNullOrEmpty(DocumentInfo.Project.Settings.BasePath))
                        {
                            DocumentInfo.DocumentFilename = saveDlg.FileName;
                        }
                        else
                        {
                            DocumentInfo.DocumentFilename = GR.Path.RelativePathTo(saveDlg.FileName, false, System.IO.Path.GetFullPath(DocumentInfo.Project.Settings.BasePath), true);
                        }
                        DocumentInfo.Element.Name      = System.IO.Path.GetFileNameWithoutExtension(DocumentInfo.DocumentFilename);
                        DocumentInfo.Element.Node.Text = System.IO.Path.GetFileName(DocumentInfo.DocumentFilename);
                        DocumentInfo.Element.Filename  = DocumentInfo.DocumentFilename;
                    }
                    saveFilename = DocumentInfo.FullPath;
                }
            }

            if (!SaveAs)
            {
                m_Charset.Name      = DocumentInfo.DocumentFilename;
                m_Charset.UsedTiles = GR.Convert.ToU32(editCharactersFrom.Text);
            }

            if (IsBinaryFile())
            {
                // save binary only!
                GR.Memory.ByteBuffer charSet = new GR.Memory.ByteBuffer();
                charSet.Reserve(256 * 8);

                for (int i = 0; i < 256; ++i)
                {
                    charSet.Append(m_Charset.Characters[i].Data);
                }
                DisableFileWatcher();
                if (!GR.IO.File.WriteAllBytes(saveFilename, charSet))
                {
                    EnableFileWatcher();
                    return(false);
                }
                SetUnmodified();
                EnableFileWatcher();
                return(true);
            }
            GR.Memory.ByteBuffer projectFile = SaveToBuffer();

            return(SaveDocumentData(saveFilename, projectFile, SaveAs));
        }
コード例 #11
0
        public GR.Memory.ByteBuffer SaveToBuffer()
        {
            GR.Memory.ByteBuffer projectFile = new GR.Memory.ByteBuffer();

            projectFile.AppendU32(2);

            var chunkProject = new GR.IO.FileChunk(FileChunkConstants.SPRITESET_PROJECT);

            var chunkInfo = new GR.IO.FileChunk(FileChunkConstants.SPRITESET_INFO);

            chunkInfo.AppendI32(TotalNumberOfSprites);
            chunkInfo.AppendString(Name);
            chunkInfo.AppendString(ExportFilename);
            chunkInfo.AppendI32(ExportStartIndex);
            chunkInfo.AppendI32(ExportSpriteCount);
            chunkProject.Append(chunkInfo.ToBuffer());

            GR.IO.FileChunk chunkScreenMultiColorData = new GR.IO.FileChunk(FileChunkConstants.MULTICOLOR_DATA);
            chunkScreenMultiColorData.AppendI32((byte)Mode);
            chunkScreenMultiColorData.AppendI32((byte)Colors.BackgroundColor);
            chunkScreenMultiColorData.AppendI32((byte)Colors.MultiColor1);
            chunkScreenMultiColorData.AppendI32((byte)Colors.MultiColor2);
            chunkProject.Append(chunkScreenMultiColorData.ToBuffer());

            foreach (var pal in Colors.Palettes)
            {
                chunkProject.Append(pal.ToBuffer());
            }

            foreach (var sprite in Sprites)
            {
                GR.IO.FileChunk chunkSprite = new GR.IO.FileChunk(FileChunkConstants.SPRITESET_SPRITE);
                chunkSprite.AppendI32((int)sprite.Mode);
                chunkSprite.AppendI32((int)sprite.Tile.Mode);
                chunkSprite.AppendI32((int)sprite.Tile.CustomColor);
                chunkSprite.AppendI32(sprite.Tile.Width);
                chunkSprite.AppendI32(sprite.Tile.Height);
                chunkSprite.AppendI32((int)sprite.Tile.Data.Length);
                chunkSprite.Append(sprite.Tile.Data);
                chunkSprite.AppendI32(sprite.Tile.Colors.ActivePalette);

                chunkProject.Append(chunkSprite.ToBuffer());
            }

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

                GR.IO.FileChunk chunkLayerInfo = new GR.IO.FileChunk(FileChunkConstants.SPRITESET_LAYER_INFO);
                chunkLayerInfo.AppendString(layer.Name);
                chunkLayerInfo.AppendI32((byte)layer.BackgroundColor);
                chunkLayerInfo.AppendI32(layer.DelayMS);
                chunkLayer.Append(chunkLayerInfo.ToBuffer());

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

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

            /*
             * // 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( (byte)Sprites[i].Mode );
             * }
             * projectFile.AppendI32( Colors.BackgroundColor );
             * projectFile.AppendI32( Colors.MultiColor1 );
             * projectFile.AppendI32( Colors.MultiColor2 );
             * // generic MC
             * projectFile.AppendU32( 0 );
             * for ( int i = 0; i < Sprites.Count; ++i )
             * {
             * projectFile.Append( Sprites[i].Tile.Data );
             * projectFile.AppendU8( (byte)Sprites[i].Color );
             * }
             * projectFile.AppendU32( ExportSpriteCount );
             *
             * // 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( FileChunkConstants.SPRITESET_LAYER );
             *
             * GR.IO.FileChunk   chunkLayerInfo = new GR.IO.FileChunk( FileChunkConstants.SPRITESET_LAYER_INFO );
             * chunkLayerInfo.AppendString( layer.Name );
             * chunkLayerInfo.AppendU8( (byte)layer.BackgroundColor );
             * chunkLayerInfo.AppendI32( layer.DelayMS );
             * chunkLayer.Append( chunkLayerInfo.ToBuffer() );
             *
             * foreach ( var sprite in layer.Sprites )
             * {
             *  GR.IO.FileChunk   chunkLayerSprite = new GR.IO.FileChunk( FileChunkConstants.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() );
             * }*/

            return(projectFile);
        }