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 bool ReadFromBuffer(GR.Memory.ByteBuffer ProjectFile) { 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.CHARSET_SCREEN_INFO: { int version = chunkReader.ReadInt32(); ScreenWidth = chunkReader.ReadInt32(); ScreenHeight = chunkReader.ReadInt32(); ExternalCharset = chunkReader.ReadString(); _Mode = (TextMode)chunkReader.ReadInt32(); ScreenOffsetX = chunkReader.ReadInt32(); ScreenOffsetY = chunkReader.ReadInt32(); CharOffset = chunkReader.ReadInt32(); Chars = new List <uint>(); for (int i = 0; i < ScreenWidth * ScreenHeight; ++i) { Chars.Add((uint)0x010020); } } break; case FileChunkConstants.MULTICOLOR_DATA: _Mode = (TextMode)chunkReader.ReadUInt8(); CharSet.Colors.BackgroundColor = chunkReader.ReadUInt8(); CharSet.Colors.MultiColor1 = chunkReader.ReadUInt8(); CharSet.Colors.MultiColor2 = chunkReader.ReadUInt8(); break; case FileChunkConstants.SCREEN_CHAR_DATA: for (int i = 0; i < Chars.Count; ++i) { if (Lookup.NumBytesOfSingleCharacter(Lookup.TextCharModeFromTextMode(Mode)) == 1) { Chars[i] = (uint)((Chars[i] & 0xffff0000) | chunkReader.ReadUInt8()); } else { Chars[i] = (uint)((Chars[i] & 0xffff0000) | chunkReader.ReadUInt16()); } } break; case FileChunkConstants.SCREEN_COLOR_DATA: for (int i = 0; i < Chars.Count; ++i) { if (Lookup.NumBytesOfSingleCharacter(Lookup.TextCharModeFromTextMode(Mode)) == 1) { Chars[i] = (uint)((Chars[i] & 0xffff) | ((uint)chunkReader.ReadUInt8() << 16)); } else { Chars[i] = (uint)((Chars[i] & 0xffff) | ((uint)chunkReader.ReadUInt16() << 16)); } } break; case FileChunkConstants.CHARSET_DATA: { if (!CharSet.ReadFromBuffer(chunk)) { return(false); } } break; } } memReader.Close(); 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 ProjectFile) { 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 Types.FileChunk.CHARSET_SCREEN_INFO: { uint version = chunkReader.ReadUInt32(); ScreenWidth = chunkReader.ReadInt32(); ScreenHeight = chunkReader.ReadInt32(); ExternalCharset = chunkReader.ReadString(); Mode = (C64Studio.Types.CharsetMode)chunkReader.ReadInt32(); ScreenOffsetX = chunkReader.ReadInt32(); ScreenOffsetY = chunkReader.ReadInt32(); Chars = new List <ushort>(); for (int i = 0; i < ScreenWidth * ScreenHeight; ++i) { Chars.Add((ushort)0x0120); } } break; case Types.FileChunk.MULTICOLOR_DATA: Mode = (C64Studio.Types.CharsetMode)chunkReader.ReadUInt8(); BackgroundColor = chunkReader.ReadUInt8(); MultiColor1 = chunkReader.ReadUInt8(); MultiColor2 = chunkReader.ReadUInt8(); break; case Types.FileChunk.SCREEN_CHAR_DATA: for (int i = 0; i < Chars.Count; ++i) { Chars[i] = (ushort)((Chars[i] & 0xff00) | chunkReader.ReadUInt8()); } break; case Types.FileChunk.SCREEN_COLOR_DATA: for (int i = 0; i < Chars.Count; ++i) { Chars[i] = (ushort)((Chars[i] & 0x00ff) | (chunkReader.ReadUInt8() << 8)); } break; case Types.FileChunk.CHARSET_DATA: { if (!CharSet.ReadFromBuffer(chunk)) { return(false); } } break; } } memReader.Close(); return(true); }