public static IEnumerable <VgmCommand> Read(VgmHeader header, ISequentialReader reader) { var vgmDataOffset = GetVGMDataAbsoluteOffset(header); reader.SkipToAbsoluteOffset(vgmDataOffset); return(ReadSequence(reader)); }
private static void Read100(ISequentialReader reader, ref V100HeaderPart part) { part.SN76489Clock = reader.ReadUInt32(); part.YM2413Clock = reader.ReadUInt32(); part.GD3Offset = reader.ReadUInt32(); part.TotalNumberOfSamples = reader.ReadUInt32(); part.LoopOffset = reader.ReadUInt32(); part.LoopNumberOfSamples = reader.ReadUInt32(); }
public static void SkipToAbsoluteOffset(this ISequentialReader reader, uint offset) { if (offset < reader.BytesRead) { throw new ArgumentOutOfRangeException(nameof(offset)); } reader.Skip(offset - reader.BytesRead); }
private static IEnumerable <VgmCommand> ReadSequence(ISequentialReader reader) { VgmCommand command; do { command = ReadOne(reader); yield return(command); } while (!(command is EndOfSoundDataCommand)); }
public static VgmCommand ReadOne(ISequentialReader reader) { var code = reader.ReadByte(); if (Map.TryGetValue(code, out var commandReader)) { return(commandReader(code, reader)); } else { throw new VgmException("Unknown command"); } }
public static VgmHeader Read(ISequentialReader reader) { var header = new VgmHeader(); var unused = new V151HeaderPart(); ReadCommon(reader, ref header.Common); if (header.Common.VgmIdentification != CommonHeaderPart.VgmIdentificationValue) { throw new VgmException("Vgm magic number does not found"); } var version = header.Common.Version; if (version != FormatVersion.V100 && version != FormatVersion.V101 && version != FormatVersion.V110 && version != FormatVersion.V150) { throw new VgmException("Unsupported version"); } Read100(reader, ref header.V100); if (version == FormatVersion.V100) { return(header); } Read101(reader, ref header.V101); if (version == FormatVersion.V101) { return(header); } Read110Part1(reader, ref header.V110); Read151Part1(reader, ref unused); Read110Part2(reader, ref header.V110); if (version == FormatVersion.V110) { return(header); } Read150(reader, ref header.V150); return(header); }
public ParserPool(ISequentialReader producer, Func <string, IStarSystem> parserFunction, Action <IStarSystem> systemHandler, bool printDebug, string debugOutputFilePath = null) { this.reader = producer ?? throw new ArgumentNullException(nameof(producer)); this.systemHandler = systemHandler ?? throw new ArgumentNullException(nameof(systemHandler)); this.parser = parserFunction ?? throw new ArgumentNullException(nameof(parserFunction)); if (printDebug) { this.debugSw = File.CreateText(debugOutputFilePath); } this.workers = new Task[12]; for (int i = 0; i < this.workers.Length; i++) { this.workers[i] = new Task(this.WorkerAction); } }
private static DataBlockCommand ReadDataBlockBody(byte c, ISequentialReader r) { var compatibility = r.ReadByte(); if (compatibility != EndOfSoundDataCode) { throw new VgmException($"Data block command code 0x{c:X2} must be folowed by 0x{EndOfSoundDataCode:X2}"); } var type = r.ReadByte(); var size = r.ReadUInt32(); r.Skip(size); return(new DataBlockCommand(c, type, size)); }
private static YM2612Port0Address2AWriteThenWaitNSamplesCommand ReadYM2612WriteAndWaitBody(byte c, ISequentialReader r) => new YM2612Port0Address2AWriteThenWaitNSamplesCommand(c);
private static WaitNPlusOneSamplesCommand ReadWaitNPlusOneSamplesBody(byte c, ISequentialReader r) => new WaitNPlusOneSamplesCommand(c);
private static EndOfSoundDataCommand ReadEndOfSoundDataBody(byte c, ISequentialReader r) => new EndOfSoundDataCommand(c);
private static WaitNSamplesCommand ReadWaitNSamplesBody(byte c, ISequentialReader r) => new WaitNSamplesCommand(c, r.ReadUInt16());
private static PsgWriteCommand ReadPsgWriteCommandBody(byte c, ISequentialReader r) => new PsgWriteCommand(c, r.ReadByte());
private static StubCommand ReadElevenBytesBody(byte c, ISequentialReader r) => ReadNBytesBody(11, c, r);
private static void Read151Part1(ISequentialReader reader, ref V151HeaderPart part) { part.SN76489Flags = reader.ReadByte(); }
private static void Read101(ISequentialReader reader, ref V101HeaderPart part) { part.Rate = reader.ReadUInt32(); }
private static StubCommand ReadZeroBytesBody(byte c, ISequentialReader r) => ReadNBytesBody(0, c, r);
private static StubCommand ReadNBytesBody(uint n, byte code, ISequentialReader reader) => n == 0 ? new StubCommand(code, new byte[0]) : new StubCommand(code, reader.ReadBytes(n));
private static void ReadCommon(ISequentialReader reader, ref CommonHeaderPart part) { part.VgmIdentification = reader.ReadUInt32(); part.EofOffset = reader.ReadUInt32(); part.Version = (FormatVersion)reader.ReadUInt32(); }
private static void Read110Part2(ISequentialReader reader, ref V110HeaderPart part) { part.YM2612Clock = reader.ReadUInt32(); part.YM2151Clock = reader.ReadUInt32(); }
private static void Read150(ISequentialReader reader, ref V150HeaderPart part) { part.VGMDataOffset = reader.ReadUInt32(); }
private static StubCommand ReadThreeBytesBody(byte c, ISequentialReader r) => ReadNBytesBody(3, c, r);
private static StubCommand ReadFiveBytesBody(byte c, ISequentialReader r) => ReadNBytesBody(5, c, r);
private static StubCommand ReadOneByteBody(byte c, ISequentialReader r) => ReadNBytesBody(1, c, r);
private static void Read110Part1(ISequentialReader reader, ref V110HeaderPart part) { part.SN76489Feedback = reader.ReadUInt16(); part.SN76489ShiftRegisterWidth = reader.ReadByte(); }