Skip to content

Commit

Permalink
Some FDS changes/fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ClusterM committed Sep 2, 2023
1 parent 8b7f346 commit cfe61e9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 36 deletions.
87 changes: 60 additions & 27 deletions FdsBlockDiskInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,25 @@ public enum Company
public Company LicenseeCode { get => (Company)manufacturerCode; set => manufacturerCode = (byte)value; }

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
byte[] gameName = Encoding.ASCII.GetBytes("---");
byte[] gameName = new byte[3];
/// <summary>
/// 3-letter ASCII code per game (e.g. ZEL for The Legend of Zelda)
/// </summary>
public string GameName { get => Encoding.ASCII.GetString(gameName).Trim(new char[] { '\0', ' ' }); set => gameName = Encoding.ASCII.GetBytes(value.PadRight(3)).Take(3).ToArray(); }
public string? GameName {
get
{
if (!gameName.Select(b => b != 0).Any())
return Encoding.ASCII.GetString(gameName).Trim(new char[] { '\0', ' ' });
else
return null;
}
set {
if (value != null)
gameName = Encoding.ASCII.GetBytes(value.PadRight(3)).Take(3).ToArray();
else
gameName = new byte[3];
}
}

[MarshalAs(UnmanagedType.U1)]
byte gameType;
Expand Down Expand Up @@ -722,31 +736,40 @@ public enum Company
/// <summary>
/// Manufacturing date
/// </summary>
public DateTime ManufacturingDate
public DateTime? ManufacturingDate
{
get
{
try
{
return new DateTime(
((manufacturingDate[0] & 0x0F) + ((manufacturingDate[0] >> 4) & 0x0F) * 10) + 1925,
((manufacturingDate[1] & 0x0F) + ((manufacturingDate[1] >> 4) & 0x0F) * 10),
((manufacturingDate[2] & 0x0F) + ((manufacturingDate[2] >> 4) & 0x0F) * 10)
);
if (!rewrittenDate.Select(b => b != 0).Any())
return new DateTime(
((manufacturingDate[0] & 0x0F) + ((manufacturingDate[0] >> 4) & 0x0F) * 10) + 1925,
((manufacturingDate[1] & 0x0F) + ((manufacturingDate[1] >> 4) & 0x0F) * 10),
((manufacturingDate[2] & 0x0F) + ((manufacturingDate[2] >> 4) & 0x0F) * 10)
);
else
return null;
}
catch
{
return new DateTime();
return null;
}
}
set
{
manufacturingDate = new byte[]
if (value != null)
{
(byte)(((value.Year - 1925) % 10) | (((value.Year - 1925) / 10) << 4)),
(byte)(((value.Month) % 10) | (((value.Month) / 10) << 4)),
(byte)(((value.Day) % 10) | (((value.Day) / 10) << 4))
};
manufacturingDate = new byte[]
{
(byte)(((value.Value.Year - 1925) % 10) | (((value.Value.Year - 1925) / 10) << 4)),
(byte)(((value.Value.Month) % 10) | (((value.Value.Month) / 10) << 4)),
(byte)(((value.Value.Day) % 10) | (((value.Value.Day) / 10) << 4))
};
} else
{
manufacturingDate = new byte[3];
}
}
}

Expand Down Expand Up @@ -777,31 +800,41 @@ public DateTime ManufacturingDate
/// "Rewritten disk" date. It's speculated this refers to the date the disk was formatted and rewritten by something like a Disk Writer kiosk.
/// In the case of an original (non-copied) disk, this should be the same as Manufacturing date
/// </summary>
public DateTime RewrittenDate
public DateTime? RewrittenDate
{
get
{
try
{
return new DateTime(
((rewrittenDate[0] & 0x0F) + ((rewrittenDate[0] >> 4) & 0x0F) * 10) + 1925,
((rewrittenDate[1] & 0x0F) + ((rewrittenDate[1] >> 4) & 0x0F) * 10),
((rewrittenDate[2] & 0x0F) + ((rewrittenDate[2] >> 4) & 0x0F) * 10)
);
if (!rewrittenDate.Select(b => b != 0).Any())
return new DateTime(
((rewrittenDate[0] & 0x0F) + ((rewrittenDate[0] >> 4) & 0x0F) * 10) + 1925,
((rewrittenDate[1] & 0x0F) + ((rewrittenDate[1] >> 4) & 0x0F) * 10),
((rewrittenDate[2] & 0x0F) + ((rewrittenDate[2] >> 4) & 0x0F) * 10)
);
else
return null;
}
catch
{
return new DateTime();
return null;
}
}
set
{
rewrittenDate = new byte[]
if (value != null)
{
(byte)(((value.Year - 1925) % 10) | (((value.Year - 1925) / 10) << 4)),
(byte)(((value.Month) % 10) | (((value.Month) / 10) << 4)),
(byte)(((value.Day) % 10) | (((value.Day) / 10) << 4))
};
manufacturingDate = new byte[]
{
(byte)(((value.Value.Year - 1925) % 10) | (((value.Value.Year - 1925) / 10) << 4)),
(byte)(((value.Value.Month) % 10) | (((value.Value.Month) / 10) << 4)),
(byte)(((value.Value.Day) % 10) | (((value.Value.Day) / 10) << 4))
};
}
else
{
manufacturingDate = new byte[3];
}
}
}

