/// <summary>
        /// Constructor for the class
        /// </summary>
        /// <param name="filename">The filename of the ROM.</param>
        /// <param name="dataFilename">The filename of the data file, to use in conjunction with this ROM.</param>
        /// <param name="paletteFilename">The filename of the palette file.</param>
        /// <param name="assetDirectory">The directory where the assets that are used by the editor reside.</param>
        public BattleCityData(string filename, string dataFilename, string paletteFilename, string assetDirectory)
        {
            ROM = new iNESROMImage(filename);

            // Set the initial defaults for the asset directory, and currentlevel
            _AssetDirectory = assetDirectory;

            // Create a new instance of the level list.
            Levels = new List<BattleCityLevel>();

            // Create a new instance of the tiles renderer.
            if (System.IO.File.Exists(paletteFilename))
            {
                //ROM.LoadPaletteFile(PaletteFilename);
                _Tiles = new NESRender(256, 16, paletteFilename);
            }
            else
            {
                //ROM.LoadDefaultPalette;
                _Tiles = new NESRender(256, 16);
            }
            LoadDataFile(dataFilename);
            // Load in the background pattern table.
            LoadPatternTable();
        }
        /// <summary>
        /// Draws the flag to a bitmap, at position 80x176.
        /// </summary>
        /// <param name="bitmap">The Bitmap object to draw the flag object to.</param>
        /// <param name="flag"></param>
        public void DrawFlag(ref Bitmap bitmap, LevelDisplayFlag flag)
        {
            NESRender pat = new NESRender(48, 32);
            int InitialX = 80;
            int InitialY = 176;

            byte PaletteIndex;

            // If the function is drawing the fortified flag, a different
            // palette index is needed.
            if ((flag & LevelDisplayFlag.ViewFortifiedFlag) == LevelDisplayFlag.ViewFortifiedFlag)
                PaletteIndex = 3;
            else
                PaletteIndex =0;

            for (byte i = 0; i < 4; i++)
            {
                for (byte x = 0; x < 6; x++)
                {
                    fixed (byte* pPal = &Palette[PaletteIndex, 0])
                    {
                        byte FlagData;
                        // If the flag we are drawing is the fortified flag, retrieve the TSA for it
                        if ((flag & LevelDisplayFlag.ViewFortifiedFlag) == LevelDisplayFlag.ViewFortifiedFlag)
                            FlagData = GetFortifiedFlagTSAData(i, x);
                        else
                            FlagData = GetFlagTSAData(i, x);

                        fixed (byte* pPat = &_PatternTable[BGPATTERNTABLE + (FlagData * 0x10)])
                        {
                            pat.DrawTile((x * 8), (i * 8), pPat, pPal);
                        }
                    }
                }
            }

            // Render the flags data to the main level bitmap at 80 x 176
            pat.DrawBitmap(ref bitmap, new Rectangle(0, 0, pat.Width, pat.Height),
                new Rectangle(InitialX, InitialY, pat.Width, pat.Height));
        }
 /// <summary>
 /// Draws a specific tank to a bitmap at co-ordinates 0,0.
 /// </summary>
 /// <param name="bitmap">The bitmap to draw the tank object to.</param>
 /// <param name="tankIndex">The index of the tank to draw.</param>
 public void DrawTank(ref Bitmap bitmap, Byte tankIndex)
 {
     NESRender pat = new NESRender(bitmap.Width, bitmap.Height);
     fixed (byte* pPal = &Palette[4, 0])
     {
         fixed (byte* pPat = &_PatternTable[((tankIndex * 0x20) * 16)])
         {
             pat.DrawTile(0, 0, pPat, pPal);
         }
         fixed (byte* pPat = &_PatternTable[((tankIndex * 0x20) * 16) + 0x10])
         {
             pat.DrawTile(0, 8, pPat, pPal);
         }
         fixed (byte* pPat = &_PatternTable[((tankIndex * 0x20) * 16) + 0x20])
         {
             pat.DrawTile(8, 0, pPat, pPal);
         }
         fixed (byte* pPat = &_PatternTable[((tankIndex * 0x20) * 16) + 0x30])
         {
             pat.DrawTile(8, 8, pPat, pPal);
         }
     }
     pat.DrawBitmap(ref bitmap);
 }
        /// <summary>
        /// Draws the background pattern table to a Bitmap object, using the specified palette colour.
        /// </summary>
        /// <param name="bitmap">The Bitmap object to draw the background pattern table to.</param>
        /// <param name="paletteIndex">The palette index to use when rendering the pattern table.</param>
        public void DrawBGPatternTable(ref Bitmap bitmap, byte paletteIndex)
        {
            NESRender pat = new NESRender(bitmap.Width, bitmap.Height);

            for (int i = 0; i < 16; i++)
            {
                for (int x = 0; x < 16; x++)
                {
                    fixed (byte* pPal = &Palette[paletteIndex, 0])
                    {
                        fixed (byte* pPat = &_PatternTable[BGPATTERNTABLE + (((i * 16) + x) * 0x10)])
                        {
                            pat.DrawTile(x * 8, i * 8, pPat, pPal);
                        }
                    }
                }
            }

            pat.DrawBitmap(ref bitmap);
        }