public static void Init() { for (int i = 0; i < 4; i++) { Entries[i] = Rom.ReadInt(Address[i]); InfoEntries[i] = new SpriteInfo[Entries[i]]; for (int j = 0; j < Entries[i]; j++) { int a = GetPointer(i, j); if (a == -1) { continue; } var ie = new SpriteInfo(); ie.bank = i; ie.index = j; Rom.Seek(a); Rom.SeekAdd(8); ie.SpriteCount = Rom.ReadUShort(); ie.Sprites = new Sprite[ie.SpriteCount]; for (int k = 0; k < ie.SpriteCount; k++) { var s = new Sprite(); s.index = k; s.SpriteCount = Rom.ReadUShort(); s.Sprites = new OamSprite[s.SpriteCount]; for (int m = 0; m < s.SpriteCount; m++) { var o = new OamSprite(); o.CoordY = Rom.ReadSByte(); o.CoordX = (short)Rom.ReadSByte(); ushort ch = Rom.ReadUShort(); o.Tile = (ushort)(ch & 0x3FF); o.FlipH = (ch & 0x400) != 0; o.FlipV = (ch & 0x800) != 0; o.ObjSize = (byte)((ch >> 12) & 3); o.ObjShape = (byte)((ch >> 14) & 3); s.Sprites[m] = o; } Rom.SeekAdd(2); ie.Sprites[k] = s; } InfoEntries[i][j] = ie; } } }
unsafe public static Bitmap[] GetEnemySprite(int index) { Bitmap[] ret = new Bitmap[2]; // Get gfx stuff int gfxPointer = GetPointer(index + 8) + 12; byte[] gfxData; if (LZ77.Decompress(Rom, gfxPointer, out gfxData) == -1) { return(null); } // Bug with MOTHER 3: for the second Mole Cricket (index 0x3D), // it uses tiles that are out of bounds in the tile data! // So let's resize the tile buffer to 32KB (max addressable size) Array.Resize(ref gfxData, 0x8000); // Get pal stuff var palette = GetPals(index); // Get OAM stuff int oamPointer = GetPointer(index + 0x2A4); var oam = new OamSprite[2][]; for (int i = 0; i < 2; i++) { // Get the front/back sprite pointer int subPointer = Rom.ReadUShort(oamPointer + 8 + (i << 1)) + oamPointer; // Get the number of sub-sprites ushort numSubSprites = Rom.ReadUShort(subPointer + 2); oam[i] = new OamSprite[numSubSprites]; // Get the OAM data for (int j = 0; j < numSubSprites; j++) { oam[i][j] = Rom.ReadOam(subPointer + 4 + (j << 3)); // Filter out the palette -- each enemy only has one palette, regardless of what the OAM entry says // This is only an issue with enemy #0 anyway oam[i][j].Palette = 0; } // Render the sprites Bitmap bmp = GfxProvider.RenderSprites(oam[i], gfxData, palette); ret[i] = bmp; } return(ret); }
private void WriteOam(OamSprite oam) { Rom.WriteSByte(oam.CoordY); Rom.WriteSByte((sbyte)oam.CoordX); ushort ch = (ushort)( (oam.Tile & 0x3FF) | (oam.FlipH ? 0x400 : 0) | (oam.FlipV ? 0x800 : 0) | ((oam.ObjSize & 3) << 12) | ((oam.ObjShape & 3) << 14)); Rom.WriteUShort(ch); }
public object Clone() { var ret = new OamSprite(); ret.CoordX = this.CoordX; ret.CoordY = this.CoordY; ret.DblSizeDisable = this.DblSizeDisable; ret.FlipH = this.FlipH; ret.FlipV = this.FlipV; ret.ObjMode = this.ObjMode; ret.ObjMosaic = this.ObjMosaic; ret.ObjShape = this.ObjShape; ret.ObjSize = this.ObjSize; ret.Palette = this.Palette; ret.Priority = this.Priority; ret.RotScale = this.RotScale; ret.RotScaleParam = this.RotScaleParam; ret.Tile = this.Tile; ret.Use8Bpp = this.Use8Bpp; return(ret); }