Expand Down Expand Up @@ -899,7 +932,7 @@ public byte[] ToBytes()
/// String representation
/// </summary>
/// <returns>Game name</returns>
public override string ToString() => GameName;
public override string ToString() => GameName ?? "---";

/// <summary>
/// Equality comparer
Expand Down
6 changes: 3 additions & 3 deletions FdsDiskSide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class FdsDiskSide
/// <summary>
/// 3-letter ASCII code per game (e.g. ZEL for The Legend of Zelda)
/// </summary>
public string GameName { get => diskInfoBlock.GameName; set => diskInfoBlock.GameName = value; }
public string? GameName { get => diskInfoBlock.GameName; set => diskInfoBlock.GameName = value; }
/// <summary>
/// $20 = " " — Normal disk
/// $45 = "E" — Event(e.g.Japanese national DiskFax tournaments)
Expand Down Expand Up @@ -55,7 +55,7 @@ public class FdsDiskSide
/// <summary>
/// Manufacturing date
/// </summary>
public DateTime ManufacturingDate { get => diskInfoBlock.ManufacturingDate; set => diskInfoBlock.ManufacturingDate = value; }
public DateTime? ManufacturingDate { get => diskInfoBlock.ManufacturingDate; set => diskInfoBlock.ManufacturingDate = value; }
/// <summary>
/// Country code. $49 = Japan
/// </summary>
Expand All @@ -64,7 +64,7 @@ public class FdsDiskSide
/// "Rewritten disk" date. It's speculated this refers to the date the disk was formatted and rewritten by something like a Disk Writer kiosk.
/// In the case of an original (non-copied) disk, this should be the same as Manufacturing date
/// </summary>
public DateTime RewrittenDate { get => diskInfoBlock.RewrittenDate; set => diskInfoBlock.RewrittenDate = value; }
public DateTime? RewrittenDate { get => diskInfoBlock.RewrittenDate; set => diskInfoBlock.RewrittenDate = value; }
/// <summary>
/// Disk Writer serial number
/// </summary>
Expand Down
12 changes: 6 additions & 6 deletions NesContainers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<Nullable>enable</Nullable>
<Title>NesContainers</Title>
<Company>Cluster</Company>
<Company>Alexey Cluster</Company>
<PackageProjectUrl>https://github.com/ClusterM/nes-containers</PackageProjectUrl>
<Copyright>Alexey 'Cluster' Avdyukhin, 2023</Copyright>
<Copyright>Alexey Cluster, 2023</Copyright>
<Description>A simple .NET Standard 2.0 library for reading and modifying NES/Famicom ROM containers: .nes (iNES, NES 2.0), .unf (UNIF), and .fds (Famicom Disk System images).</Description>
<Version>1.1.4</Version>
<Version>1.1.5</Version>
<RepositoryUrl>https://github.com/ClusterM/nes-containers</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>nes;famicom;famicom disk system</PackageTags>
<AssemblyVersion>1.1.4</AssemblyVersion>
<FileVersion>1.1.4</FileVersion>
<Authors>Alexey 'Cluster' Avdyukhin</Authors>
<AssemblyVersion>1.1.5</AssemblyVersion>
<FileVersion>1.1.5</FileVersion>
<Authors>Alexey Cluster</Authors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down

0 comments on commit cfe61e9

Please sign in to comment.