Example #1
0
        private void MapFooterCompile(CompilerContext context, MapFooter footer, StringBuilder builder, string baseSymbol)
        {
            builder.AppendLine("@@@  SECTION: MAPFOOTER  @@@");
            builder.AppendLine();
            builder.AppendLine(".align 2");
            builder.AppendLine(".global mapfooter_" + baseSymbol);
            builder.AppendLine("mapfooter_" + baseSymbol + ":");
            builder.AppendLine("\t.word " + "0x" + footer.Width.ToString("X8"));
            builder.AppendLine("\t.word " + "0x" + footer.Height.ToString("X8"));
            builder.AppendLine("\t.word mapborderblocks_" + baseSymbol);
            builder.AppendLine("\t.word mapblocks_" + baseSymbol);
            builder.AppendLine("\t.word " + "0x" + (0x082D4A94).ToString("X8"));
            builder.AppendLine("\t.word " + "0x" + (0x082D4AAC).ToString("X8"));
            builder.AppendLine("\t.byte " + footer.BorderWidth.ToString());
            builder.AppendLine("\t.byte " + footer.BorderHeight.ToString());
            builder.AppendLine("\t.hword " + footer.Padding);


            builder.AppendLine("@@@  SECTION: MAPBLOCKS  @@@");
            builder.AppendLine(".align 2");
            builder.AppendLine();
            builder.AppendLine(".global mapblocks_" + baseSymbol);
            builder.AppendLine("mapblocks_" + baseSymbol + ":");

            BlocksArrayCompile(context, builder, baseSymbol, footer.MapBlock);

            builder.AppendLine("@@@  SECTION: BORDERBLOCKS  @@@");
            builder.AppendLine(".align 2");
            builder.AppendLine();
            builder.AppendLine(".global mapborderblocks_" + baseSymbol);
            builder.AppendLine("mapborderblocks_" + baseSymbol + ":");

            BlocksArrayCompile(context, builder, baseSymbol, footer.BorderBlock);
        }
Example #2
0
        /// <summary>
        /// Transforms a MapFooter into an assembly string
        /// </summary>
        /// <param name="mapFooter"></param>
        /// <param name="baseSymbol"></param>
        /// <returns></returns>
        private static string MapFooterToString(MapFooter mapFooter, string baseSymbol)
        {
            StringBuilder b = new StringBuilder();

            // Create MapFooter structure
            b.Append("@ Section: MapFooter"); b.Append(Environment.NewLine);
            b.Append(".align 2"); b.Append(Environment.NewLine);
            b.Append(".global mapfooter_"); b.Append(baseSymbol); b.Append(Environment.NewLine);
            b.Append("mapfooter_"); b.Append(baseSymbol); b.Append(":"); b.Append(Environment.NewLine);
            b.Append("\t.word "); b.Append(mapFooter.Width.ToString()); b.Append(Environment.NewLine);
            b.Append("\t.word "); b.Append(mapFooter.Height.ToString()); b.Append(Environment.NewLine);
            b.Append("\t.word mapborderblocks_"); b.Append(baseSymbol); b.Append(Environment.NewLine);
            b.Append("\t.word mapblocks_"); b.Append(baseSymbol); b.Append(Environment.NewLine);
            b.Append("\t.word "); b.Append(mapFooter.FirstTilesetID); b.Append(Environment.NewLine);
            b.Append("\t.word "); b.Append(mapFooter.SecondTilesetID); b.Append(Environment.NewLine);
            b.Append("\t.byte "); b.Append(mapFooter.BorderWidth.ToString()); b.Append(Environment.NewLine);
            b.Append("\t.byte "); b.Append(mapFooter.BorderHeight.ToString()); b.Append(Environment.NewLine);
            b.Append("\t.hword "); b.Append(mapFooter.Padding); b.Append(Environment.NewLine);

            // Append the BorderBlocks
            b.Append(Environment.NewLine);
            b.Append(MapBorderBlocksToString(mapFooter, baseSymbol));

            //Append the MapBlocks
            b.Append(Environment.NewLine);
            b.Append(MapBlocksToString(mapFooter, baseSymbol));

            return(b.ToString());
        }
