Ejemplo n.º 1
0
        private void mnuEditLabel_Click(object sender, EventArgs e)
        {
            UInt32         address = (UInt32)ctrlHexBox.SelectionStart;
            SnesMemoryType memType = _memoryType;

            if (!memType.SupportsLabels())
            {
                AddressInfo relAddress = new AddressInfo()
                {
                    Address = (int)address,
                    Type    = memType
                };
                AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress);
                if (absAddress.Address < 0 || !absAddress.Type.SupportsLabels())
                {
                    return;
                }
                address = (uint)absAddress.Address;
                memType = absAddress.Type;
            }

            CodeLabel label = LabelManager.GetLabel(address, memType);

            if (label == null)
            {
                label = new CodeLabel()
                {
                    Address    = address,
                    MemoryType = memType
                };
            }

            ctrlLabelList.EditLabel(label);
        }
Ejemplo n.º 2
0
        private void InitMemoryTypeDropdown(bool forStartup)
        {
            cboMemoryType.SelectedIndexChanged -= this.cboMemoryType_SelectedIndexChanged;

            SnesMemoryType originalValue = forStartup ? ConfigManager.Config.Debug.HexEditor.MemoryType : cboMemoryType.GetEnumValue <SnesMemoryType>();

            cboMemoryType.BeginUpdate();
            cboMemoryType.Items.Clear();

            cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.CpuMemory));
            cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpcMemory));
            cboMemoryType.Items.Add("-");
            cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.PrgRom));
            cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.WorkRam));
            if (DebugApi.GetMemorySize(SnesMemoryType.SaveRam) > 0)
            {
                cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SaveRam));
            }
            cboMemoryType.Items.Add("-");
            cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.VideoRam));
            cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.CGRam));
            cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpriteRam));

            if (DebugApi.GetMemorySize(SnesMemoryType.DspProgramRom) > 0)
            {
                cboMemoryType.Items.Add("-");
                cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.DspProgramRom));
                cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.DspDataRom));
                cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.DspDataRam));
            }

            if (DebugApi.GetMemorySize(SnesMemoryType.Sa1InternalRam) > 0)
            {
                cboMemoryType.Items.Add("-");
                cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Sa1Memory));
                cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Sa1InternalRam));
            }

            if (DebugApi.GetMemorySize(SnesMemoryType.GsuWorkRam) > 0)
            {
                cboMemoryType.Items.Add("-");
                cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GsuMemory));
                cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GsuWorkRam));
            }

            if (DebugApi.GetMemorySize(SnesMemoryType.Cx4DataRam) > 0)
            {
                cboMemoryType.Items.Add("-");
                cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Cx4DataRam));
            }

            cboMemoryType.SelectedIndex = 0;
            cboMemoryType.SetEnumValue(originalValue);
            cboMemoryType.SelectedIndexChanged += this.cboMemoryType_SelectedIndexChanged;

            cboMemoryType.EndUpdate();
            UpdateMemoryType();
        }
Ejemplo n.º 3
0
 public static bool IsTypeCpuBreakpoint(SnesMemoryType type)
 {
     return(
         type != SnesMemoryType.Register &&
         type != SnesMemoryType.VideoRam &&
         type != SnesMemoryType.CGRam &&
         type != SnesMemoryType.SpriteRam
         );
 }
Ejemplo n.º 4
0
        private void UpdateMemoryType(SnesMemoryType memType)
        {
            _memoryType = cboMemoryType.GetEnumValue <SnesMemoryType>();

            int memSize = DebugApi.GetMemorySize(_memoryType);

            nudSize.Maximum    = Math.Min(0x40000, memSize);
            nudAddress.Maximum = memSize - nudSize.Value;
        }
Ejemplo n.º 5
0
 private static void SetLabel(uint address, SnesMemoryType memType, string label, string comment)
 {
     LabelManager.SetLabel(new CodeLabel()
     {
         Address    = address,
         MemoryType = memType,
         Label      = label,
         Comment    = comment
     }, false);
 }
Ejemplo n.º 6
0
 public static bool IsTypeCpuBreakpoint(SnesMemoryType type)
 {
     return(
         type == SnesMemoryType.CpuMemory ||
         type == SnesMemoryType.SpcMemory ||
         type == SnesMemoryType.WorkRam ||
         type == SnesMemoryType.SaveRam ||
         type == SnesMemoryType.PrgRom
         );
 }
Ejemplo n.º 7
0
        public static bool SupportsWatch(this SnesMemoryType memType)
        {
            switch (memType)
            {
            case SnesMemoryType.CpuMemory:
            case SnesMemoryType.SpcMemory:
                return(true);
            }

            return(false);
        }
