Advertisement
Zeda

relocatable

Sep 17th, 2018
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifndef rcall
  2. #define rcall saveSScreen
  3. #endif
  4.   push hl
  5.   push de
  6.   push bc
  7.   push af
  8.   ld hl,rcall+1
  9.   .db 36h \ jp (hl)
  10.   dec hl
  11.   .db 36h \ pop hl
  12.   ex de,hl
  13.   call rcall
  14.   ;HL now points here
  15. discovered_addr:
  16. ;At this point, we are going to load a routine for relative jumps
  17.   push hl
  18.   ld bc,reljump-discovered_addr
  19.   add hl,bc
  20.   ld bc,reljump_end-reljump
  21.   ldir
  22.   pop af
  23.   pop bc
  24.   pop de
  25.   pop hl
  26. ;At this point, you can "call rcall \ .dw offset"
  27.   ;Your code goes here
  28.   ret
  29.  
  30.  
  31.  
  32. reljump:
  33.   ex sp,(hl)
  34.   push de
  35.   or a      ;in the case of ADL mode, we need to make sure UDE = 0
  36.   ex de,hl  ;
  37.   sbc hl,hl ;
  38.   ex de,hl  ;
  39.   ld e,(hl)
  40.   inc hl
  41.   ld d,(hl)
  42.   inc hl
  43.   inc sp
  44.   inc sp
  45.   inc sp
  46.   inc sp
  47.   push hl
  48.   add hl,de
  49.   dec sp
  50.   dec sp
  51.   dec sp
  52.   dec sp
  53.   pop de
  54.   jp (hl)
  55. reljump_end:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement