Merge pull request #25 from mkwong98/master

A few updates
This commit is contained in:
NovaSquirrel 2021-04-15 12:23:57 -04:00 committed by GitHub
commit ccb23742dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 600 additions and 22 deletions

View file

@ -164,6 +164,7 @@ bool Disassembler::IsJump(uint8_t opCode)
bool Disassembler::IsUnconditionalJump(uint8_t opCode)
{
return (
opCode == 0x00 || //BRK
opCode == 0x40 || //RTI
opCode == 0x60 || //RTS
opCode == 0x6C || //JMP (Indirect)

View file

@ -90,6 +90,8 @@ struct HdPpuTileInfo : public HdTileKey
uint8_t BgColor;
uint8_t SpriteColor;
uint8_t PpuBackgroundColor;
uint8_t OAMIndex;
};
struct HdPpuPixelInfo
@ -111,11 +113,36 @@ struct HdPpuPixelInfo
}
};
struct HdScreenTileInfo : public HdTileKey
{
int16_t ScreenX;
int16_t ScreenY;
bool HorizontalMirroring;
bool VerticalMirroring;
bool BackgroundPriority;
bool IsNew;
};
struct HdSpriteFrameRangeInfo
{
bool lastUpdated;
bool updated;
HdScreenTileInfo last;
HdScreenTileInfo current;
uint32_t lastStartFrameNumber;
uint32_t startFrameNumber;
HdSpriteFrameRangeInfo() {
updated = false;
}
};
struct HdScreenInfo
{
HdPpuPixelInfo* ScreenTiles;
std::unordered_map<uint32_t, uint8_t> WatchedAddressValues;
uint32_t FrameNumber;
HdSpriteFrameRangeInfo* spriteFrameRanges;
HdScreenInfo(const HdScreenInfo& that) = delete;
@ -390,12 +417,4 @@ enum class HdPackOptions
DontRenderOriginalTiles = 16
};
struct HdScreenTileInfo : public HdTileKey
{
int16_t ScreenX;
int16_t ScreenY;
bool HorizontalMirroring;
bool VerticalMirroring;
bool BackgroundPriority;
bool IsNew;
};

View file

@ -298,3 +298,32 @@ struct HdPackSpriteNearbyCondition : public HdPackBaseTileCondition
return false;
}
};
struct HdPackSpriteFrameRangeCondition : public HdPackCondition
{
uint32_t OperandA;
uint32_t OperandB;
string GetConditionName() override { return "spriteFrameRange"; }
void Initialize(uint32_t operandA, uint32_t operandB)
{
OperandA = operandA;
OperandB = operandB;
}
string ToString() override
{
stringstream out;
out << "<condition>" << Name << "," << GetConditionName() << ",";
out << OperandA << ",";
out << OperandB;
return out.str();
}
bool InternalCheckCondition(HdScreenInfo* screenInfo, int x, int y, HdPpuTileInfo* tile) override
{
return (screenInfo->FrameNumber - screenInfo->spriteFrameRanges[tile->OAMIndex].startFrameNumber) % OperandA >= OperandB;
}
};

View file

