Ejemplo n.º 1
0
        private bool GenerateVMD()
        {
            if (string.IsNullOrWhiteSpace(cbSelectedMemoryDomain.SelectedItem?.ToString()) || !RTC_MemoryDomains.MemoryInterfaces.ContainsKey(cbSelectedMemoryDomain.SelectedItem.ToString()))
            {
                cbSelectedMemoryDomain.Items.Clear();
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(tbVmdName.Text) && RTC_MemoryDomains.VmdPool.ContainsKey($"[V]{tbVmdName.Text}"))
            {
                MessageBox.Show("There is already a VMD with this name in the VMD Pool");
                return(false);
            }

            MemoryInterface     mi    = RTC_MemoryDomains.MemoryInterfaces[cbSelectedMemoryDomain.SelectedItem.ToString()];
            VirtualMemoryDomain VMD   = new VirtualMemoryDomain();
            VmdPrototype        proto = new VmdPrototype();

            proto.GenDomain = cbSelectedMemoryDomain.SelectedItem.ToString();

            if (string.IsNullOrWhiteSpace(tbVmdName.Text))
            {
                proto.VmdName = RTC_Core.GetRandomKey();
            }
            else
            {
                proto.VmdName = tbVmdName.Text;
            }


            proto.BigEndian = mi.BigEndian;
            proto.WordSize  = mi.WordSize;


            if (cbUsePointerSpacer.Checked && nmPointerSpacer.Value > 1)
            {
                proto.PointerSpacer = Convert.ToInt32(nmPointerSpacer.Value);
            }
            else
            {
                proto.PointerSpacer = 1;
            }


            foreach (string line in tbCustomAddresses.Lines)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                string trimmedLine = line.Trim();

                bool remove = false;

                if (trimmedLine[0] == '-')
                {
                    remove      = true;
                    trimmedLine = trimmedLine.Substring(1);
                }

                string[] lineParts = trimmedLine.Split('-');

                if (lineParts.Length > 1)
                {
                    int start = SafeStringToInt(lineParts[0]);
                    int end   = SafeStringToInt(lineParts[1]);

                    if (end >= currentDomainSize)
                    {
                        end = Convert.ToInt32(currentDomainSize - 1);
                    }

                    if (remove)
                    {
                        proto.removeRanges.Add(new int[] { start, end });
                    }
                    else
                    {
                        proto.addRanges.Add(new int[] { start, end });
                    }
                }
                else
                {
                    int address = SafeStringToInt(lineParts[0]);

                    if (address < currentDomainSize)
                    {
                        if (remove)
                        {
                            proto.removeSingles.Add(address);
                        }
                        else
                        {
                            proto.addSingles.Add(address);
                        }
                    }
                }
            }

            if (proto.addRanges.Count == 0 && proto.addSingles.Count == 0)
            {
                //No add range was specified, use entire domain
                proto.addRanges.Add(new int[] { 0, (currentDomainSize > int.MaxValue ? int.MaxValue : Convert.ToInt32(currentDomainSize)) });
            }


            VMD = proto.Generate();


            if (VMD.PointerAddresses.Count == 0)
            {
                MessageBox.Show("The resulting VMD had no pointers so the operation got cancelled.");
                return(false);
            }

            RTC_MemoryDomains.AddVMD(VMD);

            tbVmdName.Text = "";
            cbSelectedMemoryDomain.SelectedIndex = -1;
            cbSelectedMemoryDomain.Items.Clear();

            currentDomainSize = 0;

            nmPointerSpacer.Value      = 2;
            cbUsePointerSpacer.Checked = false;

            tbCustomAddresses.Text = "";

            lbDomainSizeValue.Text = "######";
            lbEndianTypeValue.Text = "######";
            lbWordSizeValue.Text   = "######";

            //send to vmd pool menu
            RTC_Core.vmdPoolForm.RefreshVMDs();
            RTC_Core.ecForm.cbMemoryDomainTool.SelectedIndex = 1;

            GC.Collect();
            GC.WaitForPendingFinalizers();

            return(true);
        }
Ejemplo n.º 2
0
 public static void AddVMD(VmdPrototype proto) => AddVMD(proto.Generate());