WIP: NUM_TARGETS=4, and comment out bIncludeNextOpcodeAddress

This commit is contained in:
tomcw 2019-12-14 11:59:16 +00:00
parent d2010860ef
commit 67fe384715
4 changed files with 47 additions and 47 deletions

View File

@ -1113,10 +1113,11 @@ bool _CheckBreakpointValue( Breakpoint_t *pBP, int nVal )
//=========================================================================== //===========================================================================
int CheckBreakpointsIO () int CheckBreakpointsIO ()
{ {
const int NUM_TARGETS = 3; const int NUM_TARGETS = 4;
int aTarget[ NUM_TARGETS ] = int aTarget[ NUM_TARGETS ] =
{ {
NO_6502_TARGET,
NO_6502_TARGET, NO_6502_TARGET,
NO_6502_TARGET, NO_6502_TARGET,
NO_6502_TARGET NO_6502_TARGET
@ -1130,7 +1131,7 @@ int CheckBreakpointsIO ()
// bIncludeNextOpcodeAddress == false: // bIncludeNextOpcodeAddress == false:
// . JSR addr16: ignore addr16 as a target // . JSR addr16: ignore addr16 as a target
// . BRK/RTS/RTI: ignore return (or vector) addr16 as a target // . BRK/RTS/RTI: ignore return (or vector) addr16 as a target
_6502_GetTargets( regs.pc, &aTarget[0], &aTarget[1], &aTarget[2], &nBytes, true, false ); _6502_GetTargets( regs.pc, &aTarget[0], &aTarget[1], &aTarget[2], &aTarget[3], &nBytes, true, false );
if (nBytes) if (nBytes)
{ {

View File

@ -583,24 +583,20 @@ bool _6502_GetStackReturnAddress ( WORD & nAddress_ )
//=========================================================================== //===========================================================================
bool _6502_GetTargets ( WORD nAddress, int *pTargetPartial_, int *pTargetPartial2_, int *pTargetPointer_, int * pTargetBytes_, bool _6502_GetTargets ( WORD nAddress,
bool bIgnoreBranch /*= true*/, bool bIncludeNextOpcodeAddress /*= true*/ ) int *pTargetPartial_, int *pTargetPartial2_, int *pTargetPointer_, int *pTargetAfterControlFlow,
int * pTargetBytes_ /*=NULL*/, bool bIgnoreBranch /*= true*/, bool bIncludeNextOpcodeAddress /*= true*/ )
{ {
if (! pTargetPartial_) _ASSERT(pTargetPartial_ && pTargetPartial2_ && pTargetPointer_ && pTargetAfterControlFlow);
if (!pTargetPartial_ || !pTargetPartial2_ || !pTargetPointer_ || !pTargetAfterControlFlow)
return false; return false;
if (! pTargetPartial2_) // NB. pTargetBytes_ can be NULL
return false;
if (! pTargetPointer_)
return false;
// if (! pTargetBytes_)
// return false;
*pTargetPartial_ = NO_6502_TARGET; *pTargetPartial_ = NO_6502_TARGET;
*pTargetPartial2_ = NO_6502_TARGET; *pTargetPartial2_ = NO_6502_TARGET;
*pTargetPointer_ = NO_6502_TARGET; *pTargetPointer_ = NO_6502_TARGET;
*pTargetAfterControlFlow = NO_6502_TARGET;
if (pTargetBytes_) if (pTargetBytes_)
*pTargetBytes_ = 0; *pTargetBytes_ = 0;
@ -625,25 +621,25 @@ bool _6502_GetTargets ( WORD nAddress, int *pTargetPartial_, int *pTargetPartial
if (nOpcode == OPCODE_RTI) if (nOpcode == OPCODE_RTI)
{ {
//*pTargetPartial3_ = _6502_STACK_BEGIN + ((sp+1) & 0xFF); // TODO: PLP *pTargetPointer_ = _6502_STACK_BEGIN + ((sp+1) & 0xFF);
++sp; ++sp;
} }
*pTargetPartial_ = _6502_STACK_BEGIN + ((sp+1) & 0xFF); *pTargetPartial_ = _6502_STACK_BEGIN + ((sp+1) & 0xFF);
*pTargetPartial2_ = _6502_STACK_BEGIN + ((sp+2) & 0xFF); *pTargetPartial2_ = _6502_STACK_BEGIN + ((sp+2) & 0xFF);
nTarget16 = mem[*pTargetPartial_] + (mem[*pTargetPartial2_]<<8); *pTargetAfterControlFlow = mem[*pTargetPartial_] + (mem[*pTargetPartial2_]<<8);
if (nOpcode == OPCODE_RTS) if (nOpcode == OPCODE_RTS)
++nTarget16; ++(*pTargetAfterControlFlow);
} }
else if (nOpcode == OPCODE_BRK) // BRK? else if (nOpcode == OPCODE_BRK) // BRK?
{ {
*pTargetPartial_ = _6502_STACK_BEGIN + ((regs.sp+0) & 0xFF); *pTargetPartial_ = _6502_STACK_BEGIN + ((regs.sp+0) & 0xFF);
*pTargetPartial2_ = _6502_STACK_BEGIN + ((regs.sp-1) & 0xFF); *pTargetPartial2_ = _6502_STACK_BEGIN + ((regs.sp-1) & 0xFF);
//*pTargetPartial3_ = _6502_STACK_BEGIN + ((regs.sp-2) & 0xFF); // TODO: PHP //*pTargetPartial3_ = _6502_STACK_BEGIN + ((regs.sp-2) & 0xFF);
//*pTargetPartial4_ = _6502_BRK_VECTOR + 0; // TODO *pTargetPointer_ = _6502_BRK_VECTOR + 0;
//*pTargetPartial5_ = _6502_BRK_VECTOR + 1; // TODO //*pTargetPartial5_ = _6502_BRK_VECTOR + 1; // TODO
nTarget16 = *(LPWORD)(mem + _6502_BRK_VECTOR); *pTargetAfterControlFlow = *(LPWORD)(mem + _6502_BRK_VECTOR);
} }
else // PHn/PLn else // PHn/PLn
{ {
@ -651,10 +647,11 @@ bool _6502_GetTargets ( WORD nAddress, int *pTargetPartial_, int *pTargetPartial
nTarget16 = _6502_STACK_BEGIN + ((regs.sp+0) & 0xFF); nTarget16 = _6502_STACK_BEGIN + ((regs.sp+0) & 0xFF);
else else
nTarget16 = _6502_STACK_BEGIN + ((regs.sp+1) & 0xFF); nTarget16 = _6502_STACK_BEGIN + ((regs.sp+1) & 0xFF);
*pTargetPointer_ = nTarget16;
} }
if (bIncludeNextOpcodeAddress || (nOpcode != OPCODE_RTI && nOpcode != OPCODE_RTS && nOpcode != OPCODE_BRK)) // if (bIncludeNextOpcodeAddress || (nOpcode != OPCODE_RTI && nOpcode != OPCODE_RTS && nOpcode != OPCODE_BRK))
*pTargetPointer_ = nTarget16; // *pTargetPointer_ = nTarget16;
if (pTargetBytes_) if (pTargetBytes_)
*pTargetBytes_ = 1; *pTargetBytes_ = 1;
@ -668,33 +665,39 @@ bool _6502_GetTargets ( WORD nAddress, int *pTargetPartial_, int *pTargetPartial
*pTargetPartial2_ = _6502_STACK_BEGIN + ((regs.sp-1) & 0xFF); *pTargetPartial2_ = _6502_STACK_BEGIN + ((regs.sp-1) & 0xFF);
} }
if (bIncludeNextOpcodeAddress || (nOpcode != OPCODE_JSR && nOpcode != OPCODE_JMP_A)) if (nOpcode == OPCODE_JSR && nOpcode == OPCODE_JMP_A)
*pTargetAfterControlFlow = nTarget16;
else
*pTargetPointer_ = nTarget16; *pTargetPointer_ = nTarget16;
// if (bIncludeNextOpcodeAddress || (nOpcode != OPCODE_JSR && nOpcode != OPCODE_JMP_A))
// *pTargetPointer_ = nTarget16;
if (pTargetBytes_) if (pTargetBytes_)
*pTargetBytes_ = 2; *pTargetBytes_ = 2;
break; break;
case AM_IAX: // Indexed (Absolute) Indirect - ie. JMP (abs,x) case AM_IAX: // Indexed (Absolute) Indirect - ie. JMP (abs,x)
_ASSERT(nOpcode == OPCODE_JMP_IAX); _ASSERT(nOpcode == OPCODE_JMP_IAX);
nTarget16 += regs.x; nTarget16 = (nTarget16 + regs.x) & _6502_MEM_END;
*pTargetPartial_ = nTarget16; *pTargetPartial_ = nTarget16;
*pTargetPartial2_ = nTarget16+1; *pTargetPartial2_ = nTarget16+1;
if (bIncludeNextOpcodeAddress) *pTargetAfterControlFlow = *(LPWORD)(mem + nTarget16);
*pTargetPointer_ = *(LPWORD)(mem + nTarget16); // if (bIncludeNextOpcodeAddress)
// *pTargetPointer_ = *(LPWORD)(mem + nTarget16);
if (pTargetBytes_) if (pTargetBytes_)
*pTargetBytes_ = 2; *pTargetBytes_ = 2;
break; break;
case AM_AX: // Absolute, X case AM_AX: // Absolute, X
nTarget16 += regs.x; nTarget16 = (nTarget16 + regs.x) & _6502_MEM_END;
*pTargetPointer_ = nTarget16; *pTargetPointer_ = nTarget16;
if (pTargetBytes_) if (pTargetBytes_)
*pTargetBytes_ = 2; *pTargetBytes_ = 2;
break; break;
case AM_AY: // Absolute, Y case AM_AY: // Absolute, Y
nTarget16 += regs.y; nTarget16 = (nTarget16 + regs.y) & _6502_MEM_END;
*pTargetPointer_ = nTarget16; *pTargetPointer_ = nTarget16;
if (pTargetBytes_) if (pTargetBytes_)
*pTargetBytes_ = 2; *pTargetBytes_ = 2;
@ -703,9 +706,10 @@ bool _6502_GetTargets ( WORD nAddress, int *pTargetPartial_, int *pTargetPartial
case AM_NA: // Indirect (Absolute) - ie. JMP (abs) case AM_NA: // Indirect (Absolute) - ie. JMP (abs)
_ASSERT(nOpcode == OPCODE_JMP_NA); _ASSERT(nOpcode == OPCODE_JMP_NA);
*pTargetPartial_ = nTarget16; *pTargetPartial_ = nTarget16;
*pTargetPartial2_ = nTarget16+1; *pTargetPartial2_ = (nTarget16+1) & _6502_MEM_END;
if (bIncludeNextOpcodeAddress) *pTargetAfterControlFlow = *(LPWORD)(mem + nTarget16);
*pTargetPointer_ = *(LPWORD)(mem + nTarget16); // if (bIncludeNextOpcodeAddress)
// *pTargetPointer_ = *(LPWORD)(mem + nTarget16);
if (pTargetBytes_) if (pTargetBytes_)
*pTargetBytes_ = 2; *pTargetBytes_ = 2;
break; break;
@ -736,7 +740,7 @@ bool _6502_GetTargets ( WORD nAddress, int *pTargetPartial_, int *pTargetPartial
if (!bIgnoreBranch) if (!bIgnoreBranch)
{ {
*pTargetPartial_ = nTarget8; *pTargetPartial_ = nTarget8;
*pTargetPointer_ = nAddress + 2; *pTargetPointer_ = (nAddress + 2) & _6502_MEM_END;
if (nTarget8 <= _6502_BRANCH_POS) if (nTarget8 <= _6502_BRANCH_POS)
*pTargetPointer_ += nTarget8; // + *pTargetPointer_ += nTarget8; // +
@ -769,6 +773,7 @@ bool _6502_GetTargets ( WORD nAddress, int *pTargetPartial_, int *pTargetPartial
break; break;
default: default:
_ASSERT(0);
if (pTargetBytes_) if (pTargetBytes_)
*pTargetBytes_ = 0; *pTargetBytes_ = 0;
break; break;
@ -779,6 +784,8 @@ bool _6502_GetTargets ( WORD nAddress, int *pTargetPartial_, int *pTargetPartial
//=========================================================================== //===========================================================================
// TODO-TC: What is this func for? Specifically how does it use _6502_GetTargets()?
bool _6502_GetTargetAddress ( const WORD & nAddress, WORD & nTarget_ ) bool _6502_GetTargetAddress ( const WORD & nAddress, WORD & nTarget_ )
{ {
int iOpcode; int iOpcode;
@ -787,7 +794,6 @@ bool _6502_GetTargetAddress ( const WORD & nAddress, WORD & nTarget_ )
iOpcode = _6502_GetOpmodeOpbyte( nAddress, iOpmode, nOpbytes ); iOpcode = _6502_GetOpmodeOpbyte( nAddress, iOpmode, nOpbytes );
// Composite string that has the target nAddress // Composite string that has the target nAddress
// WORD nTarget = 0;
int nTargetOffset_ = 0; int nTargetOffset_ = 0;
if ((iOpmode != AM_IMPLIED) && if ((iOpmode != AM_IMPLIED) &&
@ -796,20 +802,12 @@ bool _6502_GetTargetAddress ( const WORD & nAddress, WORD & nTarget_ )
(iOpmode != AM_3)) (iOpmode != AM_3))
{ {
int nTargetPartial; int nTargetPartial;
int nTargetPartial2;
int nTargetPointer; int nTargetPointer;
WORD nTargetValue = 0; // de-ref int nTargetAfterControlFlow;
int nTargetBytes; _6502_GetTargets( nAddress, &nTargetPartial, &nTargetPartial2, &nTargetPointer, &nTargetAfterControlFlow, /*pTargetBytes_=*/NULL, /*bIgnoreBranch=*/false );
_6502_GetTargets( nAddress, &nTargetPartial, &nTargetPointer, &nTargetBytes, false );
// if (nTargetPointer == NO_6502_TARGET)
// {
// if (_6502_IsOpcodeBranch( nOpcode )
// {
// return true;
// }
// }
if (nTargetPointer != NO_6502_TARGET) if (nTargetPointer != NO_6502_TARGET)
// else
{ {
nTarget_ = nTargetPointer & _6502_MEM_END; nTarget_ = nTargetPointer & _6502_MEM_END;
return true; return true;

View File

@ -193,8 +193,9 @@ extern int g_aAssemblerFirstDirective[ NUM_ASSEMBLERS ];
int _6502_GetOpmodeOpbyte( const int iAddress, int & iOpmode_, int & nOpbytes_, const DisasmData_t** pData = NULL ); int _6502_GetOpmodeOpbyte( const int iAddress, int & iOpmode_, int & nOpbytes_, const DisasmData_t** pData = NULL );
void _6502_GetOpcodeOpmodeOpbyte( int & iOpcode_, int & iOpmode_, int & nOpbytes_ ); void _6502_GetOpcodeOpmodeOpbyte( int & iOpcode_, int & iOpmode_, int & nOpbytes_ );
bool _6502_GetStackReturnAddress( WORD & nAddress_ ); bool _6502_GetStackReturnAddress( WORD & nAddress_ );
bool _6502_GetTargets( WORD nAddress, int *pTargetPartial_, int *pTargetPartial2_, int *pTargetPointer_, int * pBytes_, bool _6502_GetTargets ( WORD nAddress,
bool bIgnoreBranch = true, bool bIncludeNextOpcodeAddress = true ); int *pTargetPartial_, int *pTargetPartial2_, int *pTargetPointer_, int *pTargetAfterControlFlow,
int * pTargetBytes_ = NULL, bool bIgnoreBranch = true, bool bIncludeNextOpcodeAddress = true );
bool _6502_GetTargetAddress( const WORD & nAddress, WORD & nTarget_ ); bool _6502_GetTargetAddress( const WORD & nAddress, WORD & nTarget_ );
bool _6502_IsOpcodeBranch( int nOpcode ); bool _6502_IsOpcodeBranch( int nOpcode );
bool _6502_IsOpcodeValid( int nOpcode ); bool _6502_IsOpcodeValid( int nOpcode );

View File

@ -100,10 +100,10 @@
, AM_ZY // 10 Zeropage, Y , AM_ZY // 10 Zeropage, Y
, AM_R // 11 Relative , AM_R // 11 Relative
, AM_IZX // 12 Indexed (Zeropage Indirect, X) , AM_IZX // 12 Indexed (Zeropage Indirect, X)
, AM_IAX // 13 Indexed (Absolute Indirect, X) , AM_IAX // 13 Indexed (Absolute Indirect, X) - ie. JMP (abs,x)
, AM_NZY // 14 Indirect (Zeropage) Indexed, Y , AM_NZY // 14 Indirect (Zeropage) Indexed, Y
, AM_NZ // 15 Indirect (Zeropage) , AM_NZ // 15 Indirect (Zeropage)
, AM_NA // 16 Indirect (Absolute) i.e. JMP , AM_NA // 16 Indirect (Absolute) - ie. JMP (abs)
, AM_DATA // Not an opcode! Markup as data , AM_DATA // Not an opcode! Markup as data
, NUM_ADDRESSING_MODES , NUM_ADDRESSING_MODES
, NUM_OPMODES = NUM_ADDRESSING_MODES , NUM_OPMODES = NUM_ADDRESSING_MODES