@ -424,6 +424,8 @@ void HdPackLoader::ProcessConditionTag(vector<string> &tokens, bool createInvert
condition.reset(new HdPackMemoryCheckConstantCondition());
} else if(tokens[1] == "frameRange") {
condition.reset(new HdPackFrameRangeCondition());
} else if(tokens[1] == "spriteFrameRange") {
condition.reset(new HdPackSpriteFrameRangeCondition());
} else {
MessageManager::Log("[HDPack] Invalid condition type: " + tokens[1]);
return;
@ -530,6 +532,27 @@ void HdPackLoader::ProcessConditionTag(vector<string> &tokens, bool createInvert
((HdPackFrameRangeCondition*)condition.get())->Initialize(operandA, operandB);
}
else if (dynamic_cast<HdPackSpriteFrameRangeCondition*>(condition.get())) {
checkConstraint(_data->Version >= 101, "[HDPack] This feature requires version 101+ of HD Packs");
checkConstraint(tokens.size() >= 4, "[HDPack] Condition tag should contain at least 4 parameters");
int32_t operandA;
int32_t operandB;
if (_data->Version == 101) {
operandA = HexUtilities::FromHex(tokens[index++]);
operandB = HexUtilities::FromHex(tokens[index++]);
}
else {
//Version 102+
operandA = std::stoi(tokens[index++]);
operandB = std::stoi(tokens[index++]);
}
checkConstraint(operandA >= 0 && operandA <= 0xFFFF, "[HDPack] Out of range spriteFrameRange operand");
checkConstraint(operandB >= 0 && operandB <= 0xFFFF, "[HDPack] Out of range spriteFrameRange operand");
((HdPackSpriteFrameRangeCondition*)condition.get())->Initialize(operandA, operandB);
}
HdPackCondition *cond = condition.get();
condition.release();

View file

@ -16,6 +16,20 @@ void HdPpu::DrawPixel()
uint16_t &pixel = _currentOutputBuffer[bufferOffset];
_lastSprite = nullptr;
//init sprite frame ranges at screen start
if (bufferOffset == 0) {
uint8_t spriteCnt = (_flags.LargeSprites ? 128 : 64);
for (int i = 0; i < spriteCnt; i++) {
_spriteFrameRanges[i].lastUpdated = _spriteFrameRanges[i].updated;
if (_spriteFrameRanges[i].updated) {
//copy last frame sprite data
memcpy(&(_spriteFrameRanges[i].last), &(_spriteFrameRanges[i].current), sizeof(_spriteFrameRanges[i].current));
_spriteFrameRanges[i].updated = false;
_spriteFrameRanges[i].lastStartFrameNumber = _spriteFrameRanges[i].startFrameNumber;
}
}
}
if(IsRenderingEnabled() || ((_state.VideoRamAddr & 0x3F00) != 0x3F00)) {
bool isChrRam = !_console->GetMapper()->HasChrRom();
BaseMapper *mapper = _console->GetMapper();
@ -85,6 +99,24 @@ void HdPpu::DrawPixel()
tileInfo.Sprite[j].PpuBackgroundColor = tileInfo.Tile.PpuBackgroundColor;
tileInfo.Sprite[j].BgColorIndex = tileInfo.Tile.BgColorIndex;
tileInfo.Sprite[j].OAMIndex = (sprite.OffsetY >= 8 ? sprite.OAMIndex + 64 : sprite.OAMIndex);
if (!_spriteFrameRanges[tileInfo.Sprite[j].OAMIndex].updated) {
//fill the current frame sprite
if (isChrRam) {
memcpy(_spriteFrameRanges[tileInfo.Sprite[j].OAMIndex].current.TileData, tileInfo.Sprite[j].TileData, 16);
}
else {
_spriteFrameRanges[tileInfo.Sprite[j].OAMIndex].current.TileIndex = tileInfo.Sprite[j].TileIndex;
}
_spriteFrameRanges[tileInfo.Sprite[j].OAMIndex].current.PaletteColors = tileInfo.Sprite[j].PaletteColors;
_spriteFrameRanges[tileInfo.Sprite[j].OAMIndex].current.HorizontalMirroring = tileInfo.Sprite[j].HorizontalMirroring;
_spriteFrameRanges[tileInfo.Sprite[j].OAMIndex].current.VerticalMirroring = tileInfo.Sprite[j].VerticalMirroring;
_spriteFrameRanges[tileInfo.Sprite[j].OAMIndex].current.BackgroundPriority = tileInfo.Sprite[j].BackgroundPriority;
_spriteFrameRanges[tileInfo.Sprite[j].OAMIndex].current.ScreenX = sprite.SpriteX;
_spriteFrameRanges[tileInfo.Sprite[j].OAMIndex].current.ScreenY = _scanline - tileInfo.Sprite[j].OffsetY;
_spriteFrameRanges[tileInfo.Sprite[j].OAMIndex].updated = true;
}
j++;
if(j >= 4) {
@ -112,6 +144,49 @@ void HdPpu::DrawPixel()
} else {
tileInfo.Tile.TileIndex = HdPpuTileInfo::NoTile;
}
//match sprite frame range at screen end
if (bufferOffset == PixelCount - 1) {
uint16_t distance;
uint16_t newDistance;
uint16_t newDistanceX;
uint16_t newDistanceY;
uint8_t spriteCnt = (_flags.LargeSprites ? 128 : 64);
for (int i = 0; i < spriteCnt; i++) {
if (_spriteFrameRanges[i].updated) {
distance = 13;
_spriteFrameRanges[i].startFrameNumber = _frameCount;
for (int j = 0; j < spriteCnt; j++) {
if (_spriteFrameRanges[j].lastUpdated) {
newDistanceX = abs(_spriteFrameRanges[i].current.ScreenX - _spriteFrameRanges[j].last.ScreenX);
newDistanceY = abs(_spriteFrameRanges[i].current.ScreenY - _spriteFrameRanges[j].last.ScreenY);
newDistance = newDistanceX + newDistanceY;
if (newDistance < distance && newDistanceX <= 6 && newDistanceY <= 6) {
//check for matches
bool compareResult = false;
if (_spriteFrameRanges[i].current.BackgroundPriority == _spriteFrameRanges[j].last.BackgroundPriority
&& _spriteFrameRanges[i].current.HorizontalMirroring == _spriteFrameRanges[j].last.HorizontalMirroring
&& _spriteFrameRanges[i].current.VerticalMirroring == _spriteFrameRanges[j].last.VerticalMirroring
&& _spriteFrameRanges[i].current.PaletteColors == _spriteFrameRanges[j].last.PaletteColors
) {
if (isChrRam) {
compareResult = (memcmp(_spriteFrameRanges[i].current.TileData, _spriteFrameRanges[j].last.TileData, 16) == 0);
}
else {
compareResult = (_spriteFrameRanges[i].current.TileIndex == _spriteFrameRanges[j].last.TileIndex);
}
}
if (compareResult) {
_spriteFrameRanges[i].startFrameNumber = _spriteFrameRanges[j].lastStartFrameNumber;
}
distance = newDistance;
}
}
}
}
}
}
} else {
//"If the current VRAM address points in the range $3F00-$3FFF during forced blanking, the color indicated by this palette location will be shown on screen instead of the backdrop color."
pixel = ReadPaletteRAM(_state.VideoRamAddr) | _intensifyColorBits;
@ -147,6 +222,7 @@ void HdPpu::SendFrame()
_console->GetNotificationManager()->SendNotification(ConsoleNotificationType::PpuFrameDone, _currentOutputBuffer);
_info->FrameNumber = _frameCount;
_info->spriteFrameRanges = _spriteFrameRanges;
_info->WatchedAddressValues.clear();
for(uint32_t address : _hdData->WatchedMemoryAddresses) {
if(address & HdPackBaseMemoryCondition::PpuMemoryMarker) {

View file

@ -1,6 +1,7 @@
#pragma once
#include "stdafx.h"
#include "PPU.h"
#include "HdData.h"
struct HdScreenInfo;
struct HdPackData;
@ -13,6 +14,7 @@ private:
HdScreenInfo *_screenInfo[2];
HdScreenInfo *_info;
uint32_t _version;
HdSpriteFrameRangeInfo _spriteFrameRanges[128];
protected:
HdPackData *_hdData = nullptr;

View file

@ -278,7 +278,7 @@ class MMC3 : public BaseMapper
if(ForceMmc3RevAIrqs() || _console->GetSettings()->CheckFlag(EmulationFlags::Mmc3IrqAltBehavior)) {
//MMC3 Revision A behavior
if((count > 0 || _irqReload) && _irqCounter == 0 && _irqEnabled) {
if(((count > 0 && _irqReloadValue > 0) || _irqReload) && _irqCounter == 0 && _irqEnabled) {
TriggerIrq();
}
} else {

View file

@ -337,6 +337,7 @@ uint8_t PPU::ReadRAM(uint16_t addr)
uint8_t step = ((_cycle - 257) % 8) > 3 ? 3 : ((_cycle - 257) % 8);
_secondaryOAMAddr = (_cycle - 257) / 8 * 4 + step;
_oamCopybuffer = _secondarySpriteRAM[_secondaryOAMAddr];
_oamID = _secondarySpriteRAMLink[_secondaryOAMAddr >> 2];
}
//Return the value that PPU is currently using for sprite evaluation/rendering
returnValue = _oamCopybuffer;
@ -690,7 +691,7 @@ void PPU::LoadTileInfo()
}
}
void PPU::LoadSprite(uint8_t spriteY, uint8_t tileIndex, uint8_t attributes, uint8_t spriteX, bool extraSprite)
void PPU::LoadSprite(uint8_t spriteY, uint8_t tileIndex, uint8_t attributes, uint8_t spriteX, bool extraSprite, uint8_t oamID)
{
bool backgroundPriority = (attributes & 0x20) == 0x20;
bool horizontalMirror = (attributes & 0x40) == 0x40;
@ -730,6 +731,7 @@ void PPU::LoadSprite(uint8_t spriteY, uint8_t tileIndex, uint8_t attributes, uin
info.AbsoluteTileAddr = _console->GetMapper()->ToAbsoluteChrAddress(tileAddr);
info.OffsetY = lineOffset;
info.SpriteX = spriteX;
info.OAMIndex = oamID;
if(_scanline >= 0) {
//Sprites read on prerender scanline are not shown on scanline 0
@ -788,7 +790,7 @@ void PPU::LoadExtraSprites()
for(uint32_t i = (_lastVisibleSpriteAddr + 4) & 0xFF; i != _firstVisibleSpriteAddr; i = (i + 4) & 0xFF) {
uint8_t spriteY = _spriteRAM[i];
if(_scanline >= spriteY && _scanline < spriteY + (_flags.LargeSprites ? 16 : 8)) {
LoadSprite(spriteY, _spriteRAM[i + 1], _spriteRAM[i + 2], _spriteRAM[i + 3], true);
LoadSprite(spriteY, _spriteRAM[i + 1], _spriteRAM[i + 2], _spriteRAM[i + 3], true, i >> 2);
_spriteCount++;
}
}
@ -799,7 +801,7 @@ void PPU::LoadExtraSprites()
void PPU::LoadSpriteTileInfo()
{
uint8_t *spriteAddr = _secondarySpriteRAM + _spriteIndex * 4;
LoadSprite(*spriteAddr, *(spriteAddr+1), *(spriteAddr+2), *(spriteAddr+3), false);
LoadSprite(*spriteAddr, *(spriteAddr+1), *(spriteAddr+2), *(spriteAddr+3), false, _secondarySpriteRAMLink[_spriteIndex]);
}
void PPU::ShiftTileRegisters()
@ -1036,12 +1038,14 @@ void PPU::ProcessSpriteEvaluation()
if(_cycle & 0x01) {
//Read a byte from the primary OAM on odd cycles
_oamCopybuffer = ReadSpriteRam(_state.SpriteRamAddr);
_oamID = _state.SpriteRamAddr >> 2;
} else {
if(_oamCopyDone) {
_spriteAddrH = (_spriteAddrH + 1) & 0x3F;
if(_secondaryOAMAddr >= 0x20) {
//"As seen above, a side effect of the OAM write disable signal is to turn writes to the secondary OAM into reads from it."
_oamCopybuffer = _secondarySpriteRAM[_secondaryOAMAddr & 0x1F];
_oamID = _secondarySpriteRAMLink[(_secondaryOAMAddr >> 2) & 0x08];
}
} else {
if(!_spriteInRange && _scanline >= _oamCopybuffer && _scanline < _oamCopybuffer + (_flags.LargeSprites ? 16 : 8)) {
@ -1051,7 +1055,7 @@ void PPU::ProcessSpriteEvaluation()
if(_secondaryOAMAddr < 0x20) {
//Copy 1 byte to secondary OAM
_secondarySpriteRAM[_secondaryOAMAddr] = _oamCopybuffer;
_secondarySpriteRAMLink[_secondaryOAMAddr >> 2] =_oamID;
if(_spriteInRange) {
_spriteAddrL++;
_secondaryOAMAddr++;
@ -1083,6 +1087,7 @@ void PPU::ProcessSpriteEvaluation()
} else {
//"As seen above, a side effect of the OAM write disable signal is to turn writes to the secondary OAM into reads from it."
_oamCopybuffer = _secondarySpriteRAM[_secondaryOAMAddr & 0x1F];
_oamID = _secondarySpriteRAMLink[(_secondaryOAMAddr >> 2) & 0x08];
//8 sprites have been found, check next sprite for overflow + emulate PPU bug
if(_spriteInRange) {

View file

@ -44,6 +44,7 @@ class PPU : public IMemoryHandler, public Snapshotable
uint8_t _spriteRAM[0x100];
uint8_t _secondarySpriteRAM[0x20];
uint8_t _secondarySpriteRAMLink[8];
bool _hasSprite[257];
uint16_t *_currentOutputBuffer;
@ -90,6 +91,7 @@ class PPU : public IMemoryHandler, public Snapshotable
uint8_t _spriteAddrL;
bool _oamCopyDone;
uint8_t _overflowBugCounter;
uint8_t _oamID;
bool _needStateUpdate;
bool _renderingEnabled;
@ -134,7 +136,7 @@ class PPU : public IMemoryHandler, public Snapshotable
void TriggerNmi();
void LoadTileInfo();
void LoadSprite(uint8_t spriteY, uint8_t tileIndex, uint8_t attributes, uint8_t spriteX, bool extraSprite);
void LoadSprite(uint8_t spriteY, uint8_t tileIndex, uint8_t attributes, uint8_t spriteX, bool extraSprite, uint8_t oamID);
void LoadSpriteTileInfo();
void LoadExtraSprites();
__forceinline void ShiftTileRegisters();

View file

@ -185,6 +185,7 @@ struct SpriteInfo : TileInfo
uint8_t SpriteX;
bool VerticalMirror; //used by HD ppu
uint8_t OAMIndex; //used by HD ppu
};
struct ApuLengthCounterState

View file

@ -48,9 +48,9 @@ protected:
SetPpuMemoryMapping(0x2000, 0x3FFF, ChrMemoryType::ChrRam, 0x6000, MemoryAccessType::ReadWrite);
}
_orgPrgRom = vector<uint8_t>(_prgRom, _prgRom + _prgSize);
if(HasBattery()) {
AddRegisterRange(0x8000, 0xFFFF, MemoryOperation::Read);
_orgPrgRom = vector<uint8_t>(_prgRom, _prgRom + _prgSize);
ApplySaveData();
}
}

View file

@ -161,6 +161,8 @@ namespace Mesen.GUI.Config
public XmlKeys CodeWindow_EditSourceFile = Keys.F4;
[ShortcutName("Code Window: Edit Label")]
public XmlKeys CodeWindow_EditLabel = Keys.F2;
[ShortcutName("Code Window: Edit Code Comment")]
public XmlKeys CodeWindow_EditCodeComment = Keys.OemSemicolon;
[ShortcutName("Code Window: Navigate Back")]
public XmlKeys CodeWindow_NavigateBack = Keys.Alt | Keys.Left;
[ShortcutName("Code Window: Navigate Forward")]
@ -257,7 +259,29 @@ namespace Mesen.GUI.Config
return "";
} else {
string keyString = new KeysConverter().ConvertToString(keys);
return keyString.Replace("+None", "").Replace("Oemcomma", ",").Replace("Oemplus", "+").Replace("Oemtilde", "Tilde").Replace("OemMinus", "-").Replace("Cancel", "Break").Replace("Escape", "Esc");
return keyString.Replace("+None", "")
.Replace("Cancel", "Break")
.Replace("Escape", "Esc")
.Replace("Oem1", ";")
.Replace("OemSemicolon", ";")
.Replace("OemPeriod", ".")
.Replace("Oemcomma", ",")
.Replace("Oemplus", "+")
.Replace("OemMinus", "-")
.Replace("Oem2", "/")
.Replace("OemQuestion", "/")
.Replace("Oem3", "Tilde")
.Replace("Oemtilde", "Tilde")
.Replace("Oem4", "[")
.Replace("OemOpenBrackets", "[")
.Replace("Oem5", "\\")
.Replace("OemPipe", "\\")
.Replace("Oem6", "]")
.Replace("OemCloseBrackets", "]")
.Replace("Oem7", "'")
.Replace("OemQuotes", "'")
.Replace("OemBackslash", "\\")
.Replace("Oem102", "\\");
}
}

View file

@ -63,6 +63,7 @@
this.mnuHidePrgAddresses = new System.Windows.Forms.ToolStripMenuItem();
this.sepEditLabel = new System.Windows.Forms.ToolStripSeparator();
this.mnuEditLabel = new System.Windows.Forms.ToolStripMenuItem();
this.mnuEditCodeComment = new System.Windows.Forms.ToolStripMenuItem();
this.mnuEditInMemoryViewer = new System.Windows.Forms.ToolStripMenuItem();
this.mnuToggleBreakpoint = new System.Windows.Forms.ToolStripMenuItem();
this.sepAddToWatch = new System.Windows.Forms.ToolStripSeparator();
@ -101,6 +102,7 @@
this.sepEditLabel,
this.mnuEditLabel,
this.mnuEditInMemoryViewer,
this.mnuEditCodeComment,
this.mnuToggleBreakpoint,
this.sepAddToWatch,
this.mnuAddToWatch,
@ -372,6 +374,14 @@
this.mnuEditLabel.Text = "Edit Label";
this.mnuEditLabel.Click += new System.EventHandler(this.mnuEditLabel_Click);
//
// mnuEditCodeComment
//
this.mnuEditCodeComment.Image = global::Mesen.GUI.Properties.Resources.EditComment;
this.mnuEditCodeComment.Name = "mnuSetComment";
this.mnuEditCodeComment.Size = new System.Drawing.Size(253, 22);
this.mnuEditCodeComment.Text = "Edit Code Comment";
this.mnuEditCodeComment.Click += new System.EventHandler(this.mnuEditCodeComment_Click);
//
// mnuEditInMemoryViewer
//
this.mnuEditInMemoryViewer.Image = global::Mesen.GUI.Properties.Resources.CheatCode;
@ -512,6 +522,7 @@
private System.Windows.Forms.ToolStripMenuItem mnuHidePrgAddresses;
private System.Windows.Forms.ToolStripSeparator sepEditLabel;
private System.Windows.Forms.ToolStripMenuItem mnuEditLabel;
private System.Windows.Forms.ToolStripMenuItem mnuEditCodeComment;
private System.Windows.Forms.ToolStripMenuItem mnuEditInMemoryViewer;
private System.Windows.Forms.ToolStripMenuItem mnuToggleBreakpoint;
private System.Windows.Forms.ToolStripSeparator sepAddToWatch;

View file

@ -49,6 +49,7 @@ namespace Mesen.GUI.Debugger.Controls
Control parent = (Control)Viewer;
mnuEditInMemoryViewer.InitShortcut(parent, nameof(DebuggerShortcutsConfig.CodeWindow_EditInMemoryViewer));
mnuEditLabel.InitShortcut(parent, nameof(DebuggerShortcutsConfig.CodeWindow_EditLabel));
mnuEditCodeComment.InitShortcut(parent, nameof(DebuggerShortcutsConfig.CodeWindow_EditCodeComment));
mnuSetNextStatement.InitShortcut(parent, nameof(DebuggerShortcutsConfig.CodeWindow_SetNextStatement));
mnuShowNextStatement.InitShortcut(parent, nameof(DebuggerShortcutsConfig.GoToProgramCounter));
mnuToggleBreakpoint.InitShortcut(parent, nameof(DebuggerShortcutsConfig.CodeWindow_ToggleBreakpoint));
@ -263,10 +264,20 @@ namespace Mesen.GUI.Debugger.Controls
{
if(UpdateContextMenu(_lastLocation)) {
if(_lastClickedAddress >= 0) {
//get selected adress of debugger text window
int startAddress, endAddress;
string rangeString;
GetSelectedAddressRange(out startAddress, out endAddress, out rangeString);
AddressTypeInfo info = new AddressTypeInfo();
InteropEmu.DebugGetAbsoluteAddressAndType((UInt32)_lastClickedAddress, info);
if(info.Address >= 0) {
ctrlLabelList.EditLabel((UInt32)info.Address, info.Type);
//if that is the same as the address we just edited, restore selected line
if (startAddress == info.Address)
{
GoToDestination(new GoToDestination() { AddressInfo = info });
}
} else {
ctrlLabelList.EditLabel((UInt32)_lastClickedAddress, AddressType.Register);
}
@ -281,6 +292,26 @@ namespace Mesen.GUI.Debugger.Controls
}
}
private void mnuEditCodeComment_Click(object sender, EventArgs e)
{
int startAddress, endAddress;
string rangeString;
GetSelectedAddressRange(out startAddress, out endAddress, out rangeString);
if (startAddress >= 0)
{
AddressTypeInfo info = new AddressTypeInfo();
info.Address = startAddress;
info.Type = AddressType.PrgRom;
if (info.Address >= 0)
{
ctrlLabelList.EditComment((UInt32)info.Address, info.Type);
GoToDestination destination = new GoToDestination();
destination.AddressInfo = info;
GoToDestination(destination);
}
}
}
private void mnuNavigateForward_Click(object sender, EventArgs e)
{
Viewer.CodeViewer.NavigateForward();
@ -662,5 +693,6 @@ namespace Mesen.GUI.Debugger.Controls
mnuPerfTrackerTextOnly.Checked = mode == PerfTrackerMode.TextOnly;
mnuPerfTrackerDisabled.Checked = mode == PerfTrackerMode.Disabled;
}
}
}

View file

@ -75,6 +75,64 @@ namespace Mesen.GUI.Debugger.Controls
}
}
public static void EditComment(UInt32 address, AddressType type)
{
string autoName = "C" + address.ToString("X4");
CodeLabel existingLabel = LabelManager.GetLabel(address, type);
CodeLabel newLabel = new CodeLabel()
{
Address = existingLabel?.Address ?? address,
AddressType = existingLabel?.AddressType ?? type,
Label = existingLabel?.Label,
Comment = existingLabel?.Comment,
Length = existingLabel?.Length ?? 1
};
if (existingLabel == null)
{
newLabel.Label = autoName;
}
bool isMultiLine = false;
if (existingLabel != null && existingLabel.Comment.Contains("\r\n"))
{
isMultiLine = true;
}
if (isMultiLine)
{
frmEditLabel frm = new frmEditLabel(newLabel, existingLabel, true);
if (frm.ShowDialog() == DialogResult.OK)
{
bool empty = string.IsNullOrWhiteSpace(newLabel.Comment) && newLabel.Label == autoName;
if (existingLabel != null)
{
LabelManager.DeleteLabel(existingLabel, empty);
}
if (!empty)
{
LabelManager.SetLabel(newLabel.Address, newLabel.AddressType, newLabel.Label, newLabel.Comment, true, CodeLabelFlags.None, newLabel.Length);
}
}
}
else
{
frmEditComment frm = new frmEditComment(newLabel, existingLabel);
if (frm.ShowDialog() == DialogResult.OK)
{
bool empty = string.IsNullOrWhiteSpace(newLabel.Comment) && newLabel.Label == autoName;
if (existingLabel != null)
{
LabelManager.DeleteLabel(existingLabel, empty);
}
if (!empty)
{
LabelManager.SetLabel(newLabel.Address, newLabel.AddressType, newLabel.Label, newLabel.Comment, true, CodeLabelFlags.None, newLabel.Length);
}
}
}
}
public int CompareLabels(ListViewItem x, ListViewItem y)
{
int result = String.Compare(((ListViewItem)x).SubItems[_sortColumn].Text, ((ListViewItem)y).SubItems[_sortColumn].Text);

View file

@ -0,0 +1,82 @@
namespace Mesen.GUI.Debugger
{
partial class frmEditComment
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if(disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblComment = new System.Windows.Forms.Label();
this.txtComment = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// baseConfigPanel
//
this.baseConfigPanel.Location = new System.Drawing.Point(0, 42);
this.baseConfigPanel.Size = new System.Drawing.Size(377, 29);
//
// lblComment
//
this.lblComment.AutoSize = true;
this.lblComment.Location = new System.Drawing.Point(3, 15);
this.lblComment.Name = "lblComment";
this.lblComment.Size = new System.Drawing.Size(54, 13);
this.lblComment.TabIndex = 4;
this.lblComment.Text = "Comment:";
//
// txtComment
//
this.txtComment.AcceptsReturn = true;
this.txtComment.Location = new System.Drawing.Point(63, 12);
this.txtComment.Name = "txtComment";
this.txtComment.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.txtComment.Size = new System.Drawing.Size(311, 20);
this.txtComment.TabIndex = 5;
//
// frmEditComment
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(377, 71);
this.Controls.Add(this.lblComment);
this.Controls.Add(this.txtComment);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "frmEditComment";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Edit Comment";
this.Load += new System.EventHandler(this.frmEditComment_Load);
this.Controls.SetChildIndex(this.baseConfigPanel, 0);
this.Controls.SetChildIndex(this.txtComment, 0);
this.Controls.SetChildIndex(this.lblComment, 0);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lblComment;
private System.Windows.Forms.TextBox txtComment;
}
}

View file

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using Mesen.GUI.Forms;
namespace Mesen.GUI.Debugger
{
public partial class frmEditComment : BaseConfigForm
{
private CodeLabel _originalLabel;
public frmEditComment(CodeLabel label, CodeLabel originalLabel = null)
{
InitializeComponent();
_originalLabel = originalLabel;
Entity = label;
AddBinding("Comment", txtComment);
}
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
txtComment.Focus();
}
protected override bool ValidateInput()
{
UpdateObject();
return !txtComment.Text.Contains('\x1');
}
protected override void OnFormClosed(FormClosedEventArgs e)
{
base.OnFormClosed(e);
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(keyData == (Keys.Control | Keys.Enter)) {
this.DialogResult = DialogResult.OK;
this.Close();
}
return base.ProcessCmdKey(ref msg, keyData);
}
private void frmEditComment_Load(object sender, EventArgs e)
{
}
}
}

View file

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View file

@ -20,9 +20,11 @@ namespace Mesen.GUI.Debugger
private int _maxPrgRomAddress = 0;
private int _maxWorkRamAddress = 0;
private int _maxSaveRamAddress = 0;
private bool focusComment = false;
public frmEditLabel(CodeLabel label, CodeLabel originalLabel = null)
public frmEditLabel(CodeLabel label, CodeLabel originalLabel = null, bool focusComment = false)
{
this.focusComment = focusComment;
InitializeComponent();
_originalLabel = originalLabel;
@ -44,7 +46,14 @@ namespace Mesen.GUI.Debugger
{
base.OnShown(e);
UpdateByteLabel();
txtLabel.Focus();
if (!focusComment)
{
txtLabel.Focus();
}
else
{
txtComment.Focus();
}
}
private int GetMaxAddress(AddressType type)

View file

@ -689,6 +689,12 @@
<Compile Include="Debugger\frmAssembler.Designer.cs">
<DependentUpon>frmAssembler.cs</DependentUpon>
</Compile>
<Compile Include="Debugger\frmEditComment.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Debugger\frmEditComment.Designer.cs">
<DependentUpon>frmEditComment.cs</DependentUpon>
</Compile>
<Compile Include="Debugger\frmExternalEditorConfig.cs">
<SubType>Form</SubType>
</Compile>
@ -1307,6 +1313,7 @@
<Compile Include="RuntimeChecker.cs" />
<Compile Include="SingleInstance.cs" />
<Compile Include="TestRunner.cs" />
<None Include="Resources\EditComment.png" />
<None Include="Resources\MoveDown.png" />
<None Include="Resources\MoveUp.png" />
<None Include="Resources\NudDownArrowDarkTheme.png" />
@ -1437,6 +1444,9 @@
<EmbeddedResource Include="Debugger\Controls\ctrlSourceViewer.resx">
<DependentUpon>ctrlSourceViewer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Debugger\frmEditComment.resx">
<DependentUpon>frmEditComment.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Debugger\frmExternalEditorConfig.resx">
<DependentUpon>frmExternalEditorConfig.cs</DependentUpon>
</EmbeddedResource>
@ -1920,7 +1930,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</Content>
<Content Include="Dependencies\resources.pl.xml">
<Content Include="Dependencies\resources.pl.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</Content>

View file

@ -350,6 +350,16 @@ namespace Mesen.GUI.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap EditComment {
get {
object obj = ResourceManager.GetObject("EditComment", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>

View file

@ -391,6 +391,9 @@
<data name="EditLabel" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\EditLabel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="EditComment" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\EditComment.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Paste" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Paste.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B