public GR.Memory.ByteBuffer SaveToBuffer() { GR.Memory.ByteBuffer projectFile = new GR.Memory.ByteBuffer(); GR.IO.FileChunk chunkProjectInfo = new GR.IO.FileChunk(FileChunkConstants.DISASSEMBLY_INFO); chunkProjectInfo.AppendString(Description); projectFile.Append(chunkProjectInfo.ToBuffer()); GR.IO.FileChunk chunkProjectData = new GR.IO.FileChunk(FileChunkConstants.DISASSEMBLY_DATA); chunkProjectData.AppendI32(DataStartAddress); chunkProjectData.AppendU32(Data.Length); chunkProjectData.Append(Data); projectFile.Append(chunkProjectData.ToBuffer()); GR.IO.FileChunk chunkJumpAddresses = new GR.IO.FileChunk(FileChunkConstants.DISASSEMBLY_JUMP_ADDRESSES); chunkJumpAddresses.AppendI32(JumpedAtAddresses.Count); foreach (int jumpAddress in JumpedAtAddresses) { chunkJumpAddresses.AppendI32(jumpAddress); } projectFile.Append(chunkJumpAddresses.ToBuffer()); GR.IO.FileChunk chunkNamedLabels = new GR.IO.FileChunk(FileChunkConstants.DISASSEMBLY_NAMED_LABELS); chunkNamedLabels.AppendI32(NamedLabels.Count); foreach (var namedLabel in NamedLabels) { chunkNamedLabels.AppendI32(namedLabel.Key); chunkNamedLabels.AppendString(namedLabel.Value); } projectFile.Append(chunkNamedLabels.ToBuffer()); return(projectFile); }
public override Types.FileInfo LoadFile(GR.Memory.ByteBuffer Filename) { _LastError = ""; Location fileLocation; Types.FileInfo fileInfo; if (!LocateFile(Filename, out fileLocation, out fileInfo)) { _LastError = "File not found"; return(null); } GR.Memory.ByteBuffer result = new GR.Memory.ByteBuffer(); bool endFound = false; while (!endFound) { Sector sec = Tracks[fileLocation.Track - 1].Sectors[fileLocation.Sector]; fileLocation = sec.NextLocation; if (fileLocation == null) { result.Append(sec.Data.SubBuffer(2, sec.Data.ByteAt(1) - 1)); endFound = true; break; } result.Append(sec.Data.SubBuffer(2)); } fileInfo.Data = result; return(fileInfo); }
public GR.Memory.ByteBuffer SaveToBuffer() { GR.Memory.ByteBuffer data = new GR.Memory.ByteBuffer(); data.Reserve(ScreenHeight * ScreenWidth * 8); GR.IO.FileChunk chunkScreenInfo = new GR.IO.FileChunk(FileChunkConstants.GRAPHIC_SCREEN_INFO); chunkScreenInfo.AppendU32((uint)SelectedCheckType); chunkScreenInfo.AppendI32(ScreenOffsetX); chunkScreenInfo.AppendI32(ScreenOffsetY); chunkScreenInfo.AppendI32(ScreenWidth); chunkScreenInfo.AppendI32(ScreenHeight); data.Append(chunkScreenInfo.ToBuffer()); GR.IO.FileChunk chunkGraphicData = new GR.IO.FileChunk(FileChunkConstants.GRAPHIC_DATA); chunkGraphicData.AppendI32(Image.Width); chunkGraphicData.AppendI32(Image.Height); chunkGraphicData.AppendI32((int)Image.PixelFormat); chunkGraphicData.AppendI32(Image.PaletteEntryCount); for (int i = 0; i < Image.PaletteEntryCount; ++i) { chunkGraphicData.AppendU8(Image.PaletteRed(i)); chunkGraphicData.AppendU8(Image.PaletteGreen(i)); chunkGraphicData.AppendU8(Image.PaletteBlue(i)); } GR.Memory.ByteBuffer imageData = Image.GetAsData(); chunkGraphicData.AppendU32(imageData.Length); chunkGraphicData.Append(imageData); data.Append(chunkGraphicData.ToBuffer()); GR.IO.FileChunk chunkScreenMultiColorData = new GR.IO.FileChunk(FileChunkConstants.MULTICOLOR_DATA); chunkScreenMultiColorData.AppendU8((byte)(MultiColor ? 1 : 0)); chunkScreenMultiColorData.AppendU8((byte)Colors.BackgroundColor); chunkScreenMultiColorData.AppendU8((byte)Colors.MultiColor1); chunkScreenMultiColorData.AppendU8((byte)Colors.MultiColor2); chunkScreenMultiColorData.AppendI32(Colors.ActivePalette); data.Append(chunkScreenMultiColorData.ToBuffer()); foreach (var pal in Colors.Palettes) { data.Append(pal.ToBuffer()); } GR.IO.FileChunk chunkColorMapping = new GR.IO.FileChunk(FileChunkConstants.GRAPHIC_COLOR_MAPPING); chunkColorMapping.AppendI32(ColorMapping.Count); for (int i = 0; i < ColorMapping.Count; ++i) { var mappings = ColorMapping[i]; chunkColorMapping.AppendI32(mappings.Count); for (int j = 0; j < mappings.Count; ++j) { chunkColorMapping.AppendU8((byte)mappings[j]); } } data.Append(chunkColorMapping.ToBuffer()); return(data); }
/* * 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); return(result); }
public GR.Memory.ByteBuffer Save() { GR.Memory.ByteBuffer bufferProject = new GR.Memory.ByteBuffer(); bufferProject.Reserve(1000000); GR.IO.FileChunk chunkProject = new GR.IO.FileChunk(Types.FileChunk.PROJECT); // version 2 -> has adjusted debug start address (to get rid of 2049) chunkProject.AppendU32(2); chunkProject.AppendString(Settings.Name); chunkProject.AppendString(Settings.Filename); chunkProject.AppendU16(Settings.DebugPort); chunkProject.AppendU16(0);// obsolete Settings.DebugStartAddress chunkProject.AppendString(Settings.BuildTool); chunkProject.AppendString(Settings.RunTool); chunkProject.AppendString(Settings.MainDocument); chunkProject.AppendString(Settings.CurrentConfig.Name); if (Core.MainForm.ActiveElement != null) { chunkProject.AppendString(Core.MainForm.ActiveElement.Filename); } else { chunkProject.AppendString(""); } uint flags = 0; chunkProject.AppendU32(flags); bufferProject.Append(chunkProject.ToBuffer()); foreach (System.Windows.Forms.TreeNode node in Node.Nodes) { ProjectElement element = (ProjectElement)node.Tag; bufferProject.Append(ElementToBuffer(element)); } foreach (ProjectConfig config in Settings.GetConfigurations()) { bufferProject.Append(config.Save()); } // only save watches once, for the active project foreach (var watch in Settings.WatchEntries) { bufferProject.Append(watch.Save()); } return(bufferProject); }
public bool Save(string Filename) { GR.Memory.ByteBuffer bufferProject = new GR.Memory.ByteBuffer(); GR.IO.FileChunk chunkProject = new GR.IO.FileChunk(Types.FileChunk.PROJECT); chunkProject.AppendU32(1); chunkProject.AppendString(Settings.Name); chunkProject.AppendString(Filename); chunkProject.AppendU16(Settings.DebugPort); chunkProject.AppendU16(Settings.DebugStartAddress); chunkProject.AppendString(Settings.BuildTool); chunkProject.AppendString(Settings.RunTool); chunkProject.AppendString(Settings.MainDocument); bufferProject.Append(chunkProject.ToBuffer()); foreach (ProjectElement element in Elements) { GR.IO.FileChunk chunkElement = new GR.IO.FileChunk(Types.FileChunk.PROJECT_ELEMENT); chunkElement.AppendU32(1); chunkElement.AppendU32((uint)element.Type); chunkElement.AppendString(element.Name); chunkElement.AppendString(element.Filename); GR.IO.FileChunk chunkElementData = new GR.IO.FileChunk(Types.FileChunk.PROJECT_ELEMENT_DATA); element.Document.SaveToChunk(chunkElementData); chunkElement.Append(chunkElementData.ToBuffer()); chunkElement.AppendString(element.TargetFilename); chunkElement.AppendU32((uint)element.TargetType); bufferProject.Append(chunkElement.ToBuffer()); } try { System.IO.File.WriteAllBytes(Filename, bufferProject.Data()); } catch (System.IO.IOException) { return(false); } m_Modified = false; return(true); }
public override Types.FileInfo LoadFile(GR.Memory.ByteBuffer Filename) { _LastError = ""; int fileIndex = 0; var fileInfo = new Types.FileInfo(); foreach (FileRecord file in FileRecords) { if (file.EntryType == 1) { if (file.Filename == Filename) { GR.Memory.ByteBuffer exportData = new GR.Memory.ByteBuffer(); exportData.AppendU16(file.StartAddress); exportData.Append(FileDatas[fileIndex]); fileInfo.Data = exportData; fileInfo.Filename = new GR.Memory.ByteBuffer(file.Filename); fileInfo.Type = Types.FileType.PRG; return(fileInfo); } } ++fileIndex; } _LastError = "file not found"; return(null); }
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); }
private void RenderFullImage(Tiny64.Machine machine, GR.Image.MemoryImage img) { // render image bool vicActive = ((machine.Memory.VIC.ReadByte(0x11) & 0x10) != 0); if (vicActive) { int vicBank = (machine.Memory.CIA2.ReadByte(0) & 0x03) ^ 0x03; int screenPos = ((machine.Memory.VIC.ReadByte(0x18) & 0xf0) >> 4) * 1024 + vicBank * 16384; int localCharDataPos = (machine.Memory.VIC.ReadByte(0x18) & 0x0e) * 1024; int charDataPos = localCharDataPos + vicBank * 16384; byte bgColor = (byte)(machine.Memory.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 );*/ } }
public GR.Memory.ByteBuffer SaveToBuffer() { GR.Memory.ByteBuffer projectFile = new GR.Memory.ByteBuffer(); GR.IO.FileChunk chunkScreenInfo = new GR.IO.FileChunk(Types.FileChunk.CHARSET_SCREEN_INFO); // version chunkScreenInfo.AppendU32(0); // width chunkScreenInfo.AppendI32(ScreenWidth); // height chunkScreenInfo.AppendI32(ScreenHeight); chunkScreenInfo.AppendString(""); chunkScreenInfo.AppendI32((int)Mode); chunkScreenInfo.AppendI32(ScreenOffsetX); chunkScreenInfo.AppendI32(ScreenOffsetY); projectFile.Append(chunkScreenInfo.ToBuffer()); GR.IO.FileChunk chunkCharSet = new GR.IO.FileChunk(Types.FileChunk.CHARSET_DATA); chunkCharSet.Append(CharSet.SaveToBuffer()); projectFile.Append(chunkCharSet.ToBuffer()); GR.IO.FileChunk chunkScreenMultiColorData = new GR.IO.FileChunk(Types.FileChunk.MULTICOLOR_DATA); chunkScreenMultiColorData.AppendU8((byte)Mode); chunkScreenMultiColorData.AppendU8((byte)BackgroundColor); chunkScreenMultiColorData.AppendU8((byte)MultiColor1); chunkScreenMultiColorData.AppendU8((byte)MultiColor2); projectFile.Append(chunkScreenMultiColorData.ToBuffer()); GR.IO.FileChunk chunkScreenCharData = new GR.IO.FileChunk(Types.FileChunk.SCREEN_CHAR_DATA); for (int i = 0; i < Chars.Count; ++i) { chunkScreenCharData.AppendU8((byte)(Chars[i] & 0xff)); } projectFile.Append(chunkScreenCharData.ToBuffer()); GR.IO.FileChunk chunkScreenColorData = new GR.IO.FileChunk(Types.FileChunk.SCREEN_COLOR_DATA); for (int i = 0; i < Chars.Count; ++i) { chunkScreenColorData.AppendU8((byte)(Chars[i] >> 8)); } projectFile.Append(chunkScreenColorData.ToBuffer()); return(projectFile); }
public GR.Memory.ByteBuffer Save() { GR.Memory.ByteBuffer bufferProject = new GR.Memory.ByteBuffer(); GR.IO.FileChunk chunkProject = new GR.IO.FileChunk(Types.FileChunk.PROJECT); chunkProject.AppendU32(1); chunkProject.AppendString(Settings.Name); chunkProject.AppendString(Settings.Filename); chunkProject.AppendU16(Settings.DebugPort); chunkProject.AppendU16(2049);// obsolete Settings.DebugStartAddress chunkProject.AppendString(Settings.BuildTool); chunkProject.AppendString(Settings.RunTool); chunkProject.AppendString(Settings.MainDocument); chunkProject.AppendString(Settings.CurrentConfig.Name); if (Core.MainForm.ActiveElement != null) { chunkProject.AppendString(Core.MainForm.ActiveElement.Filename); } else { chunkProject.AppendString(""); } bufferProject.Append(chunkProject.ToBuffer()); foreach (System.Windows.Forms.TreeNode node in Node.Nodes) { ProjectElement element = (ProjectElement)node.Tag; bufferProject.Append(ElementToBuffer(element)); } foreach (ProjectConfig config in Settings.Configs.Values) { bufferProject.Append(config.Save()); } foreach (var watch in Core.MainForm.m_DebugWatch.m_WatchEntries) { bufferProject.Append(watch.Save()); } return(bufferProject); }
public override GR.Memory.ByteBuffer Compile() { _LastError = ""; GR.Memory.ByteBuffer result = new GR.Memory.ByteBuffer(); result.AppendU16(LoadAddress); result.Append(Data); return(result); }
public GR.Memory.ByteBuffer ToBuffer() { GR.Memory.ByteBuffer newBuffer = new GR.Memory.ByteBuffer(); newBuffer.Reserve((int)Length); newBuffer.AppendU16(Type); newBuffer.AppendU32(base.Length); newBuffer.Append(this); return(newBuffer); }
public GR.Memory.ByteBuffer SaveCharsetToBuffer() { var charData = new GR.Memory.ByteBuffer(2048); for (int i = 0; i < 256; ++i) { charData.Append(Characters[i].Data); } return(charData); }
public GR.Memory.ByteBuffer SaveCharsetToBuffer() { var charData = new GR.Memory.ByteBuffer((uint)(TotalNumberOfCharacters * Lookup.NumBytesOfSingleCharacterBitmap(Mode))); for (int i = 0; i < TotalNumberOfCharacters; ++i) { charData.Append(Characters[i].Tile.Data); } return(charData); }
public GR.Memory.ByteBuffer ExportMapsAsBuffer(bool RowByRow) { GR.Memory.ByteBuffer mapData = new GR.Memory.ByteBuffer(); foreach (var map in Maps) { mapData.Append(ExportMapAsBuffer(map, RowByRow)); } return(mapData); }
public override GR.Memory.ByteBuffer Compile() { _LastError = ""; GR.Memory.ByteBuffer result = new GR.Memory.ByteBuffer(); foreach (Track track in Tracks) { foreach (Sector sector in track.Sectors) { result.Append(sector.Data); } } return(result); }
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); }
public override bool HandleExport(ExportCharsetInfo Info, TextBox EditOutput, DocumentInfo DocInfo) { var sb = new StringBuilder(); 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)) { lineOffset = 10; } int wrapByteCount = GetExportWrapCount(); bool asHex = checkExportHex.Checked; int wrapCharCount = GetExportCharCount(); List <int> exportIndices = Info.ExportIndices; GR.Memory.ByteBuffer charSet = new GR.Memory.ByteBuffer(); foreach (int index in exportIndices) { charSet.Append(Info.Charset.Characters[index].Tile.Data); } if (asHex) { sb.Append(Util.ToBASICHexData(charSet, startLine, lineOffset, wrapByteCount, wrapCharCount)); } else { sb.Append(Util.ToBASICData(charSet, startLine, lineOffset, wrapByteCount, wrapCharCount)); } EditOutput.Font = new System.Drawing.Font(Core.MainForm.m_FontC64.Families[0], 16, System.Drawing.GraphicsUnit.Pixel); EditOutput.Text = sb.ToString(); return(true); }
public override bool HandleExport(ExportSpriteInfo 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.Project.Sprites[index].Tile.Data); } bool wrapData = checkExportToDataWrap.Checked; bool prefixRes = checkExportToDataIncludeRes.Checked; if (!prefixRes) { prefix = ""; } string line = Util.ToASMData(Info.ExportData, wrapData, wrapByteCount, prefix); EditOutput.Text = line; return(true); }
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); }
public void ConvertScreens(string BasePath, List <string> ProjectFiles) { var projects = new List <RetroDevStudio.Formats.GraphicScreenProject>(); foreach (var file in ProjectFiles) { var project = new RetroDevStudio.Formats.GraphicScreenProject(); project.ReadFromBuffer(GR.IO.File.ReadAllBytes(file)); projects.Add(project); } int numChars = 0; foreach (var project in projects) { numChars += ((project.Image.Width + 7) / 8) * ((project.Image.Height + 7) / 8); } for (int i = 0; i < numChars; ++i) { m_Chars.Add(new RetroDevStudio.Formats.CharData()); } int curCharOffset = 0; int projectIndex = 0; foreach (var project in projects) { if (CheckForMCCharsetErrors(project, curCharOffset)) { Debug.Log("Found error in " + ProjectFiles[projectIndex]); return; } curCharOffset += ((project.Image.Width + 7) / 8) * ((project.Image.Height + 7) / 8); ++projectIndex; } if (CheckForDuplicates()) { // charset GR.Memory.ByteBuffer charSet = new GR.Memory.ByteBuffer(); foreach (var charInfo in m_Chars) { if (charInfo.Replacement == null) { charSet.Append(charInfo.Tile.Data); } } GR.IO.File.WriteAllBytes(System.IO.Path.Combine(BasePath, "combined.chr"), charSet); // screens int charIndexOffset = 0; projectIndex = 0; foreach (var project in projects) { // create screens from graphic var screen = new RetroDevStudio.Formats.CharsetScreenProject(); int blockWidth = ((project.Image.Width + 7) / 8); int blockHeight = ((project.Image.Height + 7) / 8); screen.SetScreenSize(blockWidth, blockHeight); for (int y = 0; y < blockHeight; ++y) { for (int x = 0; x < blockWidth; ++x) { var charData = m_Chars[charIndexOffset + x + y * blockWidth]; var origCharData = charData; while (charData.Replacement != null) { charData = charData.Replacement; } screen.Chars[x + y * blockWidth] = (ushort)((origCharData.Tile.CustomColor << 8) + charData.Index); screen.Mode = project.MultiColor ? RetroDevStudio.TextMode.COMMODORE_40_X_25_MULTICOLOR : RetroDevStudio.TextMode.COMMODORE_40_X_25_HIRES; screen.CharSet.Colors.MultiColor1 = project.Colors.MultiColor1; screen.CharSet.Colors.MultiColor2 = project.Colors.MultiColor2; screen.CharSet.Colors.BackgroundColor = project.Colors.BackgroundColor; } } screen.CharSet = new RetroDevStudio.Formats.CharsetProject(); screen.CharSet.Colors.BackgroundColor = project.Colors.BackgroundColor; screen.CharSet.Colors.MultiColor1 = project.Colors.MultiColor1; screen.CharSet.Colors.MultiColor2 = project.Colors.MultiColor2; for (uint c = 0; c < charSet.Length / 8; ++c) { screen.CharSet.Characters[(int)c].Tile.Data = charSet.SubBuffer((int)c * 8, 8); screen.CharSet.Characters[(int)c].Tile.CustomColor = 9; } string origFile = System.IO.Path.GetFileNameWithoutExtension(ProjectFiles[projectIndex]); GR.IO.File.WriteAllBytes(System.IO.Path.Combine(BasePath, origFile + ".charscreen"), screen.SaveToBuffer()); ++projectIndex; charIndexOffset += blockWidth * blockHeight; } } }
public GR.Memory.ByteBuffer SaveToBuffer() { GR.Memory.ByteBuffer projectFile = new GR.Memory.ByteBuffer(); // version projectFile.AppendU32(2); var chunkCharsetProject = new GR.IO.FileChunk(RetroDevStudio.FileChunkConstants.CHARSET_PROJECT); var chunkCharsetInfo = new GR.IO.FileChunk(RetroDevStudio.FileChunkConstants.CHARSET_INFO); chunkCharsetInfo.AppendI32((int)Mode); chunkCharsetInfo.AppendI32(TotalNumberOfCharacters); chunkCharsetInfo.AppendI32(ShowGrid ? 1 : 0); chunkCharsetProject.Append(chunkCharsetInfo.ToBuffer()); var chunkColorSettings = new GR.IO.FileChunk(RetroDevStudio.FileChunkConstants.CHARSET_COLOR_SETTINGS); chunkColorSettings.AppendI32(Colors.BackgroundColor); chunkColorSettings.AppendI32(Colors.MultiColor1); chunkColorSettings.AppendI32(Colors.MultiColor2); chunkColorSettings.AppendI32(Colors.BGColor4); chunkColorSettings.AppendI32(Colors.ActivePalette); chunkCharsetProject.Append(chunkColorSettings.ToBuffer()); foreach (var pal in Colors.Palettes) { chunkCharsetProject.Append(pal.ToBuffer()); } var chunkExport = new GR.IO.FileChunk(RetroDevStudio.FileChunkConstants.CHARSET_EXPORT); chunkExport.AppendI32(ExportStartCharacter); chunkExport.AppendI32(ExportNumCharacters); chunkExport.AppendString(ExportFilename); chunkCharsetProject.Append(chunkExport.ToBuffer()); foreach (var character in Characters) { var chunkCharsetChar = new GR.IO.FileChunk(RetroDevStudio.FileChunkConstants.CHARSET_CHAR); //chunkCharsetChar.AppendI32( (int)character.Mode ); chunkCharsetChar.AppendI32(0); // was mode chunkCharsetChar.AppendI32(character.Tile.CustomColor); chunkCharsetChar.AppendI32(character.Category); chunkCharsetChar.AppendI32((int)character.Tile.Data.Length); chunkCharsetChar.Append(character.Tile.Data); chunkCharsetProject.Append(chunkCharsetChar.ToBuffer()); } foreach (var category in Categories) { var chunkCategory = new GR.IO.FileChunk(RetroDevStudio.FileChunkConstants.CHARSET_CATEGORY); chunkCategory.AppendString(category); chunkCharsetProject.Append(chunkCategory.ToBuffer()); } var chunkPlayground = new GR.IO.FileChunk(RetroDevStudio.FileChunkConstants.CHARSET_PLAYGROUND); chunkPlayground.AppendI32(PlaygroundWidth); chunkPlayground.AppendI32(PlaygroundHeight); for (int i = 0; i < PlaygroundChars.Count; ++i) { // 16 bit index, 16 bit color chunkPlayground.AppendU32(PlaygroundChars[i]); } chunkCharsetProject.Append(chunkPlayground.ToBuffer()); projectFile.Append(chunkCharsetProject.ToBuffer()); /* * // 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] ); * } * * projectFile.AppendI32( (int)Mode ); */ return(projectFile); }
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); }
public GR.Memory.ByteBuffer SaveToBuffer() { GR.Memory.ByteBuffer projectFile = new GR.Memory.ByteBuffer(); GR.IO.FileChunk chunkProjectInfo = new GR.IO.FileChunk(Types.FileChunk.MAP_PROJECT_INFO); // version chunkProjectInfo.AppendU32(0); chunkProjectInfo.AppendString(ExternalCharset); chunkProjectInfo.AppendI32(ShowGrid ? 1 : 0); projectFile.Append(chunkProjectInfo.ToBuffer()); GR.IO.FileChunk chunkCharset = new GR.IO.FileChunk(Types.FileChunk.MAP_CHARSET); chunkCharset.Append(Charset.SaveToBuffer()); projectFile.Append(chunkCharset.ToBuffer()); GR.IO.FileChunk chunkProjectData = new GR.IO.FileChunk(Types.FileChunk.MAP_PROJECT_DATA); GR.IO.FileChunk chunkMCData = new GR.IO.FileChunk(Types.FileChunk.MULTICOLOR_DATA); chunkMCData.AppendU8((byte)Mode); chunkMCData.AppendU8((byte)BackgroundColor); chunkMCData.AppendU8((byte)MultiColor1); chunkMCData.AppendU8((byte)MultiColor2); chunkMCData.AppendU8((byte)BGColor4); chunkProjectData.Append(chunkMCData.ToBuffer()); foreach (Tile tile in Tiles) { GR.IO.FileChunk chunkTile = new GR.IO.FileChunk(Types.FileChunk.MAP_TILE); chunkTile.AppendString(tile.Name); chunkTile.AppendI32(tile.Chars.Width); chunkTile.AppendI32(tile.Chars.Height); for (int j = 0; j < tile.Chars.Height; ++j) { for (int i = 0; i < tile.Chars.Width; ++i) { TileChar tChar = tile.Chars[i, j]; chunkTile.AppendU8(tChar.Character); chunkTile.AppendU8(tChar.Color); } } chunkProjectData.Append(chunkTile.ToBuffer()); } foreach (Map map in Maps) { GR.IO.FileChunk chunkMap = new GR.IO.FileChunk(Types.FileChunk.MAP); GR.IO.FileChunk chunkMapInfo = new GR.IO.FileChunk(Types.FileChunk.MAP_INFO); chunkMapInfo.AppendString(map.Name); chunkMapInfo.AppendI32(map.TileSpacingX); chunkMapInfo.AppendI32(map.TileSpacingY); chunkMapInfo.AppendI32(map.AlternativeMultiColor1 + 1); chunkMapInfo.AppendI32(map.AlternativeMultiColor2 + 1); chunkMapInfo.AppendI32(map.AlternativeBackgroundColor + 1); chunkMapInfo.AppendI32(map.AlternativeBGColor4 + 1); chunkMapInfo.AppendI32((int)map.AlternativeMode + 1); chunkMap.Append(chunkMapInfo.ToBuffer()); GR.IO.FileChunk chunkMapData = new GR.IO.FileChunk(Types.FileChunk.MAP_DATA); chunkMapData.AppendI32(map.Tiles.Width); chunkMapData.AppendI32(map.Tiles.Height); for (int j = 0; j < map.Tiles.Height; ++j) { for (int i = 0; i < map.Tiles.Width; ++i) { chunkMapData.AppendI32(map.Tiles[i, j]); } } chunkMap.Append(chunkMapData.ToBuffer()); if (map.ExtraDataText.Length > 0) { GR.IO.FileChunk chunkMapExtraData = new GR.IO.FileChunk(Types.FileChunk.MAP_EXTRA_DATA_TEXT); chunkMapExtraData.AppendString(map.ExtraDataText); chunkMap.Append(chunkMapExtraData.ToBuffer()); } if (map.ExtraDataOld.Length > 0) { GR.IO.FileChunk chunkMapExtraData = new GR.IO.FileChunk(Types.FileChunk.MAP_EXTRA_DATA); chunkMapExtraData.AppendU32(map.ExtraDataOld.Length); chunkMapExtraData.Append(map.ExtraDataOld); chunkMap.Append(chunkMapExtraData.ToBuffer()); } chunkProjectData.Append(chunkMap.ToBuffer()); } projectFile.Append(chunkProjectData.ToBuffer()); return(projectFile); }
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); }
private int HandleGraphicscreenFile(GR.Text.ArgumentParser ArgParser) { string exportType = ArgParser.Parameter("TYPE"); if (!ValidateExportType("graphicscreen file", exportType, new string[] { "MULTICOLORBITMAPSCREENCOLOR", "MULTICOLORBITMAPCOLORSCREEN", "MULTICOLORBITMAPSCREEN", "MULTICOLORBITMAPCOLOR", "MULTICOLORBITMAP", "HIRESBITMAPSCREENCOLOR", "HIRESBITMAPCOLORSCREEN", "HIRESBITMAPSCREEN", "HIRESBITMAPCOLOR", "HIRESBITMAP" })) { return(1); } string inputFile = ArgParser.Parameter("GRAPHICSCREEN"); GR.Memory.ByteBuffer data = GR.IO.File.ReadAllBytes(inputFile); if (data == null) { System.Console.WriteLine("Couldn't read binary char file " + inputFile); return(1); } var graphicScreen = new C64Studio.Formats.GraphicScreenProject(); if (!graphicScreen.ReadFromBuffer(data)) { System.Console.WriteLine("Couldn't read graphicscreen project from file " + inputFile); return(1); } // import if (ArgParser.IsParameterSet("IMPORTIMAGE")) { var image = LoadImageFromFile(ArgParser.Parameter("IMPORTIMAGE")); if (image == null) { System.Console.WriteLine("Couldn't read image from file " + ArgParser.Parameter("IMPORTIMAGE")); return(1); } if ((image.Width > graphicScreen.ScreenWidth) || (image.Height > graphicScreen.ScreenHeight)) { System.Console.WriteLine("Couldn't read image from file " + ArgParser.Parameter("IMPORTIMAGE")); return(1); } if (image.PixelFormat != System.Drawing.Imaging.PixelFormat.Format8bppIndexed) { image.Dispose(); Console.WriteLine("Image format invalid!\nNeeds to be 8bit index"); return(1); } } // export 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 > graphicScreen.ScreenWidth) || (y + height > graphicScreen.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 = graphicScreen.ScreenWidth; height = graphicScreen.ScreenHeight; } bool exportMC = exportType.Contains("MULTICOLOR"); bool exportScreen = exportType.Contains("SCREEN"); bool exportColors = exportType.Contains("COLORS"); bool exportBitmap = exportType.Contains("BITMAP"); GR.Memory.ByteBuffer screenChar = new GR.Memory.ByteBuffer(); GR.Memory.ByteBuffer screenColor = new GR.Memory.ByteBuffer(); GR.Memory.ByteBuffer bitmapData = new GR.Memory.ByteBuffer(); bool[,] errornousChars = new bool[(width + 7) / 8, (height + 7) / 8]; var charData = new List <C64Studio.Formats.CharData>(errornousChars.Length); int numErrors = 0; if (!exportMC) { // HIRES numErrors = graphicScreen.ImageToHiresBitmapData(charData, errornousChars, x / 8, y / 8, width / 8, height / 8, out bitmapData, out screenChar, out screenColor); } else { // MC numErrors = graphicScreen.ImageToMCBitmapData(graphicScreen.ColorMapping, charData, errornousChars, x / 8, y / 8, width / 8, height / 8, out bitmapData, out screenChar, out screenColor); } if (numErrors > 0) { System.Console.WriteLine("Format did not match expectations (check for color clashes)"); return(1); } // build export data GR.Memory.ByteBuffer exportData = new GR.Memory.ByteBuffer(); if (exportType.Contains("BITMAPSCREENCOLORS")) { exportData.Append(bitmapData); exportData.Append(screenChar); exportData.Append(screenColor); } else if (exportType.Contains("BITMAPCOLORSSCREEN")) { exportData.Append(bitmapData); exportData.Append(screenColor); exportData.Append(screenChar); } else if (exportType.Contains("BITMAPCOLORS")) { exportData.Append(bitmapData); exportData.Append(screenColor); } else if (exportType.Contains("BITMAPSCREEN")) { exportData.Append(bitmapData); exportData.Append(screenChar); } else if (exportType.Contains("BITMAP")) { exportData.Append(bitmapData); } if (!GR.IO.File.WriteAllBytes(ArgParser.Parameter("EXPORT"), exportData)) { Console.WriteLine("Could not write to file " + ArgParser.Parameter("EXPORT")); return(1); } return(0); }
GR.Memory.ByteBuffer ElementToBuffer(ProjectElement Element) { GR.Memory.ByteBuffer buffer = new GR.Memory.ByteBuffer(); GR.IO.FileChunk chunkElement = new GR.IO.FileChunk(Types.FileChunk.PROJECT_ELEMENT); chunkElement.AppendU32(1); chunkElement.AppendU32((uint)Element.DocumentInfo.Type); chunkElement.AppendString(Element.Name); chunkElement.AppendString(Element.Filename); GR.IO.FileChunk chunkElementData = new GR.IO.FileChunk(Types.FileChunk.PROJECT_ELEMENT_DATA); if (Element.Document != null) { Element.Document.SaveToChunk(chunkElementData); } chunkElement.Append(chunkElementData.ToBuffer()); chunkElement.AppendString(Element.TargetFilename); chunkElement.AppendU32((uint)Element.TargetType); chunkElement.AppendI32(Element.ForcedDependency.DependentOnFile.Count); foreach (var dependency in Element.ForcedDependency.DependentOnFile) { chunkElement.AppendString(dependency.Filename); } // 3 free strings chunkElement.AppendString(""); chunkElement.AppendString(""); chunkElement.AppendString(""); chunkElement.AppendI32(Element.Settings.Count); foreach (KeyValuePair <string, ProjectElement.PerConfigSettings> configSetting in Element.Settings) { GR.IO.FileChunk chunkElementPerConfigSetting = new GR.IO.FileChunk(Types.FileChunk.PROJECT_ELEMENT_PER_CONFIG_SETTING); chunkElementPerConfigSetting.AppendString(configSetting.Key); chunkElementPerConfigSetting.AppendString(configSetting.Value.PreBuild); chunkElementPerConfigSetting.AppendString(configSetting.Value.CustomBuild); chunkElementPerConfigSetting.AppendString(configSetting.Value.PostBuild); chunkElementPerConfigSetting.AppendString(configSetting.Value.DebugFile); chunkElementPerConfigSetting.AppendI32((int)configSetting.Value.DebugFileType); chunkElementPerConfigSetting.AppendI32(configSetting.Value.PreBuildChain.Active ? 1 : 0); chunkElementPerConfigSetting.AppendI32(configSetting.Value.PreBuildChain.Entries.Count); foreach (var buildChainEntry in configSetting.Value.PreBuildChain.Entries) { chunkElementPerConfigSetting.AppendString(buildChainEntry.ProjectName); chunkElementPerConfigSetting.AppendString(buildChainEntry.Config); chunkElementPerConfigSetting.AppendString(buildChainEntry.DocumentFilename); chunkElementPerConfigSetting.AppendString(buildChainEntry.PreDefines); } chunkElementPerConfigSetting.AppendI32(configSetting.Value.PostBuildChain.Active ? 1 : 0); chunkElementPerConfigSetting.AppendI32(configSetting.Value.PostBuildChain.Entries.Count); foreach (var buildChainEntry in configSetting.Value.PostBuildChain.Entries) { chunkElementPerConfigSetting.AppendString(buildChainEntry.ProjectName); chunkElementPerConfigSetting.AppendString(buildChainEntry.Config); chunkElementPerConfigSetting.AppendString(buildChainEntry.DocumentFilename); chunkElementPerConfigSetting.AppendString(buildChainEntry.PreDefines); } chunkElement.Append(chunkElementPerConfigSetting.ToBuffer()); } chunkElement.AppendI32(Element.IsShown ? 1 : 0); chunkElement.AppendU32((uint)Element.AssemblerType); chunkElement.AppendI32(Element.ProjectHierarchy.Count); foreach (string hierarchyPart in Element.ProjectHierarchy) { chunkElement.AppendString(hierarchyPart); } // dependency - include symbols chunkElement.AppendI32(Element.ForcedDependency.DependentOnFile.Count); foreach (var dependency in Element.ForcedDependency.DependentOnFile) { chunkElement.AppendI32(dependency.IncludeSymbols ? 1 : 0); } // collapsed folding blocks chunkElement.AppendI32(Element.DocumentInfo.CollapsedFoldingBlocks.Count); foreach (int foldStartLine in Element.DocumentInfo.CollapsedFoldingBlocks) { chunkElement.AppendI32(foldStartLine); //Debug.Log( "Save folded block for line " + foldStartLine ); } buffer.Append(chunkElement.ToBuffer()); if (Element.Document != null) { GR.Memory.ByteBuffer displayDetails = Element.Document.DisplayDetails(); if (displayDetails != null) { GR.IO.FileChunk chunkElementDisplayData = new GR.IO.FileChunk(Types.FileChunk.PROJECT_ELEMENT_DISPLAY_DATA); chunkElementDisplayData.AppendString(Element.Filename); chunkElementDisplayData.AppendU32(displayDetails.Length); chunkElementDisplayData.Append(displayDetails); buffer.Append(chunkElementDisplayData.ToBuffer()); } } // child elements foreach (System.Windows.Forms.TreeNode node in Element.Node.Nodes) { ProjectElement subElement = (ProjectElement)node.Tag; buffer.Append(ElementToBuffer(subElement)); } return(buffer); }
public GR.Memory.ByteBuffer SaveToBuffer() { GR.Memory.ByteBuffer projectFile = new GR.Memory.ByteBuffer(); GR.IO.FileChunk chunkScreenInfo = new GR.IO.FileChunk(FileChunkConstants.CHARSET_SCREEN_INFO); // version chunkScreenInfo.AppendI32(0); // width chunkScreenInfo.AppendI32(ScreenWidth); // height chunkScreenInfo.AppendI32(ScreenHeight); chunkScreenInfo.AppendString(""); chunkScreenInfo.AppendI32((int)Mode); chunkScreenInfo.AppendI32(ScreenOffsetX); chunkScreenInfo.AppendI32(ScreenOffsetY); chunkScreenInfo.AppendI32(CharOffset); projectFile.Append(chunkScreenInfo.ToBuffer()); GR.IO.FileChunk chunkCharSet = new GR.IO.FileChunk(FileChunkConstants.CHARSET_DATA); chunkCharSet.Append(CharSet.SaveToBuffer()); projectFile.Append(chunkCharSet.ToBuffer()); GR.IO.FileChunk chunkScreenMultiColorData = new GR.IO.FileChunk(FileChunkConstants.MULTICOLOR_DATA); chunkScreenMultiColorData.AppendU8((byte)Mode); chunkScreenMultiColorData.AppendU8((byte)CharSet.Colors.BackgroundColor); chunkScreenMultiColorData.AppendU8((byte)CharSet.Colors.MultiColor1); chunkScreenMultiColorData.AppendU8((byte)CharSet.Colors.MultiColor2); projectFile.Append(chunkScreenMultiColorData.ToBuffer()); GR.IO.FileChunk chunkScreenCharData = new GR.IO.FileChunk(FileChunkConstants.SCREEN_CHAR_DATA); if (Lookup.NumBytesOfSingleCharacter(Lookup.TextCharModeFromTextMode(Mode)) == 2) { for (int i = 0; i < Chars.Count; ++i) { chunkScreenCharData.AppendU16((ushort)(Chars[i] & 0xffff)); } } else { for (int i = 0; i < Chars.Count; ++i) { chunkScreenCharData.AppendU8((byte)(Chars[i] & 0xffff)); } } projectFile.Append(chunkScreenCharData.ToBuffer()); GR.IO.FileChunk chunkScreenColorData = new GR.IO.FileChunk(FileChunkConstants.SCREEN_COLOR_DATA); if (Lookup.NumBytesOfSingleCharacter(Lookup.TextCharModeFromTextMode(Mode)) == 2) { for (int i = 0; i < Chars.Count; ++i) { chunkScreenColorData.AppendU16((ushort)(Chars[i] >> 16)); } } else { for (int i = 0; i < Chars.Count; ++i) { chunkScreenColorData.AppendU8((byte)(Chars[i] >> 16)); } } projectFile.Append(chunkScreenColorData.ToBuffer()); return(projectFile); }
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); }