using System; namespace NW4RTools { public class DisplayListWriter : OutputStream { public DisplayListWriter() : base(ByteEndian.BigEndian) { } public void End() { AlignTo(0x20); } public void Nop() { WriteByte(0); } public void LoadBPReg(UInt32 value) { WriteByte((byte)GXCommand.LoadBPReg); WriteUInt32(value); } public void LoadCPReg(byte command, UInt32 value) { WriteByte((byte)GXCommand.LoadCPReg); WriteByte(command); WriteUInt32(value); } public void LoadXFReg(ushort address, byte[] data) { if ((data.Length & 3) != 0) { throw new ArgumentException("Data length passed to LoadXFReg() is not aligned to 4 bytes", "data"); } if (data.Length < 4 || data.Length > 0x44) { throw new ArgumentException("Data length passed to LoadXFReg() must be at least 4 bytes and at most 0x44 bytes", "data"); } WriteByte((byte)GXCommand.LoadXFReg); WriteByte(0); WriteByte((byte)((data.Length / 4) - 1)); WriteUInt16(address); WriteBytes(data); } public void LoadPosMtxFromArray(uint number) { WriteByte((byte)GXCommand.LoadPosMtxFromArray); WriteUInt32(number); } public void LoadNrmMtxFromArray(uint number) { WriteByte((byte)GXCommand.LoadNrmMtxFromArray); WriteUInt32(number); } public void LoadTexCoordMtxFromArray(uint number) { WriteByte((byte)GXCommand.LoadTexCoordMtxFromArray); WriteUInt32(number); } public void LoadLightFromArray(uint number) { WriteByte((byte)GXCommand.LoadLightFromArray); WriteUInt32(number); } public void CallDisplayList(uint pointer, uint size) { WriteByte((byte)GXCommand.CallDL); WriteUInt32(pointer); WriteUInt32(size); } public void UnknownMetrics() { WriteByte((byte)GXCommand.UnknownMetrics); } public void BeginPrimitives(PrimitiveType type, int vatIndex, ushort vtxCount) { byte command = (byte)GXCommand.DrawPrimitiveMask; command |= (byte)((byte)type << (byte)GXCommand.PrimitiveShiftAmount); command |= (byte)vatIndex; WriteByte(command); WriteUInt16(vtxCount); } } }