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-09-26 20:38:39 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2020-09-26 20:38:39 +0300
commit65b85fa6591ae2acd5140f85df8780cefd3e3aec (patch)
tree3564fca68fdb098734ee1a5fdaecdaa4c25d7fb0
parent4765b3a72d92203f52d749a043d7b3fef2023c52 (diff)
parent697e35f8a8e7a0674513ea2a40c32c23b38816b6 (diff)
Merge branch 'master' of https://github.com/ClusterM/nes-containers
-rw-r--r--NesFile.cs29
1 files changed, 11 insertions, 18 deletions
diff --git a/NesFile.cs b/NesFile.cs
index b4fed4f..3c7e4c5 100644
--- a/NesFile.cs
+++ b/NesFile.cs
@@ -13,11 +13,11 @@ namespace com.clusterrr.Famicom.Containers
/// <summary>
/// PRG data
/// </summary>
- public byte[] PRG { get; set; } = null;
+ public byte[] PRG { get => prg; set => prg = value; }
/// <summary>
/// CHR data (can be null if none)
/// </summary>
- public byte[] CHR { get; set; } = null;
+ public byte[] CHR { get => chr; set => chr = value; }
/// <summary>
/// Trainer (can be null if none)
/// </summary>
@@ -74,6 +74,9 @@ namespace com.clusterrr.Famicom.Containers
/// </summary>
public uint ChrRamSize { get; set; } = 0;
private uint chrNvRamSize = 0;
+ private byte[] prg = null;
+ private byte[] chr = null;
+
/// <summary>
/// CHR NVRAM Size (NES 2.0 only)
/// </summary>
@@ -696,16 +699,14 @@ namespace com.clusterrr.Famicom.Containers
if ((PRG.Length % 0x4000) != 0)
{
var padding = 0x4000 - (PRG.Length % 4000);
- var newprg = new byte[PRG.Length + padding];
- Array.Copy(PRG, newprg, PRG.Length);
- PRG = newprg;
+ if (padding > 0)
+ Array.Resize(ref prg, prg.Length + padding);
}
if ((CHR.Length % 0x2000) != 0)
{
var padding = 0x2000 - (CHR.Length % 2000);
- var newchr = new byte[CHR.Length + padding];
- Array.Copy(CHR, newchr, CHR.Length);
- CHR = newchr;
+ if (padding > 0)
+ Array.Resize(ref chr, chr.Length + padding);
}
if (Version == iNesVersion.iNES)
{
@@ -758,11 +759,7 @@ namespace com.clusterrr.Famicom.Containers
{
(long padding, int exponent, int multiplier) = CalculateExponent(PRG.Length);
if (padding > 0)
- {
- var newprg = new byte[PRG.Length + padding];
- Array.Copy(PRG, newprg, PRG.Length);
- PRG = newprg;
- }
+ Array.Resize(ref prg, (int)(prg.Length + padding));
header[4] = (byte)((exponent << 2) | (multiplier & 3));
header[9] |= 0x0F;
}
@@ -776,11 +773,7 @@ namespace com.clusterrr.Famicom.Containers
{
(long padding, int exponent, int multiplier) = CalculateExponent(CHR.Length);
if (padding > 0)
- {
- var newchr = new byte[CHR.Length + padding];
- Array.Copy(CHR, newchr, CHR.Length);
- CHR = newchr;
- }
+ Array.Resize(ref chr, (int)(chr.Length + padding));
header[5] = (byte)((exponent << 2) | (multiplier & 3));
header[9] |= 0xF0;
}