public static void WriteOam(this byte[] data, int destOffset, OamSprite oam) { ushort ch1 = (ushort)( (oam.CoordY & 0xFF) | (oam.RotScale ? 0x100 : 0) | (oam.DblSizeDisable ? 0x200 : 0) | ((oam.ObjMode & 3) << 10) | (oam.ObjMosaic ? 0x1000 : 0) | (oam.Use8Bpp ? 0x2000 : 0) | ((oam.ObjShape & 3) << 14)); ushort ch2 = (ushort)( (oam.CoordX & 0x1FF) | (oam.RotScale ? ((oam.RotScaleParam & 0x1F) << 9) : (((oam.RotScaleParam & 7) << 9) | (oam.FlipH ? 0x1000 : 0) | (oam.FlipV ? 0x2000 : 0))) | ((oam.ObjSize & 3) << 14)); ushort ch3 = (ushort)( (oam.Tile & 0x3FF) | ((oam.Priority & 3) << 10) | ((oam.Palette & 0xF) << 12)); data.WriteUShort(destOffset, ch1); data.WriteUShort(destOffset + 2, ch2); data.WriteUShort(destOffset + 4, ch3); }
public static OamSprite ReadOam(this byte[] data, int srcOffset) { var ret = new OamSprite(); ushort ch1 = data.ReadUShort(srcOffset); ushort ch2 = data.ReadUShort(srcOffset + 2); ushort ch3 = data.ReadUShort(srcOffset + 4); ret.CoordY = (sbyte)(ch1 & 0xFF); ret.RotScale = (ch1 & 0x100) != 0; ret.DblSizeDisable = (ch1 & 0x200) != 0; ret.ObjMode = (byte)((ch1 >> 10) & 3); ret.ObjMosaic = (ch1 & 0x1000) != 0; ret.Use8Bpp = (ch1 & 0x2000) != 0; ret.ObjShape = (byte)((ch1 >> 14) & 3); ret.CoordX = (short)(ch2 & 0x1FF); if ((ret.CoordX & 0x100) != 0) { // Sign-extend ret.CoordX = (short)((ushort)ret.CoordX | 0xFE00); } if (ret.RotScale) { ret.RotScaleParam = (byte)((ch2 >> 9) & 0x1F); } else { ret.RotScaleParam = (byte)((ch2 >> 9) & 7); ret.FlipH = (ch2 & 0x1000) != 0; ret.FlipV = (ch2 & 0x2000) != 0; } ret.ObjSize = (byte)((ch2 >> 14) & 3); ret.Tile = (ushort)(ch3 & 0x3FF); ret.Priority = (byte)((ch3 >> 10) & 3); ret.Palette = (byte)((ch3 >> 12) & 0xF); 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 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; } } }