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 GR.Memory.ByteBuffer ToBuffer() { GR.IO.FileChunk chunkSolution = new GR.IO.FileChunk(Types.FileChunk.SOLUTION); GR.IO.FileChunk chunkSolutionInfo = new GR.IO.FileChunk(Types.FileChunk.SOLUTION_INFO); if (string.IsNullOrEmpty(Name)) { Name = System.IO.Path.GetFileNameWithoutExtension(Filename); } chunkSolutionInfo.AppendString(Name); chunkSolutionInfo.AppendString(this.Filename); chunkSolution.Append(chunkSolutionInfo.ToBuffer()); GR.IO.FileChunk chunkExpandedNodes = new GR.IO.FileChunk(Types.FileChunk.SOLUTION_NODES); foreach (string key in ExpandedNodes) { chunkExpandedNodes.AppendString(key); } chunkSolution.Append(chunkExpandedNodes.ToBuffer()); foreach (Project project in Projects) { GR.IO.FileChunk chunkSolutionProject = new GR.IO.FileChunk(Types.FileChunk.SOLUTION_PROJECT); chunkSolutionProject.AppendString(GR.Path.RelativePathTo(Filename, false, project.Settings.Filename, false)); chunkSolution.Append(chunkSolutionProject.ToBuffer()); } return(chunkSolution.ToBuffer()); }
public GR.Memory.ByteBuffer Save() { GR.IO.FileChunk chunk = new GR.IO.FileChunk(Types.FileChunk.PROJECT_CONFIG); chunk.AppendString(Name); chunk.AppendString(Defines); return(chunk.ToBuffer()); }
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); }
public bool FromBuffer(GR.Memory.ByteBuffer SolutionData, string FromFile) { GR.IO.MemoryReader memIn = new GR.IO.MemoryReader(SolutionData); GR.IO.FileChunk chunk = new GR.IO.FileChunk(); while (chunk.ReadFromStream(memIn)) { if (chunk.Type != FileChunkConstants.SOLUTION) { return(false); } GR.IO.MemoryReader memChunk = chunk.MemoryReader(); GR.IO.FileChunk subChunk = new GR.IO.FileChunk(); while (subChunk.ReadFromStream(memChunk)) { GR.IO.MemoryReader memSubChunk = subChunk.MemoryReader(); switch (subChunk.Type) { case FileChunkConstants.SOLUTION_INFO: Name = memSubChunk.ReadString(); Filename = memSubChunk.ReadString(); ActiveProject = memSubChunk.ReadString(); Filename = FromFile; Name = System.IO.Path.GetFileNameWithoutExtension(FromFile); break; case FileChunkConstants.SOLUTION_PROJECT: { string filename = memSubChunk.ReadString(); filename = GR.Path.Normalize(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Filename), filename), false); Project project = MainForm.OpenProject(filename); } break; case FileChunkConstants.SOLUTION_NODES: while (memSubChunk.DataAvailable) { string node = memSubChunk.ReadString(); if (!ExpandedNodes.Contains(node)) { ExpandedNodes.Add(node); } } break; } } } return(true); }
public GR.IO.FileChunk ToChunk() { GR.IO.FileChunk chunk = new GR.IO.FileChunk(Types.FileChunk.SETTINGS_ACCELERATOR); chunk.AppendU32((uint)Key); chunk.AppendU32((uint)Function); return(chunk); }
public GR.Memory.ByteBuffer Save() { GR.IO.FileChunk chunk = new GR.IO.FileChunk(FileChunkConstants.PROJECT_CONFIG); chunk.AppendString(Name); chunk.AppendString(Defines); chunk.AppendI32(0); chunk.AppendString(DebugStartAddressLabel); return(chunk.ToBuffer()); }
public GR.IO.FileChunk ToChunk() { GR.IO.FileChunk chunk = new GR.IO.FileChunk(FileChunkConstants.SETTINGS_ACCELERATOR); chunk.AppendU32((uint)Key); chunk.AppendU32((uint)Function); chunk.AppendU32((uint)SecondaryKey); return(chunk); }
public void FromChunk(GR.IO.FileChunk Chunk) { GR.IO.MemoryReader memIn = Chunk.MemoryReader(); Name = memIn.ReadString(); Position.X = memIn.ReadInt32(); Position.Y = memIn.ReadInt32(); Size.Width = memIn.ReadInt32(); Size.Height = memIn.ReadInt32(); DockState = (WeifenLuo.WinFormsUI.Docking.DockState)memIn.ReadInt32(); }
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 FromChunk(GR.IO.FileChunk Chunk) { if (Chunk.Type != Types.FileChunk.SETTINGS_ACCELERATOR) { return(false); } GR.IO.IReader reader = Chunk.MemoryReader(); Key = (Keys)reader.ReadUInt32(); Function = (C64Studio.Types.Function)reader.ReadUInt32(); return(true); }
public GR.Memory.ByteBuffer ToBuffer() { GR.IO.FileChunk chunkLayout = new GR.IO.FileChunk(FileChunkConstants.SETTINGS_LAYOUT); chunkLayout.AppendString(Name); chunkLayout.AppendI32(Position.X); chunkLayout.AppendI32(Position.Y); chunkLayout.AppendI32(Size.Width); chunkLayout.AppendI32(Size.Height); chunkLayout.AppendI32((int)DockState); return(chunkLayout.ToBuffer()); }
public bool FromChunk(GR.IO.FileChunk Chunk) { if (Chunk.Type != FileChunkConstants.SETTINGS_ACCELERATOR) { return(false); } GR.IO.IReader reader = Chunk.MemoryReader(); Key = (Keys)reader.ReadUInt32(); Function = (RetroDevStudio.Types.Function)reader.ReadUInt32(); SecondaryKey = (Keys)reader.ReadUInt32(); return(true); }
public GR.Memory.ByteBuffer Save() { GR.IO.FileChunk chunkWatch = new GR.IO.FileChunk(Types.FileChunk.PROJECT_WATCH_ENTRY); chunkWatch.AppendString(Name); chunkWatch.AppendI32(SizeInBytes); chunkWatch.AppendU32((uint)Type); chunkWatch.AppendU8((byte)(DisplayMemory ? 1 : 0)); chunkWatch.AppendU8((byte)(IndexedX ? 1 : 0)); chunkWatch.AppendU8((byte)(IndexedY ? 1 : 0)); chunkWatch.AppendU8((byte)(LiteralValue ? 1 : 0)); chunkWatch.AppendI32(Address); return(chunkWatch.ToBuffer()); }
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 GR.IO.FileChunk ToChunk() { GR.IO.FileChunk chunk = new GR.IO.FileChunk(Types.FileChunk.SETTINGS_TOOL); chunk.AppendU32((uint)Type); chunk.AppendString(Name); chunk.AppendString(Filename); chunk.AppendString(PRGArguments); chunk.AppendString(DebugArguments); chunk.AppendString(WorkPath); chunk.AppendString(CartArguments); chunk.AppendString(TrueDriveOnArguments); chunk.AppendString(TrueDriveOffArguments); chunk.AppendU8(PassLabelsToEmulator ? (byte)0 : (byte)1); return(chunk); }
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 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 bool FromBuffer(GR.Memory.ByteBuffer SolutionData, string FromFile) { GR.IO.MemoryReader memIn = new GR.IO.MemoryReader(SolutionData); GR.IO.FileChunk chunk = new GR.IO.FileChunk(); while (chunk.ReadFromStream(memIn)) { if (chunk.Type != Types.FileChunk.SOLUTION) { return(false); } GR.IO.MemoryReader memChunk = chunk.MemoryReader(); GR.IO.FileChunk subChunk = new GR.IO.FileChunk(); while (subChunk.ReadFromStream(memChunk)) { GR.IO.MemoryReader memSubChunk = subChunk.MemoryReader(); switch (subChunk.Type) { case Types.FileChunk.SOLUTION_INFO: Name = memSubChunk.ReadString(); Filename = memSubChunk.ReadString(); Filename = FromFile; break; case Types.FileChunk.SOLUTION_PROJECT: { string filename = memSubChunk.ReadString(); filename = GR.Path.Normalize(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Filename), filename), false); Project project = MainForm.OpenProject(filename); } break; } } } return(true); }
public bool FromChunk(GR.IO.FileChunk Chunk) { if (Chunk.Type != Types.FileChunk.SETTINGS_TOOL) { return(false); } GR.IO.IReader reader = Chunk.MemoryReader(); Type = (ToolType)reader.ReadUInt32(); Name = reader.ReadString(); Filename = reader.ReadString(); PRGArguments = reader.ReadString(); DebugArguments = reader.ReadString(); WorkPath = reader.ReadString(); CartArguments = reader.ReadString(); TrueDriveOnArguments = reader.ReadString(); TrueDriveOffArguments = reader.ReadString(); PassLabelsToEmulator = (reader.ReadUInt8() == 0); return(true); }
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 bool ReadFromBuffer(GR.Memory.ByteBuffer ProjectFile) { if (ProjectFile == null) { return(false); } GR.IO.MemoryReader memReader = new GR.IO.MemoryReader(ProjectFile); GR.IO.FileChunk chunk = new GR.IO.FileChunk(); string importedCharSet = ""; while (chunk.ReadFromStream(memReader)) { GR.IO.MemoryReader chunkReader = chunk.MemoryReader(); switch (chunk.Type) { case Types.FileChunk.MAP_PROJECT_INFO: { uint version = chunkReader.ReadUInt32(); importedCharSet = chunkReader.ReadString(); ShowGrid = (chunkReader.ReadInt32() == 1); } break; case Types.FileChunk.MAP_CHARSET: { GR.Memory.ByteBuffer data = new GR.Memory.ByteBuffer(); chunkReader.ReadBlock(data, (uint)(chunkReader.Size - chunkReader.Position)); Charset.ReadFromBuffer(data); } break; case Types.FileChunk.MAP_PROJECT_DATA: { GR.IO.FileChunk chunkData = new GR.IO.FileChunk(); while (chunkData.ReadFromStream(chunkReader)) { GR.IO.MemoryReader subChunkReader = chunkData.MemoryReader(); switch (chunkData.Type) { case Types.FileChunk.MULTICOLOR_DATA: Mode = (Types.CharsetMode)subChunkReader.ReadUInt8(); BackgroundColor = subChunkReader.ReadUInt8(); MultiColor1 = subChunkReader.ReadUInt8(); MultiColor2 = subChunkReader.ReadUInt8(); BGColor4 = subChunkReader.ReadUInt8(); break; case Types.FileChunk.MAP_TILE: { Tile tile = new Tile(); tile.Name = subChunkReader.ReadString(); int w = subChunkReader.ReadInt32(); int h = subChunkReader.ReadInt32(); tile.Chars.Resize(w, h); for (int j = 0; j < tile.Chars.Height; ++j) { for (int i = 0; i < tile.Chars.Width; ++i) { tile.Chars[i, j].Character = subChunkReader.ReadUInt8(); tile.Chars[i, j].Color = subChunkReader.ReadUInt8(); } } Tiles.Add(tile); tile.Index = Tiles.Count - 1; } break; case Types.FileChunk.MAP: { GR.IO.FileChunk mapChunk = new GR.IO.FileChunk(); Map map = new Map(); while (mapChunk.ReadFromStream(subChunkReader)) { GR.IO.MemoryReader mapChunkReader = mapChunk.MemoryReader(); switch (mapChunk.Type) { case Types.FileChunk.MAP_INFO: map.Name = mapChunkReader.ReadString(); map.TileSpacingX = mapChunkReader.ReadInt32(); map.TileSpacingY = mapChunkReader.ReadInt32(); map.AlternativeMultiColor1 = mapChunkReader.ReadInt32() - 1; map.AlternativeMultiColor2 = mapChunkReader.ReadInt32() - 1; map.AlternativeBackgroundColor = mapChunkReader.ReadInt32() - 1; map.AlternativeBGColor4 = mapChunkReader.ReadInt32() - 1; map.AlternativeMode = (C64Studio.Types.CharsetMode)(mapChunkReader.ReadInt32() - 1); break; case Types.FileChunk.MAP_DATA: { int w = mapChunkReader.ReadInt32(); int h = mapChunkReader.ReadInt32(); map.Tiles.Resize(w, h); for (int j = 0; j < map.Tiles.Height; ++j) { for (int i = 0; i < map.Tiles.Width; ++i) { map.Tiles[i, j] = mapChunkReader.ReadInt32(); } } } break; case Types.FileChunk.MAP_EXTRA_DATA: { uint len = mapChunkReader.ReadUInt32(); mapChunkReader.ReadBlock(map.ExtraDataOld, len); map.ExtraDataText = map.ExtraDataOld.ToString(); map.ExtraDataOld.Clear(); } break; case Types.FileChunk.MAP_EXTRA_DATA_TEXT: { map.ExtraDataText = mapChunkReader.ReadString(); } break; } } Maps.Add(map); } break; } } } break; } } memReader.Close(); Charset.MultiColor1 = MultiColor1; Charset.MultiColor2 = MultiColor2; Charset.BGColor4 = BGColor4; return(true); }
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); }
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 bool Load(byte[] ProjectData) { string currentConfig = "Default"; string activeElement = ""; Node = new System.Windows.Forms.TreeNode(); Node.Tag = this; GR.IO.MemoryReader memIn = new GR.IO.MemoryReader(ProjectData); GR.IO.FileChunk chunk = new GR.IO.FileChunk(); ushort origDebugStartAddress = 2049; while (chunk.ReadFromStream(memIn)) { GR.IO.MemoryReader memChunk = chunk.MemoryReader(); switch (chunk.Type) { case Types.FileChunk.PROJECT: // Project Info // Version memChunk.ReadUInt32(); Settings.Name = memChunk.ReadString(); Settings.Filename = memChunk.ReadString(); Settings.DebugPort = memChunk.ReadUInt16(); origDebugStartAddress = memChunk.ReadUInt16(); Settings.BuildTool = memChunk.ReadString(); Settings.RunTool = memChunk.ReadString(); Settings.MainDocument = memChunk.ReadString(); currentConfig = memChunk.ReadString(); activeElement = memChunk.ReadString(); Node.Text = Settings.Name; break; case Types.FileChunk.PROJECT_ELEMENT: // Element Info { // Version int version = (int)memChunk.ReadUInt32(); ProjectElement.ElementType type = (ProjectElement.ElementType)memChunk.ReadUInt32(); //System.Windows.Forms.TreeNode nodeParent = NodeFromHierarchy( ProjectElement element = CreateElement(type, Node); element.Name = memChunk.ReadString(); //element.Filename = System.IO.Path.GetFileName( memChunk.ReadString() ); element.Filename = memChunk.ReadString(); if (element.DocumentInfo.Type == ProjectElement.ElementType.FOLDER) { element.Node.Text = element.Name; } else { element.Node.Text = System.IO.Path.GetFileName(element.Filename); } GR.IO.FileChunk subChunk = new GR.IO.FileChunk(); if (!subChunk.ReadFromStream(memChunk)) { return(false); } if (subChunk.Type != Types.FileChunk.PROJECT_ELEMENT_DATA) { return(false); } // Element Data element.DocumentInfo.DocumentFilename = element.Filename; if (element.Document != null) { if (!element.Document.ReadFromReader(subChunk.MemoryReader())) { Elements.Remove(element); element.Document.Dispose(); element = null; } else { element.Document.SetDocumentFilename(element.Filename); } } element.TargetFilename = memChunk.ReadString(); element.TargetType = (Types.CompileTargetType)memChunk.ReadUInt32(); int dependencyCount = memChunk.ReadInt32(); for (int i = 0; i < dependencyCount; ++i) { string dependency = memChunk.ReadString(); element.ForcedDependency.DependentOnFile.Add(new FileDependency.DependencyInfo(dependency, true, false)); } // 3 free strings memChunk.ReadString(); memChunk.ReadString(); memChunk.ReadString(); int perConfigSettingCount = memChunk.ReadInt32(); for (int i = 0; i < perConfigSettingCount; ++i) { GR.IO.FileChunk chunkElementPerConfigSetting = new GR.IO.FileChunk(); chunkElementPerConfigSetting.ReadFromStream(memChunk); if (chunkElementPerConfigSetting.Type == Types.FileChunk.PROJECT_ELEMENT_PER_CONFIG_SETTING) { ProjectElement.PerConfigSettings perConfigSetting = new ProjectElement.PerConfigSettings(); GR.IO.MemoryReader memSubChunk = chunkElementPerConfigSetting.MemoryReader(); string config = memSubChunk.ReadString(); perConfigSetting.PreBuild = memSubChunk.ReadString(); perConfigSetting.CustomBuild = memSubChunk.ReadString(); perConfigSetting.PostBuild = memSubChunk.ReadString(); perConfigSetting.DebugFile = memSubChunk.ReadString(); perConfigSetting.DebugFileType = (C64Studio.Types.CompileTargetType)memSubChunk.ReadInt32(); perConfigSetting.PreBuildChain.Active = (memSubChunk.ReadInt32() == 1); int numEntries = memSubChunk.ReadInt32(); for (int j = 0; j < numEntries; ++j) { var entry = new BuildChainEntry(); entry.ProjectName = memSubChunk.ReadString(); entry.Config = memSubChunk.ReadString(); entry.DocumentFilename = memSubChunk.ReadString(); entry.PreDefines = memSubChunk.ReadString(); perConfigSetting.PreBuildChain.Entries.Add(entry); } perConfigSetting.PostBuildChain.Active = (memSubChunk.ReadInt32() == 1); numEntries = memSubChunk.ReadInt32(); for (int j = 0; j < numEntries; ++j) { var entry = new BuildChainEntry(); entry.ProjectName = memSubChunk.ReadString(); entry.Config = memSubChunk.ReadString(); entry.DocumentFilename = memSubChunk.ReadString(); entry.PreDefines = memSubChunk.ReadString(); perConfigSetting.PostBuildChain.Entries.Add(entry); } element.Settings[config] = perConfigSetting; } } element.IsShown = (memChunk.ReadInt32() != 0); element.AssemblerType = (C64Studio.Types.AssemblerType)memChunk.ReadUInt32(); int hierarchyPartCount = memChunk.ReadInt32(); for (int i = 0; i < hierarchyPartCount; ++i) { string part = memChunk.ReadString(); element.ProjectHierarchy.Add(part); } if (element.ProjectHierarchy.Count > 0) { // node is sub-node, move accordingly System.Windows.Forms.TreeNode parentNode = NodeFromHierarchy(element.ProjectHierarchy); if ((parentNode != null) && (parentNode != element.Node.Parent)) { element.Node.Remove(); parentNode.Nodes.Add(element.Node); } } // dependency - include symbols dependencyCount = memChunk.ReadInt32(); for (int i = 0; i < dependencyCount; ++i) { element.ForcedDependency.DependentOnFile[i].IncludeSymbols = (memChunk.ReadInt32() != 0); } // code folding entries int numFoldingEntries = memChunk.ReadInt32(); element.DocumentInfo.CollapsedFoldingBlocks = new GR.Collections.Set <int>(); for (int i = 0; i < numFoldingEntries; ++i) { int collapsedBlockLine = memChunk.ReadInt32(); element.DocumentInfo.CollapsedFoldingBlocks.Add(collapsedBlockLine); //Debug.Log( "Get collapsed blocked for " + element.DocumentInfo.FullPath + ", line " + collapsedBlockLine ); } // TODO - load other stuff if ((element != null) && (element.IsShown)) { ShowDocument(element); if (element.Document != null) { element.Document.ShowHint = DockState.Document; //element.Document.Show( MainForm.panelMain ); } } } break; case Types.FileChunk.PROJECT_ELEMENT_DISPLAY_DATA: { string elementFilename = memChunk.ReadString(); ProjectElement element = GetElementByFilename(elementFilename); if (element != null) { UInt32 numBytes = memChunk.ReadUInt32(); GR.Memory.ByteBuffer displayData = new GR.Memory.ByteBuffer(); memChunk.ReadBlock(displayData, numBytes); if (element.Document != null) { element.Document.ApplyDisplayDetails(displayData); } } } break; case Types.FileChunk.PROJECT_CONFIG: { ProjectConfig config = new ProjectConfig(); config.Load(memChunk); if (string.IsNullOrEmpty(config.DebugStartAddressLabel)) { config.DebugStartAddressLabel = origDebugStartAddress.ToString(); } Settings.Configs.Add(config.Name, config); } break; case Types.FileChunk.PROJECT_WATCH_ENTRY: { WatchEntry watch = new WatchEntry(); watch.Load(memChunk); Core.MainForm.AddWatchEntry(watch); //Debug.Log( "loaded watch entry for " + watch.Name ); } break; } } if (Settings.Configs.Count == 0) { // there must be one config ProjectConfig config = new ProjectConfig(); config.Name = "Default"; Settings.Configs.Add(config.Name, config); Settings.CurrentConfig = config; } else { if (Settings.Configs.ContainsKey(currentConfig)) { Settings.CurrentConfig = Settings.Configs[currentConfig]; } else { foreach (ProjectConfig config in Settings.Configs.Values) { Settings.CurrentConfig = config; break; } } } foreach (ProjectElement element in Elements) { if (element.Settings.Count == 0) { foreach (ProjectConfig config in Settings.Configs.Values) { // needs a default setting! element.Settings[config.Name] = new ProjectElement.PerConfigSettings(); } } if ((!string.IsNullOrEmpty(element.Filename)) && (GR.Path.IsPathEqual(element.Filename, Settings.MainDocument))) { Core.MainForm.m_SolutionExplorer.HighlightNode(element.Node); } Core.MainForm.RaiseApplicationEvent(new C64Studio.Types.ApplicationEvent(C64Studio.Types.ApplicationEvent.Type.DOCUMENT_INFO_CREATED, element.DocumentInfo)); Core.MainForm.RaiseApplicationEvent(new C64Studio.Types.ApplicationEvent(C64Studio.Types.ApplicationEvent.Type.ELEMENT_CREATED, element)); } if (!String.IsNullOrEmpty(activeElement)) { ProjectElement element = GetElementByFilename(activeElement); if ((element != null) && (element.Document != null)) { element.Document.Show(); } } m_Modified = false; return(true); }
public bool ReadFromBuffer(GR.Memory.ByteBuffer ProjectFile) { ColorMapping.Clear(); for (int i = 0; i < 16; ++i) { ColorMapping.Add(i, new List <ColorMappingTarget> { ColorMappingTarget.ANY }); } Colors.Palettes.Clear(); GR.IO.MemoryReader memReader = new GR.IO.MemoryReader(ProjectFile); GR.IO.FileChunk chunk = new GR.IO.FileChunk(); while (chunk.ReadFromStream(memReader)) { GR.IO.MemoryReader chunkReader = chunk.MemoryReader(); switch (chunk.Type) { case FileChunkConstants.GRAPHIC_SCREEN_INFO: SelectedCheckType = (CheckType)chunkReader.ReadUInt32(); ScreenOffsetX = chunkReader.ReadInt32(); ScreenOffsetY = chunkReader.ReadInt32(); ScreenWidth = chunkReader.ReadInt32(); ScreenHeight = chunkReader.ReadInt32(); if ((ScreenWidth == 0) || (ScreenHeight == 0)) { ScreenWidth = 320; ScreenHeight = 200; } break; case FileChunkConstants.GRAPHIC_COLOR_MAPPING: { ColorMapping.Clear(); int numEntries = chunkReader.ReadInt32(); for (int i = 0; i < numEntries; ++i) { ColorMapping.Add(i, new List <ColorMappingTarget>()); int numMappings = chunkReader.ReadInt32(); for (int j = 0; j < numMappings; ++j) { ColorMappingTarget mappingTarget = (ColorMappingTarget)chunkReader.ReadUInt8(); ColorMapping[i].Add(mappingTarget); } } } break; case FileChunkConstants.GRAPHIC_DATA: { int width = chunkReader.ReadInt32(); int height = chunkReader.ReadInt32(); GR.Drawing.PixelFormat format = (GR.Drawing.PixelFormat)chunkReader.ReadInt32(); int paletteCount = chunkReader.ReadInt32(); Image.Create(width, height, format); for (int i = 0; i < paletteCount; ++i) { byte r = chunkReader.ReadUInt8(); byte g = chunkReader.ReadUInt8(); byte b = chunkReader.ReadUInt8(); Image.SetPaletteColor(i, r, g, b); } uint dataSize = chunkReader.ReadUInt32(); GR.Memory.ByteBuffer imageData = new GR.Memory.ByteBuffer(); chunkReader.ReadBlock(imageData, dataSize); Image.SetData(imageData); } break; case FileChunkConstants.MULTICOLOR_DATA: MultiColor = (chunkReader.ReadUInt8() == 1); Colors.BackgroundColor = chunkReader.ReadUInt8(); Colors.MultiColor1 = chunkReader.ReadUInt8(); Colors.MultiColor2 = chunkReader.ReadUInt8(); Colors.ActivePalette = chunkReader.ReadInt32(); if ((Colors.MultiColor1 < 0) || (Colors.MultiColor1 >= 16)) { Colors.MultiColor1 = 0; } if ((Colors.MultiColor2 < 0) || (Colors.MultiColor2 >= 16)) { Colors.MultiColor2 = 0; } break; case FileChunkConstants.PALETTE: Colors.Palettes.Add(Palette.Read(chunkReader)); break; } } memReader.Close(); if (Colors.Palettes.Count == 0) { Colors.Palettes.Add(PaletteManager.PaletteFromMachine(MachineType.C64)); } return(true); }
public bool ReadFromBuffer(GR.Memory.ByteBuffer DataIn) { if (DataIn == null) { return(false); } SpriteLayers.Clear(); GR.IO.MemoryReader memIn = DataIn.MemoryReader(); uint Version = memIn.ReadUInt32(); int numSprites = 256; if (Version >= 1) { numSprites = memIn.ReadInt32(); } Sprites = new List <SpriteData>(); for (int i = 0; i < numSprites; ++i) { Sprites.Add(new SpriteData()); CustomRenderer.PaletteManager.ApplyPalette(Sprites[i].Image); } string name = memIn.ReadString(); for (int i = 0; i < numSprites; ++i) { Sprites[i].Color = memIn.ReadInt32(); } for (int i = 0; i < numSprites; ++i) { Sprites[i].Multicolor = (memIn.ReadUInt8() != 0); } BackgroundColor = memIn.ReadInt32(); MultiColor1 = memIn.ReadInt32(); MultiColor2 = memIn.ReadInt32(); bool genericMultiColor = (memIn.ReadUInt32() != 0); for (int i = 0; i < numSprites; ++i) { GR.Memory.ByteBuffer tempBuffer = new GR.Memory.ByteBuffer(); memIn.ReadBlock(tempBuffer, 64); tempBuffer.CopyTo(Sprites[i].Data, 0, 63); } UsedSprites = memIn.ReadUInt32(); ExportFilename = memIn.ReadString(); string exportPathSpriteFile = memIn.ReadString(); for (int i = 0; i < numSprites; ++i) { string desc = memIn.ReadString(); } 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(); } GR.IO.FileChunk chunk = new GR.IO.FileChunk(); while (chunk.ReadFromStream(memIn)) { switch (chunk.Type) { case Types.FileChunk.SPRITESET_LAYER: { Layer layer = new Layer(); SpriteLayers.Add(layer); var chunkReader = chunk.MemoryReader(); GR.IO.FileChunk subChunk = new GR.IO.FileChunk(); while (subChunk.ReadFromStream(chunkReader)) { var subChunkReader = subChunk.MemoryReader(); if (subChunk.Type == Types.FileChunk.SPRITESET_LAYER_ENTRY) { LayerSprite sprite = new LayerSprite(); sprite.Index = subChunkReader.ReadInt32(); sprite.Color = subChunkReader.ReadUInt8(); sprite.X = subChunkReader.ReadInt32(); sprite.Y = subChunkReader.ReadInt32(); sprite.ExpandX = (subChunkReader.ReadUInt8() != 0); sprite.ExpandY = (subChunkReader.ReadUInt8() != 0); layer.Sprites.Add(sprite); } else if (subChunk.Type == Types.FileChunk.SPRITESET_LAYER_INFO) { layer.Name = subChunkReader.ReadString(); layer.BackgroundColor = subChunkReader.ReadUInt8(); } } } break; } } return(true); }
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 bool ReadFromBuffer(GR.Memory.ByteBuffer DataIn) { if (DataIn == null) { return(false); } GR.IO.MemoryReader memIn = DataIn.MemoryReader(); uint version = memIn.ReadUInt32(); if (version == 1) { TotalNumberOfCharacters = 256; string name = memIn.ReadString(); string charsetFilename = memIn.ReadString(); for (int i = 0; i < TotalNumberOfCharacters; ++i) { Characters[i].Tile.CustomColor = memIn.ReadInt32(); } bool hasAnyMC = false; for (int i = 0; i < TotalNumberOfCharacters; ++i) { var mode = (TextCharMode)memIn.ReadUInt8(); if ((mode == TextCharMode.COMMODORE_MULTICOLOR) && (Characters[i].Tile.CustomColor < 8)) { mode = TextCharMode.COMMODORE_HIRES; } if (mode == TextCharMode.COMMODORE_MULTICOLOR) { hasAnyMC = true; } } Colors.BackgroundColor = memIn.ReadInt32(); Colors.MultiColor1 = memIn.ReadInt32(); Colors.MultiColor2 = memIn.ReadInt32(); for (int i = 0; i < TotalNumberOfCharacters; ++i) { int tileColor1 = memIn.ReadInt32(); int tileColor2 = memIn.ReadInt32(); int tileColor3 = memIn.ReadInt32(); int tileColor4 = memIn.ReadInt32(); int tileChar1 = memIn.ReadInt32(); int tileChar2 = memIn.ReadInt32(); int tileChar3 = memIn.ReadInt32(); int tileChar4 = memIn.ReadInt32(); } bool genericMulticolor = (memIn.ReadInt32() != 0); GR.Memory.ByteBuffer testbed = new GR.Memory.ByteBuffer(); memIn.ReadBlock(testbed, 64); GR.Memory.ByteBuffer charsetData = new GR.Memory.ByteBuffer(); memIn.ReadBlock(charsetData, (uint)(TotalNumberOfCharacters * 8)); for (int i = 0; i < TotalNumberOfCharacters; ++i) { Characters[i].Tile.Data = charsetData.SubBuffer(i * 8, 8); } UsedTiles = memIn.ReadUInt32(); ExportFilename = memIn.ReadString(); string exportPathBlockTable = memIn.ReadString(); string exportPathCharset = memIn.ReadString(); string exportPathEditorTiles = memIn.ReadString(); // categories Categories.Clear(); int categoryCount = memIn.ReadInt32(); for (int i = 0; i < categoryCount; ++i) { int catKey = memIn.ReadInt32(); string catName = memIn.ReadString(); Categories.Add(catName); } if (Categories.Count == 0) { // add default category Categories.Add("Uncategorized"); } for (int i = 0; i < TotalNumberOfCharacters; ++i) { Characters[i].Category = memIn.ReadInt32(); if ((Characters[i].Category < 0) || (Characters[i].Category >= Categories.Count)) { Characters[i].Category = 0; } } ExportNumCharacters = memIn.ReadInt32(); if (ExportNumCharacters < TotalNumberOfCharacters) { ExportNumCharacters = TotalNumberOfCharacters; } ShowGrid = (memIn.ReadInt32() != 0); ExportStartCharacter = memIn.ReadInt32(); Colors.BGColor4 = memIn.ReadInt32(); // playground int w = memIn.ReadInt32(); int h = memIn.ReadInt32(); if (w * h < 256) { w = 16; h = 16; } PlaygroundChars = new List <uint>(w * h); for (int i = 0; i < w * h; ++i) { ushort charInfo = memIn.ReadUInt16(); PlaygroundChars.Add((uint)((charInfo & 0xff) | ((charInfo & 0xff00) << 8))); } Mode = (TextCharMode)memIn.ReadInt32(); if (hasAnyMC) { Mode = TextCharMode.COMMODORE_MULTICOLOR; } } else if (version == 2) { Characters.Clear(); Categories.Clear(); Colors.Palettes.Clear(); TotalNumberOfCharacters = 256; Mode = TextCharMode.COMMODORE_HIRES; var chunk = new GR.IO.FileChunk(); while (chunk.ReadFromStream(memIn)) { if (chunk.Type == FileChunkConstants.CHARSET_PROJECT) { var chunkIn = chunk.MemoryReader(); var subChunk = new GR.IO.FileChunk(); while (subChunk.ReadFromStream(chunkIn)) { var subMemIn = subChunk.MemoryReader(); switch (subChunk.Type) { case FileChunkConstants.CHARSET_INFO: Mode = (TextCharMode)subMemIn.ReadInt32(); TotalNumberOfCharacters = subMemIn.ReadInt32(); ShowGrid = ((subMemIn.ReadInt32() & 1) == 1); break; case FileChunkConstants.CHARSET_COLOR_SETTINGS: Colors.BackgroundColor = subMemIn.ReadInt32(); Colors.MultiColor1 = subMemIn.ReadInt32(); Colors.MultiColor2 = subMemIn.ReadInt32(); Colors.BGColor4 = subMemIn.ReadInt32(); Colors.ActivePalette = subMemIn.ReadInt32(); break; case FileChunkConstants.PALETTE: Colors.Palettes.Add(Palette.Read(subMemIn)); break; case FileChunkConstants.CHARSET_EXPORT: ExportStartCharacter = subMemIn.ReadInt32(); ExportNumCharacters = subMemIn.ReadInt32(); ExportFilename = subMemIn.ReadString(); break; case FileChunkConstants.CHARSET_CHAR: { var charData = new CharData(); subMemIn.ReadInt32(); // was TextCharMode charData.Tile.CustomColor = subMemIn.ReadInt32(); charData.Tile.Mode = Lookup.GraphicTileModeFromTextCharMode(Mode, charData.Tile.CustomColor); charData.Category = subMemIn.ReadInt32(); int dataLength = subMemIn.ReadInt32(); charData.Tile.Data = new GR.Memory.ByteBuffer(); subMemIn.ReadBlock(charData.Tile.Data, (uint)dataLength); Characters.Add(charData); } break; case FileChunkConstants.CHARSET_CATEGORY: Categories.Add(subMemIn.ReadString()); break; case FileChunkConstants.CHARSET_PLAYGROUND: PlaygroundWidth = subMemIn.ReadInt32(); PlaygroundHeight = subMemIn.ReadInt32(); PlaygroundChars = new List <uint>(PlaygroundWidth * PlaygroundHeight); for (int i = 0; i < PlaygroundWidth * PlaygroundHeight; ++i) { // 16 bit index, 16 bit color PlaygroundChars.Add(subMemIn.ReadUInt32()); } break; } } } } if (Colors.Palettes.Count == 0) { Colors.Palettes.Add(PaletteManager.PaletteFromNumColors(Lookup.NumberOfColorsInCharacter(Mode))); } } else { return(false); } return(true); }
public bool ReadFromBuffer(GR.Memory.ByteBuffer DataIn) { if (DataIn == null) { return(false); } Data.Clear(); JumpedAtAddresses.Clear(); NamedLabels.Clear(); Description = ""; GR.IO.MemoryReader memIn = DataIn.MemoryReader(); GR.IO.FileChunk chunk = new GR.IO.FileChunk(); while (chunk.ReadFromStream(memIn)) { var chunkReader = chunk.MemoryReader(); switch (chunk.Type) { case FileChunkConstants.DISASSEMBLY_INFO: Description = chunkReader.ReadString(); break; case FileChunkConstants.DISASSEMBLY_DATA: { DataStartAddress = chunkReader.ReadInt32(); uint dataLength = chunkReader.ReadUInt32(); chunkReader.ReadBlock(Data, dataLength); } break; case FileChunkConstants.DISASSEMBLY_JUMP_ADDRESSES: { int numEntries = chunkReader.ReadInt32(); for (int i = 0; i < numEntries; ++i) { int value = chunkReader.ReadInt32(); JumpedAtAddresses.Add(value); } } break; case FileChunkConstants.DISASSEMBLY_NAMED_LABELS: { int numEntries = chunkReader.ReadInt32(); for (int i = 0; i < numEntries; ++i) { int address = chunkReader.ReadInt32(); string name = chunkReader.ReadString(); NamedLabels[address] = name; } } break; } } return(true); }