public UndoCharscreenValuesChange(CharsetScreenProject Project, CharsetScreenEditor Editor) { this.Project = Project; this.Editor = Editor; BackgroundColor = Project.BackgroundColor; Multicolor1 = Project.MultiColor1; Multicolor2 = Project.MultiColor2; BGColor4 = Project.BGColor4; Mode = Project.Mode; }
public UndoMapValueChange(MapEditor Editor, MapProject.Map Map) { MapEditor = Editor; AffectedMap = Map; AlternativeColor1 = Map.AlternativeMultiColor1; AlternativeColor2 = Map.AlternativeMultiColor2; AlternativeBGColor = Map.AlternativeBackgroundColor; AlternativeBGColor4 = Map.AlternativeBGColor4; ExtraData = Map.ExtraDataText; Name = Map.Name; TileSpacingX = Map.TileSpacingX; TileSpacingY = Map.TileSpacingY; AlternativeMode = Map.AlternativeMode; }
public static void DisplayChar(Formats.CharsetProject Charset, int CharIndex, GR.Image.IImage TargetImage, int X, int Y, int AlternativeColor, int AltBGColor, int AltMColor1, int AltMColor2, int AltBGColor4, Types.CharsetMode AlternativeMode) { Formats.CharData Char = Charset.Characters[CharIndex]; if (AlternativeMode == C64Studio.Types.CharsetMode.ECM) { // ECM Formats.CharData origChar = Charset.Characters[CharIndex % 64]; int bgColor = AltBGColor; switch (CharIndex / 64) { case 1: bgColor = AltMColor1; break; case 2: bgColor = AltMColor2; break; case 3: bgColor = AltBGColor4; break; } Displayer.CharacterDisplayer.DisplayHiResChar(origChar.Data, bgColor, AlternativeColor, TargetImage, X, Y); } else if (AlternativeMode == C64Studio.Types.CharsetMode.MULTICOLOR) { Displayer.CharacterDisplayer.DisplayMultiColorChar(Char.Data, AltBGColor, AltMColor1, AltMColor2, AlternativeColor, TargetImage, X, Y); } else if (AlternativeMode == C64Studio.Types.CharsetMode.HIRES) { Displayer.CharacterDisplayer.DisplayHiResChar(Char.Data, AltBGColor, AlternativeColor, TargetImage, X, Y); } }
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); }
private bool LoadVersion7(GR.Memory.ByteBuffer Data) { BackgroundColor = Data.ByteAt(4); MultiColor1 = Data.ByteAt(5); MultiColor2 = Data.ByteAt(6); BackgroundColor4 = Data.ByteAt(7); CustomColor = Data.ByteAt(8); TileColorMode = (ColorMode)Data.ByteAt(9); CharsetMode = (Types.CharsetMode)Data.ByteAt(10); byte flags = Data.ByteAt(11); bool tileSysEnabled = ((flags & 0x01) != 0); ushort charDataBlockID = 0xdab0; ushort charAttributeBlockID = 0xdab1; ushort mapDataBlockID = 0xdab2; if (!tileSysEnabled) { // fake tiles (one per char) TileWidth = 1; TileHeight = 1; NumTiles = 256; for (int i = 0; i < NumTiles; ++i) { Tile tile = new Tile(); tile.CharData.Resize((uint)(TileWidth * TileHeight * 2)); tile.CharData.SetU16At(0, (ushort)i); tile.ColorData.Resize((uint)(TileWidth * TileHeight)); tile.ColorData.SetU8At(0, (byte)CustomColor); Tiles.Add(tile); } } var reader = Data.MemoryReader(); reader.Skip(12); while (reader.DataAvailable) { ushort blockID = reader.ReadUInt16NetworkOrder(); if (blockID == mapDataBlockID) { if (tileSysEnabled) { // Tile data block // TILECNT: Tile count minus one(16 - bit, LSBF). NumTiles = reader.ReadUInt16() + 1; // TILEWID: Tile width( byte). TileWidth = reader.ReadUInt8(); // TILEHEI: Tile height( byte). TileHeight = reader.ReadUInt8(); // TILEDAT: Tile data, 16 bits per tile cell( LSBF) for TILEWID* TILEHEI cells * TILECNT items, cells are in LRTB order. for (int i = 0; i < NumTiles; ++i) { Tile tile = new Tile(); tile.CharData.Resize((uint)(TileWidth * TileHeight * 2)); tile.ColorData.Resize((uint)(TileWidth * TileHeight)); Tiles.Add(tile); } if (NumChars < 256) { // add all chars for safety reasons for (int i = NumChars; i < 256; ++i) { SingleChar newChar = new SingleChar(); newChar.Data = new GR.Memory.ByteBuffer(8); Characters.Add(newChar); } } for (int i = 0; i < NumTiles; ++i) { for (int j = 0; j < TileWidth * TileHeight; ++j) { Tiles[i].CharData.SetU16At(j * 2, reader.ReadUInt16()); } } } else { // BLKMARK : Block marker (0xDA, 0xBn). // MAPWID: Map Width(16 - bit, LSBF). // MAPHEI: Map height(16 - bit, LSBF). // MAPDAT: Map data, 16 bits per cell( LSBF ) for MAPWID* MAPHEI cells, cells are in LRTB order. MapWidth = reader.ReadUInt16(); MapHeight = reader.ReadUInt16(); MapData = new GR.Memory.ByteBuffer((uint)(MapWidth * MapHeight)); for (int i = 0; i < MapHeight; ++i) { for (int j = 0; j < MapWidth; ++j) { MapData.SetU8At(i * MapWidth + j, (byte)reader.ReadUInt16()); } } } } if (blockID == charDataBlockID) { // Character data block // CHARCNT: Character image count minus one( 16 - bit, LSBF ). NumChars = reader.ReadUInt16() + 1; // CHARDAT : Character image data( eight bytes / rows per image for CHARCNT images, rows are in TB order ). for (int charIndex = 0; charIndex < NumChars; ++charIndex) { SingleChar newChar = new SingleChar(); newChar.Data = new GR.Memory.ByteBuffer(); newChar.Color = CustomColor; reader.ReadBlock(newChar.Data, 8); Characters.Add(newChar); } if (!tileSysEnabled) { if (NumChars < 256) { // add all chars for safety reasons for (int i = NumChars; i < 256; ++i) { SingleChar newChar = new SingleChar(); newChar.Data = new GR.Memory.ByteBuffer(8); newChar.Color = CustomColor; Characters.Add(newChar); } } } } else if (blockID == charAttributeBlockID) { // char attributes // BLKMARK: Block marker(0xDA, 0xB1). // CHARATTS: Char attribute data, one byte per char image for CHARCNT images, low nybble = colour, high nybble = material. // nb.colours are only stored when the colouring mode is "per character". for (int charIndex = 0; charIndex < NumChars; ++charIndex) { if (TileColorMode == ColorMode.PER_TILE_CELL) { Characters[charIndex].Color = reader.ReadUInt8() & 0x0f; if (!tileSysEnabled) { Tiles[charIndex].ColorData.SetU8At(0, (byte)Characters[charIndex].Color); } } } } } /* * * * int headerSize = 20; * int offsetToCharData = headerSize; * int offsetToCharAttribs = offsetToCharData + NumChars * 8; * int offsetToTileData = offsetToCharAttribs + NumChars; * int offsetToTileColors = offsetToTileData + NumTiles * TileWidth * TileHeight * 2; * if ( ( tileSysEnabled ) || ( noTiles ) ) ||{ ||offsetToTileColors = offsetToTileData; ||} ||int offsetToMapData = offsetToTileColors + NumTiles; ||if ( ( TileColorMode != ColorMode.PER_TILE ) || ( noTiles ) ) ||{ ||offsetToMapData = offsetToTileColors; ||} || ||// tile_data ||if ( noTiles ) ||{ ||for ( int i = 0; i < NumTiles; ++i ) ||{ || Tile tile = new Tile(); || || tile.CharData.Resize( (uint)( TileWidth * TileHeight * 2 ) ); || tile.CharData.SetU16At( 0, (ushort)i ); || || tile.ColorData.Resize( (uint)( TileWidth * TileHeight ) ); || tile.ColorData.SetU8At( 0, (byte)CustomColor ); || || Tiles.Add( tile ); ||} ||if ( NumChars < 256 ) ||{ || // add all chars for safety reasons || for ( int i = NumChars; i < 256; ++i ) || { || SingleChar newChar = new SingleChar(); || newChar.Data = new GR.Memory.ByteBuffer( 8 ); || if ( TileColorMode == ColorMode.PER_TILE_CELL ) || { || newChar.Color = Data.ByteAt( offsetToCharAttribs + i ) & 0x0f; || } || else || { || newChar.Color = CustomColor; || } || || Characters.Add( newChar ); || } ||} ||} ||else ||{ ||for ( int i = 0; i < NumTiles; ++i ) ||{ || Tile tile = new Tile(); || || tile.CharData.Resize( (uint)( TileWidth * TileHeight * 2 ) ); || tile.ColorData.Resize( (uint)( TileWidth * TileHeight ) ); || || Tiles.Add( tile ); ||} || ||if ( tileSysEnabled ) ||{ || byte curCharIndex = 0; || for ( int i = 0; i < NumTiles; ++i ) || { || for ( int j = 0; j < TileWidth * TileHeight; ++j ) || { || Tiles[i].CharData.SetU16At( j * 2, curCharIndex ); ++curCharIndex; || } || } ||} ||else ||{ || // tile_data. Size = NUM_TILES * TILE_WIDTH * TILE_HEIGHT bytes * 2 bytes. (only exists if CHAR_DATA is not "Expanded") || for ( int i = 0; i < NumTiles; ++i ) || { || for ( int j = 0; j < TileWidth * TileHeight; ++j ) || { || Tiles[i].CharData.SetU16At( j * 2, Data.UInt16At( offsetToTileData + i * TileWidth * TileHeight * 2 + j * 2 ) ); || } || } ||} ||} || ||// TILE_COLOURS. Size = NUM_TILES bytes (1 byte per tile = "RAM colour". only exists if COLOR_MODE = 1 (Per Tile) ||if ( TileColorMode == ColorMode.PER_TILE ) ||{ ||for ( int i = 0; i < NumTiles; ++i ) ||{ || for ( int y = 0; y < TileHeight; ++y ) || { || for ( int x = 0; x < TileWidth; ++x ) || { || Tiles[i].ColorData.SetU8At( x + y * TileWidth, (byte)( Data.ByteAt( offsetToTileColors + i ) & 0x0f ) ); || } || } ||} ||} ||else if ( TileColorMode == ColorMode.PER_TILE_CELL ) ||{ ||// with V5 this actually means per character ||for ( int i = 0; i < NumTiles; ++i ) ||{ || for ( int y = 0; y < TileHeight; ++y ) || { || for ( int x = 0; x < TileWidth; ++x ) || { || byte charColor = (byte)Characters[Tiles[i].CharData.ByteAt( 2 * ( x + y * TileWidth ) )].Color; || Tiles[i].ColorData.SetU8At( x + y * TileWidth, charColor ); || } || } ||} ||} ||else if ( TileColorMode == ColorMode.GLOBAL ) ||{ ||for ( int i = 0; i < NumTiles; ++i ) ||{ || for ( int y = 0; y < TileHeight; ++y ) || { || for ( int x = 0; x < TileWidth; ++x ) || { || Tiles[i].ColorData.SetU8At( x + y * TileWidth, (byte)CustomColor ); || } || } ||} ||} ||else if ( TileColorMode == ColorMode.PER_TILE_CELL ) ||{ ||for ( int i = 0; i < NumTiles; ++i ) ||{ || for ( int y = 0; y < TileHeight; ++y ) || { || for ( int x = 0; x < TileWidth; ++x ) || { || Tiles[i].ColorData.SetU8At( x + y * TileWidth, (byte)( Data.ByteAt( offsetCellAttribs + i * TileWidth * TileHeight + x + y * TileHeight ) & 0x0f ) ); || } || } ||} ||} || */ 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); }