Skip to content

Instantly share code, notes, and snippets.

@skochinsky
Last active October 30, 2020 13:46
Show Gist options
  • Save skochinsky/cb988b42e306ee76473d7b4fb8f7e49e to your computer and use it in GitHub Desktop.
Save skochinsky/cb988b42e306ee76473d7b4fb8f7e49e to your computer and use it in GitHub Desktop.
/*scan for far jumps or calls and print their location and destinations
jmp: 1= search for jumps(0= calls)
low16: only consider destinations with offset < 16
*/
static scan_jmp_call(jmp, low16)
{
// start at the minimal address
auto a = 0;
auto x, seg, offs, dest;
for (a = 0; x != BADADDR; a = x + 5 )// skip 5 bytes (size of far jmp/call opcode)
{
//msg("%a...\n", a);
x = find_binary(a, SEARCH_CASE|SEARCH_NEXT|SEARCH_DOWN, jmp? "EA" : "9A");
if ( x == BADADDR )
break;
// EA offl offh segl segh
// extract segment:offset from the instruction
offs = word(x+1);
seg = word(x+3);
dest = to_ea(seg, offs);
// skip big offsets if asked
if (low16 && offs >=16 )
continue;
// skip non-existing destinations
if (!is_mapped(dest))
continue;
msg("%a: %04X:%04X -> %06X\n", x, seg, offs, dest);
a = x+5;
}
}
static main()
{
msg("Far jumps (low16)\n");
scan_jmp_call(1, 1);
msg("Far calls (low16)\n");
scan_jmp_call(0, 1);
msg("Far jumps (all)\n");
scan_jmp_call(1, 0);
msg("Far calls (all)\n");
scan_jmp_call(0, 0);
}
//split a rom loaded at 0x80000 into 64K segments
auto base;
auto start = base << 4;
auto size = 0x10000;
for (base = 0x8000; base < 0x10000; base = base + 0x1000 )
{
start = base << 4;
// create a 64K segment
add_segm_ex(start, start+size, base, 0, saRelPara, scPub,ADDSEG_NOSREG);
set_segm_name(start, sprintf("seg_%04X", base));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment