public WorldMap_FE7_Large(string path, Palette palette = null) { TSA_Image image; if (palette == null) { image = new TSA_Image(WIDTH, HEIGHT, new GBA.Bitmap(path), PALETTES, false); } else { image = new TSA_Image(WIDTH, HEIGHT, new GBA.Bitmap(path), palette, PALETTES, false); } Palettes = image.Palettes; Graphics = new Tileset[SECTIONS]; TSA_Sections = new TSA_Array[SECTIONS]; int width = 32; int height = 32; for (int i = 0; i < SECTIONS; i++) { if (i == 8) { height = 22; } Graphics[i] = new Tileset(width * height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Graphics[i].Add(image.Graphics[ (i % 4 * width + x) + (i / 4 * width + y) * WIDTH]); } } TSA_Sections[i] = TSA_Array.GetBasicTSA(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { TSA_Sections[i].SetPalette(x, y, image.Tiling[ (i % 4 * width) + x, (i / 4 * width) + y].Palette); } } } }
void Core_LoadBackground() { try { Size bgsize = Background.GetBGSize(CurrentType); byte[] palette = Core.ReadData((Pointer)Current["Palette"], (CurrentType == BackgroundType.Battle) ? 0 : // is compressed Background.GetPaletteAmount(CurrentType) * GBA.Palette.LENGTH); byte[] tileset; TSA_Array tsa; switch (CurrentType) { case BackgroundType.Dialog: tileset = Core.ReadData((Pointer)Current["Tileset"], 0); tsa = Core.ReadTSA((Pointer)Current["TSA"], bgsize.Width, bgsize.Height, false, true); break; case BackgroundType.Battle: palette[0] = 0x00; palette[1] = 0x00; // force 1st color black on battle BGs tileset = Core.ReadData((Pointer)Current["Tileset"], 0); tsa = Core.ReadTSA((Pointer)Current["TSA"], bgsize.Width, bgsize.Height, true, false); break; case BackgroundType.Screen: if (Core.CurrentROM is FE6) { tileset = Core.ReadData((Pointer)Current["Tileset"], 0); tsa = TSA_Array.GetBasicTSA(bgsize.Width, bgsize.Height); } else if (Core.CurrentROM is FE7 && Core.ReadByte(Current.GetAddress(Current.EntryIndex)) == 0x00) { tileset = Core.ReadData((Pointer)Current["Tileset"], 0); tsa = Core.ReadTSA((Pointer)Current["TSA"], bgsize.Width, bgsize.Height, false, true); } else // its stored in 32x2 strips { tsa = Core.ReadTSA((Pointer)Current["TSA"], bgsize.Width, bgsize.Height, false, true); int amount = 10; int length = 32 * 2 * Tile.LENGTH; tileset = new byte[amount * length]; Pointer table = (Pointer)Current["Tileset"]; Pointer address; byte[] buffer; for (int i = 0; i < amount; i++) { address = Core.ReadPointer(table + i * 4); buffer = Core.ReadData(address, 0); Array.Copy(buffer, 0, tileset, i * length, length); } // assemble BGs that are stored in 32x2 strips } break; default: throw new Exception("Invalid background type."); } CurrentBackground = new Background(palette, tileset, tsa); Background_ImageBox.Load(CurrentBackground); Background_PaletteBox.Load(Palette.Merge(CurrentBackground.Palettes)); } catch (Exception ex) { Program.ShowError("Could not load the background image from the ROM.", ex); Background_ImageBox.Reset(); Background_PaletteBox.Reset(); } }