Ejemplo n.º 8
0
        private void cboBreakpointType_SelectedIndexChanged(object sender, EventArgs e)
        {
            SnesMemoryType type = cboBreakpointType.GetEnumValue <SnesMemoryType>();

            chkExec.Visible = Breakpoint.IsTypeCpuBreakpoint(type);

            string maxValue = (DebugApi.GetMemorySize(type) - 1).ToString("X2");
            string minValue = "".PadLeft(maxValue.Length, '0');

            lblRange.Text = $"(range: ${minValue}-${maxValue})";
        }
Ejemplo n.º 9
0
 public static bool IsRelativeMemory(this SnesMemoryType memType)
 {
     switch (memType)
     {
     case SnesMemoryType.CpuMemory:
     case SnesMemoryType.SpcMemory:
     case SnesMemoryType.Sa1Memory:
     case SnesMemoryType.GsuMemory:
         return(true);
     }
     return(false);
 }
Ejemplo n.º 10
0
        public static CpuType ToCpuType(this SnesMemoryType memType)
        {
            switch (memType)
            {
            case SnesMemoryType.SpcMemory:
            case SnesMemoryType.SpcRam:
            case SnesMemoryType.SpcRom:
                return(CpuType.Spc);

            default:
                return(CpuType.Cpu);
            }
        }
Ejemplo n.º 11
0
        private void mnuAddBreakpoint_Click(object sender, EventArgs e)
        {
            SnesMemoryType memType    = _cpuType == CpuType.NecDsp ? SnesMemoryType.DspProgramRom : _cpuType.ToMemoryType();
            Breakpoint     breakpoint = new Breakpoint()
            {
                MemoryType = memType, CpuType = _cpuType
            };

            if (new frmBreakpoint(breakpoint).ShowDialog() == DialogResult.OK)
            {
                BreakpointManager.AddBreakpoint(breakpoint);
            }
        }
Ejemplo n.º 12
0
        private CodeLabel CreateLabel(Int32 address, SnesMemoryType memoryType, UInt32 length)
        {
            CodeLabel label = null;

            if (memoryType == SnesMemoryType.WorkRam)
            {
                if (!_workRamLabels.TryGetValue(address, out label))
                {
                    label = new CodeLabel()
                    {
                        Address = (UInt32)address, MemoryType = SnesMemoryType.WorkRam, Comment = string.Empty, Label = string.Empty, Length = length
                    };
                    _workRamLabels[address] = label;
                }
            }
            else if (memoryType == SnesMemoryType.SaveRam)
            {
                if (!_saveRamLabels.TryGetValue(address, out label))
                {
                    label = new CodeLabel()
                    {
                        Address = (UInt32)address, MemoryType = SnesMemoryType.SaveRam, Comment = string.Empty, Label = string.Empty, Length = length
                    };
                    _saveRamLabels[address] = label;
                }
            }
            else if (memoryType == SnesMemoryType.SpcRam)
            {
                if (!_spcRamLabels.TryGetValue(address, out label))
                {
                    label = new CodeLabel()
                    {
                        Address = (UInt32)address, MemoryType = SnesMemoryType.SpcRam, Comment = string.Empty, Label = string.Empty, Length = length
                    };
                    _spcRamLabels[address] = label;
                }
            }
            else
            {
                if (!_romLabels.TryGetValue(address, out label))
                {
                    label = new CodeLabel()
                    {
                        Address = (UInt32)address, MemoryType = SnesMemoryType.PrgRom, Comment = string.Empty, Label = string.Empty, Length = length
                    };
                    _romLabels[address] = label;
                }
            }

            return(label);
        }
