public void WriteToSlotSelectionRegister(byte value) { slotSelectionRegisterValue = value; for (int p = 0; p < 4; p++) { Z80Page page = p; var primarySlotNumber = value & 3; SlotNumber slotNumber; if (isExpanded[primarySlotNumber]) { var subslotNumber = secondarySlotsSelectedForEachPrimarySlot[primarySlotNumber][page]; slotNumber = new SlotNumber(primarySlotNumber, subslotNumber); } else { slotNumber = new SlotNumber((byte)primarySlotNumber); } SetVisibleSlot(page, slotNumber); value >>= 2; } if (SlotSelectionRegisterWritten != null) { SlotSelectionRegisterWritten(this, new SlotSelectionRegisterWrittenEventArgs(slotSelectionRegisterValue)); } }
private void ThrowIfUndefinedSlot(SlotNumber slot) { if (!slotContents.ContainsKey(slot)) { throw new InvalidOperationException(string.Format("Slot {0} is not expanded", slot.PrimarySlotNumber)); } }
private void UpdateSlotVisibleInPage3IsExpanded(Z80Page page, SlotNumber slotNumber) { if (page == 3) { slotVisibleInPage3IsExpanded = isExpanded[slotNumber.PrimarySlotNumber]; } }
public void Can_create_instance_from_encoded_slot_number_for_expanded_slot() { var slotNumber = (byte)(RandomSlotNumber() & 0x80); var sut = new SlotNumber(slotNumber); Assert.IsNotNull(sut); }
public FightExtraPair(FightExtra type, Dictionary<DamageType, string> spellTypes) { this.Type = type; this.Item = null; this.Slot = SlotNumber.Ammo; this.SpellTypes = spellTypes; }
public FightExtraPair(FightExtra type, Item item) { this.Type = type; this.Item = item; this.Slot = SlotNumber.Ammo; this.Spell = ""; }
public FightExtraPair(FightExtra type, Item item, SlotNumber slot) { this.Type = type; this.Item = item; this.Slot = slot; this.Spell = ""; }
/// <summary> /// スキルを発動する /// </summary> public void Invoke(SlotNumber slotNumber) { if (slots [(int)slotNumber] != null) { slots [(int)slotNumber].Invoke(); } }
public RookieDriveFddPlugin(PluginContext context, IDictionary <string, object> pluginConfig) { kernelRoutines = new Dictionary <ushort, Action> { { 0x4010, DSKIO }, { 0x4013, () => DSKCHG_GETDPB(true) }, { 0x4016, () => DSKCHG_GETDPB(false) }, { 0x4019, CHOICE }, { 0x401C, DSKFMT }, { 0x401F, MTOFF } }; addressOfCallInihrd = pluginConfig.GetValueOrDefault <ushort>("addressOfCallInihrd", 0x176F); addressOfCallDrives = pluginConfig.GetValueOrDefault <ushort>("addressOfCallDrives", 0x1850); this.slotNumber = new SlotNumber(pluginConfig.GetValue <byte>("NestorMSX.slotNumber")); this.kernelFilePath = pluginConfig.GetMachineFilePath(pluginConfig.GetValueOrDefault("kernelFile", "MsxDosKernel.rom")); this.z80 = context.Cpu; this.memory = context.SlotsSystem; z80.BeforeInstructionFetch += (sender, args) => BeforeZ80InstructionFetch(z80.Registers.PC); this.kernelContents = File.ReadAllBytes(kernelFilePath); ValidateKernelFileContents(kernelContents); host = new UsbHost(new CH376UsbHostHardware(UsbServiceProvider.GetCH376Ports())); UpdateCbiInstance(); }
public void SetSlotContents(SlotNumber slot, IMemory contents) { ThrowIfUndefinedSlot(slot); slotContents[slot] = contents ?? NotConnectedMemory.Value; UpdateVisibleSlots(); }
public FightExtraPair(FightExtra type, Dictionary <DamageType, string> spellTypes) { this.Type = type; this.Item = null; this.Slot = SlotNumber.Ammo; this.SpellTypes = spellTypes; }
public FightExtraPair(FightExtra type, string spell) { this.Type = type; this.Item = null; this.Slot = SlotNumber.Ammo; this.Spell = spell; }
private void WriteToSecondarySlotRegister(byte value) { var primarySlotNumber = visibleSlotNumbers[3].PrimarySlotNumber; secondarySlotSelectionRegisterForEachPrimarySlot[primarySlotNumber] = value; var tempValue = value; for (int p = 0; p < 4; p++) { TwinBit page = p; TwinBit subslotNumber = tempValue & 3; secondarySlotsSelectedForEachPrimarySlot[primarySlotNumber][page] = subslotNumber; if (visibleSlotNumbers[page].PrimarySlotNumber == primarySlotNumber) { var newSlotNumber = new SlotNumber(primarySlotNumber, subslotNumber); SetVisibleSlot((int)page, newSlotNumber); } tempValue >>= 2; } if (SecondarySlotSelectionRegisterWritten != null) { SecondarySlotSelectionRegisterWritten( this, new SecondarySlotSelectionRegisterWrittenEventArgs(value, primarySlotNumber)); } }
public void Can_parse_hexadecimal_numbers() { var unparsedSlotNumber = "#8E"; var parsedSlotNumber = SlotNumber.Parse(unparsedSlotNumber); var expected = new SlotNumber(2, 3); Assert.AreEqual(expected, parsedSlotNumber); }
public void Can_parse_decimal_numbers() { var unparsedSlotNumber = (128 + 4 * 3 + 2).ToString(); var parsedSlotNumber = SlotNumber.Parse(unparsedSlotNumber); var expected = new SlotNumber(2, 3); Assert.AreEqual(expected, parsedSlotNumber); }
public void Can_parse_slot_slash_subslot_numbers() { var unparsedSlotNumber = "2-3"; var parsedSlotNumber = SlotNumber.Parse(unparsedSlotNumber); var expected = new SlotNumber(2, 3); Assert.AreEqual(expected, parsedSlotNumber); }
// Rotation/Orientation? // ... public string ToJSON() { Dictionary <string, string> tmp = new Dictionary <string, string>(); tmp.Add("SlotNumber", SlotNumber.ToString()); tmp.Add("Checksum", MetaData.Checksum.ToString()); return(Serial.DictToJSON(tmp)); }
public void Two_expanded_instances_are_equal_if_slot_and_subslot_are_equal() { var slotNumber = (byte)(Fixture.Create <byte>() | 0x80); var sut1 = new SlotNumber(slotNumber); var sut2 = new SlotNumber(slotNumber); Assert.True(sut1 == sut2); Assert.True(sut1.Equals(sut2)); }
public void Can_be_compared_to_byte_and_unused_bits_are_ignored() { var slotNumber = (byte)(Fixture.Create <byte>() | 0x80); var slotNumberWithExtraBits = (byte)(slotNumber | 0x70); var sut = new SlotNumber(slotNumber); Assert.True(slotNumberWithExtraBits == sut); Assert.True(sut.Equals(slotNumberWithExtraBits)); }
public void Primary_and_expanded_instances_are_equal_if_primary_slot_is_equal_and_subslot_is_zero() { var slotNumber = (byte)(Fixture.Create <byte>() & 0x03); var sut1 = new SlotNumber(slotNumber); var sut2 = new SlotNumber((byte)(slotNumber | 0x80)); Assert.True(sut1 == sut2); Assert.True(sut1.Equals(sut2)); }
public void Can_deal_with_whitespace() { var strings = new[] { " 142 ", " #8E ", " 2-3 " }; var expected = new SlotNumber(2, 3); foreach (var s in strings) { Assert.AreEqual(expected, SlotNumber.Parse(s)); } }
public void Instance_for_non_expanded_slot_from_encoded_slot_number_has_proper_properties() { var slotNumber = RandomSlotNumber(); var sut = new SlotNumber(slotNumber); Assert.AreEqual(slotNumber, sut.PrimarySlotNumber); Assert.AreEqual(0, sut.SubSlotNumber); Assert.False(sut.IsExpandedSlot); Assert.AreEqual(slotNumber, sut.EncodedByte); }
public void Cannot_parse_invalid_strings() { Assert.Throws <ArgumentNullException>(() => SlotNumber.Parse(null)); var invalidStrings = new[] { "", "999", "abc", "#FFF", "#xx", "3-4", "-2", "1-", "a-b" }; foreach (var s in invalidStrings) { Assert.Throws <FormatException>(() => SlotNumber.Parse(s)); } }
private void CreateSlotsSystem() { foreach (var slotConfig in machineConfig["slots"] as IDictionary <string, object> ) { SlotNumber slotNumber; if (!SlotNumber.TryParse(slotConfig.Key, out slotNumber)) { continue; } var pluginConfig = (IDictionary <string, object>)slotConfig.Value; pluginConfig["NestorMSX.slotNumber"] = slotNumber.EncodedByte; var typeName = (string)pluginConfig["type"]; injectedConfig.MergeInto(pluginConfig); object pluginInstance; try { pluginInstance = PluginsLoader.GetPluginInstanceForSlot(typeName, pluginConfig, machineSharedPluginsConfig, globalSharedPluginsConfig, injectedConfig); RegisterPlugin(pluginInstance); } catch (Exception ex) { var message = ex.InnerException?.Message ?? ex.Message; tell($"Could not load plugin {typeName} in slot {slotConfig.Key}: {message}", new object[0]); continue; } var getMemoryMethod = pluginInstance.GetType().GetMethod("GetMemory"); IMemory memory; try { memory = (IMemory)getMemoryMethod.Invoke(pluginInstance, null); } catch (TargetInvocationException ex) { tell($"Error when invoking GetMemory for plugin {typeName} in slot {slotConfig.Key}: {ex.InnerException.Message}", new object[0]); continue; } try { SlotsSystem.SetSlotContents(slotNumber, memory); } catch (Exception ex) { tell($"Error when setting contents for slot {slotConfig.Key}: {ex.Message}", new object[0]); } } }
public void Instance_for_expanded_slot_from_primary_and_expanded_slot_number_has_proper_properties() { var primarySlotNumber = RandomSlotNumber(); var subSlotNumber = RandomSlotNumber(); var sut = new SlotNumber(primarySlotNumber, subSlotNumber); Assert.AreEqual(primarySlotNumber, sut.PrimarySlotNumber); Assert.AreEqual(subSlotNumber, sut.SubSlotNumber); Assert.True(sut.IsExpandedSlot); var expected = EncodedByte(primarySlotNumber, subSlotNumber); Assert.AreEqual(expected, sut.EncodedByte); }
private void OnSelected(bool isOn) { var slotSelectedMessage = Database.Instance.Select <TextData>("TextDataTable") .Select("SLOT_SELECT_MESSAGE") .text; slotSelectedMessage = slotSelectedMessage.Replace("${slotNumber}", SlotNumber.ToString()); if (isOn) { onSelected.Invoke(this); TextDisplay.Instance.Show(slotSelectedMessage); SaveSlotSystem.Instance.SelectSlot(SlotNumber); } }
public void EnableSlot(Z80Page page, SlotNumber slot) { ThrowIfUndefinedSlot(slot); SetVisibleSlot(page, slot); byte newSlotSelectionRegisterValue = 0; for (var p = 0; p < 4; p++) { newSlotSelectionRegisterValue |= (byte)(visibleSlotNumbers[p].PrimarySlotNumber << 2 * p); } slotSelectionRegisterValue = newSlotSelectionRegisterValue; }
private TcpipUnapiPlugin(PluginContext context, IDictionary <string, object> pluginConfig) { slotNumber = new SlotNumber((byte)pluginConfig["NestorMSX.slotNumber"]); cpu = context.Cpu; slots = context.SlotsSystem; cpu.BeforeInstructionFetch += Cpu_BeforeInstructionFetch; bool hasIp(NetworkInterface iface, string ip) { return(iface.GetIPProperties().UnicastAddresses.Any(a => a.Address.ToString() == ip)); } bool hasIpv4Address(NetworkInterface iface) { return(iface.GetIPProperties().UnicastAddresses.Any(a => IsIPv4(a.Address))); } var ipAddress = pluginConfig.GetValueOrDefault("ipAddress", ""); var networkInterfaces = NetworkInterface.GetAllNetworkInterfaces() .Where(i => i.Supports(NetworkInterfaceComponent.IPv4)); if (ipAddress == "") { networkInterface = networkInterfaces.FirstOrDefault(i => hasIpv4Address(i) && i.NetworkInterfaceType != NetworkInterfaceType.Loopback) ?? networkInterfaces.FirstOrDefault(i => hasIpv4Address(i)); ipInfo = networkInterface?.GetIPProperties().UnicastAddresses.First(a => IsIPv4(a.Address)); } else { networkInterface = networkInterfaces.FirstOrDefault(i => hasIp(i, ipAddress)); ipInfo = networkInterface?.GetIPProperties().UnicastAddresses.First(a => a.Address.ToString() == ipAddress); } if (networkInterface == null) { throw new Exception(ipAddress == "" ? "No IPv4 network interfaces available" : $"There is no network interface with the IP address {ipAddress}"); } dnsServersAvailable = networkInterface.GetIPProperties().DnsAddresses.Any(); mtu = (short)Math.Min(32767, networkInterface.GetIPProperties().GetIPv4Properties().Mtu); InitRoutinesArray(); }
private void FillMissingSlotContentsWithNotConnectedMemory() { for (byte primary = MinSlotPartNumber; primary <= MaxSlotPartNumber; primary++) { if (isExpanded[primary]) { for (int secondary = MinSlotPartNumber; secondary <= MaxSlotPartNumber; secondary++) { var slotNumber = new SlotNumber(primary, secondary); if (!ThereIsContentForSlot(slotNumber)) { slotContents[slotNumber] = NotConnectedMemory.Value; } } } else if (!ThereIsContentForSlot(primary)) { slotContents[primary] = NotConnectedMemory.Value; } } }
public override string ToString() { return(SlotNumber.ToString()); }
public IMemory GetSlotContents(SlotNumber slot) { ThrowIfUndefinedSlot(slot); return(slotContents[slot]); }