MCPcopy Create free account
hub / github.com/AppleWin/AppleWin / _6502_CalcRelativeOffset

Function _6502_CalcRelativeOffset

source/Debugger/Debugger_Assembler.cpp:489–521  ·  view source on GitHub ↗

===========================================================================

Source from the content-addressed store, hash-verified

487
488//===========================================================================
489bool _6502_CalcRelativeOffset ( int nOpcode, int nBaseAddress, int nTargetAddress, WORD * pTargetOffset_ )
490{
491 if (_6502_IsOpcodeBranch(nOpcode))
492 {
493 // Branch is
494 // a) relative to address+2
495 // b) in 2's compliment
496 //
497 // i.e.
498 // 300: D0 7F -> BNE $381 0x381 - 0x300 = 0x81 +129
499 // 300: D0 80 -> BNE $282 0x282 - 0x300 = -126
500 //
501 // 300: D0 7E BNE $380
502 // ^ ^ ^ ^
503 // | | | TargetAddress
504 // | | TargetOffset
505 // | Opcode
506 // BaseAddress
507 int nDistance = nTargetAddress - nBaseAddress;
508 if (pTargetOffset_)
509 *pTargetOffset_ = (BYTE)(nDistance - 2);
510
511 if ((nDistance - 2) > _6502_BRANCH_POS)
512 m_iAsmAddressMode = NUM_OPMODES; // signal bad
513
514 if ((nDistance - 2) < _6502_BRANCH_NEG)
515 m_iAsmAddressMode = NUM_OPMODES; // signal bad
516
517 return true;
518 }
519
520 return false;
521}
522
523//===========================================================================
524int _6502_GetOpmodeOpbyte ( const int nBaseAddress, int & iOpmode_, int & nOpbyte_, const DisasmData_t** pData_ )

Callers 2

Calls 1

_6502_IsOpcodeBranchFunction · 0.85

Tested by

no test coverage detected