// /*************************************************************************** // Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : Saturn.cs // Author(s) : Natalia Portillo // // Component : Device structures decoders. // // --[ Description ] ---------------------------------------------------------- // // Decodes Sega Saturn IP.BIN. // // --[ License ] -------------------------------------------------------------- // // This library is free software; you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; either version 2.1 of the // License, or (at your option) any later version. // // This library 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 // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, see . // // ---------------------------------------------------------------------------- // Copyright © 2011-2025 Natalia Portillo // ****************************************************************************/ using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.InteropServices; using System.Text; using Aaru.Logging; using Marshal = Aaru.Helpers.Marshal; namespace Aaru.Decoders.Sega; /// Represents the IP.BIN from a SEGA Saturn [SuppressMessage("ReSharper", "InconsistentNaming")] [SuppressMessage("ReSharper", "MemberCanBeInternal")] [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] public static class Saturn { const string MODULE_NAME = "Saturn IP.BIN Decoder"; /// Decodes an IP.BIN sector in Saturn format /// IP.BIN sector /// Decoded IP.BIN public static IPBin? DecodeIPBin(byte[] ipbin_sector) { if(ipbin_sector == null) return null; if(ipbin_sector.Length < 512) return null; IPBin ipbin = Marshal.ByteArrayToStructureLittleEndian(ipbin_sector); AaruLogging.Debug(MODULE_NAME, "saturn_ipbin.maker_id = \"{0}\"", Encoding.ASCII.GetString(ipbin.maker_id)); AaruLogging.Debug(MODULE_NAME, "saturn_ipbin.product_no = \"{0}\"", Encoding.ASCII.GetString(ipbin.product_no)); AaruLogging.Debug(MODULE_NAME, "saturn_ipbin.product_version = \"{0}\"", Encoding.ASCII.GetString(ipbin.product_version)); AaruLogging.Debug(MODULE_NAME, "saturn_ipbin.release_date = \"{0}\"", Encoding.ASCII.GetString(ipbin.release_date)); AaruLogging.Debug(MODULE_NAME, "saturn_ipbin.saturn_media = \"{0}\"", Encoding.ASCII.GetString(ipbin.saturn_media)); AaruLogging.Debug(MODULE_NAME, "saturn_ipbin.disc_no = {0}", (char)ipbin.disc_no); AaruLogging.Debug(MODULE_NAME, "saturn_ipbin.disc_no_separator = \"{0}\"", (char)ipbin.disc_no_separator); AaruLogging.Debug(MODULE_NAME, "saturn_ipbin.disc_total_nos = {0}", (char)ipbin.disc_total_nos); AaruLogging.Debug(MODULE_NAME, "saturn_ipbin.release_date = \"{0}\"", Encoding.ASCII.GetString(ipbin.release_date)); AaruLogging.Debug(MODULE_NAME, "saturn_ipbin.spare_space1 = \"{0}\"", Encoding.ASCII.GetString(ipbin.spare_space1)); AaruLogging.Debug(MODULE_NAME, "saturn_ipbin.region_codes = \"{0}\"", Encoding.ASCII.GetString(ipbin.region_codes)); AaruLogging.Debug(MODULE_NAME, "saturn_ipbin.peripherals = \"{0}\"", Encoding.ASCII.GetString(ipbin.peripherals)); AaruLogging.Debug(MODULE_NAME, "saturn_ipbin.product_name = \"{0}\"", Encoding.ASCII.GetString(ipbin.product_name)); return Encoding.ASCII.GetString(ipbin.SegaHardwareID) == "SEGA SEGASATURN " ? ipbin : null; } /// Pretty prints a decoded IP.BIN in Saturn format /// Decoded IP.BIN /// Description of the IP.BIN contents public static string Prettify(IPBin? decoded) { if(decoded == null) return null; IPBin ipbin = decoded.Value; var IPBinInformation = new StringBuilder(); IPBinInformation.AppendLine("--------------------------------"); IPBinInformation.AppendLine(Localization.SEGA_IP_BIN_INFORMATION); IPBinInformation.AppendLine("--------------------------------"); // Decoding all data CultureInfo provider = CultureInfo.InvariantCulture; var ipbindate = DateTime.ParseExact(Encoding.ASCII.GetString(ipbin.release_date), "yyyyMMdd", provider); IPBinInformation.AppendFormat(Localization.Product_name_0, Encoding.ASCII.GetString(ipbin.product_name)) .AppendLine(); IPBinInformation.Append($"Product number: {Encoding.ASCII.GetString(ipbin.product_no)}").AppendLine(); IPBinInformation.AppendFormat(Localization.Product_version_0, Encoding.ASCII.GetString(ipbin.product_version)) .AppendLine(); IPBinInformation.AppendFormat(Localization.Release_date_0, ipbindate).AppendLine(); IPBinInformation.AppendFormat(Localization.Disc_number_0_of_1, (char)ipbin.disc_no, (char)ipbin.disc_total_nos) .AppendLine(); IPBinInformation.AppendFormat(Localization.Peripherals).AppendLine(); foreach(byte peripheral in ipbin.peripherals) { switch((char)peripheral) { case 'A': IPBinInformation.AppendLine(Localization.Game_supports_analog_controller); break; case 'J': IPBinInformation.AppendLine(Localization.Game_supports_JoyPad); break; case 'K': IPBinInformation.AppendLine(Localization.Game_supports_keyboard); break; case 'M': IPBinInformation.AppendLine(Localization.Game_supports_mouse); break; case 'S': IPBinInformation.AppendLine(Localization.Game_supports_analog_steering_controller); break; case 'T': IPBinInformation.AppendLine(Localization.Game_supports_multitap); break; case ' ': break; default: IPBinInformation.AppendFormat(Localization.Game_supports_unknown_peripheral_0, peripheral) .AppendLine(); break; } } IPBinInformation.AppendLine(Localization.Regions_supported); foreach(byte region in ipbin.region_codes) { switch((char)region) { case 'J': IPBinInformation.AppendLine(Localization.Japanese_NTSC); break; case 'U': IPBinInformation.AppendLine(Localization.North_America_NTSC); break; case 'E': IPBinInformation.AppendLine(Localization.Europe_PAL); break; case 'T': IPBinInformation.AppendLine(Localization.Asia_NTSC); break; case ' ': break; default: IPBinInformation.AppendFormat(Localization.Game_supports_unknown_region_0, region).AppendLine(); break; } } return IPBinInformation.ToString(); } #region Nested type: IPBin [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct IPBin { /// Must be "SEGA SEGASATURN " [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] SegaHardwareID; /// 0x010, "SEGA ENTERPRISES" [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] maker_id; /// 0x020, Product number [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)] public byte[] product_no; /// 0x02A, Product version [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] public byte[] product_version; /// 0x030, YYYYMMDD [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] release_date; /// 0x038, "CD-" [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] saturn_media; /// 0x03B, Disc number public byte disc_no; /// // 0x03C, '/' public byte disc_no_separator; /// // 0x03D, Total number of discs public byte disc_total_nos; /// 0x03E, " " [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] spare_space1; /// 0x040, Region codes, space-filled [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] region_codes; /// 0x050, Supported peripherals, see above [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] peripherals; /// 0x060, Game name, space-filled [MarshalAs(UnmanagedType.ByValArray, SizeConst = 112)] public byte[] product_name; } #endregion }