Example #3
0
        /// <summary>
        /// Reads a MapFooter from a ROM
        /// </summary>
        /// <param name="reader">BinaryReader object to read from</param>
        /// <param name="footerOffset">Offset of Footer Data in ROM</param>
        /// <param name="prefix">Prefix to put in front of tileset symbols</param>
        /// <returns>MapFooter object representing a map footer of the ROM</returns>
        private static MapFooter FooterFromReader(BinaryReader reader, uint footerOffset, string prefix)
        {
            reader.BaseStream.Seek(footerOffset & 0x1FFFFFF, SeekOrigin.Begin);
            MapFooter footer = new MapFooter();

            footer.Width  = reader.ReadUInt32();
            footer.Height = reader.ReadUInt32();
            uint   borderOffset      = reader.ReadUInt32();
            uint   mapDataOffset     = reader.ReadUInt32();
            uint   blocksetOneOffset = reader.ReadUInt32();
            uint   blocksetTwoOffset = reader.ReadUInt32();
            byte   borderWidth       = reader.ReadByte();
            byte   borderHeight      = reader.ReadByte();
            ushort padding           = reader.ReadUInt16();

            reader.BaseStream.Seek(borderOffset & 0x1FFFFFF, SeekOrigin.Begin);

            ushort[][] borderBlock = new ushort[borderHeight][];
            for (int y = 0; y < borderHeight; ++y)
            {
                borderBlock[y] = new ushort[borderWidth];
                for (int x = 0; x < borderWidth; ++x)
                {
                    borderBlock[y][x] = reader.ReadUInt16();
                }
            }

            //ushort[][] mapBlock = Enumerable.Repeat(new ushort[footer.Width], (int)footer.Height).ToArray();
            ushort[][] mapBlock = new ushort[footer.Height][];
            for (int y = 0; y < footer.Height; ++y)
            {
                mapBlock[y] = new ushort[footer.Width];
                for (int x = 0; x < footer.Width; ++x)
                {
                    mapBlock[y][x] = reader.ReadUInt16();
                }
            }

            footer.FirstTilesetID        = "tileset_" + blocksetOneOffset.ToString("X8") + TS_PRIM_SUF;
            footer.SecondTilesetID       = "tileset_" + blocksetTwoOffset.ToString("X8") + TS_SEC_SUF;
            footer.BorderBlock           = borderBlock;
            footer.MapBlock              = mapBlock;
            footer.BorderWidth           = borderWidth;
            footer.BorderHeight          = borderHeight;
            footer.FirstTilesetInternal  = blocksetOneOffset;
            footer.SecondTilesetInternal = blocksetTwoOffset;

            return(footer);
        }
Example #4
0
        /// <summary>
        /// Transforms a MapFooter's MapBlocks into an assembly string
        /// </summary>
        /// <param name="mapFooter"></param>
        /// <param name="baseSymbol"></param>
        /// <returns></returns>
        private static string MapBlocksToString(MapFooter mapFooter, string baseSymbol)
        {
            StringBuilder b = new StringBuilder();

            b.Append("@ Section: MapBlocks"); b.Append(Environment.NewLine);
            b.Append(".align 2"); b.Append(Environment.NewLine);
            b.Append(".global mapblocks_"); b.Append(baseSymbol); b.Append(Environment.NewLine);
            b.Append("mapblocks_"); b.Append(baseSymbol); b.Append(":"); b.Append(Environment.NewLine);
            for (int i = 0; i < mapFooter.Height; i++)
            {
                for (int j = 0; j < mapFooter.Width; j++)
                {
                    b.Append("\t.hword "); b.Append(mapFooter.MapBlock[i][j].ToString()); b.Append(Environment.NewLine);
                }
            }

            return(b.ToString());
        }