public static int Comparision_OAM(OAM c1, OAM c2) { if (c1.obj2.priority < c2.obj2.priority) return 1; else if (c1.obj2.priority > c2.obj2.priority) return -1; else // Same priority { if (c1.num_cell < c2.num_cell) return 1; else if (c1.num_cell > c2.num_cell) return -1; else // Same cell return 0; } }
public static Byte[] Get_OAMdata(OAM oam, byte[] image, ColorFormat format) { if (format == ColorFormat.colors16) image = Helper.BitsConverter.BytesToBit4(image); List<byte> data = new List<byte>(); int y1 = 128 + oam.obj0.yOffset; int y2 = y1 + oam.height; int x1 = 256 + oam.obj1.xOffset; int x2 = x1 + oam.width; for (int ht = 0; ht < 256; ht++) for (int wt = 0; wt < 512; wt++) if (ht >= y1 && ht < y2) if (wt >= x1 && wt < x2) data.Add(image[wt + ht * 512]); if (format == ColorFormat.colors16) return Helper.BitsConverter.Bits4ToByte(data.ToArray()); else return data.ToArray(); }
public static OAM OAMInfo(ushort[] obj) { OAM oam = new OAM(); // Obj 0 oam.obj0.yOffset = (sbyte)(obj[0] & 0xFF); oam.obj0.rs_flag = (byte)((obj[0] >> 8) & 1); if (oam.obj0.rs_flag == 0) oam.obj0.objDisable = (byte)((obj[0] >> 9) & 1); else oam.obj0.doubleSize = (byte)((obj[0] >> 9) & 1); oam.obj0.objMode = (byte)((obj[0] >> 10) & 3); oam.obj0.mosaic_flag = (byte)((obj[0] >> 12) & 1); oam.obj0.depth = (byte)((obj[0] >> 13) & 1); oam.obj0.shape = (byte)((obj[0] >> 14) & 3); // Obj 1 oam.obj1.xOffset = obj[1] & 0x01FF; if (oam.obj1.xOffset >= 0x100) oam.obj1.xOffset -= 0x200; if (oam.obj0.rs_flag == 0) { oam.obj1.unused = (byte)((obj[1] >> 9) & 7); oam.obj1.flipX = (byte)((obj[1] >> 12) & 1); oam.obj1.flipY = (byte)((obj[1] >> 13) & 1); } else oam.obj1.select_param = (byte)((obj[1] >> 9) & 0x1F); oam.obj1.size = (byte)((obj[1] >> 14) & 3); // Obj 2 oam.obj2.tileOffset = (uint)(obj[2] & 0x03FF); oam.obj2.priority = (byte)((obj[2] >> 10) & 3); oam.obj2.index_palette = (byte)((obj[2] >> 12) & 0xF); Size size = Get_OAMSize(oam.obj0.shape, oam.obj1.size); oam.width = (ushort)size.Width; oam.height = (ushort)size.Height; return oam; }
public static ushort[] OAMInfo(OAM oam) { ushort[] obj = new ushort[3]; // OBJ0 obj[0] = 0; obj[0] += (ushort)((sbyte)(oam.obj0.yOffset) & 0xFF); obj[0] += (ushort)((oam.obj0.rs_flag & 1) << 8); if (oam.obj0.rs_flag == 0x00) obj[0] += (ushort)((oam.obj0.objDisable & 1) << 9); else obj[0] += (ushort)((oam.obj0.doubleSize & 1) << 9); obj[0] += (ushort)((oam.obj0.objMode & 3) << 10); obj[0] += (ushort)((oam.obj0.mosaic_flag & 1) << 12); obj[0] += (ushort)((oam.obj0.depth & 1) << 13); obj[0] += (ushort)((oam.obj0.shape & 3) << 14); // OBJ1 obj[1] = 0; if (oam.obj1.xOffset < 0) oam.obj1.xOffset += 0x200; obj[1] += (ushort)(oam.obj1.xOffset & 0x1FF); if (oam.obj0.rs_flag == 0) { obj[1] += (ushort)((oam.obj1.unused & 0x7) << 9); obj[1] += (ushort)((oam.obj1.flipX & 1) << 12); obj[1] += (ushort)((oam.obj1.flipY & 1) << 13); } else obj[1] += (ushort)((oam.obj1.select_param & 0x1F) << 9); obj[1] += (ushort)((oam.obj1.size & 3) << 14); // OBJ2 obj[2] = 0; obj[2] += (ushort)(oam.obj2.tileOffset & 0x3FF); obj[2] += (ushort)((oam.obj2.priority & 3) << 10); obj[2] += (ushort)((oam.obj2.index_palette & 0xF) << 12); return obj; }
public RawSprite(OAM[] oams, uint blocksize, bool editable = false) { Bank bank = new Bank(); bank.name = "Bank 1"; bank.oams = oams; Set_Banks(new Bank[] { bank }, blocksize, editable); }
public override void Read(string fileIn) { ncob = new sNCOB(); BinaryReader br = new BinaryReader(File.OpenRead(fileIn)); // Read the header ncob.generic.id = br.ReadChars(4); ncob.generic.endianess = br.ReadUInt16(); ncob.generic.constant = br.ReadUInt16(); ncob.generic.file_size = br.ReadUInt32(); ncob.generic.header_size = br.ReadUInt16(); ncob.generic.nSection = br.ReadUInt16(); for (int i = 0; i < ncob.generic.nSection; i++) { string type = new String(br.ReadChars(4)); switch (type) { case "CELL": ncob.cell.type = "CELL".ToCharArray(); ncob.cell.size = br.ReadUInt32(); ncob.cell.num_banks = br.ReadUInt32(); ncob.cell.banks = new Ekona.Images.Bank[ncob.cell.num_banks]; for (int b = 0; b < ncob.cell.num_banks; b++) { ncob.cell.banks[b] = new Ekona.Images.Bank(); ncob.cell.banks[b].oams = new OAM[br.ReadUInt32()]; for (int o = 0; o < ncob.cell.banks[b].oams.Length; o++) { OAM oam = new OAM(); oam.obj1.xOffset = br.ReadInt16(); oam.obj0.yOffset = br.ReadInt16(); ushort unk1 = br.ReadUInt16(); if (unk1 != 0) System.Windows.Forms.MessageBox.Show("Unk1 different to 0"); oam.obj1.flipX = br.ReadByte(); oam.obj1.flipY = br.ReadByte(); uint unk2 = br.ReadUInt32(); if (unk2 != 0) System.Windows.Forms.MessageBox.Show("Unk2 different to 0"); oam.obj0.shape = br.ReadByte(); oam.obj1.size = br.ReadByte(); oam.obj2.priority = br.ReadByte(); oam.obj2.index_palette = br.ReadByte(); oam.obj2.tileOffset = br.ReadUInt32(); oam.width = (ushort)Actions.Get_OAMSize(oam.obj0.shape, oam.obj1.size).Width; oam.height = (ushort)Actions.Get_OAMSize(oam.obj0.shape, oam.obj1.size).Height; oam.num_cell = (ushort)o; ncob.cell.banks[b].oams[o] = oam; } } break; case "CHAR": ncob.chars.type = "CHAR".ToCharArray(); ncob.chars.size = br.ReadUInt32(); ncob.chars.unknown = br.ReadUInt32(); ncob.chars.data_size = br.ReadUInt32(); ncob.chars.data = br.ReadBytes((int)ncob.chars.data_size); break; default: uint size = br.ReadUInt32(); br.BaseStream.Position += size - 8; break; } } br.Close(); img = new RawImage(ncob.chars.data, TileForm.Horizontal, ColorFormat.colors16, 0x20, ncob.chars.data.Length / 0x20, false); Set_Banks(ncob.cell.banks, 0, false); }
int Comparision_Cell2(OAM c1, OAM c2) { if (c1.num_cell > c2.num_cell) return 1; else if (c1.num_cell < c2.num_cell) return -1; else return 0; }