public void Write() { if (compressed) { // compress data byte[] uncompData = Arrays.UshortToByte(data); byte[] compData = Compress.CompLZ77(uncompData); int newLen = compData.Length; // write new data if (newLen <= origLen) { int offset = rom.ReadPtr(pointer); rom.ArrayToRom(compData, 0, offset, newLen); } else { int offset = rom.WriteToEnd(compData); rom.WritePtr(pointer, offset); } origLen = newLen; } else { byte[] bytes = Arrays.UshortToByte(data); int offset = rom.ReadPtr(pointer); rom.ArrayToRom(bytes, 0, offset, bytes.Length); } }
public void WriteToEnd(Rom rom, int pointer) { // compress data byte[] compData = Compress.CompLZ77(Data); // write new data int offset = rom.WriteToEnd(compData); rom.WritePtr(pointer, offset); }
public void CompLZ77Test() { byte[] input = new byte[] { 1, 2, 3, 4, 5, 0, 1, 2, 0, 1, 2, 3, 4, 5 }; byte[] expected = new byte[] { 0x10, 0x0E, 0, 0, 0x00, 1, 2, 3, 4, 5, 0, 1, 2, 0xC0, 0x00, 0x02, 0x00, 0x08 }; CollectionAssert.AreEqual(expected, Compress.CompLZ77(input)); }
public void WriteCopy(int newPointer) { int offset; if (compressed) { byte[] uncompData = Arrays.UshortToByte(data); byte[] compData = Compress.CompLZ77(uncompData); offset = rom.WriteToEnd(compData); } else { byte[] bytes = Arrays.UshortToByte(data); offset = rom.WriteToEnd(bytes); } rom.WritePtr(newPointer, offset); }
public void Write() { // compress data byte[] compData = Compress.CompLZ77(Data); int newLen = compData.Length; // write new data if (newLen <= origLen) { int offset = rom.ReadPtr(pointer); rom.ArrayToRom(compData, 0, offset, newLen); } else { int offset = rom.WriteToEnd(compData); rom.WritePtr(pointer, offset); } origLen = newLen; }