public void InitMemoryTypeDropdown() { cboMemoryType.SelectedIndexChanged -= cboMemoryType_SelectedIndexChanged; AddressType originalValue = cboMemoryType.GetEnumValue <AddressType>(); cboMemoryType.BeginUpdate(); cboMemoryType.Items.Clear(); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(AddressType.InternalRam)); if (InteropEmu.DebugGetMemorySize(DebugMemoryType.PrgRom) > 0) { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(AddressType.PrgRom)); } if (InteropEmu.DebugGetMemorySize(DebugMemoryType.WorkRam) > 0) { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(AddressType.WorkRam)); } if (InteropEmu.DebugGetMemorySize(DebugMemoryType.SaveRam) > 0) { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(AddressType.SaveRam)); } cboMemoryType.SelectedIndex = 0; cboMemoryType.SetEnumValue(originalValue); cboMemoryType.SelectedIndexChanged += cboMemoryType_SelectedIndexChanged; cboMemoryType.EndUpdate(); UpdateMemoryType(); }
private void ctxMenu_Opening(object sender, CancelEventArgs e) { int baseAddress = _bottomBank ? 0x1000 : 0x0000; bool ppuMemory = this.cboChrSelection.SelectedIndex == 0; if (this.cboChrSelection.SelectedIndex > 1) { baseAddress += (this.cboChrSelection.SelectedIndex - 1) * 0x2000; } int tileIndex = GetLargeSpriteIndex(_tileIndex); bool isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0; StringBuilder sb = new StringBuilder(); if (isChrRam) { for (int i = 0; i < 16; i++) { sb.Append(InteropEmu.DebugGetMemoryValue(ppuMemory ? DebugMemoryType.PpuMemory : DebugMemoryType.ChrRom, (UInt32)(baseAddress + tileIndex * 16 + i)).ToString("X2")); } } else { int absoluteTileIndex = ppuMemory ? InteropEmu.DebugGetAbsoluteChrAddress((uint)(baseAddress + tileIndex * 16)) / 16 : (baseAddress / 16 + tileIndex); sb.Append(absoluteTileIndex.ToString()); } sb.Append(","); for (int i = 0; i < 4; i++) { sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PaletteMemory, (uint)(this._selectedPalette * 4 + i)).ToString("X2")); } _copyData = sb.ToString(); }
private DebugMemoryType GetChrMemoryType() { bool ppuMemory = this.cboChrSelection.SelectedIndex == 0; bool isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0; return(ppuMemory ? DebugMemoryType.PpuMemory : (isChrRam ? DebugMemoryType.ChrRam : DebugMemoryType.ChrRom)); }
public void LoadCartridgeAtSameState(string baseDir, string cartridgeFile, Func <int, int> getNewPc) { if (!IsRunning()) { return; } var wasPaused = InteropEmu.DebugIsExecutionStopped(); InteropEmu.DebugStep(0); var state = new DebugState(); InteropEmu.DebugGetState(ref state); var prgSize = InteropEmu.DebugGetMemorySize(DebugMemoryType.PrgRom); using (var file = File.OpenRead(cartridgeFile)) { var buffer = new byte[prgSize]; file.Position = 16; // Header offset file.Read(buffer, 0, prgSize); InteropEmu.DebugSetMemoryValues(DebugMemoryType.PrgRom, 0, buffer); } //state.CPU.PC = (ushort)getNewPc(state.CPU.PC); //InteropEmu.DebugSetState(state); InteropEmu.DebugSetNextStatement((ushort)getNewPc(state.CPU.PC)); }
public void GetData() { UInt32[] paletteData; _chrPixelData = InteropEmu.DebugGetChrBank(_chrSelection, 9, false, CdlHighlightType.None, false, false, out paletteData); bool isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0; if (_chrSelection < 2) { byte[] chrData = InteropEmu.DebugGetMemoryState(DebugMemoryType.PpuMemory); Array.Copy(chrData, _chrSelection * 0x1000, _chrData, 0, 0x1000); } else { byte[] chrData = InteropEmu.DebugGetMemoryState(isChrRam ? DebugMemoryType.ChrRam : DebugMemoryType.ChrRom); int startIndex = (_chrSelection - 2) * 0x1000; if (startIndex >= chrData.Length) { //Can occur when switching games startIndex = 0; } Array.Copy(chrData, startIndex, _chrData, 0, 0x1000); } }
private void cboBreakpointType_SelectedIndexChanged(object sender, EventArgs e) { DebugMemoryType type = cboBreakpointType.GetEnumValue <DebugMemoryType>(); chkExec.Visible = Breakpoint.IsTypeCpuBreakpoint(type); string maxValue = (InteropEmu.DebugGetMemorySize(type) - 1).ToString("X2"); string minValue = "".PadLeft(maxValue.Length, '0'); lblRange.Text = $"(range: ${minValue}-${maxValue})"; }
private void InitMemoryTypeDropdown(bool forStartup) { cboMemoryType.SelectedIndexChanged -= this.cboMemoryType_SelectedIndexChanged; DebugMemoryType originalValue = forStartup ? ConfigManager.Config.DebugInfo.RamMemoryType : cboMemoryType.GetEnumValue <DebugMemoryType>(); cboMemoryType.BeginUpdate(); cboMemoryType.Items.Clear(); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.CpuMemory)); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.PpuMemory)); cboMemoryType.Items.Add("-"); if (InteropEmu.DebugGetMemorySize(DebugMemoryType.PrgRom) > 0) { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.PrgRom)); } if (InteropEmu.DebugGetMemorySize(DebugMemoryType.WorkRam) > 0) { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.WorkRam)); } if (InteropEmu.DebugGetMemorySize(DebugMemoryType.SaveRam) > 0) { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.SaveRam)); } if (cboMemoryType.Items.Count > 3) { cboMemoryType.Items.Add("-"); } if (InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) > 0) { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.ChrRom)); } if (InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRam) > 0) { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.ChrRam)); } cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.NametableRam)); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.PaletteMemory)); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.SpriteMemory)); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.SecondarySpriteMemory)); cboMemoryType.SelectedIndex = 0; cboMemoryType.SetEnumValue(originalValue); cboMemoryType.SelectedIndexChanged += this.cboMemoryType_SelectedIndexChanged; cboMemoryType.EndUpdate(); UpdateMemoryType(); }
public string ToHdPackFormat(int tileAddr, int palette, bool forSprite, bool isAbsoluteAddress) { bool isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0; StringBuilder sb = new StringBuilder(); if (isAbsoluteAddress) { if (isChrRam) { for (int i = 0; i < 16; i++) { sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.ChrRam, (uint)(tileAddr + i)).ToString("X2")); } } else { sb.Append((tileAddr / 16).ToString()); } } else { if (isChrRam) { for (int i = 0; i < 16; i++) { sb.Append(_ppuMemory[tileAddr + i].ToString("X2")); } } else { sb.Append(_absoluteTileIndexes[tileAddr / 16].ToString("X2")); } } if (forSprite) { sb.Append(",FF"); for (int i = 1; i < 4; i++) { sb.Append(_paletteRam[palette * 4 + i].ToString("X2")); } } else { sb.Append(","); for (int i = 0; i < 4; i++) { sb.Append(_paletteRam[palette * 4 + i].ToString("X2")); } } return(sb.ToString()); }
private void ctxMenu_Opening(object sender, CancelEventArgs e) { if (_selectedSprite < 0) { _contextMenuSpriteIndex = -1; return; } _contextMenuSpriteIndex = _selectedSprite; int ramAddr = _selectedSprite * 4; int spriteY = _spriteRam[ramAddr]; int tileIndex = _spriteRam[ramAddr + 1]; int palette = (_spriteRam[ramAddr + 2] & 0x03) + 4; int spriteX = _spriteRam[ramAddr + 3]; int tileAddr; if (_largeSprites) { tileAddr = ((tileIndex & 0x01) == 0x01 ? 0x1000 : 0x0000) + ((tileIndex & 0xFE) << 4); } else { tileAddr = _spritePatternAddr + (tileIndex << 4); } bool isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0; StringBuilder sb = new StringBuilder(); if (isChrRam) { for (int i = 0; i < 16; i++) { sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PpuMemory, (UInt32)(tileAddr + i)).ToString("X2")); } } else { int absoluteTileIndex = InteropEmu.DebugGetAbsoluteChrAddress((uint)tileAddr) / 16; sb.Append(absoluteTileIndex.ToString()); } sb.Append(",FF"); for (int i = 1; i < 4; i++) { sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PaletteMemory, (uint)(palette * 4 + i)).ToString("X2")); } _copyData = sb.ToString(); }
public frmEditLabel(CodeLabel label, CodeLabel originalLabel = null) { InitializeComponent(); _originalLabel = originalLabel; Entity = label; _maxPrgRomAddress = Math.Max(0, InteropEmu.DebugGetMemorySize(DebugMemoryType.PrgRom) - 1); _maxWorkRamAddress = Math.Max(0, InteropEmu.DebugGetMemorySize(DebugMemoryType.WorkRam) - 1); _maxSaveRamAddress = Math.Max(0, InteropEmu.DebugGetMemorySize(DebugMemoryType.SaveRam) - 1); AddBinding("AddressType", cboRegion); AddBinding("Address", txtAddress); AddBinding("Label", txtLabel); AddBinding("Comment", txtComment); }
private void mnuEditInMemoryViewer_Click(object sender, EventArgs e) { int baseAddress = _hoverBottomBank ? 0x1000 : 0x0000; if (this.cboChrSelection.SelectedIndex > 1) { baseAddress += (this.cboChrSelection.SelectedIndex - 1) * 0x2000; } bool ppuMemory = this.cboChrSelection.SelectedIndex == 0; bool isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0; DebugMemoryType memType = ppuMemory ? DebugMemoryType.PpuMemory : (isChrRam ? DebugMemoryType.ChrRam : DebugMemoryType.ChrRom); int tileIndex = GetLargeSpriteIndex(_hoverTileIndex >= 0 ? _hoverTileIndex : _tileIndex); DebugWindowManager.OpenMemoryViewer(baseAddress + tileIndex * 16, memType); }
public void RefreshData() { //Data needed for HD Pack copy bool isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0; if (isChrRam) { _ppuMemory = InteropEmu.DebugGetMemoryState(DebugMemoryType.PpuMemory); } else { for (int i = 0; i < 512; i++) { _absoluteTileIndexes[i] = InteropEmu.DebugGetAbsoluteChrAddress((uint)i * 16) / 16; } } _paletteRam = InteropEmu.DebugGetMemoryState(DebugMemoryType.PaletteMemory); }
protected override bool ValidateInput() { if (txtCondition.Text.Trim().Length > 0) { EvalResultType resultType; InteropEmu.DebugEvaluateExpression(txtCondition.Text.Replace(Environment.NewLine, " "), out resultType); if (resultType == EvalResultType.Invalid) { picExpressionWarning.Visible = true; return(false); } } picExpressionWarning.Visible = false; DebugMemoryType type = cboBreakpointType.GetEnumValue <DebugMemoryType>(); int maxValue = InteropEmu.DebugGetMemorySize(type) - 1; if (radRange.Checked) { int start = 0, end = 0; int.TryParse(txtFrom.Text, NumberStyles.HexNumber, null, out start); int.TryParse(txtTo.Text, NumberStyles.HexNumber, null, out end); if (end < start || end > maxValue || start > maxValue) { return(false); } } int address; if (int.TryParse(txtAddress.Text, NumberStyles.HexNumber, null, out address)) { if (address > maxValue) { return(false); } } return(chkRead.Checked || chkWrite.Checked || (chkExec.Checked && Breakpoint.IsTypeCpuBreakpoint(type)) || txtCondition.Text.Length > 0); }
private string ToHdPackFormat(int spriteIndex) { int ramAddr = spriteIndex * 4; int spriteY = _spriteRam[ramAddr]; int tileIndex = _spriteRam[ramAddr + 1]; int palette = (_spriteRam[ramAddr + 2] & 0x03) + 4; int spriteX = _spriteRam[ramAddr + 3]; int tileAddr; if (_largeSprites) { tileAddr = ((tileIndex & 0x01) == 0x01 ? 0x1000 : 0x0000) + ((tileIndex & 0xFE) << 4); } else { tileAddr = _spritePatternAddr + (tileIndex << 4); } bool isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0; StringBuilder sb = new StringBuilder(); if (isChrRam) { for (int i = 0; i < 16; i++) { sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PpuMemory, (UInt32)(tileAddr + i)).ToString("X2")); } } else { int absoluteTileIndex = InteropEmu.DebugGetAbsoluteChrAddress((uint)tileAddr) / 16; sb.Append(absoluteTileIndex.ToString()); } sb.Append(",FF"); for (int i = 1; i < 4; i++) { sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PaletteMemory, (uint)(palette * 4 + i)).ToString("X2")); } return(sb.ToString()); }
private void InitMemoryTypeDropdown() { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.CpuMemory)); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.PpuMemory)); cboMemoryType.Items.Add("-"); if (InteropEmu.DebugGetMemorySize(DebugMemoryType.PrgRom) > 0) { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.PrgRom)); } if (InteropEmu.DebugGetMemorySize(DebugMemoryType.WorkRam) > 0) { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.WorkRam)); } if (InteropEmu.DebugGetMemorySize(DebugMemoryType.SaveRam) > 0) { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.SaveRam)); } if (cboMemoryType.Items.Count > 3) { cboMemoryType.Items.Add("-"); } if (InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) > 0) { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.ChrRom)); } if (InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRam) > 0) { cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.ChrRam)); } cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.PaletteMemory)); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.SpriteMemory)); cboMemoryType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.SecondarySpriteMemory)); this.cboMemoryType.SelectedIndex = 0; }
private void DrawPixel(bool leftButton, int x, int y) { int baseAddress = _bottomBank ? 0x1000 : 0x0000; bool ppuMemory = this.cboChrSelection.SelectedIndex == 0; if (this.cboChrSelection.SelectedIndex > 1) { baseAddress += (this.cboChrSelection.SelectedIndex - 1) * 0x2000; } int tileIndex = GetLargeSpriteIndex(_tileIndex); bool isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0; DebugMemoryType memType = ppuMemory? DebugMemoryType.PpuMemory : (isChrRam ? DebugMemoryType.ChrRam : DebugMemoryType.ChrRom); byte orgByte1 = InteropEmu.DebugGetMemoryValue(memType, (UInt32)(baseAddress + tileIndex * 16 + y)); byte orgByte2 = InteropEmu.DebugGetMemoryValue(memType, (UInt32)(baseAddress + tileIndex * 16 + y + 8)); byte byte1 = (byte)(orgByte1 & ~(0x80 >> x)); byte byte2 = (byte)(orgByte2 & ~(0x80 >> x)); byte value = 0; if (leftButton) { value = (byte)ctrlTilePalette.SelectedColor; byte1 |= (byte)(((value << 7) & 0x80) >> x); byte2 |= (byte)(((value << 6) & 0x80) >> x); } if (byte1 != orgByte1 || byte2 != orgByte2) { InteropEmu.DebugSetMemoryValue(memType, (UInt32)(baseAddress + tileIndex * 16 + y), byte1); InteropEmu.DebugSetMemoryValue(memType, (UInt32)(baseAddress + tileIndex * 16 + y + 8), byte2); GetData(); RefreshViewer(); } }
private string ToHdPackFormat(int nametableIndex, int nametableTileIndex) { int x = nametableTileIndex % 32; int y = nametableTileIndex / 32; int baseAddress = 0x2000 + _nametableIndex * 0x400; int tileIndex = _tileData[_nametableIndex][nametableTileIndex]; int attributeData = _attributeData[_nametableIndex][nametableTileIndex]; int shift = (x & 0x02) | ((y & 0x02) << 1); int paletteBaseAddr = ((attributeData >> shift) & 0x03) << 2; DebugState state = new DebugState(); InteropEmu.DebugGetState(ref state); int bgAddr = state.PPU.ControlFlags.BackgroundPatternAddr; int tileAddr = bgAddr + tileIndex * 16; bool isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0; StringBuilder sb = new StringBuilder(); if (isChrRam) { for (int i = 0; i < 16; i++) { sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PpuMemory, (uint)(tileAddr + i)).ToString("X2")); } } else { int absoluteTileIndex = InteropEmu.DebugGetAbsoluteChrAddress((uint)tileAddr) / 16; sb.Append(absoluteTileIndex.ToString()); } sb.Append(","); for (int i = 0; i < 4; i++) { sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PaletteMemory, (uint)(paletteBaseAddr + i)).ToString("X2")); } return(sb.ToString()); }
protected override bool ValidateInput() { if (txtCondition.Text.Trim().Length > 0) { EvalResultType resultType; InteropEmu.DebugEvaluateExpression(txtCondition.Text.Replace(Environment.NewLine, " "), out resultType, false); if (resultType == EvalResultType.Invalid) { picExpressionWarning.Visible = true; return(false); } } picExpressionWarning.Visible = false; DebugMemoryType type = cboBreakpointType.GetEnumValue <DebugMemoryType>(); int maxValue = InteropEmu.DebugGetMemorySize(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); }
private void ctxMenu_Opening(object sender, CancelEventArgs e) { int baseAddress = 0x2000 + _nametableIndex * 0x400; int tileIndex = _tileData[_nametableIndex][_tileY * 32 + _tileX]; int attributeData = _attributeData[_nametableIndex][_tileY * 32 + _tileX]; int shift = (_tileX & 0x02) | ((_tileY & 0x02) << 1); int paletteBaseAddr = ((attributeData >> shift) & 0x03) << 2; DebugState state = new DebugState(); InteropEmu.DebugGetState(ref state); int bgAddr = state.PPU.ControlFlags.BackgroundPatternAddr; int tileAddr = bgAddr + tileIndex * 16; bool isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0; StringBuilder sb = new StringBuilder(); if (isChrRam) { for (int i = 0; i < 16; i++) { sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PpuMemory, (uint)(tileAddr + i)).ToString("X2")); } } else { int absoluteTileIndex = InteropEmu.DebugGetAbsoluteChrAddress((uint)tileAddr) / 16; sb.Append(absoluteTileIndex.ToString()); } sb.Append(","); for (int i = 0; i < 4; i++) { sb.Append(InteropEmu.DebugGetMemoryValue(DebugMemoryType.PaletteMemory, (uint)(paletteBaseAddr + i)).ToString("X2")); } _copyData = sb.ToString(); }
public void RefreshData() { //Data needed for HD Pack copy bool isChrRam = InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) == 0; if (isChrRam) { _ppuMemory = InteropEmu.DebugGetMemoryState(DebugMemoryType.PpuMemory); } else { for (int i = 0; i < 512; i++) { _absoluteTileIndexes[i] = InteropEmu.DebugGetAbsoluteChrAddress((uint)i * 16) / 16; } } _paletteRam = InteropEmu.DebugGetMemoryState(DebugMemoryType.PaletteMemory); for (int i = 4; i < 4 * 8; i += 4) { //Override color 0 in each palette with the background color _paletteRam[i] = _paletteRam[0]; } }
public void Import(string path, bool silent = false) { string[] fileRows = File.ReadAllLines(path); string basePath = Path.GetDirectoryName(path); foreach (string row in fileRows) { try { if (LoadLines(row) || LoadSpans(row) || LoadSymbols(row) || LoadCSymbols(row) || LoadFiles(row, basePath) || LoadSegments(row)) { continue; } } catch { _errorCount++; } } LoadFileData(basePath); int prgSize = InteropEmu.DebugGetMemorySize(DebugMemoryType.PrgRom); if (prgSize > 0) { byte[] cdlFile = new byte[prgSize]; foreach (KeyValuePair <int, SpanInfo> kvp in _spans) { SegmentInfo segment; if (_segments.TryGetValue(kvp.Value.SegmentID, out segment)) { if (!segment.IsRam && kvp.Value.Size != segment.Size) { int prgAddress = kvp.Value.Offset + segment.FileOffset - iNesHeaderSize; if (prgAddress >= 0 && prgAddress < prgSize) { for (int i = 0; i < kvp.Value.Size; i++) { if (cdlFile[prgAddress + i] == 0 && !kvp.Value.IsData && kvp.Value.Size <= 3) { cdlFile[prgAddress + i] = (byte)0x01; } else if (kvp.Value.IsData) { cdlFile[prgAddress + i] = (byte)0x02; } } } } } } InteropEmu.DebugSetCdlData(cdlFile); } foreach (LineInfo line in _lines.Values) { if (line.SpanID == null) { continue; } FileInfo file = _files[line.FileID]; SpanInfo span = _spans[line.SpanID.Value]; SegmentInfo segment = _segments[span.SegmentID]; if (!segment.IsRam) { for (int i = 0; i < span.Size; i++) { int prgAddress = segment.FileOffset - iNesHeaderSize + span.Offset + i; LineInfo existingLine; if (_linesByPrgAddress.TryGetValue(prgAddress, out existingLine) && existingLine.Type == LineType.External) { //Give priority to lines that come from C files continue; } _linesByPrgAddress[prgAddress] = line; if (i == 0) { _prgAddressByLine[file.ID.ToString() + "_" + line.LineNumber.ToString()] = prgAddress; } } } } LoadLabels(); int labelCount = 0; DebugImportConfig config = ConfigManager.Config.DebugInfo.ImportConfig; if (config.DbgImportComments) { LoadComments(); } if (config.DbgImportPrgRomLabels) { LabelManager.SetLabels(_romLabels.Values); labelCount += _romLabels.Count; } if (config.DbgImportRamLabels) { LabelManager.SetLabels(_ramLabels.Values); labelCount += _ramLabels.Count; } if (!silent) { if (_errorCount > 0) { _errorCount -= _filesNotFound.Count; string message = $"Import completed with {labelCount} labels imported"; if (_errorCount > 0) { message += $"and {_errorCount} errors - please file a bug report and attach the DBG file you tried to import."; } if (_filesNotFound.Count > 0) { message += Environment.NewLine + Environment.NewLine + "The following files could not be found:"; foreach (string file in _filesNotFound) { message += Environment.NewLine + file; } } MessageBox.Show(message, "Mesen", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show($"Import completed with {labelCount} labels imported.", "Mesen", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
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("MemoryType", cboBreakpointType); AddBinding("Enabled", chkEnabled); AddBinding("MarkEvent", chkMarkOnEventViewer); AddBinding("ProcessDummyReadWrites", chkProcessDummyReadWrites); AddBinding("Address", txtAddress); AddBinding("StartAddress", txtFrom); AddBinding("EndAddress", txtTo); AddBinding("BreakOnRead", chkRead); AddBinding("BreakOnWrite", chkWrite); AddBinding("BreakOnExec", chkExec); AddBinding("Condition", txtCondition); cboBreakpointType.Items.Clear(); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.CpuMemory)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.PpuMemory)); cboBreakpointType.Items.Add("-"); if (InteropEmu.DebugGetMemorySize(DebugMemoryType.PrgRom) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.PrgRom)); } if (InteropEmu.DebugGetMemorySize(DebugMemoryType.WorkRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.WorkRam)); } if (InteropEmu.DebugGetMemorySize(DebugMemoryType.SaveRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.SaveRam)); } if (cboBreakpointType.Items.Count > 3) { cboBreakpointType.Items.Add("-"); } if (InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRom) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.ChrRom)); } if (InteropEmu.DebugGetMemorySize(DebugMemoryType.ChrRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.ChrRam)); } cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.NametableRam)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(DebugMemoryType.PaletteMemory)); this.toolTip.SetToolTip(this.picExpressionWarning, "Condition contains invalid syntax or symbols."); this.toolTip.SetToolTip(this.picHelp, frmBreakpoint.GetConditionTooltip(false)); }
private void BuildCdlData() { int prgSize = InteropEmu.DebugGetMemorySize(DebugMemoryType.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)CdlPrgFlags.Data && !span.IsData && span.Size <= 3) { cdlFile[prgAddress + i] = (byte)CdlPrgFlags.Code; } else if (span.IsData) { cdlFile[prgAddress + i] = (byte)CdlPrgFlags.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)CdlPrgFlags.Data; } } //Find/identify functions and jump targets byte[] prgRomContent = InteropEmu.DebugGetMemoryState(DebugMemoryType.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 == 0x90 || opCode == 0xB0 || opCode == 0xD0 || opCode == 0xF0 || opCode == 0x4C || opCode == 0x20 || opCode == 0x4C || opCode == 0x6C) { //This symbol is used with a JSR/jump instruction, so it's either a function or jump target bool isJsr = opCode == 0x20; SpanInfo definitionSpan = GetSymbolDefinitionSpan(symbol); if (definitionSpan != null) { int definitionPrgAddr = GetPrgAddress(definitionSpan); if (definitionPrgAddr >= 0 && definitionPrgAddr < prgRomContent.Length) { cdlFile[definitionPrgAddr] |= (byte)(isJsr ? CdlPrgFlags.SubEntryPoint : CdlPrgFlags.JumpTarget); break; } } } } } } } } InteropEmu.DebugSetCdlData(cdlFile); }