private void AddGameboyTypes(bool excludeCpuMemory) { if (DebugApi.GetMemorySize(SnesMemoryType.GbPrgRom) > 0) { if (this.Items.Count > 0) { this.Items.Add("-"); } if (!excludeCpuMemory) { this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GameboyMemory)); } this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbPrgRom)); this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbWorkRam)); if (DebugApi.GetMemorySize(SnesMemoryType.GbCartRam) > 0) { this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbCartRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.GbBootRom) > 0) { this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbBootRom)); } this.Items.Add("-"); this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbVideoRam)); this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbSpriteRam)); } }
private void InitMemoryTypeDropdown() { cboMemoryType.BeginUpdate(); cboMemoryType.Items.Clear(); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.VideoRam)); cboMemoryType.Items.Add("-"); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.CpuMemory)); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.PrgRom)); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.WorkRam)); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SaveRam)); if (DebugApi.GetMemorySize(SnesMemoryType.GsuWorkRam) > 0) { cboMemoryType.Items.Add("-"); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GsuWorkRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.Sa1InternalRam) > 0) { cboMemoryType.Items.Add("-"); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Sa1InternalRam)); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Sa1Memory)); } cboMemoryType.SelectedIndex = 0; cboMemoryType.EndUpdate(); }
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)); cboMemoryType.SelectedIndex = 0; cboMemoryType.SetEnumValue(originalValue); cboMemoryType.SelectedIndexChanged += this.cboMemoryType_SelectedIndexChanged; cboMemoryType.EndUpdate(); UpdateMemoryType(); }
private void mnuResetCdlLog_Click(object sender, EventArgs e) { int memSize = DebugApi.GetMemorySize(_cpuType == CpuType.Gameboy ? SnesMemoryType.GbPrgRom : SnesMemoryType.PrgRom); byte[] emptyCdlLog = new byte[memSize]; DebugApi.SetCdlData(_cpuType, emptyCdlLog, emptyCdlLog.Length); RefreshDisassembly(); }
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; }
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})"; }
private void nudSize_ValueChanged(object sender, EventArgs e) { _options.PageSize = (int)nudSize.Value; int memSize = DebugApi.GetMemorySize(_memoryType); nudAddress.Increment = nudSize.Value; nudAddress.Maximum = memSize - nudSize.Value; RefreshData(); RefreshViewer(); }
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))); }
private void InitMemoryTypeDropdown() { cboMemoryType.BeginUpdate(); cboMemoryType.Items.Clear(); if (EmuApi.GetRomInfo().CoprocessorType == CoprocessorType.Gameboy) { AddGameboyTypes(); } else { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.VideoRam)); cboMemoryType.Items.Add("-"); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.CpuMemory)); 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)); } if (DebugApi.GetMemorySize(SnesMemoryType.GsuWorkRam) > 0) { cboMemoryType.Items.Add("-"); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GsuWorkRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.Sa1InternalRam) > 0) { cboMemoryType.Items.Add("-"); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Sa1InternalRam)); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Sa1Memory)); } if (DebugApi.GetMemorySize(SnesMemoryType.BsxPsRam) > 0) { cboMemoryType.Items.Add("-"); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.BsxPsRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.BsxMemoryPack) > 0) { cboMemoryType.Items.Add("-"); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.BsxMemoryPack)); } AddGameboyTypes(); } cboMemoryType.SelectedIndex = 0; cboMemoryType.EndUpdate(); }
private void AddGameboyTypes() { if (DebugApi.GetMemorySize(SnesMemoryType.GbPrgRom) > 0) { if (cboMemoryType.Items.Count > 0) { cboMemoryType.Items.Add("-"); } cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbVideoRam)); cboMemoryType.Items.Add("-"); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GameboyMemory)); cboMemoryType.Items.Add("-"); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbPrgRom)); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbWorkRam)); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbCartRam)); } }
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); }
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(); }
public frmEditLabel(CodeLabel label) { InitializeComponent(); _originalLabel = label; Entity = label.Clone(); AddBinding(nameof(CodeLabel.MemoryType), cboType); AddBinding(nameof(CodeLabel.Address), txtAddress); AddBinding(nameof(CodeLabel.Label), txtLabel); AddBinding(nameof(CodeLabel.Comment), txtComment); AddBinding(nameof(CodeLabel.Length), nudLength); CpuType cpuType = label.MemoryType.ToCpuType(); cboType.Items.Clear(); if (cpuType == CpuType.Cpu) { if (DebugApi.GetMemorySize(SnesMemoryType.PrgRom) > 0) { cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.PrgRom)); } if (DebugApi.GetMemorySize(SnesMemoryType.WorkRam) > 0) { cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.WorkRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.SaveRam) > 0) { cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SaveRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.Sa1InternalRam) > 0) { cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Sa1InternalRam)); } cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Register)); } else if (cpuType == CpuType.Spc) { cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpcRam)); cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpcRom)); } }
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); }
protected override void OnLoad(EventArgs evt) { base.OnLoad(evt); if (DesignMode) { return; } _tileData = new byte[0x400000]; _tileImage = new Bitmap(512, 512, PixelFormat.Format32bppPArgb); ctrlImagePanel.Image = _tileImage; BaseConfigForm.InitializeComboBox(cboFormat, typeof(TileFormat)); BaseConfigForm.InitializeComboBox(cboLayout, typeof(TileLayout)); InitMemoryTypeDropdown(); InitShortcuts(); TileViewerConfig config = ConfigManager.Config.Debug.TileViewer; RestoreLocation(config.WindowLocation, config.WindowSize); cboMemoryType.SetEnumValue(config.Source); cboFormat.SetEnumValue(config.Format); cboLayout.SetEnumValue(config.Layout); nudColumns.Value = config.ColumnCount; int memSize = DebugApi.GetMemorySize(_memoryType); config.Address = Math.Min(memSize - config.PageSize, config.Address); UpdateMemoryType(config.Source); nudAddress.Value = config.Address; nudSize.Value = config.PageSize; mnuAutoRefresh.Checked = config.AutoRefresh; chkShowTileGrid.Checked = config.ShowTileGrid; ctrlImagePanel.ImageScale = config.ImageScale; ctrlScanlineCycleSelect.Initialize(config.RefreshScanline, config.RefreshCycle); ctrlPaletteViewer.SelectedPalette = config.SelectedPalette; nudSize.Increment = 0x1000; nudSize.Minimum = 0x1000; nudSize.Maximum = Math.Min(memSize, 0x40000); nudAddress.Increment = nudSize.Value; nudAddress.Maximum = memSize - nudSize.Value; _address = config.Address; _options.Format = config.Format; _options.Layout = config.Layout; _options.Palette = config.SelectedPalette; _options.Width = config.ColumnCount; _options.PageSize = config.PageSize; ctrlImagePanel.GridSizeX = config.ShowTileGrid ? 8 : 0; ctrlImagePanel.GridSizeY = config.ShowTileGrid ? 8 : 0; _refreshManager = new WindowRefreshManager(this); _refreshManager.AutoRefresh = config.AutoRefresh; _refreshManager.AutoRefreshSpeed = config.AutoRefreshSpeed; mnuAutoRefreshLow.Click += (s, e) => _refreshManager.AutoRefreshSpeed = RefreshSpeed.Low; mnuAutoRefreshNormal.Click += (s, e) => _refreshManager.AutoRefreshSpeed = RefreshSpeed.Normal; mnuAutoRefreshHigh.Click += (s, e) => _refreshManager.AutoRefreshSpeed = RefreshSpeed.High; mnuAutoRefreshSpeed.DropDownOpening += (s, e) => UpdateRefreshSpeedMenu(); RefreshData(); RefreshViewer(); cboMemoryType.SelectedIndexChanged += cboMemoryType_SelectedIndexChanged; nudAddress.ValueChanged += nudAddress_ValueChanged; chkShowTileGrid.Click += chkShowTileGrid_Click; cboFormat.SelectedIndexChanged += cboFormat_SelectedIndexChanged; cboLayout.SelectedIndexChanged += cboLayout_SelectedIndexChanged; nudColumns.ValueChanged += nudColumns_ValueChanged; nudSize.ValueChanged += nudSize_ValueChanged; ctrlPaletteViewer.SelectionChanged += ctrlPaletteViewer_SelectionChanged; mnuAutoRefresh.CheckedChanged += mnuAutoRefresh_CheckedChanged; UpdatePaletteControl(); btnPresetBg1.Click += (s, e) => GoToBgLayer(0); btnPresetBg2.Click += (s, e) => GoToBgLayer(1); btnPresetBg3.Click += (s, e) => GoToBgLayer(2); btnPresetBg4.Click += (s, e) => GoToBgLayer(3); btnPresetOam1.Click += (s, e) => GoToOamPreset(0); btnPresetOam2.Click += (s, e) => GoToOamPreset(1); }
private void AddSnesMemoryTypes(bool excludeCpuMemory) { if (!excludeCpuMemory) { this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.CpuMemory)); this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpcMemory)); this.Items.Add("-"); } this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.PrgRom)); this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.WorkRam)); if (DebugApi.GetMemorySize(SnesMemoryType.SaveRam) > 0) { this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SaveRam)); } this.Items.Add("-"); this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.VideoRam)); this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.CGRam)); this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpriteRam)); if (DebugApi.GetMemorySize(SnesMemoryType.DspProgramRom) > 0) { this.Items.Add("-"); this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.DspProgramRom)); this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.DspDataRom)); this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.DspDataRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.Sa1InternalRam) > 0) { this.Items.Add("-"); if (!excludeCpuMemory) { this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Sa1Memory)); } this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Sa1InternalRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.GsuWorkRam) > 0) { this.Items.Add("-"); if (!excludeCpuMemory) { this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GsuMemory)); } this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GsuWorkRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.Cx4DataRam) > 0) { this.Items.Add("-"); if (!excludeCpuMemory) { this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Cx4Memory)); } this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Cx4DataRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.BsxPsRam) > 0) { this.Items.Add("-"); this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.BsxPsRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.BsxMemoryPack) > 0) { this.Items.Add("-"); this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.BsxMemoryPack)); } }
private void mnuResetCdlLog_Click(object sender, EventArgs e) { byte[] emptyCdlLog = new byte[DebugApi.GetMemorySize(SnesMemoryType.PrgRom)]; DebugApi.SetCdlData(emptyCdlLog, emptyCdlLog.Length); RefreshDisassembly(); }
public frmBreakpoint(Breakpoint breakpoint) { InitializeComponent(); Entity = breakpoint; switch (breakpoint.AddressType) { case BreakpointAddressType.AnyAddress: radAnyAddress.Checked = true; break; case BreakpointAddressType.SingleAddress: radSpecificAddress.Checked = true; break; case BreakpointAddressType.AddressRange: radRange.Checked = true; break; } AddBinding(nameof(Breakpoint.MemoryType), cboBreakpointType); AddBinding(nameof(Breakpoint.Enabled), chkEnabled); AddBinding(nameof(Breakpoint.MarkEvent), chkMarkOnEventViewer); AddBinding(nameof(Breakpoint.Address), txtAddress); AddBinding(nameof(Breakpoint.StartAddress), txtFrom); AddBinding(nameof(Breakpoint.EndAddress), txtTo); AddBinding(nameof(Breakpoint.BreakOnRead), chkRead); AddBinding(nameof(Breakpoint.BreakOnWrite), chkWrite); AddBinding(nameof(Breakpoint.BreakOnExec), chkExec); AddBinding(nameof(Breakpoint.Condition), txtCondition); _cpuType = breakpoint.CpuType; cboBreakpointType.Items.Clear(); if (_cpuType == CpuType.Cpu || _cpuType == CpuType.Sa1 || _cpuType == CpuType.Gsu || _cpuType == CpuType.Cx4) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(_cpuType.ToMemoryType())); cboBreakpointType.Items.Add("-"); if (DebugApi.GetMemorySize(SnesMemoryType.PrgRom) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.PrgRom)); } if (_cpuType == CpuType.Cpu && DebugApi.GetMemorySize(SnesMemoryType.WorkRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.WorkRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.SaveRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SaveRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.Sa1InternalRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Sa1InternalRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.GsuWorkRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GsuWorkRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.BsxPsRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.BsxPsRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.BsxMemoryPack) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.BsxMemoryPack)); } if (_cpuType == CpuType.Cpu) { if (cboBreakpointType.Items.Count > 2) { cboBreakpointType.Items.Add("-"); } cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.VideoRam)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpriteRam)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.CGRam)); } } else if (_cpuType == CpuType.Spc) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpcMemory)); cboBreakpointType.Items.Add("-"); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpcRam)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpcRom)); } else if (_cpuType == CpuType.NecDsp) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.DspProgramRom)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.DspDataRom)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.DspDataRam)); } else if (_cpuType == CpuType.Gameboy) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GameboyMemory)); cboBreakpointType.Items.Add("-"); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbPrgRom)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbWorkRam)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbHighRam)); if (DebugApi.GetMemorySize(SnesMemoryType.GbCartRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbCartRam)); } } this.toolTip.SetToolTip(this.picExpressionWarning, "Condition contains invalid syntax or symbols."); this.toolTip.SetToolTip(this.picHelp, frmBreakpoint.GetConditionTooltip(false)); }
private void BuildCdlData() { int prgSize = DebugApi.GetMemorySize(SnesMemoryType.PrgRom); if (prgSize <= 0) { return; } byte[] cdlFile = new byte[prgSize]; byte[] prgRomContent = DebugApi.GetMemoryState(SnesMemoryType.PrgRom); //Mark data/code regions foreach (SpanInfo span in _spans.Values) { if (_scopeSpans.Contains(span.ID)) { //Skip any span used by a scope, they don't correspond to an actual line of code continue; } int prgAddress = GetPrgAddress(span); if (prgAddress >= 0 && prgAddress < prgSize) { for (int i = 0; i < span.Size; i++) { if (cdlFile[prgAddress + i] != (byte)CdlFlags.Data && !span.IsData && span.Size <= 4) { cdlFile[prgAddress + i] = (byte)CdlFlags.Code; byte opCode = prgRomContent[prgAddress]; if (span.Size == 2) { if (IsVarWidthMemoryInstruction(opCode)) { //8-bit immediate memory operation, set M flag cdlFile[prgAddress + i] |= (byte)CdlFlags.MemoryMode8; } else if (IsVarWidthIndexInstruction(opCode)) { //8-bit immediate index operation, set X flag cdlFile[prgAddress + i] |= (byte)CdlFlags.IndexMode8; } } } else if (span.IsData) { cdlFile[prgAddress + i] = (byte)CdlFlags.Data; } else if (cdlFile[prgAddress + i] == 0) { //Mark bytes as tentative data, until we know that the bytes are actually code cdlFile[prgAddress + i] = 0x04; } } } } for (int i = 0; i < cdlFile.Length; i++) { if (cdlFile[i] == 0x04) { //Mark all bytes marked as tentative data as data cdlFile[i] = (byte)CdlFlags.Data; } } //Find/identify functions and jump targets foreach (SymbolInfo symbol in _symbols.Values) { LineInfo line; if (!symbol.SegmentID.HasValue) { //This is a constant, ignore it continue; } foreach (int reference in symbol.References) { if (_lines.TryGetValue(reference, out line) && line.SpanIDs.Count > 0) { SpanInfo span; if (_spans.TryGetValue(line.SpanIDs[0], out span) && !span.IsData && span.Size <= 4) { int referencePrgAddr = GetPrgAddress(span); if (referencePrgAddr >= 0 && referencePrgAddr < prgRomContent.Length) { byte opCode = prgRomContent[referencePrgAddr]; if (IsBranchInstruction(opCode)) { //This symbol is used with a JSR/jump instruction, so it's either a function or jump target bool isJsr = opCode == 0x20 || opCode == 0x22; //JSR/JSL SpanInfo definitionSpan = GetSymbolDefinitionSpan(symbol); if (definitionSpan != null) { int definitionPrgAddr = GetPrgAddress(definitionSpan); if (definitionPrgAddr >= 0 && definitionPrgAddr < prgRomContent.Length) { cdlFile[definitionPrgAddr] |= (byte)(isJsr ? CdlFlags.SubEntryPoint : CdlFlags.JumpTarget); break; } } } } } } } } DebugApi.SetCdlData(CpuType.Cpu, cdlFile, cdlFile.Length); }
private void BuildCdlData() { int prgSize = DebugApi.GetMemorySize(SnesMemoryType.PrgRom); if (prgSize <= 0) { return; } byte[] cdlFile = new byte[prgSize]; //Mark data/code regions foreach (SpanInfo span in _spans.Values) { int prgAddress = GetPrgAddress(span); if (prgAddress >= 0 && prgAddress < prgSize) { for (int i = 0; i < span.Size; i++) { if (cdlFile[prgAddress + i] != (byte)CdlFlags.Data && !span.IsData && span.Size <= 4) { cdlFile[prgAddress + i] = (byte)CdlFlags.Code; } else if (span.IsData) { cdlFile[prgAddress + i] = (byte)CdlFlags.Data; } else if (cdlFile[prgAddress + i] == 0) { //Mark bytes as tentative data, until we know that the bytes are actually code cdlFile[prgAddress + i] = 0x04; } } } } for (int i = 0; i < cdlFile.Length; i++) { if (cdlFile[i] == 0x04) { //Mark all bytes marked as tentative data as data cdlFile[i] = (byte)CdlFlags.Data; } } //Find/identify functions and jump targets byte[] prgRomContent = DebugApi.GetMemoryState(SnesMemoryType.PrgRom); foreach (SymbolInfo symbol in _symbols.Values) { LineInfo line; if (!symbol.SegmentID.HasValue) { //This is a constant, ignore it continue; } foreach (int reference in symbol.References) { if (_lines.TryGetValue(reference, out line) && line.SpanIDs.Count > 0) { SpanInfo span; if (_spans.TryGetValue(line.SpanIDs[0], out span) && !span.IsData && span.Size <= 3) { int referencePrgAddr = GetPrgAddress(span); if (referencePrgAddr >= 0 && referencePrgAddr < prgRomContent.Length) { byte opCode = prgRomContent[referencePrgAddr]; if (opCode == 0x20 || opCode == 0x10 || opCode == 0x30 || opCode == 0x50 || opCode == 0x70 || opCode == 0x80 || opCode == 0x90 || opCode == 0xB0 || opCode == 0xD0 || opCode == 0xF0 || opCode == 0x4C || opCode == 0x20 || opCode == 0x4C || opCode == 0x5C || opCode == 0x6C) { //This symbol is used with a JSR/jump instruction, so it's either a function or jump target bool isJsr = opCode == 0x20 || opCode == 0x22; //JSR/JSL SpanInfo definitionSpan = GetSymbolDefinitionSpan(symbol); if (definitionSpan != null) { int definitionPrgAddr = GetPrgAddress(definitionSpan); if (definitionPrgAddr >= 0 && definitionPrgAddr < prgRomContent.Length) { cdlFile[definitionPrgAddr] |= (byte)(isJsr ? CdlFlags.SubEntryPoint : CdlFlags.JumpTarget); break; } } } } } } } } DebugApi.SetCdlData(cdlFile, cdlFile.Length); }
private void UpdateResults() { string searchString = txtSearch.Text.Trim(); List <string> searchStrings = new List <string>(); searchStrings.Add(searchString.ToLower()); searchStrings.AddRange(searchString.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); for (int i = 0; i < searchString.Length; i++) { char ch = searchString[i]; if (ch >= 'A' && ch <= 'Z') { searchString = searchString.Remove(i, 1).Insert(i, " " + (char)(ch + 'a' - 'A')); } } searchStrings.AddRange(searchString.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); searchStrings = searchStrings.Distinct().ToList(); _resultCount = 0; int size = DebugApi.GetMemorySize(SnesMemoryType.PrgRom); byte[] cdlData = DebugApi.GetCdlData(0, (uint)size, SnesMemoryType.PrgRom); List <SearchResultInfo> searchResults = new List <SearchResultInfo>(); bool isEmptySearch = string.IsNullOrWhiteSpace(searchString); if (!isEmptySearch) { if (_symbolProvider != null) { if (_showFilesAndConstants) { foreach (SourceFileInfo file in _symbolProvider.SourceFiles) { if (Contains(file.Name, searchStrings)) { searchResults.Add(new SearchResultInfo() { Caption = Path.GetFileName(file.Name), AbsoluteAddress = null, SearchResultType = SearchResultType.File, File = file, SourceLocation = null, RelativeAddress = null, CodeLabel = null }); } } } foreach (SourceSymbol symbol in _symbolProvider.GetSymbols()) { if (Contains(symbol.Name, searchStrings)) { SourceCodeLocation def = _symbolProvider.GetSymbolDefinition(symbol); AddressInfo? addressInfo = _symbolProvider.GetSymbolAddressInfo(symbol); int value = 0; AddressInfo?relAddress = null; bool isConstant = addressInfo == null; if (!_showFilesAndConstants && isConstant) { continue; } if (addressInfo != null) { value = DebugApi.GetMemoryValue(addressInfo.Value.Type, (uint)addressInfo.Value.Address); relAddress = DebugApi.GetRelativeAddress(addressInfo.Value, CpuType.Cpu); //TODO } else { //For constants, the address field contains the constant's value value = symbol.Address ?? 0; } SearchResultType resultType = SearchResultType.Data; if (isConstant) { resultType = SearchResultType.Constant; } else if (addressInfo?.Type == SnesMemoryType.PrgRom && addressInfo.Value.Address < cdlData.Length) { if ((cdlData[addressInfo.Value.Address] & (byte)CdlFlags.JumpTarget) != 0) { resultType = SearchResultType.JumpTarget; } else if ((cdlData[addressInfo.Value.Address] & (byte)CdlFlags.SubEntryPoint) != 0) { resultType = SearchResultType.Function; } } searchResults.Add(new SearchResultInfo() { Caption = symbol.Name, AbsoluteAddress = addressInfo, Length = _symbolProvider.GetSymbolSize(symbol), SearchResultType = resultType, Value = value, File = def?.File, SourceLocation = def, RelativeAddress = relAddress, CodeLabel = LabelManager.GetLabel(symbol.Name) }); } } } else { foreach (CodeLabel label in LabelManager.GetLabels(CpuType.Cpu)) //TODO { if (Contains(label.Label, searchStrings)) { SearchResultType resultType = SearchResultType.Data; AddressInfo addressInfo = label.GetAbsoluteAddress(); if (addressInfo.Type == SnesMemoryType.PrgRom && addressInfo.Address < cdlData.Length) { if ((cdlData[addressInfo.Address] & (byte)CdlFlags.JumpTarget) != 0) { resultType = SearchResultType.JumpTarget; } else if ((cdlData[addressInfo.Address] & (byte)CdlFlags.SubEntryPoint) != 0) { resultType = SearchResultType.Function; } } AddressInfo relAddress = label.GetRelativeAddress(CpuType.Cpu); //TODO searchResults.Add(new SearchResultInfo() { Caption = label.Label, AbsoluteAddress = label.GetAbsoluteAddress(), Length = (int)label.Length, Value = label.GetValue(), SearchResultType = resultType, File = null, Disabled = !_allowOutOfScope && relAddress.Address < 0, RelativeAddress = relAddress, CodeLabel = label }); } } } } searchResults.Sort((SearchResultInfo a, SearchResultInfo b) => { int comparison = a.Disabled.CompareTo(b.Disabled); if (comparison == 0) { bool aStartsWithSearch = a.Caption.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase); bool bStartsWithSearch = b.Caption.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase); comparison = bStartsWithSearch.CompareTo(aStartsWithSearch); if (comparison == 0) { comparison = a.Caption.CompareTo(b.Caption); } } return(comparison); }); _resultCount = Math.Min(searchResults.Count, MaxResultCount); SelectedResult = 0; lblResultCount.Visible = !isEmptySearch; lblResultCount.Text = searchResults.Count.ToString() + (searchResults.Count == 1 ? " result" : " results"); if (searchResults.Count > MaxResultCount) { lblResultCount.Text += " (" + MaxResultCount.ToString() + " shown)"; } if (searchResults.Count == 0 && !isEmptySearch) { _resultCount++; searchResults.Add(new SearchResultInfo() { Caption = "No results found." }); pnlResults.BackColor = SystemColors.ControlLight; } else { pnlResults.BackColor = SystemColors.ControlDarkDark; } if (Program.IsMono) { pnlResults.Visible = false; } else { //Suspend layout causes a crash on Mono tlpResults.SuspendLayout(); } for (int i = 0; i < _resultCount; i++) { _results[i].Initialize(searchResults[i]); _results[i].Tag = searchResults[i]; _results[i].Visible = true; } for (int i = _resultCount; i < MaxResultCount; i++) { _results[i].Visible = false; } pnlResults.VerticalScroll.Value = 0; tlpResults.Height = (_results[0].Height + 1) * _resultCount; pnlResults.ResumeLayout(); if (Program.IsMono) { pnlResults.Visible = true; tlpResults.Width = pnlResults.ClientSize.Width - 17; } else { tlpResults.ResumeLayout(); tlpResults.Width = pnlResults.ClientSize.Width - 1; } }