Skip to content

Commit cfe61e9

Browse files
committed
Some FDS changes/fixes.
1 parent 8b7f346 commit cfe61e9

File tree

3 files changed

+69
-36
lines changed

3 files changed

+69
-36
lines changed

FdsBlockDiskInfo.cs

+60-27
Original file line numberDiff line numberDiff line change
@@ -653,11 +653,25 @@ public enum Company
653653
public Company LicenseeCode { get => (Company)manufacturerCode; set => manufacturerCode = (byte)value; }
654654

655655
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
656-
byte[] gameName = Encoding.ASCII.GetBytes("---");
656+
byte[] gameName = new byte[3];
657657
/// <summary>
658658
/// 3-letter ASCII code per game (e.g. ZEL for The Legend of Zelda)
659659
/// </summary>
660-
public string GameName { get => Encoding.ASCII.GetString(gameName).Trim(new char[] { '\0', ' ' }); set => gameName = Encoding.ASCII.GetBytes(value.PadRight(3)).Take(3).ToArray(); }
660+
public string? GameName {
661+
get
662+
{
663+
if (!gameName.Select(b => b != 0).Any())
664+
return Encoding.ASCII.GetString(gameName).Trim(new char[] { '\0', ' ' });
665+
else
666+
return null;
667+
}
668+
set {
669+
if (value != null)
670+
gameName = Encoding.ASCII.GetBytes(value.PadRight(3)).Take(3).ToArray();
671+
else
672+
gameName = new byte[3];
673+
}
674+
}
661675

662676
[MarshalAs(UnmanagedType.U1)]
663677
byte gameType;
@@ -722,31 +736,40 @@ public enum Company
722736
/// <summary>
723737
/// Manufacturing date
724738
/// </summary>
725-
public DateTime ManufacturingDate
739+
public DateTime? ManufacturingDate
726740
{
727741
get
728742
{
729743
try
730744
{
731-
return new DateTime(
732-
((manufacturingDate[0] & 0x0F) + ((manufacturingDate[0] >> 4) & 0x0F) * 10) + 1925,
733-
((manufacturingDate[1] & 0x0F) + ((manufacturingDate[1] >> 4) & 0x0F) * 10),
734-
((manufacturingDate[2] & 0x0F) + ((manufacturingDate[2] >> 4) & 0x0F) * 10)
735-
);
745+
if (!rewrittenDate.Select(b => b != 0).Any())
746+
return new DateTime(
747+
((manufacturingDate[0] & 0x0F) + ((manufacturingDate[0] >> 4) & 0x0F) * 10) + 1925,
748+
((manufacturingDate[1] & 0x0F) + ((manufacturingDate[1] >> 4) & 0x0F) * 10),
749+
((manufacturingDate[2] & 0x0F) + ((manufacturingDate[2] >> 4) & 0x0F) * 10)
750+
);
751+
else
752+
return null;
736753
}
737754
catch
738755
{
739-
return new DateTime();
756+
return null;
740757
}
741758
}
742759
set
743760
{
744-
manufacturingDate = new byte[]
761+
if (value != null)
745762
{
746-
(byte)(((value.Year - 1925) % 10) | (((value.Year - 1925) / 10) << 4)),
747-
(byte)(((value.Month) % 10) | (((value.Month) / 10) << 4)),
748-
(byte)(((value.Day) % 10) | (((value.Day) / 10) << 4))
749-
};
763+
manufacturingDate = new byte[]
764+
{
765+
(byte)(((value.Value.Year - 1925) % 10) | (((value.Value.Year - 1925) / 10) << 4)),
766+
(byte)(((value.Value.Month) % 10) | (((value.Value.Month) / 10) << 4)),
767+
(byte)(((value.Value.Day) % 10) | (((value.Value.Day) / 10) << 4))
768+
};
769+
} else
770+
{
771+
manufacturingDate = new byte[3];
772+
}
750773
}
751774
}
752775

