public FirmwareRom(string name, string serializedData) { Name = name; using (var reader = new BinaryStateReader(serializedData)) { // Header var magicNumber = reader.ReadUInt32(); if (magicNumber != MagicNumber) { throw new LoadStateException("Firmware ROM", String.Format("Magic number is incorrect. Expected: {0:X}. Found: {1:X}.", MagicNumber, magicNumber)); } var versionNumber = reader.ReadUInt32(); if (versionNumber != VersionNumber) { throw new LoadStateException("Firmware ROM", String.Format("Unsupported version number: {0}", versionNumber)); } // Data var wordCount = reader.ReadInt32(); Data = new ushort[wordCount]; for (var i = 0; i < wordCount; i++) { Data[i] = reader.ReadUInt16(); } } }
public FloppyDisk(string serializedData) { _sectors = new Dictionary <ushort, ushort[]>(); using (var reader = new BinaryStateReader(serializedData)) { // Header var magicNumber = reader.ReadUInt32(); if (magicNumber != MagicNumber) { throw new LoadStateException("M35FD Floppy Disk", String.Format("Magic number is incorrect. Expected: {0:X}. Found: {1:X}.", MagicNumber, magicNumber)); } var versionNumber = reader.ReadUInt32(); if (versionNumber != VersionNumber) { throw new LoadStateException("M35FD Floppy Disk", String.Format("Unsupported version number: {0}", versionNumber)); } // Data var sectorCount = reader.ReadInt32(); for (var i = 0; i < sectorCount; i++) { var sectorNumber = reader.ReadUInt16(); var sectorData = new ushort[WordsPerSector]; for (var j = 0; j < WordsPerSector; j++) { sectorData[j] = reader.ReadUInt16(); } _sectors.Add(sectorNumber, sectorData); } } }