Ejemplo n.º 13
0
        protected override bool ValidateInput()
        {
            UpdateObject();

            UInt32         address    = ((CodeLabel)Entity).Address;
            UInt32         length     = ((CodeLabel)Entity).Length;
            SnesMemoryType type       = ((CodeLabel)Entity).MemoryType;
            CodeLabel      sameLabel  = LabelManager.GetLabel(txtLabel.Text);
            int            maxAddress = DebugApi.GetMemorySize(type) - 1;

            if (maxAddress <= 0)
            {
                lblRange.Text = "(unavailable)";
            }
            else
            {
                lblRange.Text = "(Max: $" + maxAddress.ToString("X4") + ")";
            }

            for (UInt32 i = 0; i < length; i++)
            {
                CodeLabel sameAddress = LabelManager.GetLabel(address + i, type);
                if (sameAddress != null)
                {
                    if (_originalLabel == null)
                    {
                        //A label already exists and we're not editing an existing label, so we can't add it
                        return(false);
                    }
                    else
                    {
                        if (sameAddress.Label != _originalLabel.Label && !sameAddress.Label.StartsWith(_originalLabel.Label + "+"))
                        {
                            //A label already exists, we're trying to edit an existing label, but the existing label
                            //and the label we're editing aren't the same label.  Can't override an existing label with a different one.
                            return(false);
                        }
                    }
                }
            }

            return
                (length >= 1 && length <= 65536 &&
                 address + (length - 1) <= maxAddress &&
                 (sameLabel == null || sameLabel == _originalLabel) &&
                 (txtLabel.Text.Length > 0 || txtComment.Text.Length > 0) &&
                 !txtComment.Text.Contains('\x1') &&
                 (txtLabel.Text.Length == 0 || LabelManager.LabelRegex.IsMatch(txtLabel.Text)));
        }
Ejemplo n.º 14
0
        public static bool SupportsLabels(this SnesMemoryType memType)
        {
            switch (memType)
            {
            case SnesMemoryType.PrgRom:
            case SnesMemoryType.WorkRam:
            case SnesMemoryType.SaveRam:
            case SnesMemoryType.Register:
            case SnesMemoryType.SpcRam:
            case SnesMemoryType.SpcRom:
                return(true);
            }

            return(false);
        }
Ejemplo n.º 15
0
        public static bool IsPpuMemory(this SnesMemoryType memType)
        {
            switch (memType)
            {
            case SnesMemoryType.VideoRam:
            case SnesMemoryType.SpriteRam:
            case SnesMemoryType.CGRam:
            case SnesMemoryType.GbVideoRam:
            case SnesMemoryType.GbSpriteRam:
                return(true);

            default:
                return(false);
            }
        }
Ejemplo n.º 16
0
        public static bool SupportsWatch(this SnesMemoryType memType)
        {
            switch (memType)
            {
            case SnesMemoryType.CpuMemory:
            case SnesMemoryType.SpcMemory:
            case SnesMemoryType.Sa1Memory:
            case SnesMemoryType.GsuMemory:
            case SnesMemoryType.NecDspMemory:
            case SnesMemoryType.Cx4Memory:
            case SnesMemoryType.GameboyMemory:
                return(true);
            }

            return(false);
        }
Ejemplo n.º 17
0
 public ByteColorProvider(SnesMemoryType memoryType, bool showExec, bool showWrite, bool showRead, int framesToFade, bool hideUnusedBytes, bool hideReadBytes, bool hideWrittenBytes, bool hideExecutedBytes, bool highlightDataBytes, bool highlightCodeBytes, bool highlightLabelledBytes, bool highlightBreakpoints)
 {
     _memoryType             = memoryType;
     _showExec               = showExec;
     _showWrite              = showWrite;
     _showRead               = showRead;
     _framesToFade           = framesToFade;
     _hideUnusedBytes        = hideUnusedBytes;
     _hideReadBytes          = hideReadBytes;
     _hideWrittenBytes       = hideWrittenBytes;
     _hideExecutedBytes      = hideExecutedBytes;
     _highlightDataBytes     = highlightDataBytes;
     _highlightCodeBytes     = highlightCodeBytes;
     _highlightLabelledBytes = highlightLabelledBytes;
     _highlightBreakpoints   = highlightBreakpoints;
 }
Ejemplo n.º 18
0
        public void RefreshData(SnesMemoryType memoryType)
        {
            if (_memoryType != memoryType)
            {
                _memoryType   = memoryType;
                _byteProvider = null;
            }

            byte[] data = DebugApi.GetMemoryState(this._memoryType);

            if (data != null)
            {
                bool changed = true;
                if (this._byteProvider != null && data.Length == this._byteProvider.Length)
                {
                    changed = false;
                    for (int i = 0; i < this._byteProvider.Length; i++)
                    {
                        if (this._byteProvider.Bytes[i] != data[i])
                        {
                            changed = true;
                            break;
                        }
                    }
                }

                if (changed)
                {
                    if (_byteProvider == null || _byteProvider.Length != data.Length)
                    {
                        _byteProvider              = new StaticByteProvider(data);
                        _byteProvider.ByteChanged += (int byteIndex, byte newValue, byte oldValue) => {
                            DebugApi.SetMemoryValue(_memoryType, (UInt32)byteIndex, newValue);
                        };
                        _byteProvider.BytesChanged += (int byteIndex, byte[] values) => {
                            DebugApi.SetMemoryValues(_memoryType, (UInt32)byteIndex, values, values.Length);
                        };
                        this.ctrlHexBox.ByteProvider = _byteProvider;
                    }
                    else
                    {
                        _byteProvider.SetData(data);
                    }
                    this.ctrlHexBox.Refresh();
                }
            }
        }
