2017-10-08 17:50:29 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Saturn.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Device structures decoders.
|
2017-10-08 17:50:29 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Decodes Sega Saturn IP.BIN.
|
2017-10-08 17:50:29 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:28 +00:00
|
|
|
|
// Copyright © 2011-2020 Natalia Portillo
|
2017-10-08 17:50:29 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 19:33:46 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
using System;
|
2017-12-22 02:04:18 +00:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2017-10-08 17:50:29 +01:00
|
|
|
|
using System.Globalization;
|
2017-10-08 18:55:06 +01:00
|
|
|
|
using System.Runtime.InteropServices;
|
2017-10-08 17:50:29 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using DiscImageChef.Console;
|
2019-02-28 00:04:13 +00:00
|
|
|
|
using Marshal = DiscImageChef.Helpers.Marshal;
|
2017-10-08 17:50:29 +01:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Decoders.Sega
|
|
|
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
|
|
|
|
|
|
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
2017-10-08 17:50:29 +01:00
|
|
|
|
public static class Saturn
|
|
|
|
|
|
{
|
|
|
|
|
|
public static IPBin? DecodeIPBin(byte[] ipbin_sector)
|
|
|
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
|
if(ipbin_sector == null)
|
|
|
|
|
|
return null;
|
2017-10-08 17:50:29 +01:00
|
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
|
if(ipbin_sector.Length < 512)
|
|
|
|
|
|
return null;
|
2017-10-08 17:50:29 +01:00
|
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
|
var ipbin = Marshal.ByteArrayToStructureLittleEndian<IPBin>(ipbin_sector);
|
2017-10-08 17:50:29 +01:00
|
|
|
|
|
2018-09-09 19:54:08 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.maker_id = \"{0}\"",
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Encoding.ASCII.GetString(ipbin.maker_id));
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2018-09-09 19:54:08 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.product_no = \"{0}\"",
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Encoding.ASCII.GetString(ipbin.product_no));
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2018-09-09 19:54:08 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.product_version = \"{0}\"",
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Encoding.ASCII.GetString(ipbin.product_version));
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2018-09-09 19:54:08 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.release_datedate = \"{0}\"",
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Encoding.ASCII.GetString(ipbin.release_date));
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2018-09-09 19:54:08 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.saturn_media = \"{0}\"",
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Encoding.ASCII.GetString(ipbin.saturn_media));
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2018-09-09 19:54:08 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.disc_no = {0}", (char)ipbin.disc_no);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2018-09-09 19:54:08 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.disc_no_separator = \"{0}\"",
|
2017-12-19 20:33:03 +00:00
|
|
|
|
(char)ipbin.disc_no_separator);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2018-09-09 19:54:08 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.disc_total_nos = {0}",
|
2017-12-19 20:33:03 +00:00
|
|
|
|
(char)ipbin.disc_total_nos);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2018-09-09 19:54:08 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.release_date = \"{0}\"",
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Encoding.ASCII.GetString(ipbin.release_date));
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2018-09-09 19:54:08 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.spare_space1 = \"{0}\"",
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Encoding.ASCII.GetString(ipbin.spare_space1));
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2018-09-09 19:54:08 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.region_codes = \"{0}\"",
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Encoding.ASCII.GetString(ipbin.region_codes));
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2018-09-09 19:54:08 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.peripherals = \"{0}\"",
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Encoding.ASCII.GetString(ipbin.peripherals));
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2018-09-09 19:54:08 +01:00
|
|
|
|
DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.product_name = \"{0}\"",
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Encoding.ASCII.GetString(ipbin.product_name));
|
2017-10-08 17:50:29 +01:00
|
|
|
|
|
2017-10-08 18:55:06 +01:00
|
|
|
|
return Encoding.ASCII.GetString(ipbin.SegaHardwareID) == "SEGA SEGASATURN " ? ipbin : (IPBin?)null;
|
2017-10-08 17:50:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string Prettify(IPBin? decoded)
|
|
|
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
|
if(decoded == null)
|
|
|
|
|
|
return null;
|
2017-10-08 17:50:29 +01:00
|
|
|
|
|
|
|
|
|
|
IPBin ipbin = decoded.Value;
|
|
|
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
|
var IPBinInformation = new StringBuilder();
|
2017-10-08 17:50:29 +01:00
|
|
|
|
|
|
|
|
|
|
IPBinInformation.AppendLine("--------------------------------");
|
|
|
|
|
|
IPBinInformation.AppendLine("SEGA IP.BIN INFORMATION:");
|
|
|
|
|
|
IPBinInformation.AppendLine("--------------------------------");
|
|
|
|
|
|
|
|
|
|
|
|
// Decoding all data
|
2018-06-22 08:08:38 +01:00
|
|
|
|
DateTime ipbindate;
|
2017-10-08 17:50:29 +01:00
|
|
|
|
CultureInfo provider = CultureInfo.InvariantCulture;
|
|
|
|
|
|
ipbindate = DateTime.ParseExact(Encoding.ASCII.GetString(ipbin.release_date), "yyyyMMdd", provider);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
|
|
|
|
|
IPBinInformation.AppendFormat("Product name: {0}", Encoding.ASCII.GetString(ipbin.product_name)).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
|
|
|
|
|
IPBinInformation.AppendFormat("Product number: {0}", Encoding.ASCII.GetString(ipbin.product_no)).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
|
|
|
|
|
IPBinInformation.AppendFormat("Product version: {0}", Encoding.ASCII.GetString(ipbin.product_version)).
|
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
IPBinInformation.AppendFormat("Release date: {0}", ipbindate).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
|
|
|
|
|
IPBinInformation.AppendFormat("Disc number {0} of {1}", (char)ipbin.disc_no, (char)ipbin.disc_total_nos).
|
|
|
|
|
|
AppendLine();
|
2017-10-08 17:50:29 +01:00
|
|
|
|
|
|
|
|
|
|
IPBinInformation.AppendFormat("Peripherals:").AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
foreach(byte peripheral in ipbin.peripherals)
|
|
|
|
|
|
switch((char)peripheral)
|
|
|
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
|
case'A':
|
2017-10-08 17:50:29 +01:00
|
|
|
|
IPBinInformation.AppendLine("Game supports analog controller.");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
break;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
case'J':
|
2017-10-08 17:50:29 +01:00
|
|
|
|
IPBinInformation.AppendLine("Game supports JoyPad.");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
break;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
case'K':
|
2017-10-08 17:50:29 +01:00
|
|
|
|
IPBinInformation.AppendLine("Game supports keyboard.");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
break;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
case'M':
|
2017-10-08 17:50:29 +01:00
|
|
|
|
IPBinInformation.AppendLine("Game supports mouse.");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
break;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
case'S':
|
2017-10-08 17:50:29 +01:00
|
|
|
|
IPBinInformation.AppendLine("Game supports analog steering controller.");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
break;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
case'T':
|
2017-10-08 17:50:29 +01:00
|
|
|
|
IPBinInformation.AppendLine("Game supports multitap.");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
break;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
case' ': break;
|
2017-10-08 17:50:29 +01:00
|
|
|
|
default:
|
|
|
|
|
|
IPBinInformation.AppendFormat("Game supports unknown peripheral {0}.", peripheral).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
IPBinInformation.AppendLine("Regions supported:");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
foreach(byte region in ipbin.region_codes)
|
|
|
|
|
|
switch((char)region)
|
|
|
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
|
case'J':
|
2017-10-08 17:50:29 +01:00
|
|
|
|
IPBinInformation.AppendLine("Japanese NTSC.");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
break;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
case'U':
|
2017-10-08 17:50:29 +01:00
|
|
|
|
IPBinInformation.AppendLine("North America NTSC.");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
break;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
case'E':
|
2017-10-08 17:50:29 +01:00
|
|
|
|
IPBinInformation.AppendLine("Europe PAL.");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
break;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
case'T':
|
2017-10-08 17:50:29 +01:00
|
|
|
|
IPBinInformation.AppendLine("Asia NTSC.");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
break;
|
2019-11-25 00:54:38 +00:00
|
|
|
|
case' ': break;
|
2017-10-08 17:50:29 +01:00
|
|
|
|
default:
|
|
|
|
|
|
IPBinInformation.AppendFormat("Game supports unknown region {0}.", region).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
2017-10-08 17:50:29 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return IPBinInformation.ToString();
|
|
|
|
|
|
}
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
public struct IPBin
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>Must be "SEGA SEGASATURN "</summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
|
|
|
|
|
public byte[] SegaHardwareID;
|
|
|
|
|
|
/// <summary>0x010, "SEGA ENTERPRISES"</summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
|
|
|
|
|
public byte[] maker_id;
|
|
|
|
|
|
/// <summary>0x020, Product number</summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
|
|
|
|
|
|
public byte[] product_no;
|
|
|
|
|
|
/// <summary>0x02A, Product version</summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
|
|
|
|
|
|
public byte[] product_version;
|
|
|
|
|
|
/// <summary>0x030, YYYYMMDD</summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
|
|
|
|
|
public byte[] release_date;
|
|
|
|
|
|
/// <summary>0x038, "CD-"</summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
|
|
|
|
|
public byte[] saturn_media;
|
|
|
|
|
|
/// <summary>0x03B, Disc number</summary>
|
|
|
|
|
|
public byte disc_no;
|
|
|
|
|
|
/// <summary>// 0x03C, '/'</summary>
|
|
|
|
|
|
public byte disc_no_separator;
|
|
|
|
|
|
/// <summary>// 0x03D, Total number of discs</summary>
|
|
|
|
|
|
public byte disc_total_nos;
|
|
|
|
|
|
/// <summary>0x03E, " "</summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
|
|
|
|
|
public byte[] spare_space1;
|
|
|
|
|
|
/// <summary>0x040, Region codes, space-filled</summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
|
|
|
|
|
public byte[] region_codes;
|
|
|
|
|
|
/// <summary>0x050, Supported peripherals, see above</summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
|
|
|
|
|
public byte[] peripherals;
|
|
|
|
|
|
/// <summary>0x060, Game name, space-filled</summary>
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 112)]
|
|
|
|
|
|
public byte[] product_name;
|
|
|
|
|
|
}
|
2017-10-08 17:50:29 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|