Skip to content

Commit 704c3bf

Browse files
committed
More error checks
1 parent 50912d0 commit 704c3bf

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

NesContainers.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
<PackageProjectUrl>https://github.com/ClusterM/nes-containers</PackageProjectUrl>
1717
<Copyright>Alexey 'Cluster' Avdyukhin, 2022</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.2</Version>
19+
<Version>1.1.3</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.2</AssemblyVersion>
24-
<FileVersion>1.1.2</FileVersion>
23+
<AssemblyVersion>1.1.3</AssemblyVersion>
24+
<FileVersion>1.1.3</FileVersion>
2525
<Authors>Alexey 'Cluster' Avdyukhin</Authors>
2626
</PropertyGroup>
2727

NesFile.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,14 @@ public byte[] ToBytes()
728728
throw new InvalidDataException("Mapper number > 255 is supported by NES 2.0 only");
729729
if (Submapper != 0)
730730
throw new InvalidDataException("Submapper number is supported by NES 2.0 only");
731+
if (prgRamSize > 0)
732+
throw new InvalidDataException("PRG RAM size is supported by NES 2.0 only");
733+
if (prgNvRamSize > 0)
734+
throw new InvalidDataException("PRG NVRAM size is supported by NES 2.0 only");
735+
if (chrRamSize > 0)
736+
throw new InvalidDataException("CHR RAM size is supported by NES 2.0 only");
737+
if (chrNvRamSize > 0)
738+
throw new InvalidDataException("CHR NVRAM size is supported by NES 2.0 only");
731739
var length16k = prg.Length / 0x4000;
732740
if (length16k > 0xFF) throw new ArgumentOutOfRangeException("PRG size is too big for iNES, use NES 2.0 instead");
733741
header[4] = (byte)Math.Ceiling((double)prg.Length / 0x4000);
@@ -833,7 +841,7 @@ public byte[] ToBytes()
833841
header[8] |= (byte)(Submapper << 4);
834842
// Check battery value
835843
if ((prgNvRamSize > 0 || chrNvRamSize > 0) && !Battery)
836-
throw new InvalidDataException("Battery flag must be set when PrgNvRamSize or ChrNvRamSize is non-zero");
844+
throw new InvalidDataException("Battery flag must be set when PRG NVRAM size or CHR NVRAM size is non-zero");
837845
// PRG RAM (volatile) shift count
838846
header[10] |= (byte)(prgRamSize & 0x0F);
839847
// PRG-NVRAM/EEPROM (non-volatile) shift count

0 commit comments

Comments
 (0)