Ejemplo n.º 19
0
        private void UpdateMemoryType(SnesMemoryType memType)
        {
            _memoryType = cboMemoryType.GetEnumValue <SnesMemoryType>();

            bool isVram = _memoryType == SnesMemoryType.VideoRam;

            nudOffset.Visible = !isVram;
            nudBank.Visible   = !isVram;
            lblOffset.Visible = !isVram;
            lblBank.Visible   = !isVram;
            if (isVram)
            {
                nudBank.Value   = 0;
                nudOffset.Value = 0;
            }

            nudBank.Maximum = Math.Max(1, (DebugApi.GetMemorySize(_memoryType) / 0x10000) - 1);
        }
Ejemplo n.º 20
0
        private static UInt64 GetKey(UInt32 address, SnesMemoryType SnesMemoryType)
        {
            switch (SnesMemoryType)
            {
            case SnesMemoryType.PrgRom: return(address | ((ulong)1 << 32));

            case SnesMemoryType.WorkRam: return(address | ((ulong)2 << 32));

            case SnesMemoryType.SaveRam: return(address | ((ulong)3 << 32));

            case SnesMemoryType.Register: return(address | ((ulong)4 << 32));

            case SnesMemoryType.SpcRam: return(address | ((ulong)5 << 32));

            case SnesMemoryType.SpcRom: return(address | ((ulong)6 << 32));
            }
            throw new Exception("Invalid type");
        }
Ejemplo n.º 21
0
        public bool Matches(UInt32 address, SnesMemoryType type, CpuType?cpuType)
        {
            if ((cpuType.HasValue && cpuType.Value != this.CpuType) || IsTypeCpuBreakpoint(type) != this.IsCpuBreakpoint)
            {
                return(false);
            }

            if (this.AddressType == BreakpointAddressType.SingleAddress)
            {
                return(address == this.Address && type == this.MemoryType);
            }
            else if (this.AddressType == BreakpointAddressType.AddressRange)
            {
                return(address >= this.StartAddress && address <= this.EndAddress && type == this.MemoryType);
            }

            return(false);
        }
Ejemplo n.º 22
0
        private void cboMemoryType_SelectedIndexChanged(object sender, EventArgs e)
        {
            _memoryType = cboMemoryType.GetEnumValue <SnesMemoryType>();

            bool isVram = _memoryType == SnesMemoryType.VideoRam;

            nudOffset.Visible = !isVram;
            nudBank.Visible   = !isVram;
            lblOffset.Visible = !isVram;
            lblBank.Visible   = !isVram;
            if (isVram)
            {
                nudBank.Value   = 0;
                nudOffset.Value = 0;
            }

            nudBank.Maximum = Math.Max(1, (DebugApi.GetMemorySize(_memoryType) / 0x10000) - 1);
            RefreshViewer();
        }
Ejemplo n.º 23
0
        public static bool SupportsLabels(this SnesMemoryType memType)
        {
            switch (memType)
            {
            case SnesMemoryType.PrgRom:
            case SnesMemoryType.WorkRam:
            case SnesMemoryType.SaveRam:
            case SnesMemoryType.Register:
            case SnesMemoryType.SpcRam:
            case SnesMemoryType.SpcRom:
            case SnesMemoryType.Sa1InternalRam:
            case SnesMemoryType.GbPrgRom:
            case SnesMemoryType.GbWorkRam:
            case SnesMemoryType.GbCartRam:
            case SnesMemoryType.GbHighRam:
            case SnesMemoryType.GbBootRom:
                return(true);
            }

            return(false);
        }
