From 98961780dced20591aa2e1a543c4cd830f17d515 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sun, 8 Dec 2019 03:55:37 -0500 Subject: [PATCH] trying something new --- .../Nintendo/Associations/Z64.uexml | 20 ++++ ...lEditor.Content.PlatformIndependent.csproj | 3 + .../Executable/Nintendo/N64/N64CountryCode.cs | 107 ++++++++++++++++++ .../Executable/Nintendo/N64/N64MediaFormat.cs | 32 ++++++ .../Executable/Nintendo/N64/Z64DataFormat.cs | 81 +++++++++++++ .../UniversalEditor.Plugins.Nintendo.csproj | 6 + 6 files changed, 249 insertions(+) create mode 100644 CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Extensions/Nintendo/Associations/Z64.uexml create mode 100644 CSharp/Plugins/UniversalEditor.Plugins.Nintendo/DataFormats/Executable/Nintendo/N64/N64CountryCode.cs create mode 100644 CSharp/Plugins/UniversalEditor.Plugins.Nintendo/DataFormats/Executable/Nintendo/N64/N64MediaFormat.cs create mode 100644 CSharp/Plugins/UniversalEditor.Plugins.Nintendo/DataFormats/Executable/Nintendo/N64/Z64DataFormat.cs diff --git a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Extensions/Nintendo/Associations/Z64.uexml b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Extensions/Nintendo/Associations/Z64.uexml new file mode 100644 index 00000000..0d867705 --- /dev/null +++ b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Extensions/Nintendo/Associations/Z64.uexml @@ -0,0 +1,20 @@ + + + + + + + + *.z64 + + + + + + + + + + + + \ No newline at end of file diff --git a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj index 1d5f2313..c345fd44 100644 --- a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj +++ b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj @@ -659,6 +659,7 @@ + @@ -684,6 +685,8 @@ + + diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Nintendo/DataFormats/Executable/Nintendo/N64/N64CountryCode.cs b/CSharp/Plugins/UniversalEditor.Plugins.Nintendo/DataFormats/Executable/Nintendo/N64/N64CountryCode.cs new file mode 100644 index 00000000..63f43f0a --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Nintendo/DataFormats/Executable/Nintendo/N64/N64CountryCode.cs @@ -0,0 +1,107 @@ +// +// N64CountryCode.cs +// +// Author: +// Mike Becker +// +// Copyright (c) 2019 Mike Becker +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.DataFormats.Executable.Nintendo.N64 +{ + public enum N64CountryCode : byte + { + /// + /// Beta - '7' + /// + Beta = 0x37, + /// + /// Asian (NTSC) - 'A' + /// + Asian = 0x41, + /// + /// Brazilian - 'B' + /// + Brazilian = 0x42, + /// + /// Chinese - 'C' + /// + Chinese, + /// + /// German - 'D' + /// + German = 0x44, + /// + /// North America - 'E' + /// + NorthAmerica = 0x45, + /// + /// French - 'F' + /// + French = 0x46, + /// + /// LodgeNet Gateway64 (NTSC) - 'G' + /// + Gateway64NTSC = 0x47, + /// + /// Dutch - 'H' + /// + Dutch = 0x48, + /// + /// Italian - 'I' + /// + Italian = 0x49, + /// + /// Japanese - 'J' + /// + Japanese = 0x4A, + /// + /// Korean - 'K' + /// + Korean = 0x4B, + /// + /// LodgeNet Gateway64 (PAL) - 'L' + /// + Gateway64PAL = 0x4C, + /// + /// Canadian ('N') + /// + Canadian = 0x4E, + /// + /// European (basic spec) - 'P' + /// + EuropeanBasic = 0x50, + /// + /// Spanish - 'S' + /// + Spanish = 0x53, + /// + /// Australian - 'U' + /// + Australian = 0x55, + /// + /// Scandinavian - 'W' + /// + Scandinavian = 0x57, + /// + /// European - 'X' + /// + European1 = 0x58, + /// + /// European - 'Y' + /// + European2 = 0x59 + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Nintendo/DataFormats/Executable/Nintendo/N64/N64MediaFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.Nintendo/DataFormats/Executable/Nintendo/N64/N64MediaFormat.cs new file mode 100644 index 00000000..0de375f5 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Nintendo/DataFormats/Executable/Nintendo/N64/N64MediaFormat.cs @@ -0,0 +1,32 @@ +// +// N64MediaFormat.cs +// +// Author: +// Mike Becker +// +// Copyright (c) 2019 Mike Becker +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.DataFormats.Executable.Nintendo.N64 +{ + public enum N64MediaFormat : uint + { + CartridgeExpandable = 67, + SixtyFourDD = 68, + SixtyFourDDExpansion = 69, + Cartridge = 78, + Aleck64 = 90 + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Nintendo/DataFormats/Executable/Nintendo/N64/Z64DataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.Nintendo/DataFormats/Executable/Nintendo/N64/Z64DataFormat.cs new file mode 100644 index 00000000..83e06713 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Nintendo/DataFormats/Executable/Nintendo/N64/Z64DataFormat.cs @@ -0,0 +1,81 @@ +// +// Z64DataFormat.cs +// +// Author: +// Mike Becker +// +// Copyright (c) 2019 Mike Becker +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using UniversalEditor.IO; +using UniversalEditor.ObjectModels.Executable; + +namespace UniversalEditor.DataFormats.Executable.Nintendo.N64 +{ + public class Z64DataFormat : DataFormat + { + private static DataFormatReference _dfr = null; + protected override DataFormatReference MakeReferenceInternal() + { + if (_dfr == null) + { + _dfr = base.MakeReferenceInternal(); + _dfr.Capabilities.Add(typeof(ExecutableObjectModel), DataFormatCapabilities.All); + } + return _dfr; + } + + protected override void LoadInternal(ref ObjectModel objectModel) + { + ExecutableObjectModel exe = (objectModel as ExecutableObjectModel); + + Reader reader = Accessor.Reader; + + byte endiannessIndicator = reader.ReadByte(); + byte initialPI_BSB_DOM1_LAT_REG = reader.ReadByte(); + if (endiannessIndicator == 0x80 && initialPI_BSB_DOM1_LAT_REG == 0x37) + { + reader.Endianness = Endianness.BigEndian; + } + else if (endiannessIndicator == 0x37 && initialPI_BSB_DOM1_LAT_REG == 0x80) + { + reader.Endianness = Endianness.LittleEndian; + } + byte initialPI_BSD_DOM1_PWD_REG = reader.ReadByte(); + byte initialPI_BSB_DOM1_PGS_REG = reader.ReadByte(); + + uint clockRateOverride = reader.ReadUInt32(); + uint programCounter = reader.ReadUInt32(); + uint releaseAddress = reader.ReadUInt32(); + uint crc1 = reader.ReadUInt32(); + uint crc2 = reader.ReadUInt32(); + ulong unknown1 = reader.ReadUInt64(); // zero + string imageName = reader.ReadFixedLengthString(20).TrimNull().Trim(); + uint unknown2 = reader.ReadUInt32(); // zero + N64MediaFormat mediaformat = (N64MediaFormat) reader.ReadUInt32(); + string cartridgeID = reader.ReadFixedLengthString(2); + N64CountryCode countryCode = (N64CountryCode) reader.ReadByte(); + byte version = reader.ReadByte(); + + byte[] bootloader = reader.ReadBytes(4032); + exe.Sections.Add("bootloader", bootloader); + } + + protected override void SaveInternal(ObjectModel objectModel) + { + throw new NotImplementedException(); + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Nintendo/UniversalEditor.Plugins.Nintendo.csproj b/CSharp/Plugins/UniversalEditor.Plugins.Nintendo/UniversalEditor.Plugins.Nintendo.csproj index 313f005b..f9e5152f 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.Nintendo/UniversalEditor.Plugins.Nintendo.csproj +++ b/CSharp/Plugins/UniversalEditor.Plugins.Nintendo/UniversalEditor.Plugins.Nintendo.csproj @@ -51,6 +51,9 @@ + + + @@ -66,6 +69,9 @@ UniversalEditor.Plugins.Executable + + +