Exemplo n.º 1
0
 /// <summary>
 /// Copies this instance's properties to another Subtile.
 /// </summary>
 /// <param name="dst"></param>
 public void CopyTo(Subtile dst)
 {
     dst.Index     = this.Index;
     dst.Palette   = this.Palette;
     dst.Priority1 = this.Priority1;
     dst.Mirror    = this.Mirror;
     dst.Invert    = this.Invert;
     this.Pixels.CopyTo(dst.Pixels, 0);
     this.Colors.CopyTo(dst.Colors, 0);
 }
Exemplo n.º 2
0
 // Constructors
 public Tile(int index)
 {
     this.Subtiles = new Subtile[4];
     this.Index    = index; // set tile Number
     this.pixels   = new int[16 * 16];
     for (int p = 0; p < 4; p++)
     {
         Subtiles[p] = new Subtile(0, new byte[0x20], 0, new int[16], false, false, false, false);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a non-referenced copy of this instance.
        /// </summary>
        /// <returns></returns>
        public Subtile Copy()
        {
            var copy = new Subtile();

            copy.Pixels    = Bits.Copy(this.Pixels);
            copy.Colors    = Bits.Copy(this.Colors);
            copy.Priority1 = this.Priority1;
            copy.Mirror    = this.Mirror;
            copy.Invert    = this.Invert;
            copy.Index     = this.Index;
            copy.Palette   = this.Palette;
            return(copy);
        }
Exemplo n.º 4
0
 // Tiles
 public static bool Compare(Subtile subtileA, Subtile subtileB)
 {
     if (Bits.Compare(subtileA.Pixels, subtileB.Pixels) &&
         subtileA.Palette == subtileB.Palette &&
         subtileA.Index == subtileB.Index &&
         subtileA.Priority1 == subtileB.Priority1 &&
         Bits.Compare(subtileA.Colors, subtileB.Colors) &&
         subtileA.Mirror == subtileB.Mirror &&
         subtileA.Invert == subtileB.Invert)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Writes this tileset's tile data to the elements in the global Model.
        /// NOTE: The ROM buffer is not modified during this operation.
        /// <param name="width">The width, in 16x16 tile units, of the tileset.</param>
        public void WriteToModel(int width)
        {
            int offset = 0;

            if (Type != TilesetType.Mode7)
            {
                for (int l = 0; l < Tilesets_tiles.Length; l++)
                {
                    if (Tilesets_tiles[l] == null)
                    {
                        continue;
                    }
                    for (int y = 0; y < Tilesets_tiles[l].Length / width; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            Tile tile = Tilesets_tiles[l][y * width + x];
                            for (int s = 0; s < 4; s++)
                            {
                                offset  = y * (width * 8) + (x * 4);
                                offset += (s % 2) * 2;
                                offset += (s / 2) * (width * 4);
                                Subtile subtile = tile.Subtiles[s];
                                if (subtile == null)
                                {
                                    continue;
                                }
                                Bits.SetShort(Tilesets_bytes[l], offset, (ushort)subtile.Index);
                                Tilesets_bytes[l][offset + 1] |= (byte)(subtile.Palette << 2);
                                Bits.SetBit(Tilesets_bytes[l], offset + 1, 5, subtile.Priority1);
                                Bits.SetBit(Tilesets_bytes[l], offset + 1, 6, subtile.Mirror);
                                Bits.SetBit(Tilesets_bytes[l], offset + 1, 7, subtile.Invert);
                            }
                        }
                    }
                }
                if (Type == TilesetType.Area)
                {
                    Areas.Model.Modify_Tilesets[areaMap.TilesetL1 + 0x20] = true;
                    Areas.Model.Modify_Tilesets[areaMap.TilesetL2 + 0x20] = true;
                    Areas.Model.Modify_Tilesets[areaMap.TilesetL3]        = true;
                    //
                    Buffer.BlockCopy(Graphics, 0, Areas.Model.GraphicSets[areaMap.GraphicSet1 + 0x48], 0, 0x2000);
                    Buffer.BlockCopy(Graphics, 0x2000, Areas.Model.GraphicSets[areaMap.GraphicSet2 + 0x48], 0, 0x1000);
                    Buffer.BlockCopy(Graphics, 0x3000, Areas.Model.GraphicSets[areaMap.GraphicSet3 + 0x48], 0, 0x1000);
                    Buffer.BlockCopy(Graphics, 0x4000, Areas.Model.GraphicSets[areaMap.GraphicSet4 + 0x48], 0, 0x1000);
                    Buffer.BlockCopy(Graphics, 0x5000, Areas.Model.GraphicSets[areaMap.GraphicSet5 + 0x48], 0, 0x1000);
                    //
                    Areas.Model.Modify_GraphicSets[areaMap.GraphicSet1 + 0x48] = true;
                    Areas.Model.Modify_GraphicSets[areaMap.GraphicSet2 + 0x48] = true;
                    Areas.Model.Modify_GraphicSets[areaMap.GraphicSet3 + 0x48] = true;
                    Areas.Model.Modify_GraphicSets[areaMap.GraphicSet4 + 0x48] = true;
                    Areas.Model.Modify_GraphicSets[areaMap.GraphicSet5 + 0x48] = true;
                }
                else if (Type == TilesetType.SideScrolling)
                {
                    Buffer.BlockCopy(Graphics, 0, Minecart.Model.SSGraphics, 0, Graphics.Length);
                }
                else if (Type == TilesetType.Title)
                {
                    Buffer.BlockCopy(Tilesets_bytes[0], 0, Intro.Model.Title_Data, 0, 0x1000);
                    Buffer.BlockCopy(Tilesets_bytes[1], 0, Intro.Model.Title_Data, 0x1000, 0x1000);
                    Buffer.BlockCopy(Tilesets_bytes[2], 0, Intro.Model.Title_Data, 0xBBE0, 0x300);
                    Buffer.BlockCopy(Graphics, 0, Intro.Model.Title_Data, 0x6C00, 0x4FE0);
                    Buffer.BlockCopy(GraphicsL3, 0x40, Intro.Model.Title_Data, 0xBEE0, 0x1B80);
                }
                else if (Type == TilesetType.Opening)
                {
                    Buffer.BlockCopy(Tilesets_bytes[0], 0, Intro.Model.Cast_Data, 0, 0x480);
                    Buffer.BlockCopy(Graphics, 0, Intro.Model.Cast_Data, 0x480, 0x1340);
                }
            }
            else
            {
                if (Tileset_tiles == null)
                {
                    return;
                }
                for (int y = 0; y < 16; y++)
                {
                    for (int x = 0; x < 16; x++)
                    {
                        int i = y * 16 + x;
                        for (int z = 0; z < 4; z++)
                        {
                            offset  = y * (width * 4) + (x * 2);
                            offset += z % 2;
                            offset += (z / 2) * (width * 2);
                            Subtile subtile = Tileset_tiles[i].Subtiles[z];
                            byte    tilenum = (byte)subtile.Index;
                            Subtile_bytes[offset]  = tilenum;
                            Palette_bytes[tilenum] = (byte)subtile.Palette;
                        }
                    }
                }
                Buffer.BlockCopy(Graphics, 0, Minecart.Model.M7Graphics, 0, Graphics.Length);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Writes this tileset's tile data of a specified layer to the elements in the global Model.
        /// NOTE: The ROM buffer is not modified during this operation.
        /// </summary>
        /// <param name="width">The width, in 16x16 tile units, of the tileset.</param>
        /// <param name="layer">The layer to read the tile data from.</param>
        public void WriteToModel(int width, int layer)
        {
            if (Tilesets_tiles[layer] == null)
            {
                return;
            }
            //
            int offset = 0;

            if (Type == TilesetType.Area || Type == TilesetType.Title)
            {
                for (int y = 0; y < Tilesets_tiles[layer].Length / width; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        int index = y * width + x;
                        if (index >= Tilesets_tiles[layer].Length)
                        {
                            continue;
                        }
                        Tile tile = Tilesets_tiles[layer][index];
                        for (int s = 0; s < 4; s++)
                        {
                            offset  = y * (width * 8) + (x * 4);
                            offset += (s % 2) * 2;
                            offset += (s / 2) * (width * 4);
                            Subtile subtile = tile.Subtiles[s];
                            if (subtile == null)
                            {
                                continue;
                            }
                            Bits.SetShort(Tilesets_bytes[layer], offset, (ushort)subtile.Index);
                            Tilesets_bytes[layer][offset + 1] |= (byte)(subtile.Palette << 2);
                            Bits.SetBit(Tilesets_bytes[layer], offset + 1, 5, subtile.Priority1);
                            Bits.SetBit(Tilesets_bytes[layer], offset + 1, 6, subtile.Mirror);
                            Bits.SetBit(Tilesets_bytes[layer], offset + 1, 7, subtile.Invert);
                        }
                    }
                }
                if (Type == TilesetType.Area)
                {
                    if (layer == 0)
                    {
                        Areas.Model.Modify_Tilesets[areaMap.TilesetL1 + 0x20] = true;
                    }
                    if (layer == 1)
                    {
                        Areas.Model.Modify_Tilesets[areaMap.TilesetL2 + 0x20] = true;
                    }
                    if (layer == 2)
                    {
                        Areas.Model.Modify_Tilesets[areaMap.TilesetL3] = true;
                    }
                    //
                    Buffer.BlockCopy(Graphics, 0, Areas.Model.GraphicSets[areaMap.GraphicSet1 + 0x48], 0, 0x2000);
                    Buffer.BlockCopy(Graphics, 0x2000, Areas.Model.GraphicSets[areaMap.GraphicSet2 + 0x48], 0, 0x1000);
                    Buffer.BlockCopy(Graphics, 0x3000, Areas.Model.GraphicSets[areaMap.GraphicSet3 + 0x48], 0, 0x1000);
                    Buffer.BlockCopy(Graphics, 0x4000, Areas.Model.GraphicSets[areaMap.GraphicSet4 + 0x48], 0, 0x1000);
                    Buffer.BlockCopy(Graphics, 0x5000, Areas.Model.GraphicSets[areaMap.GraphicSet5 + 0x48], 0, 0x1000);
                    //
                    Areas.Model.Modify_GraphicSets[areaMap.GraphicSet1 + 0x48] = true;
                    Areas.Model.Modify_GraphicSets[areaMap.GraphicSet2 + 0x48] = true;
                    Areas.Model.Modify_GraphicSets[areaMap.GraphicSet3 + 0x48] = true;
                    Areas.Model.Modify_GraphicSets[areaMap.GraphicSet4 + 0x48] = true;
                    Areas.Model.Modify_GraphicSets[areaMap.GraphicSet5 + 0x48] = true;
                }
                else if (Type == TilesetType.Title)
                {
                    Buffer.BlockCopy(Tilesets_bytes[0], 0, Intro.Model.Title_Data, 0, 0x1000);
                    Buffer.BlockCopy(Tilesets_bytes[1], 0, Intro.Model.Title_Data, 0x1000, 0x1000);
                    Buffer.BlockCopy(Tilesets_bytes[2], 0, Intro.Model.Title_Data, 0xBBE0, 0x300);
                    Buffer.BlockCopy(Graphics, 0, Intro.Model.Title_Data, 0x6C00, 0x4FE0);
                    Buffer.BlockCopy(GraphicsL3, 0x40, Intro.Model.Title_Data, 0xBEE0, 0x1B80);
                }
            }
            else
            {
                WriteToModel(width);
            }
        }