Ejemplo n.º 24
0
        private static UInt64 GetKey(UInt32 address, SnesMemoryType memType)
        {
            switch (memType)
            {
            case SnesMemoryType.PrgRom: return(address | ((ulong)1 << 32));

            case SnesMemoryType.WorkRam: return(address | ((ulong)2 << 32));

            case SnesMemoryType.SaveRam: return(address | ((ulong)3 << 32));

            case SnesMemoryType.Register: return(address | ((ulong)4 << 32));

            case SnesMemoryType.SpcRam: return(address | ((ulong)5 << 32));

            case SnesMemoryType.SpcRom: return(address | ((ulong)6 << 32));

            case SnesMemoryType.Sa1InternalRam: return(address | ((ulong)7 << 32));

            case SnesMemoryType.GsuWorkRam: return(address | ((ulong)8 << 32));

            case SnesMemoryType.BsxPsRam: return(address | ((ulong)9 << 32));

            case SnesMemoryType.BsxMemoryPack: return(address | ((ulong)10 << 32));

            case SnesMemoryType.DspProgramRom: return(address | ((ulong)11 << 32));

            case SnesMemoryType.GbPrgRom: return(address | ((ulong)12 << 32));

            case SnesMemoryType.GbWorkRam: return(address | ((ulong)13 << 32));

            case SnesMemoryType.GbCartRam: return(address | ((ulong)14 << 32));

            case SnesMemoryType.GbHighRam: return(address | ((ulong)15 << 32));

            case SnesMemoryType.GbBootRom: return(address | ((ulong)16 << 32));

            case SnesMemoryType.GameboyMemory: return(address | ((ulong)17 << 32));
            }
            throw new Exception("Invalid type");
        }
Ejemplo n.º 25
0
        protected override bool ValidateInput()
        {
            if (txtCondition.Text.Trim().Length > 0)
            {
                EvalResultType resultType;
                DebugApi.EvaluateExpression(txtCondition.Text.Replace(Environment.NewLine, " "), _cpuType, out resultType, false);
                if (resultType == EvalResultType.Invalid)
                {
                    picExpressionWarning.Visible = true;
                    return(false);
                }
            }
            picExpressionWarning.Visible = false;

            SnesMemoryType type     = cboBreakpointType.GetEnumValue <SnesMemoryType>();
            int            maxValue = DebugApi.GetMemorySize(type) - 1;

            if (radSpecificAddress.Checked)
            {
                if (ValidateAddress(txtAddress, maxValue) < 0)
                {
                    return(false);
                }
            }
            else if (radRange.Checked)
            {
                int start = ValidateAddress(txtFrom, maxValue);
                int end   = ValidateAddress(txtTo, maxValue);

                if (start < 0 || end < 0 || end < start)
                {
                    return(false);
                }
            }

            return(chkRead.Checked || chkWrite.Checked || (chkExec.Checked && Breakpoint.IsTypeCpuBreakpoint(type)) || txtCondition.Text.Length > 0);
        }
Ejemplo n.º 26
0
        public static CpuType ToCpuType(this SnesMemoryType memType)
        {
            switch (memType)
            {
            case SnesMemoryType.SpcMemory:
            case SnesMemoryType.SpcRam:
            case SnesMemoryType.SpcRom:
                return(CpuType.Spc);

            case SnesMemoryType.GsuMemory:
            case SnesMemoryType.GsuWorkRam:
                return(CpuType.Gsu);

            case SnesMemoryType.Sa1InternalRam:
            case SnesMemoryType.Sa1Memory:
                return(CpuType.Sa1);

            case SnesMemoryType.DspDataRam:
            case SnesMemoryType.DspDataRom:
            case SnesMemoryType.DspProgramRom:
                return(CpuType.NecDsp);

            case SnesMemoryType.GbPrgRom:
            case SnesMemoryType.GbWorkRam:
            case SnesMemoryType.GbCartRam:
            case SnesMemoryType.GbHighRam:
            case SnesMemoryType.GbBootRom:
            case SnesMemoryType.GbVideoRam:
            case SnesMemoryType.GbSpriteRam:
            case SnesMemoryType.GameboyMemory:
                return(CpuType.Gameboy);

            default:
                return(CpuType.Cpu);
            }
        }
Ejemplo n.º 27
0
 [DllImport(DllPath)] public static extern void SetMemoryState(SnesMemoryType type, [In] byte[] buffer, Int32 length);
Ejemplo n.º 28
0
        public static Breakpoint GetMatchingBreakpoint(UInt32 startAddress, UInt32 endAddress, SnesMemoryType memoryType)
        {
            bool isAddressRange = startAddress != endAddress;

            return(Breakpoints.Where((bp) =>
                                     bp.MemoryType == memoryType &&
                                     ((!isAddressRange && bp.Address == startAddress) || (isAddressRange && bp.StartAddress == startAddress && bp.EndAddress == endAddress))
                                     ).FirstOrDefault());
        }
Ejemplo n.º 29
0
 [DllImport(DllPath)] public static extern void SetMemoryValues(SnesMemoryType type, UInt32 address, [In] byte[] data, Int32 length);
Ejemplo n.º 30
0
 private void UpdateMemoryType()
 {
     _memoryType = cboMemoryType.GetEnumValue <SnesMemoryType>();
     RefreshData();
 }