示例#1
0
        // Saving
        public void WriteToROM()
        {
            Comp.Compress(Model.Logos_Graphics, 0x3E004C, 0x2000, 0xE1C, "World map logos, banners");

            // World maps
            foreach (var worldMap in worldMaps)
            {
                worldMap.WriteToROM();
            }

            // Graphics
            Model.Logos_PaletteSet.WriteToBuffer(Menus.Model.Menu_Palette_Bytes, 0xE0);
            int offset  = Bits.GetShort(Model.ROM, 0x3E000C) + 0x3E0000;
            int maxComp = Bits.GetShort(Model.ROM, 0x3E000E) - Bits.GetShort(Model.ROM, 0x3E000C);

            Comp.Compress(Menus.Model.Menu_Palette_Bytes, offset, 0x200, maxComp, "World map logo palettes");
            Comp.Compress(Model.Graphics, 0x3E2E81, 0x8000, 0x56F6, "Graphics");

            // Tilesets
            byte[] compress  = new byte[0x800];
            int    totalSize = 0;
            int    pOffset   = 0x3E0014;
            int    dOffset   = 0x3E929F;
            int    size      = 0;

            for (int i = 0; i < Model.Tilesets_Bytes.Length; i++)
            {
                Bits.SetShort(Model.ROM, pOffset, (ushort)dOffset);
                size       = Comp.Compress(Model.Tilesets_Bytes[i], compress);
                totalSize += size + 1;
                if (totalSize > 0x4D8)
                {
                    MessageBox.Show(
                        "Recompressed tilesets exceed allotted ROM space by " + (totalSize - 0x4D6).ToString() + " bytes.\nSaving has been discontinued for tilesets " + i.ToString() + " and higher.\nChange or delete some tiles to reduce the size.",
                        "LAZY SHELL");
                    break;
                }
                else
                {
                    Model.ROM[dOffset] = 1; dOffset++;
                    Bits.SetBytes(Model.ROM, dOffset, compress, 0, size - 1);
                    dOffset += size;
                    pOffset += 2;
                }
            }
            Bits.SetShort(Model.ROM, pOffset, (ushort)dOffset);
            Comp.Compress(Model.Logos_Tileset, dOffset, 0x800, 0xC1, "World map logo tileset");

            // Palettes
            PaletteSet.WriteToBuffer(Model.Palettes, 0);
            Comp.Compress(Model.Palettes, 0x3E988C, 0x100, 0xD4, "Palette set");
            this.Modified = false;
        }
示例#2
0
 // Saving
 public void WriteToROM()
 {
     // Palette set
     PaletteSet.WriteToBuffer();
     spritePaletteSet.WriteToBuffer();
     Tileset.WriteToModel(16);
     // Tilesets
     if (Comp.Compress(Model.Title_Data, 0x3F216E, 0xDA60, 0x7E92, "Main title"))
     {
         this.Modified = false;
     }
 }
示例#3
0
        /// <summary>
        /// Converts this effect animation's object data to binary format and sets the
        /// buffer's value to the new output. After the operation is complete, a value
        /// indicating the change in size of the new ouptut data is returned.
        /// </summary>
        /// <returns></returns>
        public int WriteToBuffer()
        {
            int size = this.Buffer.Length;

            // Create temporary buffer with max bank size
            byte[] temp = new byte[0x10000];

            // Write formatting properties
            temp[12] = Width;
            temp[13] = Height;
            Bits.SetShort(temp, 14, Codec);

            #region Dynamic data

            // Start of dynamic data in buffer
            int offset = 18;

            // Write graphics
            Bits.SetShort(temp, 2, 0x12);
            System.Buffer.BlockCopy(GraphicSet, 0, temp, 18, GraphicSetLength);
            offset += GraphicSetLength;

            // Write palettes
            Bits.SetShort(temp, 4, (ushort)offset);
            PaletteSet.WriteToBuffer(temp, offset);
            offset += PaletteSetLength;

            // Write tileset
            Bits.SetShort(temp, 16, (ushort)offset);
            int tilesetoffset = offset;
            foreach (var t in Tileset_tiles.Tiles)
            {
                if (t.Index >= TilesetLength / 8)
                {
                    break;
                }
                if (t.Index > 0 && t.Index % 8 == 0)
                {
                    offset += 32;
                }
                for (int i = 0; i < 4; i++)
                {
                    Bits.SetShort(temp, offset, (byte)t.Subtiles[i].Index); offset++;
                    Bits.SetBit(temp, offset, 5, t.Subtiles[i].Priority1);
                    Bits.SetBit(temp, offset, 6, t.Subtiles[i].Mirror);
                    Bits.SetBit(temp, offset, 7, t.Subtiles[i].Invert);
                    if (i % 2 == 0)
                    {
                        offset++;
                    }
                    else if (i == 1)
                    {
                        offset += 29;
                    }
                    else if (i == 3)
                    {
                        offset -= 31;
                    }
                }
            }

            // Copy updated tileset data to tileset bytes buffer
            System.Buffer.BlockCopy(temp, tilesetoffset, Tileset_bytes, 0, Tileset_bytes.Length);

            // Add 32 because last loop operation subtracted 31
            offset += 32;

            // 0xFFFF sets boundary of tileset data
            Bits.SetShort(temp, offset, 0xFFFF); offset += 2;

            // Write sequences
            Bits.SetShort(temp, 6, (ushort)offset);
            int fOffset = Sequences.Count * 2 + 2;  // offset of first frame packet
            foreach (var s in Sequences)
            {
                if (s.Frames.Count != 0)
                {
                    Bits.SetShort(temp, offset, (ushort)(fOffset + offset));
                    fOffset += s.Frames.Count * 2 + 1;
                }
                else
                {
                    Bits.SetShort(temp, offset, 0xFFFF);
                }
                offset += 2;
            }

            // Write frames
            Bits.SetShort(temp, offset, 0); offset += 2;
            foreach (var s in Sequences)
            {
                foreach (var f in s.Frames)
                {
                    Bits.SetByte(temp, offset, f.Duration); offset++;
                    Bits.SetByte(temp, offset, f.Mold); offset++;
                }
                Bits.SetByte(temp, offset, 0); offset++;
            }

            // Write mold pointers
            Bits.SetShort(temp, 8, (ushort)offset);
            int mOffset = Molds.Count * 2 + 2;    // offset of first mold tilemap
            foreach (var m in Molds)
            {
                if (!m.Empty)
                {
                    Bits.SetShort(temp, offset, (ushort)(mOffset + offset));
                    mOffset += m.Compress(m.Tiles, Width, Height).Length - 2;
                }
                else
                {
                    Bits.SetShort(temp, offset, 0xFFFF);
                }
                offset += 2;
            }

            // Write mold data
            Bits.SetShort(temp, offset, 0); offset += 2;
            foreach (var m in Molds)
            {
                if (!m.Empty)
                {
                    byte[] mold = m.Compress(m.Tiles, Width, Height);
                    System.Buffer.BlockCopy(mold, 0, temp, offset, mold.Length);
                    offset += mold.Length;
                }
            }

            #endregion

            // Set animation length
            Bits.SetShort(temp, 0, (ushort)offset);

            // Finally, write local data to this.Buffer
            this.Buffer = new byte[offset];
            Bits.SetBytes(this.Buffer, 0, temp);

            // Return size difference of old and new buffer data
            return(size - this.Buffer.Length);
        }