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-24 11:20:11 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2020-09-24 11:20:11 +0300
commit4f703d2d45f82bf7e87d9152d42b89856eda7c50 (patch)
tree7ca876167a7b683751be57b15716da76ae5a4972
parent4dad10cc03d5c78ce20a4d79a0f37bc95339649a (diff)
Minor refactoring
-rw-r--r--NesFile.cs201
1 files changed, 97 insertions, 104 deletions
diff --git a/NesFile.cs b/NesFile.cs
index 9396fc0..9073613 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>
@@ -377,183 +380,183 @@ namespace com.clusterrr.Famicom.Containers
/// <summary>
/// Famicom Four Players Adapter with two additional standard controllers
/// </summary>
- FamicomFourPlayersAdapter = 0x03,
+ FamicomFourPlayersAdapter = 0x03,
/// <summary>
/// Vs. System
- /// </summary>
- VsSystem = 0x04,
+ /// </summary>
+ VsSystem = 0x04,
/// <summary>
/// Vs. System with reversed inputs
- /// </summary>
- VsSystemWithReversedInputs = 0x05,
+ /// </summary>
+ VsSystemWithReversedInputs = 0x05,
/// <summary>
/// Vs. Pinball (Japan)
- /// </summary>
- VsPinball = 0x06,
+ /// </summary>
+ VsPinball = 0x06,
/// <summary>
/// Vs. Zapper
- /// </summary>
- VsZapper = 0x07,
+ /// </summary>
+ VsZapper = 0x07,
/// <summary>
/// Zapper ($4017)
- /// </summary>
- Zapper = 0x08,
+ /// </summary>
+ Zapper = 0x08,
/// <summary>
/// Two Zappers
- /// </summary>
- TwoZappers = 0x09,
+ /// </summary>
+ TwoZappers = 0x09,
/// <summary>
/// Bandai Hyper Shot Lightgun
- /// </summary>
- BandaiHyperShotLightgun = 0x0A,
+ /// </summary>
+ BandaiHyperShotLightgun = 0x0A,
/// <summary>
/// Power Pad Side A
- /// </summary>
- PowerPadSideA = 0x0B,
+ /// </summary>
+ PowerPadSideA = 0x0B,
/// <summary>
/// Power Pad Side B
- /// </summary>
+ /// </summary>
PowerPadSideB = 0x0C,
/// <summary>
/// Family Trainer Side A
- /// </summary>
- FamilyTrainerSideA = 0x0D,
+ /// </summary>
+ FamilyTrainerSideA = 0x0D,
/// <summary>
/// Family Trainer Side B
- /// </summary>
- FamilyTrainerSideB = 0x0E,
+ /// </summary>
+ FamilyTrainerSideB = 0x0E,
/// <summary>
/// Arkanoid Vaus Controller (NES)
- /// </summary>
- ArkanoidVausControllerNES = 0x0F,
+ /// </summary>
+ ArkanoidVausControllerNES = 0x0F,
/// <summary>
/// Arkanoid Vaus Controller (Famicom)
- /// </summary>
- ArkanoidVausControllerFamicom = 0x10,
+ /// </summary>
+ ArkanoidVausControllerFamicom = 0x10,
/// <summary>
/// Two Vaus Controllers plus Famicom Data Recorder
- /// </summary>
- TwoVausControllersPlusFamicomDataRecorder = 0x11,
+ /// </summary>
+ TwoVausControllersPlusFamicomDataRecorder = 0x11,
/// <summary>
/// Konami Hyper Shot Controller
- /// </summary>
- KonamiHyperShotController = 0x12,
+ /// </summary>
+ KonamiHyperShotController = 0x12,
/// <summary>
/// Coconuts Pachinko Controller
- /// </summary>
- CoconutsPachinkoController = 0x13,
+ /// </summary>
+ CoconutsPachinkoController = 0x13,
/// <summary>
/// Exciting Boxing Punching Bag (Blowup Doll)
- /// </summary>
- ExcitingBoxingPunchingBag = 0x14,
+ /// </summary>
+ ExcitingBoxingPunchingBag = 0x14,
/// <summary>
/// Jissen Mahjong Controller
- /// </summary>
- JissenMahjongController = 0x15,
+ /// </summary>
+ JissenMahjongController = 0x15,
/// <summary>
/// Party Tap
- /// </summary>
- PartyTap = 0x16,
+ /// </summary>
+ PartyTap = 0x16,
/// <summary>
/// Oeka Kids Tablet
- /// </summary>
- OekaKidsTablet = 0x17,
+ /// </summary>
+ OekaKidsTablet = 0x17,
/// <summary>
/// Sunsoft Barcode Battler
- /// </summary>
- SunsoftBarcodeBattler = 0x18,
+ /// </summary>
+ SunsoftBarcodeBattler = 0x18,
/// <summary>
/// Miracle Piano Keyboard
- /// </summary>
- MiraclePianoKeyboard = 0x19,
+ /// </summary>
+ MiraclePianoKeyboard = 0x19,
/// <summary>
/// Pokkun Moguraa (Whack-a-Mole Mat and Mallet)
- /// </summary>
- PokkunMoguraa = 0x1A,
+ /// </summary>
+ PokkunMoguraa = 0x1A,
/// <summary>
/// Top Rider(Inflatable Bicycle)
- /// </summary>
- TopRider = 0x1B,
+ /// </summary>
+ TopRider = 0x1B,
/// <summary>
/// Double-Fisted (Requires or allows use of two controllers by one player)
- /// </summary>
- DoubleFisted = 0x1C,
+ /// </summary>
+ DoubleFisted = 0x1C,
/// <summary>
/// Famicom 3D System
- /// </summary>
- Famicom3DSystem = 0x1D,
+ /// </summary>
+ Famicom3DSystem = 0x1D,
/// <summary>
/// Doremikko Keyboard
- /// </summary>
- DoremikkoKeyboard = 0x1E,
+ /// </summary>
+ DoremikkoKeyboard = 0x1E,
/// <summary>
/// R.O.B. Gyro Set
- /// </summary>
- RobGyroSet = 0x1F,
+ /// </summary>
+ RobGyroSet = 0x1F,
/// <summary>
/// Famicom Data Recorder (don't emulate keyboard)
- /// </summary>
+ /// </summary>
FamicomDataRecorder = 0x20,
/// <summary>
/// ASCII Turbo File
- /// </summary>
+ /// </summary>
ASCIITurboFile = 0x21,
/// <summary>
/// IGS Storage Battle Box
- /// </summary>
- IGSStorageBattleBox = 0x22,
+ /// </summary>
+ IGSStorageBattleBox = 0x22,
/// <summary>
/// Family BASIC Keyboard plus Famicom Data Recorder
- /// </summary>
- FamilyBasicKeyboardPlusFamicomDataRecorder = 0x23,
+ /// </summary>
+ FamilyBasicKeyboardPlusFamicomDataRecorder = 0x23,
/// <summary>
/// Dongda PEC-586 Keyboard
- /// </summary>
- DongdaPEC586Keyboard = 0x24,
+ /// </summary>
+ DongdaPEC586Keyboard = 0x24,
/// <summary>
/// Bit Corp. Bit-79 Keyboard
- /// </summary>
- BitCorpBit79Keyboard = 0x25,
+ /// </summary>
+ BitCorpBit79Keyboard = 0x25,
/// <summary>
/// Subor Keyboard
- /// </summary>
- SuborKeyboard = 0x26,
+ /// </summary>
+ SuborKeyboard = 0x26,
/// <summary>
/// Subor Keyboard plus mouse (3x8-bit protocol)
- /// </summary>
- SuborKeyboardPlusMouse3x8 = 0x27,
+ /// </summary>
+ SuborKeyboardPlusMouse3x8 = 0x27,
/// <summary>
/// Subor Keyboard plus mouse (24-bit protocol)
- /// </summary>
- SuborKeyboardPlusMouse24 = 0x28,
+ /// </summary>
+ SuborKeyboardPlusMouse24 = 0x28,
/// <summary>
/// SNES Mouse ($4017.d0)
- /// </summary>
- SnesMouse4017 = 0x29,
+ /// </summary>
+ SnesMouse4017 = 0x29,
/// <summary>
/// Multicart
- /// </summary>
- Multicart = 0x2A,
+ /// </summary>
+ Multicart = 0x2A,
/// <summary>
/// Two SNES controllers replacing the two standard NES controllers
- /// </summary>
- TwoSnesControllers = 0x2B,
+ /// </summary>
+ TwoSnesControllers = 0x2B,
/// <summary>
/// RacerMate Bicycle
- /// </summary>
- RacerMateBicycle = 0x2C,
+ /// </summary>
+ RacerMateBicycle = 0x2C,
/// <summary>
/// U-Force
- /// </summary>
- UForce = 0x2D,
+ /// </summary>
+ UForce = 0x2D,
/// <summary>
/// R.O.B. Stack-Up
- /// </summary>
- RobStackUp = 0x2E,
+ /// </summary>
+ RobStackUp = 0x2E,
/// <summary>
/// City Patrolman Lightgun
- /// </summary>
- CityPatrolmanLightgun = 0x2F
+ /// </summary>
+ CityPatrolmanLightgun = 0x2F
}
/// <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)
{
@@ -754,11 +755,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;
}
@@ -772,11 +769,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;
}