Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/nes-containers.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2020-12-13 11:04:58 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2020-12-13 11:04:58 +0300
commitcd2cfcd941ba3acba938fef4d2259e72b9a224c7 (patch)
treef8266877365d883fe1284bfe01e03cec416911ea
parentd6b78dd900047be58daa2b2d8a67e783837d4aea (diff)
Trainer property fix
-rw-r--r--NesFile.cs21
1 files changed, 15 insertions, 6 deletions
diff --git a/NesFile.cs b/NesFile.cs
index 2a9a4dc..0f7f455 100644
--- a/NesFile.cs
+++ b/NesFile.cs
@@ -22,7 +22,15 @@ namespace com.clusterrr.Famicom.Containers
/// <summary>
/// Trainer (can be null if none)
/// </summary>
- public byte[] Trainer { get; set; } = null;
+ public IEnumerable<byte> Trainer
+ {
+ get => Array.AsReadOnly(trainer); set
+ {
+ if (value != null && value.Count() != 0 && value.Count() != 512)
+ throw new ArgumentOutOfRangeException("Trainer size must be 512 bytes");
+ chr = trainer.ToArray();
+ }
+ }
/// <summary>
/// Miscellaneous ROM (NES 2.0 only, can be null if none)
/// </summary>
@@ -77,6 +85,7 @@ namespace com.clusterrr.Famicom.Containers
private uint chrNvRamSize = 0;
private byte[] prg = null;
private byte[] chr = null;
+ private byte[] trainer = null;
/// <summary>
/// CHR NVRAM Size (NES 2.0 only)
@@ -597,9 +606,9 @@ namespace com.clusterrr.Famicom.Containers
Mirroring = (MirroringType)(header[6] & 1);
Battery = (header[6] & (1 << 1)) != 0;
if ((header[6] & (1 << 2)) != 0)
- Trainer = new byte[512];
+ trainer = new byte[512];
else
- Trainer = null;
+ trainer = new byte[0];
if ((header[6] & (1 << 3)) != 0)
Mirroring = MirroringType.FourScreenVram;
if (Version == iNesVersion.iNES)
@@ -649,10 +658,10 @@ namespace com.clusterrr.Famicom.Containers
}
uint offset = (uint)header.Length;
- if (Trainer != null)
+ if (trainer != null && trainer.Length > 0)
{
- Array.Copy(data, offset, Trainer, 0, Trainer.Length);
- offset += (uint)Trainer.Length;
+ Array.Copy(data, offset, trainer, 0, trainer.Length);
+ offset += (uint)trainer.Length;
}
prg = new byte[prgSize];