@@ -777,31 +800,41 @@ public DateTime ManufacturingDate
777800
/// "Rewritten disk" date. It's speculated this refers to the date the disk was formatted and rewritten by something like a Disk Writer kiosk.
778801
/// In the case of an original (non-copied) disk, this should be the same as Manufacturing date
779802
/// </summary>
780-
public DateTime RewrittenDate
803+
public DateTime? RewrittenDate
781804
{
782805
get
783806
{
784807
try
785808
{
786-
return new DateTime(
787-
((rewrittenDate[0] & 0x0F) + ((rewrittenDate[0] >> 4) & 0x0F) * 10) + 1925,
788-
((rewrittenDate[1] & 0x0F) + ((rewrittenDate[1] >> 4) & 0x0F) * 10),
789-
((rewrittenDate[2] & 0x0F) + ((rewrittenDate[2] >> 4) & 0x0F) * 10)
790-
);
809+
if (!rewrittenDate.Select(b => b != 0).Any())
810+
return new DateTime(
811+
((rewrittenDate[0] & 0x0F) + ((rewrittenDate[0] >> 4) & 0x0F) * 10) + 1925,
812+
((rewrittenDate[1] & 0x0F) + ((rewrittenDate[1] >> 4) & 0x0F) * 10),
813+
((rewrittenDate[2] & 0x0F) + ((rewrittenDate[2] >> 4) & 0x0F) * 10)
814+
);
815+
else
816+
return null;
791817
}
792818
catch
793819
{
794-
return new DateTime();
820+
return null;
795821
}
796822
}
797823
set
798824
{
799-
rewrittenDate = new byte[]
825+
if (value != null)
800826
{
801-
(byte)(((value.Year - 1925) % 10) | (((value.Year - 1925) / 10) << 4)),
802-
(byte)(((value.Month) % 10) | (((value.Month) / 10) << 4)),
803-
(byte)(((value.Day) % 10) | (((value.Day) / 10) << 4))
804-
};
827+
manufacturingDate = new byte[]
828+
{
829+
(byte)(((value.Value.Year - 1925) % 10) | (((value.Value.Year - 1925) / 10) << 4)),
830+
(byte)(((value.Value.Month) % 10) | (((value.Value.Month) / 10) << 4)),
831+
(byte)(((value.Value.Day) % 10) | (((value.Value.Day) / 10) << 4))
832+
};
833+
}
834+
else
835+
{
836+
manufacturingDate = new byte[3];
837+
}
805838
}
806839
}
807840

@@ -899,7 +932,7 @@ public byte[] ToBytes()
899932
/// String representation
900933
/// </summary>
901934
/// <returns>Game name</returns>
902-
public override string ToString() => GameName;
935+
public override string ToString() => GameName ?? "---";
903936

904937
/// <summary>
905938
/// Equality comparer

FdsDiskSide.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class FdsDiskSide
2525
/// <summary>
2626
/// 3-letter ASCII code per game (e.g. ZEL for The Legend of Zelda)
2727
/// </summary>
28-
public string GameName { get => diskInfoBlock.GameName; set => diskInfoBlock.GameName = value; }
28+
public string? GameName { get => diskInfoBlock.GameName; set => diskInfoBlock.GameName = value; }
2929
/// <summary>
3030
/// $20 = " " — Normal disk
3131
/// $45 = "E" — Event(e.g.Japanese national DiskFax tournaments)
@@ -55,7 +55,7 @@ public class FdsDiskSide
5555
/// <summary>
5656
/// Manufacturing date
5757
/// </summary>
58-
public DateTime ManufacturingDate { get => diskInfoBlock.ManufacturingDate; set => diskInfoBlock.ManufacturingDate = value; }
58+
public DateTime? ManufacturingDate { get => diskInfoBlock.ManufacturingDate; set => diskInfoBlock.ManufacturingDate = value; }
5959
/// <summary>
6060
/// Country code. $49 = Japan
6161
/// </summary>
@@ -64,7 +64,7 @@ public class FdsDiskSide
6464
/// "Rewritten disk" date. It's speculated this refers to the date the disk was formatted and rewritten by something like a Disk Writer kiosk.
6565
/// In the case of an original (non-copied) disk, this should be the same as Manufacturing date
6666
/// </summary>
67-
public DateTime RewrittenDate { get => diskInfoBlock.RewrittenDate; set => diskInfoBlock.RewrittenDate = value; }
67+
public DateTime? RewrittenDate { get => diskInfoBlock.RewrittenDate; set => diskInfoBlock.RewrittenDate = value; }
6868
/// <summary>
6969
/// Disk Writer serial number
7070
/// </summary>

NesContainers.csproj

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
<PackageReadmeFile>README.md</PackageReadmeFile>
1313
<Nullable>enable</Nullable>
1414
<Title>NesContainers</Title>
15-
<Company>Cluster</Company>
15+
<Company>Alexey Cluster</Company>
1616
<PackageProjectUrl>https://github.com/ClusterM/nes-containers</PackageProjectUrl>
17-
<Copyright>Alexey 'Cluster' Avdyukhin, 2023</Copyright>
17+
<Copyright>Alexey Cluster, 2023</Copyright>
1818
<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>
19-
<Version>1.1.4</Version>
19+
<Version>1.1.5</Version>
2020
<RepositoryUrl>https://github.com/ClusterM/nes-containers</RepositoryUrl>
2121
<RepositoryType>git</RepositoryType>
2222
<PackageTags>nes;famicom;famicom disk system</PackageTags>
23-
<AssemblyVersion>1.1.4</AssemblyVersion>
24-
<FileVersion>1.1.4</FileVersion>
25-
<Authors>Alexey 'Cluster' Avdyukhin</Authors>
23+
<AssemblyVersion>1.1.5</AssemblyVersion>
24+
<FileVersion>1.1.5</FileVersion>
25+
<Authors>Alexey Cluster</Authors>
2626
</PropertyGroup>
2727

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

0 commit comments

Comments
 (0)