public void DrawMetaTile(ref Bitmap b, Point p, TileSet tset, PaletteSet pset, int tileId, bool overwrite) { byte[] tileData = new byte[8]; //write 8 bytes from tileId *8 to tileData Array.Copy(metaTileSetData, tileId << 3, tileData, 0, 8); try { DrawTileData(ref b, tileData, p, tset, pset.Palettes, this.isBg1, overwrite); } catch (ArgumentNullException e) { throw new ArgumentNullException("Attempt to draw empty metatile. Num: 0x" + tileId.ToString("X"), e); } }
private void LoadRoom(int areaIndex) { metadata = new RoomMetaData(areaIndex, this.Index); //build tileset using tile addrs from room metadata tset = metadata.GetTileSet(); //palettes pset = metadata.GetPaletteSet(); //room data bg2RoomData = new byte[0x2000]; //this seems to be the maximum size bg1RoomData = new byte[0x2000]; //2000 isnt too much memory, so this is just easier bg2Exists = metadata.GetBG2Data(ref bg2RoomData, ref bg2MetaTiles); //loads in the data and tiles bg1Exists = metadata.GetBG1Data(ref bg1RoomData, ref bg1MetaTiles); //loads in the data, tiles and sets bg1Use20344B0 Loaded = true; //do not load data a 2nd time for this room }
public void DrawMetaTile(ref Bitmap b, Point p, TileSet tset, PaletteSet pset, int tileId, bool overwrite) { byte[] tileData = new byte[8]; //write 8 bytes from tileId *8 to tileData Array.Copy(metaTileSetData, tileId << 3, tileData, 0, 8); try { if (tileData.Length == 0) { throw new ArgumentNullException("metaTileData", "Cannot draw empty metatile."); } int i = 0; for (int y = 0; y < 2; y += 1) { for (int x = 0; x < 2; x += 1) { UInt16 data = 0; data = (ushort)(tileData[i] | (tileData[i + 1] << 8)); i += 2; int tnum = data & 0x3FF; //bits 1-10 if (isBg1) { tnum += 0x200; } bool hflip = ((data >> 10) & 1) == 1; //is bit 11 set? bool vflip = ((data >> 11) & 1) == 1; //is bit 12 set? int pnum = data >> 12; //last 4 bits tset.DrawQuarterTile(ref b, new Point(p.X + (x * 8), p.Y + (y * 8)), tnum, pset.Palettes[pnum], hflip, vflip, overwrite); } } } catch (ArgumentNullException e) { throw new ArgumentNullException("Attempt to draw empty metatile. Num: 0x" + tileId.ToString("X"), e); } }
public void LoadRoom(int areaIndex) { metadata = new RoomMetaData(areaIndex, this.Index); //build tileset using tile addrs from room metadata tset = metadata.GetTileSet(); //palettes pset = metadata.GetPaletteSet(); //room data bg2RoomData = new byte[0x2000]; //this seems to be the maximum size bg1RoomData = new byte[0x2000]; //2000 isnt too much memory, so this is just easier bg2Exists = metadata.GetBG2Data(ref bg2RoomData, ref bg2MetaTiles); //loads in the data and tiles bg1Exists = metadata.GetBG1Data(ref bg1RoomData, ref bg1MetaTiles); //loads in the data, tiles and sets bg1Use20344B0 if (!bg1Exists && !bg2Exists) { throw new RoomException("No layers exist for this room, the room is highly likely invalid."); } Loaded = true; //do not load data a 2nd time for this room }
private void SwapTiles(int areaIndex, ushort[] oldchunks, ushort[] newchunks, ushort x, ushort y) { var r = ROM.Instance.reader; var header = ROM.Instance.headers; int updatepal = -1; for (int i = 0; i < 3; i++) { if (newchunks[i] == oldchunks[i]) { continue; } if (newchunks[i] == 0x00FF) { continue; } int baseaddr, src, src2, dest, dest2; byte[] newtiles = new byte[0x1000]; switch (areaIndex) { case 0x02: case 0x15: baseaddr = areaIndex != 0x15 ? header.swapBase : header.swapBase + 0x060; r.SetPosition(baseaddr + (newchunks[i] << 4)); src = (int)(header.tileOffset + r.ReadUInt32()); //source addrs are stored as offsets from 85A2E80 dest = (int)r.ReadUInt32() & 0xFFFFFF; //mask off the 0x6000000 part src2 = (int)(header.tileOffset + r.ReadUInt32()); //there are 2 sets of tiles for each chunk dest2 = (int)r.ReadUInt32() & 0xFFFFFF; //one for each bg newtiles = r.ReadBytes(0x1000, src); tset.SetChunk(newtiles, dest); newtiles = r.ReadBytes(0x1000, src2); tset.SetChunk(newtiles, dest2); break; case 0x01: //area 01 works differently, 8 chunks and palette update for (int j = 0; j < 8; j++) { if (j == 0) { //update palette byte pnum = r.ReadByte(header.paletteChangeBase + newchunks[i]); updatepal = (int)pnum; } baseaddr = header.area1SwapBase; r.SetPosition(baseaddr + (newchunks[i] << 6) + (j << 3)); src = (header.tileOffset + (int)r.ReadUInt32()); dest = (int)r.ReadUInt32() & 0xFFFFFF; newtiles = r.ReadBytes(0x1000, src); tset.SetChunk(newtiles, dest); } break; } } if (updatepal > 0) //if the palette number changed due to swapping, create new paletteset { pset = new PaletteSet(updatepal); } }