diff --git a/SabreTools.Library/DatFiles/ItemDictionary.cs b/SabreTools.Library/DatFiles/ItemDictionary.cs index 4819eeed..92bf0a4b 100644 --- a/SabreTools.Library/DatFiles/ItemDictionary.cs +++ b/SabreTools.Library/DatFiles/ItemDictionary.cs @@ -113,6 +113,12 @@ namespace SabreTools.Library.DatFiles [JsonIgnore] public long DeviceReferenceCount { get; private set; } = 0; + /// + /// Number of DIP Switch items + /// + [JsonIgnore] + public long DipSwitchCount { get; private set; } = 0; + /// /// Number of Disk items /// @@ -500,6 +506,9 @@ namespace SabreTools.Library.DatFiles case ItemType.DeviceReference: DeviceReferenceCount++; break; + case ItemType.DipSwitch: + DipSwitchCount++; + break; case ItemType.Disk: DiskCount++; if ((item as Disk).ItemStatus != ItemStatus.Nodump) @@ -644,6 +653,9 @@ namespace SabreTools.Library.DatFiles case ItemType.DeviceReference: DeviceReferenceCount--; break; + case ItemType.DipSwitch: + DipSwitchCount--; + break; case ItemType.Disk: DiskCount--; if ((item as Disk).ItemStatus != ItemStatus.Nodump) diff --git a/SabreTools.Library/DatFiles/Json.cs b/SabreTools.Library/DatFiles/Json.cs index 3e1c22c0..bda51aa2 100644 --- a/SabreTools.Library/DatFiles/Json.cs +++ b/SabreTools.Library/DatFiles/Json.cs @@ -229,6 +229,9 @@ namespace SabreTools.Library.DatFiles case ItemType.DeviceReference: datItem = datItemObj.ToObject(); break; + case ItemType.DipSwitch: + datItem = datItemObj.ToObject(); + break; case ItemType.Disk: datItem = datItemObj.ToObject(); break; diff --git a/SabreTools.Library/DatFiles/Listxml.cs b/SabreTools.Library/DatFiles/Listxml.cs index ce133632..633734df 100644 --- a/SabreTools.Library/DatFiles/Listxml.cs +++ b/SabreTools.Library/DatFiles/Listxml.cs @@ -247,6 +247,24 @@ namespace SabreTools.Library.DatFiles reader.Read(); break; + case "dipswitch": + var dipSwitch = new DipSwitch + { + Name = reader.GetAttribute("name"), + Tag = reader.GetAttribute("tag"), + Mask = reader.GetAttribute("mask"), + Conditions = new List(), + Locations = new List(), + Values = new List(), + }; + + // Now read the internal tags + ReadDipSwitch(reader.ReadSubtree(), dipSwitch); + + // Skip the dipswitch now that we've processed it + reader.Skip(); + break; + case "disk": datItems.Add(new Disk { @@ -411,25 +429,6 @@ namespace SabreTools.Library.DatFiles reader.Skip(); break; - case "dipswitch": - var dipSwitch = new ListXmlDipSwitch(); - dipSwitch.Name = reader.GetAttribute("name"); - dipSwitch.Tag = reader.GetAttribute("tag"); - dipSwitch.Mask = reader.GetAttribute("mask"); - - // Now read the internal tags - ReadDipSwitch(reader.ReadSubtree(), dipSwitch); - - // Ensure the list exists - if (machine.DipSwitches == null) - machine.DipSwitches = new List(); - - machine.DipSwitches.Add(dipSwitch); - - // Skip the dipswitch now that we've processed it - reader.Skip(); - break; - case "port": var port = new ListXmlPort(); port.Tag = reader.GetAttribute("tag"); @@ -658,8 +657,8 @@ namespace SabreTools.Library.DatFiles /// Read DipSwitch information /// /// XmlReader representing a diskarea block - /// ListXmlDipSwitch to populate - private void ReadDipSwitch(XmlReader reader, ListXmlDipSwitch dipSwitch) + /// DipSwitch to populate + private void ReadDipSwitch(XmlReader reader, DipSwitch dipSwitch) { // If we have an empty dipswitch, skip it if (reader == null) @@ -1289,80 +1288,6 @@ namespace SabreTools.Library.DatFiles xtw.WriteEndElement(); } } - if (datItem.Machine.DipSwitches != null) - { - foreach (var dipSwitch in datItem.Machine.DipSwitches) - { - xtw.WriteStartElement("dipswitch"); - - xtw.WriteOptionalAttributeString("name", dipSwitch.Name); - xtw.WriteOptionalAttributeString("tag", dipSwitch.Tag); - xtw.WriteOptionalAttributeString("mask", dipSwitch.Mask); - - if (dipSwitch.Conditions != null) - { - foreach (var condition in dipSwitch.Conditions) - { - xtw.WriteStartElement("condition"); - - xtw.WriteOptionalAttributeString("tag", condition.Tag); - xtw.WriteOptionalAttributeString("mask", condition.Mask); - xtw.WriteOptionalAttributeString("relation", condition.Relation); - xtw.WriteOptionalAttributeString("value", condition.Value); - - // End condition - xtw.WriteEndElement(); - } - } - if (dipSwitch.Locations != null) - { - foreach (var location in dipSwitch.Locations) - { - xtw.WriteStartElement("diplocation"); - - xtw.WriteOptionalAttributeString("name", location.Name); - xtw.WriteOptionalAttributeString("number", location.Number); - xtw.WriteOptionalAttributeString("inverted", location.Inverted.FromYesNo()); - - // End diplocation - xtw.WriteEndElement(); - } - } - if (dipSwitch.Values != null) - { - foreach (var value in dipSwitch.Values) - { - xtw.WriteStartElement("dipvalue"); - - xtw.WriteOptionalAttributeString("name", value.Name); - xtw.WriteOptionalAttributeString("value", value.Value); - xtw.WriteOptionalAttributeString("default", value.Default.FromYesNo()); - - if (value.Conditions != null) - { - foreach (var condition in value.Conditions) - { - xtw.WriteStartElement("condition"); - - xtw.WriteOptionalAttributeString("tag", condition.Tag); - xtw.WriteOptionalAttributeString("mask", condition.Mask); - xtw.WriteOptionalAttributeString("relation", condition.Relation); - xtw.WriteOptionalAttributeString("value", condition.Value); - - // End condition - xtw.WriteEndElement(); - } - } - - // End dipvalue - xtw.WriteEndElement(); - } - } - - // End dipswitch - xtw.WriteEndElement(); - } - } if (datItem.Machine.Ports != null) { foreach (var port in datItem.Machine.Ports) @@ -1626,6 +1551,61 @@ namespace SabreTools.Library.DatFiles xtw.WriteEndElement(); break; + case ItemType.DipSwitch: + var dipSwitch = datItem as DipSwitch; + xtw.WriteStartElement("dipswitch"); + xtw.WriteOptionalAttributeString("name", dipSwitch.Name); + xtw.WriteOptionalAttributeString("tag", dipSwitch.Tag); + xtw.WriteOptionalAttributeString("mask", dipSwitch.Mask); + if (dipSwitch.Conditions != null) + { + foreach (var condition in dipSwitch.Conditions) + { + xtw.WriteStartElement("condition"); + xtw.WriteOptionalAttributeString("tag", condition.Tag); + xtw.WriteOptionalAttributeString("mask", condition.Mask); + xtw.WriteOptionalAttributeString("relation", condition.Relation); + xtw.WriteOptionalAttributeString("value", condition.Value); + xtw.WriteEndElement(); + } + } + if (dipSwitch.Locations != null) + { + foreach (var location in dipSwitch.Locations) + { + xtw.WriteStartElement("diplocation"); + xtw.WriteOptionalAttributeString("name", location.Name); + xtw.WriteOptionalAttributeString("number", location.Number); + xtw.WriteOptionalAttributeString("inverted", location.Inverted.FromYesNo()); + xtw.WriteEndElement(); + } + } + if (dipSwitch.Values != null) + { + foreach (var value in dipSwitch.Values) + { + xtw.WriteStartElement("dipvalue"); + xtw.WriteOptionalAttributeString("name", value.Name); + xtw.WriteOptionalAttributeString("value", value.Value); + xtw.WriteOptionalAttributeString("default", value.Default.FromYesNo()); + if (value.Conditions != null) + { + foreach (var condition in value.Conditions) + { + xtw.WriteStartElement("condition"); + xtw.WriteOptionalAttributeString("tag", condition.Tag); + xtw.WriteOptionalAttributeString("mask", condition.Mask); + xtw.WriteOptionalAttributeString("relation", condition.Relation); + xtw.WriteOptionalAttributeString("value", condition.Value); + xtw.WriteEndElement(); + } + } + xtw.WriteEndElement(); + } + } + xtw.WriteEndElement(); + break; + case ItemType.Disk: var disk = datItem as Disk; xtw.WriteStartElement("disk"); diff --git a/SabreTools.Library/DatFiles/SabreDat.cs b/SabreTools.Library/DatFiles/SabreDat.cs index 401e77a8..b3706e74 100644 --- a/SabreTools.Library/DatFiles/SabreDat.cs +++ b/SabreTools.Library/DatFiles/SabreDat.cs @@ -218,6 +218,7 @@ namespace SabreTools.Library.DatFiles /// Name of the file to be parsed /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) + /// TODO: This is horrendeously out of date. Once all done promoting, try to make this like JSON private bool ReadDirectory( XmlReader reader, List parent, @@ -350,6 +351,21 @@ namespace SabreTools.Library.DatFiles DatItem datItem; switch (reader.GetAttribute("type").ToLowerInvariant()) { + case "adjuster": + datItem = new Adjuster + { + Name = reader.GetAttribute("name"), + Default = reader.GetAttribute("default").AsYesNo(), + Conditions = new List(), + }; + + // Now read the internal tags + ReadAdjuster(reader.ReadSubtree(), datItem); + + // Skip the adjuster now that we've processed it + reader.Skip(); + break; + case "archive": datItem = new Archive { @@ -394,6 +410,51 @@ namespace SabreTools.Library.DatFiles }; break; + case "configuration": + datItem = new Configuration + { + Name = reader.GetAttribute("name"), + Tag = reader.GetAttribute("tag"), + Mask = reader.GetAttribute("mask"), + Conditions = new List(), + Locations = new List(), + Settings = new List(), + }; + + // Now read the internal tags + ReadConfiguration(reader.ReadSubtree(), datItem); + + // Skip the configuration now that we've processed it + reader.Skip(); + break; + + case "device_ref": + datItem = new DeviceReference + { + Name = reader.GetAttribute("name"), + }; + + reader.Read(); + break; + + case "dipswitch": + datItem = new DipSwitch + { + Name = reader.GetAttribute("name"), + Tag = reader.GetAttribute("tag"), + Mask = reader.GetAttribute("mask"), + Conditions = new List(), + Locations = new List(), + Values = new List(), + }; + + // Now read the internal tags + ReadDipSwitch(reader.ReadSubtree(), datItem); + + // Skip the dipswitch now that we've processed it + reader.Skip(); + break; + case "disk": datItem = new Disk { @@ -566,6 +627,314 @@ namespace SabreTools.Library.DatFiles } } + /// + /// Read Adjuster information + /// + /// XmlReader representing a diskarea block + /// Adjuster to populate + private void ReadAdjuster(XmlReader reader, DatItem adjuster) + { + // If we have an empty port, skip it + if (reader == null) + return; + + // If the DatItem isn't an Adjuster, skip it + if (adjuster.ItemType != ItemType.Adjuster) + return; + + // Get list ready + (adjuster as Adjuster).Conditions = new List(); + + // Otherwise, add what is possible + reader.MoveToContent(); + + while (!reader.EOF) + { + // We only want elements + if (reader.NodeType != XmlNodeType.Element) + { + reader.Read(); + continue; + } + + // Get the information from the adjuster + switch (reader.Name) + { + case "condition": + var condition = new ListXmlCondition(); + condition.Tag = reader.GetAttribute("tag"); + condition.Mask = reader.GetAttribute("mask"); + condition.Relation = reader.GetAttribute("relation"); + condition.Value = reader.GetAttribute("value"); + + (adjuster as Adjuster).Conditions.Add(condition); + + reader.Read(); + break; + + default: + reader.Read(); + break; + } + } + } + + /// + /// Read Configuration information + /// + /// XmlReader representing a diskarea block + /// Configuration to populate + private void ReadConfiguration(XmlReader reader, DatItem configuration) + { + // If we have an empty configuration, skip it + if (reader == null) + return; + + // If the DatItem isn't an Configuration, skip it + if (configuration.ItemType != ItemType.Configuration) + return; + + // Get lists ready + (configuration as Configuration).Conditions = new List(); + (configuration as Configuration).Locations = new List(); + (configuration as Configuration).Settings = new List(); + + // Otherwise, add what is possible + reader.MoveToContent(); + + while (!reader.EOF) + { + // We only want elements + if (reader.NodeType != XmlNodeType.Element) + { + reader.Read(); + continue; + } + + // Get the information from the dipswitch + switch (reader.Name) + { + case "condition": + var condition = new ListXmlCondition(); + condition.Tag = reader.GetAttribute("tag"); + condition.Mask = reader.GetAttribute("mask"); + condition.Relation = reader.GetAttribute("relation"); + condition.Value = reader.GetAttribute("value"); + + (configuration as Configuration).Conditions.Add(condition); + + reader.Read(); + break; + + case "conflocation": + var confLocation = new ListXmlConfLocation(); + confLocation.Name = reader.GetAttribute("name"); + confLocation.Number = reader.GetAttribute("number"); + confLocation.Inverted = reader.GetAttribute("inverted").AsYesNo(); + + (configuration as Configuration).Locations.Add(confLocation); + + reader.Read(); + break; + + case "confsetting": + var confSetting = new ListXmlConfSetting(); + confSetting.Name = reader.GetAttribute("name"); + confSetting.Value = reader.GetAttribute("value"); + confSetting.Default = reader.GetAttribute("default").AsYesNo(); + + // Now read the internal tags + ReadConfSetting(reader, confSetting); + + (configuration as Configuration).Settings.Add(confSetting); + + // Skip the dipvalue now that we've processed it + reader.Read(); + break; + + default: + reader.Read(); + break; + } + } + } + + /// + /// Read ConfSetting information + /// + /// XmlReader representing a diskarea block + /// ListXmlConfSetting to populate + private void ReadConfSetting(XmlReader reader, ListXmlConfSetting confSetting) + { + // If we have an empty confsetting, skip it + if (reader == null) + return; + + // Get list ready + confSetting.Conditions = new List(); + + // Otherwise, add what is possible + reader.MoveToContent(); + + while (!reader.EOF) + { + // We only want elements + if (reader.NodeType != XmlNodeType.Element) + { + reader.Read(); + continue; + } + + // Get the information from the confsetting + switch (reader.Name) + { + case "condition": + var condition = new ListXmlCondition(); + condition.Tag = reader.GetAttribute("tag"); + condition.Mask = reader.GetAttribute("mask"); + condition.Relation = reader.GetAttribute("relation"); + condition.Value = reader.GetAttribute("value"); + + confSetting.Conditions.Add(condition); + + reader.Read(); + break; + + default: + reader.Read(); + break; + } + } + } + + /// + /// Read DipSwitch information + /// + /// XmlReader representing a diskarea block + /// DipSwitch to populate + private void ReadDipSwitch(XmlReader reader, DatItem dipSwitch) + { + // If we have an empty dipswitch, skip it + if (reader == null) + return; + + // If the DatItem isn't an DipSwitch, skip it + if (dipSwitch.ItemType != ItemType.DipSwitch) + return; + + // Get lists ready + (dipSwitch as DipSwitch).Conditions = new List(); + (dipSwitch as DipSwitch).Locations = new List(); + (dipSwitch as DipSwitch).Values = new List(); + + // Otherwise, add what is possible + reader.MoveToContent(); + + while (!reader.EOF) + { + // We only want elements + if (reader.NodeType != XmlNodeType.Element) + { + reader.Read(); + continue; + } + + // Get the information from the dipswitch + switch (reader.Name) + { + case "condition": + var condition = new ListXmlCondition(); + condition.Tag = reader.GetAttribute("tag"); + condition.Mask = reader.GetAttribute("mask"); + condition.Relation = reader.GetAttribute("relation"); + condition.Value = reader.GetAttribute("value"); + + (dipSwitch as DipSwitch).Conditions.Add(condition); + + reader.Read(); + break; + + case "diplocation": + var dipLocation = new ListXmlDipLocation(); + dipLocation.Name = reader.GetAttribute("name"); + dipLocation.Number = reader.GetAttribute("number"); + dipLocation.Inverted = reader.GetAttribute("inverted").AsYesNo(); + + (dipSwitch as DipSwitch).Locations.Add(dipLocation); + + reader.Read(); + break; + + case "dipvalue": + var dipValue = new ListXmlDipValue(); + dipValue.Name = reader.GetAttribute("name"); + dipValue.Value = reader.GetAttribute("value"); + dipValue.Default = reader.GetAttribute("default").AsYesNo(); + + // Now read the internal tags + ReadDipValue(reader, dipValue); + + (dipSwitch as DipSwitch).Values.Add(dipValue); + + // Skip the dipvalue now that we've processed it + reader.Read(); + break; + + default: + reader.Read(); + break; + } + } + } + + /// + /// Read DipValue information + /// + /// XmlReader representing a diskarea block + /// ListXmlDipValue to populate + private void ReadDipValue(XmlReader reader, ListXmlDipValue dipValue) + { + // If we have an empty dipvalue, skip it + if (reader == null) + return; + + // Get list ready + dipValue.Conditions = new List(); + + // Otherwise, add what is possible + reader.MoveToContent(); + + while (!reader.EOF) + { + // We only want elements + if (reader.NodeType != XmlNodeType.Element) + { + reader.Read(); + continue; + } + + // Get the information from the dipvalue + switch (reader.Name) + { + case "condition": + var condition = new ListXmlCondition(); + condition.Tag = reader.GetAttribute("tag"); + condition.Mask = reader.GetAttribute("mask"); + condition.Relation = reader.GetAttribute("relation"); + condition.Value = reader.GetAttribute("value"); + + dipValue.Conditions.Add(condition); + + reader.Read(); + break; + + default: + reader.Read(); + break; + } + } + } + /// /// Create and open an output file for writing direct from a dictionary /// @@ -940,6 +1309,62 @@ namespace SabreTools.Library.DatFiles xtw.WriteEndElement(); break; + case ItemType.DipSwitch: + var dipSwitch = datItem as DipSwitch; + xtw.WriteStartElement("file"); + xtw.WriteAttributeString("type", "dipswitch"); + xtw.WriteOptionalAttributeString("name", dipSwitch.Name); + xtw.WriteOptionalAttributeString("tag", dipSwitch.Tag); + xtw.WriteOptionalAttributeString("mask", dipSwitch.Mask); + if (dipSwitch.Conditions != null) + { + foreach (var condition in dipSwitch.Conditions) + { + xtw.WriteStartElement("condition"); + xtw.WriteOptionalAttributeString("tag", condition.Tag); + xtw.WriteOptionalAttributeString("mask", condition.Mask); + xtw.WriteOptionalAttributeString("relation", condition.Relation); + xtw.WriteOptionalAttributeString("value", condition.Value); + xtw.WriteEndElement(); + } + } + if (dipSwitch.Locations != null) + { + foreach (var location in dipSwitch.Locations) + { + xtw.WriteStartElement("diplocation"); + xtw.WriteOptionalAttributeString("name", location.Name); + xtw.WriteOptionalAttributeString("number", location.Number); + xtw.WriteOptionalAttributeString("inverted", location.Inverted.FromYesNo()); + xtw.WriteEndElement(); + } + } + if (dipSwitch.Values != null) + { + foreach (var value in dipSwitch.Values) + { + xtw.WriteStartElement("dipvalue"); + xtw.WriteOptionalAttributeString("name", value.Name); + xtw.WriteOptionalAttributeString("value", value.Value); + xtw.WriteOptionalAttributeString("default", value.Default.FromYesNo()); + if (value.Conditions != null) + { + foreach (var condition in value.Conditions) + { + xtw.WriteStartElement("condition"); + xtw.WriteOptionalAttributeString("tag", condition.Tag); + xtw.WriteOptionalAttributeString("mask", condition.Mask); + xtw.WriteOptionalAttributeString("relation", condition.Relation); + xtw.WriteOptionalAttributeString("value", condition.Value); + xtw.WriteEndElement(); + } + } + xtw.WriteEndElement(); + } + } + xtw.WriteEndElement(); + break; + case ItemType.Disk: var disk = datItem as Disk; xtw.WriteStartElement("file"); diff --git a/SabreTools.Library/DatFiles/SoftwareList.cs b/SabreTools.Library/DatFiles/SoftwareList.cs index c4e22b09..bc0ef639 100644 --- a/SabreTools.Library/DatFiles/SoftwareList.cs +++ b/SabreTools.Library/DatFiles/SoftwareList.cs @@ -336,19 +336,20 @@ namespace SabreTools.Library.DatFiles break; case "dipswitch": - var dipSwitch = new ListXmlDipSwitch(); - dipSwitch.Name = reader.GetAttribute("name"); - dipSwitch.Tag = reader.GetAttribute("tag"); - dipSwitch.Mask = reader.GetAttribute("mask"); + var dipSwitch = new DipSwitch + { + Name = reader.GetAttribute("name"), + Tag = reader.GetAttribute("tag"), + Mask = reader.GetAttribute("mask"), + Conditions = new List(), + Locations = new List(), + Values = new List(), + }; // Now read the internal tags ReadDipSwitch(reader.ReadSubtree(), dipSwitch); - // Ensure the list exists - if (machine.DipSwitches == null) - machine.DipSwitches = new List(); - - machine.DipSwitches.Add(dipSwitch); + items.Add(dipSwitch); // Skip the dipswitch now that we've processed it reader.Skip(); @@ -517,8 +518,8 @@ namespace SabreTools.Library.DatFiles /// Read DipSwitch DipValues information /// /// XmlReader representing a diskarea block - /// ListXMLDipSwitch to populate - private void ReadDipSwitch(XmlReader reader, ListXmlDipSwitch dipSwitch) + /// DipSwitch to populate + private void ReadDipSwitch(XmlReader reader, DipSwitch dipSwitch) { // If we have an empty dipswitch, skip it if (reader == null) @@ -720,29 +721,6 @@ namespace SabreTools.Library.DatFiles } } - if (datItem.Machine.DipSwitches != null && datItem.Machine.DipSwitches.Count > 0) - { - foreach (ListXmlDipSwitch dip in datItem.Machine.DipSwitches) - { - xtw.WriteStartElement("dipswitch"); - xtw.WriteRequiredAttributeString("name", dip.Name); - xtw.WriteRequiredAttributeString("tag", dip.Tag); - xtw.WriteRequiredAttributeString("mask", dip.Mask); - - foreach (ListXmlDipValue dipval in dip.Values) - { - xtw.WriteStartElement("dipvalue"); - xtw.WriteRequiredAttributeString("name", dipval.Name); - xtw.WriteRequiredAttributeString("value", dipval.Value); - xtw.WriteRequiredAttributeString("default", dipval.Default == true ? "yes" : "no"); - xtw.WriteEndElement(); - } - - // End dipswitch - xtw.WriteEndElement(); - } - } - xtw.Flush(); } catch (Exception ex) @@ -809,6 +787,26 @@ namespace SabreTools.Library.DatFiles string areaName = datItem.AreaName; switch (datItem.ItemType) { + case ItemType.DipSwitch: + var dipSwitch = datItem as DipSwitch; + xtw.WriteStartElement("dipswitch"); + xtw.WriteRequiredAttributeString("name", dipSwitch.Name); + xtw.WriteRequiredAttributeString("tag", dipSwitch.Tag); + xtw.WriteRequiredAttributeString("mask", dipSwitch.Mask); + if (dipSwitch.Values != null) + { + foreach (ListXmlDipValue dipValue in dipSwitch.Values) + { + xtw.WriteStartElement("dipvalue"); + xtw.WriteRequiredAttributeString("name", dipValue.Name); + xtw.WriteOptionalAttributeString("value", dipValue.Value); + xtw.WriteOptionalAttributeString("default", dipValue.Default.FromYesNo()); + xtw.WriteEndElement(); + } + } + xtw.WriteEndElement(); + break; + case ItemType.Disk: var disk = datItem as Disk; if (string.IsNullOrWhiteSpace(areaName)) diff --git a/SabreTools.Library/DatItems/Auxiliary.cs b/SabreTools.Library/DatItems/Auxiliary.cs index a57e7f17..9346b8fc 100644 --- a/SabreTools.Library/DatItems/Auxiliary.cs +++ b/SabreTools.Library/DatItems/Auxiliary.cs @@ -198,33 +198,6 @@ namespace SabreTools.Library.DatItems public string VBStart { get; set; } // TODO: Int32? Float? } - /// - /// Represents one ListXML dipswitch - /// - /// Also used by SoftwareList - /// TODO: Promote to DatItem level (contains list) - [JsonObject("dipswitch")] - public class ListXmlDipSwitch - { - [JsonProperty("name")] - public string Name { get; set; } - - [JsonProperty("tag")] - public string Tag { get; set; } - - [JsonProperty("mask")] - public string Mask { get; set; } - - [JsonProperty("conditions")] - public List Conditions { get; set; } - - [JsonProperty("locations")] - public List Locations { get; set; } - - [JsonProperty("values")] - public List Values { get; set; } - } - /// /// Represents one ListXML diplocation /// diff --git a/SabreTools.Library/DatItems/Configuration.cs b/SabreTools.Library/DatItems/Configuration.cs index b0dbb939..ae8c0ed6 100644 --- a/SabreTools.Library/DatItems/Configuration.cs +++ b/SabreTools.Library/DatItems/Configuration.cs @@ -137,7 +137,7 @@ namespace SabreTools.Library.DatItems // Otherwise, treat it as a Configuration Configuration newOther = other as Configuration; - // If the Adjuster information matches + // If the Configuration information matches return (Name == newOther.Name && Tag == newOther.Tag && Mask == newOther.Mask); // TODO: Handle DatItem_Condition* diff --git a/SabreTools.Library/DatItems/DatItem.cs b/SabreTools.Library/DatItems/DatItem.cs index 96e4d2d0..6931bad8 100644 --- a/SabreTools.Library/DatItems/DatItem.cs +++ b/SabreTools.Library/DatItems/DatItem.cs @@ -279,6 +279,12 @@ namespace SabreTools.Library.DatItems Field.DatItem_Tag, Field.DatItem_ChipType, Field.DatItem_Clock, + + // DIP Switch.Values + Field.DatItem_Values, + Field.DatItem_Value_Name, + Field.DatItem_Value_Value, + Field.DatItem_Value_Default, // Ram Option Field.DatItem_Content, @@ -347,7 +353,6 @@ namespace SabreTools.Library.DatItems // SoftwareList Field.Machine_Supported, Field.Machine_SharedFeatures, - Field.Machine_DipSwitches, }; #endregion @@ -471,6 +476,9 @@ namespace SabreTools.Library.DatItems case ItemType.DeviceReference: return new DeviceReference(); + case ItemType.DipSwitch: + return new DipSwitch(); + case ItemType.Disk: return new Disk(); diff --git a/SabreTools.Library/DatItems/DipSwitch.cs b/SabreTools.Library/DatItems/DipSwitch.cs new file mode 100644 index 00000000..bdd64738 --- /dev/null +++ b/SabreTools.Library/DatItems/DipSwitch.cs @@ -0,0 +1,256 @@ +using System.Collections.Generic; +using System.Linq; + +using SabreTools.Library.Filtering; +using Newtonsoft.Json; + +namespace SabreTools.Library.DatItems +{ + /// + /// Represents which DIP Switch(es) is associated with a set + /// + [JsonObject("dipswitch")] + public class DipSwitch : DatItem + { + #region Fields + + /// + /// Tag associated with the dipswitch + /// + [JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)] + public string Tag { get; set; } + + /// + /// Mask associated with the dipswitch + /// + [JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore)] + public string Mask { get; set; } + + /// + /// Conditions associated with the dipswitch + /// + [JsonProperty("conditions")] + public List Conditions { get; set; } + + /// + /// Locations associated with the dipswitch + /// + [JsonProperty("locations")] + public List Locations { get; set; } + + /// + /// Settings associated with the dipswitch + /// + [JsonProperty("values")] + public List Values { get; set; } + + #endregion + + #region Accessors + + /// + /// Set fields with given values + /// + /// Mappings dictionary + public override void SetFields(Dictionary mappings) + { + // Set base fields + base.SetFields(mappings); + + // Handle DipSwitch-specific fields + if (mappings.Keys.Contains(Field.DatItem_Tag)) + Tag = mappings[Field.DatItem_Tag]; + + if (mappings.Keys.Contains(Field.DatItem_Mask)) + Mask = mappings[Field.DatItem_Mask]; + + // TODO: Handle DatItem_Condition* + // TODO: Handle DatItem_Location* + // TODO: Handle DatItem_Value* + } + + #endregion + + #region Constructors + + /// + /// Create a default, empty DipSwitch object + /// + public DipSwitch() + { + Name = string.Empty; + ItemType = ItemType.DipSwitch; + } + + #endregion + + #region Cloning Methods + + public override object Clone() + { + return new DipSwitch() + { + Name = this.Name, + ItemType = this.ItemType, + DupeType = this.DupeType, + + AltName = this.AltName, + AltTitle = this.AltTitle, + + Original = this.Original, + OpenMSXSubType = this.OpenMSXSubType, + OpenMSXType = this.OpenMSXType, + Remark = this.Remark, + Boot = this.Boot, + + Part = this.Part, + Features = this.Features, + AreaName = this.AreaName, + AreaSize = this.AreaSize, + AreaWidth = this.AreaWidth, + AreaEndianness = this.AreaEndianness, + Value = this.Value, + LoadFlag = this.LoadFlag, + + Machine = this.Machine.Clone() as Machine, + Source = this.Source.Clone() as Source, + Remove = this.Remove, + + Tag = this.Tag, + Mask = this.Mask, + Conditions = this.Conditions, + Locations = this.Locations, + Values = this.Values, + }; + } + + #endregion + + #region Comparision Methods + + public override bool Equals(DatItem other) + { + // If we don't have a DipSwitch, return false + if (ItemType != other.ItemType) + return false; + + // Otherwise, treat it as a DipSwitch + DipSwitch newOther = other as DipSwitch; + + // If the DipSwitch information matches + return (Name == newOther.Name && Tag == newOther.Tag && Mask == newOther.Mask); + + // TODO: Handle DatItem_Condition* + // TODO: Handle DatItem_Location* + // TODO: Handle DatItem_Value* + } + + #endregion + + #region Filtering + + /// + /// Check to see if a DatItem passes the filter + /// + /// Filter to check against + /// True if the item passed the filter, false otherwise + public override bool PassesFilter(Filter filter) + { + // Check common fields first + if (!base.PassesFilter(filter)) + return false; + + // Filter on tag + if (filter.DatItem_Tag.MatchesPositiveSet(Tag) == false) + return false; + if (filter.DatItem_Tag.MatchesNegativeSet(Tag) == true) + return false; + + // Filter on mask + if (filter.DatItem_Mask.MatchesPositiveSet(Mask) == false) + return false; + if (filter.DatItem_Mask.MatchesNegativeSet(Mask) == true) + return false; + + // TODO: Handle DatItem_Condition* + // TODO: Handle DatItem_Location* + // TODO: Handle DatItem_Value* + + return true; + } + + /// + /// Remove fields from the DatItem + /// + /// List of Fields to remove + public override void RemoveFields(List fields) + { + // Remove common fields first + base.RemoveFields(fields); + + // Remove the fields + if (fields.Contains(Field.DatItem_Tag)) + Tag = null; + + if (fields.Contains(Field.DatItem_Mask)) + Mask = null; + + if (fields.Contains(Field.DatItem_Conditions)) + Conditions = null; + + if (fields.Contains(Field.DatItem_Locations)) + Locations = null; + + if (fields.Contains(Field.DatItem_Values)) + Values = null; + + // TODO: Handle DatItem_Condition* + // TODO: Handle DatItem_Location* + // TODO: Handle DatItem_Value* + } + + #endregion + + #region Sorting and Merging + + /// + /// Replace fields from another item + /// + /// DatItem to pull new information from + /// List of Fields representing what should be updated + public override void ReplaceFields(DatItem item, List fields) + { + // Replace common fields first + base.ReplaceFields(item, fields); + + // If we don't have a DipSwitch to replace from, ignore specific fields + if (item.ItemType != ItemType.DipSwitch) + return; + + // Cast for easier access + DipSwitch newItem = item as DipSwitch; + + // Replace the fields + if (fields.Contains(Field.DatItem_Tag)) + Tag = newItem.Tag; + + if (fields.Contains(Field.DatItem_Mask)) + Mask = newItem.Mask; + + if (fields.Contains(Field.DatItem_Conditions)) + Conditions = newItem.Conditions; + + if (fields.Contains(Field.DatItem_Locations)) + Locations = newItem.Locations; + + if (fields.Contains(Field.DatItem_Values)) + Values = newItem.Values; + + // TODO: Handle DatItem_Condition* + // TODO: Handle DatItem_Location* + // TODO: Handle DatItem_Value* + } + + #endregion + } +} diff --git a/SabreTools.Library/DatItems/Enums.cs b/SabreTools.Library/DatItems/Enums.cs index 40421127..a07a9b04 100644 --- a/SabreTools.Library/DatItems/Enums.cs +++ b/SabreTools.Library/DatItems/Enums.cs @@ -179,24 +179,6 @@ namespace SabreTools.Library.DatItems Machine_Input_Control_Ways2, Machine_Input_Control_Ways3, - // DipSwitches - Machine_DipSwitches, - Machine_DipSwitch_Name, - Machine_DipSwitch_Tag, - Machine_DipSwitch_Mask, - - // DipSwitches.Locations - Machine_DipSwitch_Locations, - Machine_DipSwitch_Location_Name, - Machine_DipSwitch_Location_Number, - Machine_DipSwitch_Location_Inverted, - - // DipSwitches.Values - Machine_DipSwitch_Values, - Machine_DipSwitch_Value_Name, - Machine_DipSwitch_Value_Value, - Machine_DipSwitch_Value_Default, - // Ports Machine_Ports, Machine_Port_Tag, @@ -404,6 +386,12 @@ namespace SabreTools.Library.DatItems DatItem_Setting_Value, DatItem_Setting_Default, + // DIP Switch.Values + DatItem_Values, + DatItem_Value_Name, + DatItem_Value_Value, + DatItem_Value_Default, + // Ram Option DatItem_Content, @@ -456,6 +444,7 @@ namespace SabreTools.Library.DatItems Chip, Configuration, DeviceReference, + DipSwitch, RamOption, Release, Sample, diff --git a/SabreTools.Library/DatItems/Machine.cs b/SabreTools.Library/DatItems/Machine.cs index 5f3493a6..104d77d9 100644 --- a/SabreTools.Library/DatItems/Machine.cs +++ b/SabreTools.Library/DatItems/Machine.cs @@ -176,14 +176,6 @@ namespace SabreTools.Library.DatItems [JsonProperty("inputs", DefaultValueHandling = DefaultValueHandling.Ignore)] public List Inputs { get; set; } = null; - /// - /// List of associated dipswitches - /// - /// Also in SoftwareList - /// TODO: Order ListXML and SoftwareList outputs by area names - [JsonProperty("dipswitches", DefaultValueHandling = DefaultValueHandling.Ignore)] - public List DipSwitches { get; set; } = null; - /// /// List of associated ports /// @@ -570,7 +562,6 @@ namespace SabreTools.Library.DatItems Sounds = this.Sounds, Conditions = this.Conditions, Inputs = this.Inputs, - DipSwitches = this.DipSwitches, Ports = this.Ports, Drivers = this.Drivers, Features = this.Features, @@ -1173,16 +1164,8 @@ namespace SabreTools.Library.DatItems // TODO: Inputs // TODO: Inputs.Controls - // TODO: DipSwitches - // TODO: DipSwitches.Locations - // TODO: DipSwitches.Values - // TODO: Configurations - // TODO: Configurations.Locations - // TODO: Configurations.Settings // TODO: Ports // TODO: Ports.Analogs - // TODO: Adjusters - // TODO: Adjusters.Conditions // TODO: Drivers // TODO: Features // TODO: Devices @@ -1190,8 +1173,6 @@ namespace SabreTools.Library.DatItems // TODO: Devices.Extensions // TODO: Slots // TODO: Slots.SlotOptions - // TODO: SoftwareLists - // TODO: RamOptions #endregion // ListXML @@ -1545,9 +1526,6 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.Machine_SharedFeatures)) SharedFeatures = null; - if (fields.Contains(Field.Machine_DipSwitches)) - DipSwitches = null; - #endregion } @@ -1707,9 +1685,6 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.Machine_SharedFeatures)) SharedFeatures = machine.SharedFeatures; - if (fields.Contains(Field.Machine_DipSwitches)) - DipSwitches = machine.DipSwitches; - #endregion } diff --git a/SabreTools.Library/Filtering/Filter.cs b/SabreTools.Library/Filtering/Filter.cs index c60201f6..43b30b03 100644 --- a/SabreTools.Library/Filtering/Filter.cs +++ b/SabreTools.Library/Filtering/Filter.cs @@ -101,24 +101,6 @@ namespace SabreTools.Library.Filtering public FilterItem Machine_Input_Control_Ways2 { get; private set; } = new FilterItem(); public FilterItem Machine_Input_Control_Ways3 { get; private set; } = new FilterItem(); - // DipSwitches - public FilterItem Machine_DipSwitches { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Machine_DipSwitch_Name { get; private set; } = new FilterItem(); - public FilterItem Machine_DipSwitch_Tag { get; private set; } = new FilterItem(); - public FilterItem Machine_DipSwitch_Mask { get; private set; } = new FilterItem(); - - // DipSwitches.Locations - public FilterItem Machine_DipSwitch_Locations { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Machine_DipSwitch_Location_Name { get; private set; } = new FilterItem(); - public FilterItem Machine_DipSwitch_Location_Number { get; private set; } = new FilterItem(); - public FilterItem Machine_DipSwitch_Location_Inverted { get; private set; } = new FilterItem() { Neutral = null }; - - // DipSwitches.Values - public FilterItem Machine_DipSwitch_Values { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Machine_DipSwitch_Value_Name { get; private set; } = new FilterItem(); - public FilterItem Machine_DipSwitch_Value_Value { get; private set; } = new FilterItem(); - public FilterItem Machine_DipSwitch_Value_Default { get; private set; } = new FilterItem() { Neutral = null }; - // Ports public FilterItem Machine_Ports { get; private set; } = new FilterItem() { Neutral = null }; public FilterItem Machine_Port_Tag { get; private set; } = new FilterItem(); @@ -326,6 +308,12 @@ namespace SabreTools.Library.Filtering public FilterItem DatItem_Setting_Value { get; private set; } = new FilterItem(); public FilterItem DatItem_Setting_Default { get; private set; } = new FilterItem() { Neutral = null }; + // DipSwitch.Values + public FilterItem DatItem_Values { get; private set; } = new FilterItem() { Neutral = null }; + public FilterItem DatItem_Value_Name { get; private set; } = new FilterItem(); + public FilterItem DatItem_Value_Value { get; private set; } = new FilterItem(); + public FilterItem DatItem_Value_Default { get; private set; } = new FilterItem() { Neutral = null }; + // Ram Option public FilterItem DatItem_Content { get; private set; } = new FilterItem(); @@ -848,93 +836,6 @@ namespace SabreTools.Library.Filtering Machine_Input_Control_Ways3.PositiveSet.Add(value); break; - // DipSwitches - case Field.Machine_DipSwitches: - if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) - Machine_DipSwitches.Neutral = false; - else - Machine_DipSwitches.Neutral = true; - break; - - case Field.Machine_DipSwitch_Name: - if (negate) - Machine_DipSwitch_Name.NegativeSet.Add(value); - else - Machine_DipSwitch_Name.PositiveSet.Add(value); - break; - - case Field.Machine_DipSwitch_Tag: - if (negate) - Machine_DipSwitch_Tag.NegativeSet.Add(value); - else - Machine_DipSwitch_Tag.PositiveSet.Add(value); - break; - - case Field.Machine_DipSwitch_Mask: - if (negate) - Machine_DipSwitch_Mask.NegativeSet.Add(value); - else - Machine_DipSwitch_Mask.PositiveSet.Add(value); - break; - - // DipSwitches.Locations - case Field.Machine_DipSwitch_Locations: - if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) - Machine_DipSwitch_Locations.Neutral = false; - else - Machine_DipSwitch_Locations.Neutral = true; - break; - - case Field.Machine_DipSwitch_Location_Name: - if (negate) - Machine_DipSwitch_Location_Name.NegativeSet.Add(value); - else - Machine_DipSwitch_Location_Name.PositiveSet.Add(value); - break; - - case Field.Machine_DipSwitch_Location_Number: - if (negate) - Machine_DipSwitch_Location_Number.NegativeSet.Add(value); - else - Machine_DipSwitch_Location_Number.PositiveSet.Add(value); - break; - - case Field.Machine_DipSwitch_Location_Inverted: - if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) - Machine_DipSwitch_Location_Inverted.Neutral = false; - else - Machine_DipSwitch_Location_Inverted.Neutral = true; - break; - - // DipSwitches.Values - case Field.Machine_DipSwitch_Values: - if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) - Machine_DipSwitch_Values.Neutral = false; - else - Machine_DipSwitch_Values.Neutral = true; - break; - - case Field.Machine_DipSwitch_Value_Name: - if (negate) - Machine_DipSwitch_Value_Name.NegativeSet.Add(value); - else - Machine_DipSwitch_Value_Name.PositiveSet.Add(value); - break; - - case Field.Machine_DipSwitch_Value_Value: - if (negate) - Machine_DipSwitch_Value_Value.NegativeSet.Add(value); - else - Machine_DipSwitch_Value_Value.PositiveSet.Add(value); - break; - - case Field.Machine_DipSwitch_Value_Default: - if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) - Machine_DipSwitch_Value_Default.Neutral = false; - else - Machine_DipSwitch_Value_Default.Neutral = true; - break; - // Ports case Field.Machine_Ports: if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) @@ -1860,6 +1761,35 @@ namespace SabreTools.Library.Filtering DatItem_Setting_Default.Neutral = true; break; + // DipSwitches.Values + case Field.DatItem_Values: + if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) + DatItem_Values.Neutral = false; + else + DatItem_Values.Neutral = true; + break; + + case Field.DatItem_Value_Name: + if (negate) + DatItem_Value_Name.NegativeSet.Add(value); + else + DatItem_Value_Name.PositiveSet.Add(value); + break; + + case Field.DatItem_Value_Value: + if (negate) + DatItem_Value_Value.NegativeSet.Add(value); + else + DatItem_Value_Value.PositiveSet.Add(value); + break; + + case Field.DatItem_Value_Default: + if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) + DatItem_Value_Default.Neutral = false; + else + DatItem_Value_Default.Neutral = true; + break; + // Ram Option case Field.DatItem_Content: if (negate) diff --git a/SabreTools.Library/Tools/Converters.cs b/SabreTools.Library/Tools/Converters.cs index 8df92d68..f9e7613f 100644 --- a/SabreTools.Library/Tools/Converters.cs +++ b/SabreTools.Library/Tools/Converters.cs @@ -575,42 +575,6 @@ namespace SabreTools.Library.Tools case "input_control_ways3": return Field.Machine_Input_Control_Ways3; - case "dipswitches": - return Field.Machine_DipSwitches; - - case "dipswitch_name": - return Field.Machine_DipSwitch_Name; - - case "dipswitch_tag": - return Field.Machine_DipSwitch_Tag; - - case "dipswitch_mask": - return Field.Machine_DipSwitch_Mask; - - case "dipswitch_locations": - return Field.Machine_DipSwitch_Locations; - - case "dipswitch_location_name": - return Field.Machine_DipSwitch_Location_Name; - - case "dipswitch_location_number": - return Field.Machine_DipSwitch_Location_Number; - - case "dipswitch_location_inverted": - return Field.Machine_DipSwitch_Location_Inverted; - - case "dipswitch_values": - return Field.Machine_DipSwitch_Values; - - case "dipswitch_value_name": - return Field.Machine_DipSwitch_Value_Name; - - case "dipswitch_value_value": - return Field.Machine_DipSwitch_Value_Value; - - case "dipswitch_value_default": - return Field.Machine_DipSwitch_Value_Default; - case "ports": return Field.Machine_Ports; @@ -1061,6 +1025,19 @@ namespace SabreTools.Library.Tools case "setting_default": return Field.DatItem_Setting_Default; + // DIP Switch + case "values": + return Field.DatItem_Values; + + case "value_name": + return Field.DatItem_Value_Name; + + case "value_value": + return Field.DatItem_Value_Value; + + case "value_default": + return Field.DatItem_Value_Default; + // Ram Option case "content": return Field.DatItem_Content; @@ -1288,13 +1265,6 @@ namespace SabreTools.Library.Tools case "shared features": case "shared-features": return Field.Machine_SharedFeatures; - case "dipswitch": - case "dip switch": - case "dip-switch": - case "dipswitches": - case "dip switches": - case "dip-switches": - return Field.Machine_DipSwitches; #endregion @@ -1605,6 +1575,8 @@ namespace SabreTools.Library.Tools return ItemType.Configuration; case "device_ref": return ItemType.DeviceReference; + case "dipswitch": + return ItemType.DipSwitch; case "disk": return ItemType.Disk; case "media": @@ -1632,6 +1604,7 @@ namespace SabreTools.Library.Tools "chip" => ItemType.Chip, "configuration" => ItemType.Configuration, "device_ref" => ItemType.DeviceReference, + "dipswitch" => ItemType.DipSwitch, "disk" => ItemType.Disk, "media" => ItemType.Media, "ramoption" => ItemType.RamOption, @@ -2044,6 +2017,8 @@ namespace SabreTools.Library.Tools return "configuration"; case ItemType.DeviceReference: return "device_ref"; + case ItemType.DipSwitch: + return "dipswitch"; case ItemType.Disk: return "disk"; case ItemType.Media: @@ -2071,6 +2046,7 @@ namespace SabreTools.Library.Tools ItemType.Chip => "chip", ItemType.Configuration => "configuration", ItemType.DeviceReference => "device_ref", + ItemType.DipSwitch => "dipswitch", ItemType.Disk => "disk", ItemType.Media => "media", ItemType.RamOption => "ramoption",