So I recently purchased an Arduino Uno Rev3 from Radioshack for $35. (Later seen online for <20) in hopes of transferring some functions over to it for use with my Xbox repair services. I have what I believe to be all the coding needed, however I have no idea how to implement into the r3 board. The code below is C# and pc based. I also have a hex file used in a board that once preformed this function for me. I used Xloader to try and load it once but after 20 mins I exited. Would it be possible to use this code on the board? I am sure it needs altering tho.
using System;
using System.IO;
using x360Utils.NAND;
public class BasicNANDReader: IDisposable {
public BasicNANDReader(string file): this(File.OpenRead(file)) { }
public BasicNANDReader(Stream input)
{
BaseStream = input;
CheckMagic();
CheckForMeta();
}
public bool HasSpare { get; internal set; }
public long Length {
get {
if(!HasSpare)
return BaseStream.Length;
return (BaseStream.Length / 0x210) * 0x200;
}
}
public long Position {
get {
if(!HasSpare)
return BaseStream.Position;
return (BaseStream.Position / 0x210) * 0x200 + BaseStream.Position % 0x210;
}
set { SetPosition(value); }
}
public Stream BaseStream { get; private set; }
public void Dispose() { BaseStream.Dispose(); }
internal virtual void SetPosition(long offset) { Seek(offset, SeekOrigin.Begin); }
internal void CheckMagic() {
BaseStream.Seek(0, SeekOrigin.Begin);
var buf = new byte[2];
BaseStream.Read(buf, 0, 2);
if(buf[0] != 0xFF || buf[1] != 0x4F)
throw new NANDReaderException(NANDReaderException.ErrorTypes.BadMagic, string.Format("Expected: 0xFF4F Got: 0x{0:X2}{1:X2}", buf[0], buf[1]));
}
internal void CheckForMeta() {
BaseStream.Seek(0, SeekOrigin.Begin);
var buf = new byte[0x630]; // 3 page buffer
if(BaseStream.Read(buf, 0, buf.Length) != buf.Length)
throw new NANDReaderException(NANDReaderException.ErrorTypes.NotEnoughData);
HasSpare = true; // Let's assume it has spare before we begin...
for(var i = 0; i < buf.Length; i += 0x210) {
if(!Meta.CheckPageEcd(ref buf, i))
HasSpare = false; // We don't have spare...
}
}
public void Close() { BaseStream.Close(); }
public virtual int Read(byte[] buffer, int offset, int count) {
if(!HasSpare)
return BaseStream.Read(buffer, offset, count);
var read = 0;
if(BaseStream.Position % 0x210 > 0) {
int pageOffset = (int)(0x200 - BaseStream.Position % 0x210);
var size = Program.GetSmallest(pageOffset, count);
read = BaseStream.Read(buffer, offset, size);
offset += size;
if(size == pageOffset)
BaseStream.Seek(0x10, SeekOrigin.Current);
}
while(read < count) {
var size = Program.GetSmallest(0x200, count - read);
read += BaseStream.Read(buffer, offset, size);
offset += size;
if(size == 0x200)
BaseStream.Seek(0x10, SeekOrigin.Current);
}
return read;
}
public byte ReadByte() {
var buf = new byte[1];
if(Read(buf, 0, 1) == 1)
return buf[0];
throw new NANDReaderException(NANDReaderException.ErrorTypes.NotEnoughData);
}
public byte[] ReadBytes(int count) {
var buf = new byte[count];
if(Read(buf, 0, count) == count)
return buf;
throw new NANDReaderException(NANDReaderException.ErrorTypes.NotEnoughData);
}
public void Seek(long offset, SeekOrigin origin) {
if(HasSpare)
offset = ((offset / 0x200) * 0x210) + offset % 0x210;
BaseStream.Seek(offset, origin);
}
}
}