public SpanReader ReadAsSubReader(int length) { var reader = new SpanReader(_span.Slice(0, length)); Advance(length); return(reader); }
private void ReadTrainer(ref SpanReader span) { if (HasTrainer) { Trainer = span.ReadAsByteArray(512); } }
private void Load(byte[] content) { var span = new SpanReader(content); ReadHeader(ref span); ReadTrainer(ref span); ReadPrgRom(ref span); ReadChrRom(ref span); Debug.Assert(span.IsCosumed, "nes not consumed."); }
private void ReadHeader(ref SpanReader span) { if (span.ReadAsUnsignedInt() != _magicNumber) { throw new InvalidDataException("Invalid nes file."); } PrgRomSize = span.ReadAsByte() * 16u * 1024; ChrRomSize = span.ReadAsByte() * 8u * 1024; var flag6 = span.ReadAsByte(); MirroringMode = (MirroringMode)(flag6 & 0b1); HasTrainer = (flag6 & 0b001) != 0; var flag7 = span.ReadAsByte(); PrgRamSize = Math.Max((byte)1, span.ReadAsByte()) * 8u * 1024; var flag9 = span.ReadAsByte(); var flag10 = span.ReadAsByte(); span.Advance(5); }
private void ReadPrgRom(ref SpanReader span) { PrgRom = span.ReadAsByteArray((int)PrgRomSize); }
private void ReadChrRom(ref SpanReader span) { ChrRom = span.ReadAsByteArray((int)ChrRomSize); }