Promote DipSwitch

This commit is contained in:
Matt Nadareski
2020-09-01 13:36:32 -07:00
parent 88b40b1b06
commit 7d3f3f1803
13 changed files with 874 additions and 349 deletions

View File

@@ -198,33 +198,6 @@ namespace SabreTools.Library.DatItems
public string VBStart { get; set; } // TODO: Int32? Float?
}
/// <summary>
/// Represents one ListXML dipswitch
/// </summary>
/// <remarks>Also used by SoftwareList</remarks>
/// 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<ListXmlCondition> Conditions { get; set; }
[JsonProperty("locations")]
public List<ListXmlDipLocation> Locations { get; set; }
[JsonProperty("values")]
public List<ListXmlDipValue> Values { get; set; }
}
/// <summary>
/// Represents one ListXML diplocation
/// </summary>

View File

@@ -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*

View File

@@ -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();

View File

@@ -0,0 +1,256 @@
using System.Collections.Generic;
using System.Linq;
using SabreTools.Library.Filtering;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
{
/// <summary>
/// Represents which DIP Switch(es) is associated with a set
/// </summary>
[JsonObject("dipswitch")]
public class DipSwitch : DatItem
{
#region Fields
/// <summary>
/// Tag associated with the dipswitch
/// </summary>
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Tag { get; set; }
/// <summary>
/// Mask associated with the dipswitch
/// </summary>
[JsonProperty("mask", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Mask { get; set; }
/// <summary>
/// Conditions associated with the dipswitch
/// </summary>
[JsonProperty("conditions")]
public List<ListXmlCondition> Conditions { get; set; }
/// <summary>
/// Locations associated with the dipswitch
/// </summary>
[JsonProperty("locations")]
public List<ListXmlDipLocation> Locations { get; set; }
/// <summary>
/// Settings associated with the dipswitch
/// </summary>
[JsonProperty("values")]
public List<ListXmlDipValue> Values { get; set; }
#endregion
#region Accessors
/// <summary>
/// Set fields with given values
/// </summary>
/// <param name="mappings">Mappings dictionary</param>
public override void SetFields(Dictionary<Field, string> 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
/// <summary>
/// Create a default, empty DipSwitch object
/// </summary>
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
/// <summary>
/// Check to see if a DatItem passes the filter
/// </summary>
/// <param name="filter">Filter to check against</param>
/// <returns>True if the item passed the filter, false otherwise</returns>
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;
}
/// <summary>
/// Remove fields from the DatItem
/// </summary>
/// <param name="fields">List of Fields to remove</param>
public override void RemoveFields(List<Field> 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
/// <summary>
/// Replace fields from another item
/// </summary>
/// <param name="item">DatItem to pull new information from</param>
/// <param name="fields">List of Fields representing what should be updated</param>
public override void ReplaceFields(DatItem item, List<Field> 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
}
}

View File

@@ -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,

View File

@@ -176,14 +176,6 @@ namespace SabreTools.Library.DatItems
[JsonProperty("inputs", DefaultValueHandling = DefaultValueHandling.Ignore)]
public List<ListXmlInput> Inputs { get; set; } = null;
/// <summary>
/// List of associated dipswitches
/// </summary>
/// <remarks>Also in SoftwareList</remarks>
/// TODO: Order ListXML and SoftwareList outputs by area names
[JsonProperty("dipswitches", DefaultValueHandling = DefaultValueHandling.Ignore)]
public List<ListXmlDipSwitch> DipSwitches { get; set; } = null;
/// <summary>
/// List of associated ports
/// </summary>
@@ -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
}