Skip to content

Commit

Permalink
GoToNextUnreachedInPoint: add menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
binary1230 committed Nov 22, 2023
1 parent 9277552 commit 468c031
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 49 deletions.
52 changes: 52 additions & 0 deletions DiztinGUIsh/window/MainWindow.Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,58 @@ private void GoToUnreached(bool fromStartOrEnd, bool forwardDirection)

SelectOffset(unreached, 1, BuildUnreachedHistoryArgs(fromStartOrEnd, forwardDirection));
}

private void GoToNextUnreachedInPoint(int offset)
{
// experimental. jump to next instruction that is an in point (something known jumps to it)
// AND is also marked as "unknown"
// these are often small branches not taken during tracelog runs,
// and are easy targets for filling them in relatively risk-free since you know the M and X flags of
// the instruction of where you jumped FROM.
var snesData = Project.Data.GetSnesApi();
var (foundOffset, iaSourceOffsetPc) = snesData.FindNextUnreachedInPointAfter(offset);
if (foundOffset == -1)
{
ShowInfo("Can't jump to next unreached InPoint (none found)", "Woops");
return;
}

// now, if we want to get real fancy.... copy the MX flags from the previous place to here so when we step from here, it works.

// less aggressive way:
// if (iaSource != -1)
// {
// snesData.SetMxFlags(iaSource, snesData.GetMxFlags(iaSource));
// }
// SelectOffset(foundOffset, -1);

// more aggressive way (fine, unless your source data is a lie)
// do this instead of SelectOffset so we copy the MX flags from the previous location to here.
//if (iaSource != -1)
// StepIn(iaSource);

if (iaSourceOffsetPc != -1)
{
// this is vaguely doing what Step() does without marking the bytes we're on as opcode+operands.
// we'll set the flags and such but, leave the actual marking to be an explicit action by the user
var (opcode, directPage, dataBank, xFlag, mFlag) =
snesData.GetCpuStateFor(iaSourceOffsetPc, -1);

// set the place we're GOING to with the jump point's MX flags
snesData.SetDataBank(foundOffset, dataBank);
snesData.SetDirectPage(foundOffset, directPage);
snesData.SetXFlag(foundOffset, xFlag);
snesData.SetMFlag(foundOffset, mFlag);

// very optional. just to create an entry in the history.
// SelectOffset(iaSource, -1, new ISnesNavigation.HistoryArgs {Description = "Find next unreached: origin point"});
MarkHistoryPoint(iaSourceOffsetPc,
new ISnesNavigation.HistoryArgs { Description = "Find next unreached: branch origin" }, "origin");
}

// now do the real thing
SelectOffset(foundOffset, -1, new ISnesNavigation.HistoryArgs { Description = "Find next unreached in-point" }, overshootAmount: 20);
}

private static ISnesNavigation.HistoryArgs BuildUnreachedHistoryArgs(bool fromStartOrEnd, bool forwardDirection)
{
Expand Down
13 changes: 12 additions & 1 deletion DiztinGUIsh/window/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 2 additions & 47 deletions DiztinGUIsh/window/MainWindow.MainTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,57 +77,12 @@ private void table_KeyDown(object sender, KeyEventArgs e)
var amount = 0x01;

Console.WriteLine(e.KeyCode);

var snesData = Project.Data.GetSnesApi();

switch (e.KeyCode)
{
case Keys.F3:
// experimental. jump to next instruction that is an in point (something known jumps to it)
// AND is also marked as "unknown"
// these are often small branches not taken during tracelog runs,
// and are easy targets for filling them in relatively risk-free since you know the M and X flags of
// the instruction of where you jumped FROM.
var (foundOffset, iaSourceOffsetPc) = snesData.FindNextUnreachedInPointAfter(offset);
if (foundOffset == -1)
{
ShowInfo("Can't jump to next unreached InPoint (none found)", "Woops");
return;
}

// now, if we want to get real fancy.... copy the MX flags from the previous place to here so when we step from here, it works.

// less aggressive way:
// if (iaSource != -1)
// {
// snesData.SetMxFlags(iaSource, snesData.GetMxFlags(iaSource));
// }
// SelectOffset(foundOffset, -1);

// more aggressive way (fine, unless your source data is a lie)
// do this instead of SelectOffset so we copy the MX flags from the previous location to here.
//if (iaSource != -1)
// StepIn(iaSource);

if (iaSourceOffsetPc != -1)
{
// this is vaguely doing what Step() does without marking the bytes we're on as opcode+operands.
// we'll set the flags and such but, leave the actual marking to be an explicit action by the user
var (opcode, directPage, dataBank, xFlag, mFlag) = snesData.GetCpuStateFor(iaSourceOffsetPc, -1);

// set the place we're GOING to with the jump point's MX flags
snesData.SetDataBank(foundOffset, dataBank);
snesData.SetDirectPage(foundOffset, directPage);
snesData.SetXFlag(foundOffset, xFlag);
snesData.SetMFlag(foundOffset, mFlag);

// very optional. just to create an entry in the history.
// SelectOffset(iaSource, -1, new ISnesNavigation.HistoryArgs {Description = "Find next unreached: origin point"});
MarkHistoryPoint(iaSourceOffsetPc, new ISnesNavigation.HistoryArgs {Description = "Find next unreached: branch origin"}, "origin");
}

// now do the real thing
SelectOffset(foundOffset, -1, new ISnesNavigation.HistoryArgs {Description = "Find next unreached in-point"}, overshootAmount: 20);

GoToNextUnreachedInPoint(offset);
break;

case Keys.Home:
Expand Down
5 changes: 4 additions & 1 deletion DiztinGUIsh/window/MainWindow.SimpleUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ private void gotoNearUnreachedToolStripMenuItem_Click(object sender, EventArgs e

private void gotoNextUnreachedToolStripMenuItem_Click(object sender, EventArgs e) =>
GoToUnreached(false, true);


private void gotoNextUnreachedInPointToolStripMenuItem_Click(object sender, EventArgs e) =>
GoToNextUnreachedInPoint(SelectedOffset);

private void markOneToolStripMenuItem_Click(object sender, EventArgs e) =>
Mark(SelectedOffset);

Expand Down

0 comments on commit 468c031

Please sign in to comment.