-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFdsDiskFile.cs
93 lines (87 loc) · 3.46 KB
/
FdsDiskFile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System.Collections.Generic;
using System.Linq;
namespace com.clusterrr.Famicom.Containers
{
/// <summary>
/// File on FDS disk - header and data
/// </summary>
public class FdsDiskFile
{
private FdsBlockFileHeader headerBlock;
private FdsBlockFileData dataBlock;
/// <summary>
/// FDS block with file header
/// </summary>
public FdsBlockFileHeader HeaderBlock { get => headerBlock; set => headerBlock = value; }
/// <summary>
/// FDS block with file contents
/// </summary>
public FdsBlockFileData DataBlock { get => dataBlock; set => dataBlock = value; }
/// <summary>
/// File number
/// </summary>
public byte FileNumber { get => HeaderBlock.FileNumber; set => HeaderBlock.FileNumber = value; }
/// <summary>
/// File indicate code (ID specified at disk-read function call)
/// </summary>
public byte FileIndicateCode { get => HeaderBlock.FileIndicateCode; set => HeaderBlock.FileIndicateCode = value; }
/// <summary>
/// Filename
/// </summary>
public string FileName { get => HeaderBlock.FileName; set => HeaderBlock.FileName = value; }
/// <summary>
/// File address - the destination address when loading
/// </summary>
public ushort FileAddress { get => HeaderBlock.FileAddress; set => HeaderBlock.FileAddress = value; }
/// <summary>
/// File size
/// </summary>
public ushort FileSize { get => (ushort)DataBlock.Data.Count(); }
/// <summary>
/// Kind of the file: program, character or nametable
/// </summary>
public FdsBlockFileHeader.Kind FileKind { get => HeaderBlock.FileKind; set => HeaderBlock.FileKind = value; }
/// <summary>
/// File contents
/// </summary>
public IEnumerable<byte> Data
{
get => DataBlock.Data;
set
{
DataBlock.Data = value;
HeaderBlock.FileSize = (ushort)DataBlock.Data.Count();
}
}
/// <summary>
/// Construcor
/// </summary>
/// <param name="headerBlock">File header block</param>
/// <param name="dataBlock">File data block</param>
public FdsDiskFile(FdsBlockFileHeader headerBlock, FdsBlockFileData dataBlock)
{
this.headerBlock = headerBlock;
this.dataBlock = dataBlock;
headerBlock.FileSize = (ushort)dataBlock.Data.Count();
}
/// <summary>
/// Construcor for empty FdsDiskFile object
/// </summary>
public FdsDiskFile()
{
this.headerBlock = new FdsBlockFileHeader();
this.dataBlock = new FdsBlockFileData();
HeaderBlock.FileSize = (ushort)DataBlock.Data.Count();
}
/// <summary>
/// Returns raw file contents
/// </summary>
/// <returns>Raw file contents</returns>
public byte[] ToBytes() => Enumerable.Concat(HeaderBlock.ToBytes(), DataBlock.ToBytes()).ToArray();
/// <summary>
/// String representation: filename, file kind, data block info
/// </summary>
/// <returns>String representation of the file</returns>
public override string ToString() => $"{FileName} ({FileKind}, {dataBlock})";
}
}