mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add and use Endianness enum
This commit is contained in:
@@ -257,7 +257,7 @@ namespace SabreTools.Library.DatFiles
|
||||
Name = reader.GetAttribute("name"),
|
||||
Size = Sanitizer.CleanSize(reader.GetAttribute("size")),
|
||||
Width = reader.GetAttribute("width"),
|
||||
Endianness = reader.GetAttribute("endianness"),
|
||||
Endianness = reader.GetAttribute("endianness").AsEndianness(),
|
||||
};
|
||||
|
||||
List<DatItem> roms = ReadDataArea(reader.ReadSubtree(), dataArea);
|
||||
@@ -770,7 +770,7 @@ namespace SabreTools.Library.DatFiles
|
||||
xtw.WriteRequiredAttributeString("name", dataAreaName);
|
||||
xtw.WriteOptionalAttributeString("size", rom.DataArea?.Size.ToString());
|
||||
xtw.WriteOptionalAttributeString("width", rom.DataArea?.Width);
|
||||
xtw.WriteOptionalAttributeString("endianness", rom.DataArea?.Endianness);
|
||||
xtw.WriteOptionalAttributeString("endianness", rom.DataArea?.Endianness.FromEndianness());
|
||||
|
||||
xtw.WriteStartElement("rom");
|
||||
xtw.WriteRequiredAttributeString("name", rom.Name);
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace SabreTools.Library.DatItems
|
||||
/// Byte endianness of the area
|
||||
/// </summary>
|
||||
[JsonProperty("endianness", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Endianness { get; set; } // TODO: (big|little) "little"
|
||||
public Endianness Endianness { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -50,6 +50,22 @@ namespace SabreTools.Library.DatItems
|
||||
External = 1 << 3,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine the endianness
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum Endianness
|
||||
{
|
||||
/// <summary>
|
||||
/// This is a fake flag that is used for filter only
|
||||
/// </summary>
|
||||
NULL = 0,
|
||||
|
||||
// TODO: (big|little) "little"
|
||||
Big = 1 << 0,
|
||||
Little = 1 << 1,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine the emulation status
|
||||
/// </summary>
|
||||
|
||||
@@ -665,9 +665,6 @@ namespace SabreTools.Library.DatItems
|
||||
if (filter.Machine_Runnable.MatchesNegative(Runnable.NULL, Runnable) == true)
|
||||
return false;
|
||||
|
||||
// TODO: Inputs
|
||||
// TODO: Inputs.Controls
|
||||
|
||||
#endregion // ListXML
|
||||
|
||||
#region Logiqx
|
||||
@@ -781,7 +778,6 @@ namespace SabreTools.Library.DatItems
|
||||
/// Remove fields from the Machine
|
||||
/// </summary>
|
||||
/// <param name="fields">List of Fields to remove</param>
|
||||
/// TODO: Add new ListXML and SoftwareList fields
|
||||
public void RemoveFields(List<Field> fields)
|
||||
{
|
||||
#region Common
|
||||
@@ -928,7 +924,6 @@ namespace SabreTools.Library.DatItems
|
||||
/// <param name="item">DatItem to pull new information from</param>
|
||||
/// <param name="fields">List of Fields representing what should be updated</param>
|
||||
/// <param name="onlySame">True if descriptions should only be replaced if the game name is the same, false otherwise</param>
|
||||
/// TODO: Add new ListXML and SoftwareList fields
|
||||
public void ReplaceFields(Machine machine, List<Field> fields, bool onlySame)
|
||||
{
|
||||
#region Common
|
||||
|
||||
@@ -397,7 +397,7 @@ namespace SabreTools.Library.DatItems
|
||||
if (DataArea == null)
|
||||
DataArea = new DataArea();
|
||||
|
||||
DataArea.Endianness = mappings[Field.DatItem_AreaEndianness];
|
||||
DataArea.Endianness = mappings[Field.DatItem_AreaEndianness].AsEndianness();
|
||||
}
|
||||
|
||||
if (mappings.Keys.Contains(Field.DatItem_LoadFlag))
|
||||
@@ -913,9 +913,9 @@ namespace SabreTools.Library.DatItems
|
||||
return false;
|
||||
|
||||
// Filter on area endianness
|
||||
if (filter.DatItem_AreaEndianness.MatchesPositiveSet(DataArea?.Endianness) == false)
|
||||
if (filter.DatItem_AreaEndianness.MatchesPositive(Endianness.NULL, DataArea?.Endianness ?? Endianness.NULL) == false)
|
||||
return false;
|
||||
if (filter.DatItem_AreaEndianness.MatchesNegativeSet(DataArea?.Endianness) == true)
|
||||
if (filter.DatItem_AreaEndianness.MatchesNegative(Endianness.NULL, DataArea?.Endianness ?? Endianness.NULL) == true)
|
||||
return false;
|
||||
|
||||
// Filter on load flag
|
||||
@@ -1069,7 +1069,7 @@ namespace SabreTools.Library.DatItems
|
||||
if (fields.Contains(Field.DatItem_AreaEndianness))
|
||||
{
|
||||
if (DataArea != null)
|
||||
DataArea.Endianness = null;
|
||||
DataArea.Endianness = Endianness.NULL;
|
||||
}
|
||||
|
||||
if (fields.Contains(Field.DatItem_LoadFlag))
|
||||
@@ -1317,7 +1317,7 @@ namespace SabreTools.Library.DatItems
|
||||
if (DataArea == null)
|
||||
DataArea = new DataArea();
|
||||
|
||||
DataArea.Endianness = newItem.DataArea?.Endianness;
|
||||
DataArea.Endianness = newItem.DataArea?.Endianness ?? Endianness.NULL;
|
||||
}
|
||||
|
||||
if (fields.Contains(Field.DatItem_LoadFlag))
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace SabreTools.Library.Filtering
|
||||
public FilterItem<string> DatItem_AreaName { get; private set; } = new FilterItem<string>();
|
||||
public FilterItem<long?> DatItem_AreaSize { get; private set; } = new FilterItem<long?>() { Positive = null, Negative = null, Neutral = null };
|
||||
public FilterItem<string> DatItem_AreaWidth { get; private set; } = new FilterItem<string>();
|
||||
public FilterItem<string> DatItem_AreaEndianness { get; private set; } = new FilterItem<string>();
|
||||
public FilterItem<Endianness> DatItem_AreaEndianness { get; private set; } = new FilterItem<Endianness>() { Positive = Endianness.NULL, Negative = Endianness.NULL };
|
||||
public FilterItem<LoadFlag> DatItem_LoadFlag { get; private set; } = new FilterItem<LoadFlag>() { Positive = LoadFlag.NULL, Negative = LoadFlag.NULL };
|
||||
public FilterItem<string> DatItem_Part_Name { get; private set; } = new FilterItem<string>();
|
||||
public FilterItem<string> DatItem_Part_Interface { get; private set; } = new FilterItem<string>();
|
||||
@@ -921,9 +921,9 @@ namespace SabreTools.Library.Filtering
|
||||
|
||||
case Field.DatItem_AreaEndianness:
|
||||
if (negate)
|
||||
DatItem_AreaEndianness.NegativeSet.Add(value);
|
||||
DatItem_AreaEndianness.Negative |= value.AsEndianness();
|
||||
else
|
||||
DatItem_AreaEndianness.PositiveSet.Add(value);
|
||||
DatItem_AreaEndianness.Positive |= value.AsEndianness();
|
||||
break;
|
||||
|
||||
case Field.DatItem_LoadFlag:
|
||||
|
||||
@@ -208,6 +208,33 @@ namespace SabreTools.Library.Tools
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Endianness value from input string
|
||||
/// </summary>
|
||||
/// <param name="endianness">String to get value from</param>
|
||||
/// <returns>Endianness value corresponding to the string</returns>
|
||||
public static Endianness AsEndianness(this string endianness)
|
||||
{
|
||||
#if NET_FRAMEWORK
|
||||
switch (endianness?.ToLowerInvariant())
|
||||
{
|
||||
case "big":
|
||||
return Endianness.Big;
|
||||
case "little":
|
||||
return Endianness.Little;
|
||||
default:
|
||||
return Endianness.NULL;
|
||||
}
|
||||
#else
|
||||
return endianness?.ToLowerInvariant() switch
|
||||
{
|
||||
"big" => Endianness.Big,
|
||||
"little" => Endianness.Little,
|
||||
_ => Endianness.NULL,
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get FeatureStatus value from input string
|
||||
/// </summary>
|
||||
@@ -2207,6 +2234,33 @@ namespace SabreTools.Library.Tools
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input Endianness
|
||||
/// </summary>
|
||||
/// <param name="endianness">Endianness to get value from</param>
|
||||
/// <returns>String value corresponding to the Endianness</returns>
|
||||
public static string FromEndianness(this Endianness endianness)
|
||||
{
|
||||
#if NET_FRAMEWORK
|
||||
switch (endianness)
|
||||
{
|
||||
case Endianness.Big:
|
||||
return "big";
|
||||
case Endianness.Little:
|
||||
return "little";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
#else
|
||||
return endianness switch
|
||||
{
|
||||
Endianness.Big => "big",
|
||||
Endianness.Little => "little",
|
||||
_ => null,
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input FeatureStatus
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user