public void Write(uint startAddress, byte[] data) { int bytesWritten = 0; while (bytesWritten < data.Length) { byte count = (byte)Math.Min(16, data.Length - bytesWritten); // Add 5 to the count since the 4 address bytes and checksum will be written separately int checksum = count + 5; long address = startAddress + bytesWritten; SRecordWriter.CalculateChecksum(address, ref checksum); StringBuilder builder = new StringBuilder(); for (int index = 0; index < count; index++) { byte value = data[index + bytesWritten]; checksum += value; builder.AppendFormat("{0:X2}", value); } byte lastByte = (byte)(checksum & 0xFF); byte complement = (byte)(lastByte ^ 0xFF); builder.Append(complement.ToString("X2")); string dataString = builder.ToString(); // Adding 5 to the count since the 4 address bytes and checksum are written separately //Trace.WriteLine("S3{0:X2}{1:X8}{2}", count + 5, address, dataString); writer.WriteLine("S3{0:X2}{1:X8}{2}", count + 5, address, dataString); bytesWritten += (int)count; } }
/// <summary> /// Print the current contents of the ROM in the address range for the given patch. /// Contains a check against metadata when IsMetaChecked = true /// </summary> private bool TryCheckPrintBaseline(Patch patch, Stream outStream) { uint patchLength = patch.Length; byte[] buffer = new byte[patchLength]; //read baseline ROM data blob into buffer if (!this.TryReadBuffer(outStream, patch.StartAddress, buffer)) { return false; } if (patch.IsMetaChecked) { patch.MetaCheck((IEnumerable<byte>)buffer); } using ( StreamWriter textWriter = File.AppendText(this.ModIdent + ".patch")) { //TextWriter textWriter = new StreamWriter(consoleOutputStream); //OUTPUT DIRECT TO FILE, ADD VERSIONING SYSTEM SRecordWriter writer = new SRecordWriter(textWriter); // The "baselineOffset" delta is how we distinguish baseline data from patch data. writer.Write(patch.StartAddress + BaselineOffset, buffer); } return true; }