using System.Collections.Generic; using System.Linq; namespace com.clusterrr.Famicom.Containers { /// /// File on FDS disk - header and data /// public class FdsDiskFile { private FdsBlockFileHeader headerBlock; private FdsBlockFileData dataBlock; /// /// FDS block with file header /// public FdsBlockFileHeader HeaderBlock { get => headerBlock; set => headerBlock = value; } /// /// FDS block with file contents /// public FdsBlockFileData DataBlock { get => dataBlock; set => dataBlock = value; } /// /// File number /// public byte FileNumber { get => HeaderBlock.FileNumber; set => HeaderBlock.FileNumber = value; } /// /// File indicate code (ID specified at disk-read function call) /// public byte FileIndicateCode { get => HeaderBlock.FileIndicateCode; set => HeaderBlock.FileIndicateCode = value; } /// /// Filename /// public string FileName { get => HeaderBlock.FileName; set => HeaderBlock.FileName = value; } /// /// File address - the destination address when loading /// public ushort FileAddress { get => HeaderBlock.FileAddress; set => HeaderBlock.FileAddress = value; } /// /// File size /// public ushort FileSize { get => (ushort)DataBlock.Data.Count(); } /// /// Kind of the file: program, character or nametable /// public FdsBlockFileHeader.Kind FileKind { get => HeaderBlock.FileKind; set => HeaderBlock.FileKind = value; } /// /// File contents /// public IEnumerable Data { get => DataBlock.Data; set { DataBlock.Data = value; HeaderBlock.FileSize = (ushort)DataBlock.Data.Count(); } } /// /// Construcor /// /// File header block /// File data block public FdsDiskFile(FdsBlockFileHeader headerBlock, FdsBlockFileData dataBlock) { this.headerBlock = headerBlock; this.dataBlock = dataBlock; headerBlock.FileSize = (ushort)dataBlock.Data.Count(); } /// /// Construcor for empty FdsDiskFile object /// public FdsDiskFile() { this.headerBlock = new FdsBlockFileHeader(); this.dataBlock = new FdsBlockFileData(); HeaderBlock.FileSize = (ushort)DataBlock.Data.Count(); } /// /// Returns raw file contents /// /// Raw file contents public byte[] ToBytes() => Enumerable.Concat(HeaderBlock.ToBytes(), DataBlock.ToBytes()).ToArray(); /// /// String representation: filename, file kind, data block info /// /// String representation of the file public override string ToString() => $"{FileName} ({FileKind}, {dataBlock})"; } }