Skip to content

Commit

Permalink
Fix Direct Page opcodes log generation
Browse files Browse the repository at this point in the history
The low byte of DP was affecting the opcode itself.
  • Loading branch information
VitorVilela7 committed Aug 6, 2019
1 parent 61cc0cd commit 7ab27df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DiztinGUIsh/static/LogCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private static string GetLine(int offset, string special)
}
}
}
int ia = Util.GetIntermediateAddress(offset);
int ia = Util.GetIntermediateAddress(offset, true);
if (ia >= 0 && flag == Data.FlagType.Opcode && Data.GetInOutPoint(offset) == Data.InOutPoint.OutPoint && Data.GetFlag(Util.ConvertSNEStoPC(ia)) != Data.FlagType.Opcode)
{
err.WriteLine("({0}) Offset 0x{1:X}: Branch or jump instruction to a non-instruction.", ++errorCount, offset);
Expand Down
7 changes: 4 additions & 3 deletions DiztinGUIsh/static/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static int GetIntermediateAddressOrPointer(int offset)
{
case Data.FlagType.Unreached:
case Data.FlagType.Opcode:
return GetIntermediateAddress(offset);
return GetIntermediateAddress(offset, true);
case Data.FlagType.Pointer16Bit:
int bank = Data.GetDataBank(offset);
return (bank << 16) | GetROMWord(offset);
Expand All @@ -53,11 +53,12 @@ public static int GetIntermediateAddressOrPointer(int offset)
return -1;
}

public static int GetIntermediateAddress(int offset)
public static int GetIntermediateAddress(int offset, bool resolve = false)
{
// FIX ME: log and generation of dp opcodes. search references
switch (Data.GetArchitechture(offset))
{
case Data.Architechture.CPU65C816: return CPU65C816.GetIntermediateAddress(offset);
case Data.Architechture.CPU65C816: return CPU65C816.GetIntermediateAddress(offset, resolve);
case Data.Architechture.APUSPC700: return -1;
case Data.Architechture.GPUSuperFX: return -1;
}
Expand Down
19 changes: 13 additions & 6 deletions DiztinGUIsh/static/diz/CPU65C816.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ public static int Step(int offset, bool branch, bool force, int prevOffset)
|| opcode == 0x70 || opcode == 0x90 || opcode == 0xB0 || opcode == 0xD0 // BVS BCC BCS BNE
|| opcode == 0xF0 || opcode == 0x20 || opcode == 0x22)))) // BEQ JSR JSL
{
int iaNextOffsetPC = Util.ConvertSNEStoPC(Util.GetIntermediateAddress(offset));
int iaNextOffsetPC = Util.ConvertSNEStoPC(Util.GetIntermediateAddress(offset, true));
if (iaNextOffsetPC >= 0) nextOffset = iaNextOffsetPC;
}

return nextOffset;
}

public static int GetIntermediateAddress(int offset)
public static int GetIntermediateAddress(int offset, bool resolve)
{
int bank, directPage, operand, programCounter;
int opcode = Data.GetROMByte(offset);
Expand All @@ -80,9 +80,16 @@ public static int GetIntermediateAddress(int offset)
case AddressMode.DIRECT_PAGE_INDIRECT_Y_INDEX:
case AddressMode.DIRECT_PAGE_LONG_INDIRECT:
case AddressMode.DIRECT_PAGE_LONG_INDIRECT_Y_INDEX:
directPage = Data.GetDirectPage(offset);
operand = Data.GetROMByte(offset + 1);
return (directPage + operand) & 0xFFFF;
if (resolve)
{
directPage = Data.GetDirectPage(offset);
operand = Data.GetROMByte(offset + 1);
return (directPage + operand) & 0xFFFF;
}
else
{
goto case AddressMode.DIRECT_PAGE_S_INDEX;
}
case AddressMode.DIRECT_PAGE_S_INDEX:
case AddressMode.DIRECT_PAGE_S_INDEX_INDIRECT_Y_INDEX:
return Data.GetROMByte(offset + 1);
Expand Down Expand Up @@ -185,7 +192,7 @@ public static int GetInstructionLength(int offset)
public static void MarkInOutPoints(int offset)
{
int opcode = Data.GetROMByte(offset);
int iaOffsetPC = Util.ConvertSNEStoPC(Util.GetIntermediateAddress(offset));
int iaOffsetPC = Util.ConvertSNEStoPC(Util.GetIntermediateAddress(offset, true));

// set read point on EA
if (iaOffsetPC >= 0 && ( // these are all read/write/math instructions
Expand Down

0 comments on commit 7ab27df

Please sign in to comment.