      .include #system
      .include #stddef
      .include #macros
; ------------------------------
; Natuerlich!'s handy dandy
;         RELOCATOR
; (c)1989/1990 by Natuerlich!
; All Rights Reserved.
; not written for speed or
; beauty
; -----------------------------
; change these defines to
; suit your taste. Must be zero
; page though
; -----------------------------
:src     =  $F0               ; -> org prg
:dst     =  $F2               ; -> reloc prg
:mdif    =  $F4               ; org-reloc
:dif     =  :mdif
:mod     =  $F5               ; datatype flag [ KEEP THESE
:siz     =  $F6               ; end of org      TOGETHER  ]
:vre     =  $F8               ; -> reltab
:vim     =  $FA               ; -> immtab
;
:foo     =  $FC               ; local vars for immediate
:pages   =  $FE               ; relocation
:entries =  $FF
; ---
p_reloc  POKE  :src+1,>|R_START ; uppercase labels come from the linker
         sta   :foo+1
         
         lda   |MEMLO         ; this is effectively:
         cmp   #1             ; :dst = (|MEMLO & 0xFF00) +
         lda   #0             ;           (|MEMLO & 0xFF ? 0x100 : 0)
         sta   :dst           ; another case when using ML really pays off
         sta   :src
         adc   |MEMLO+1
         sta   :dst+1
         sta   :found+2

         DPOKE :vim,|IMMTAB
         lda   #>|R_START+$100 ; Carry is clear 
         sbc   :dst+1          ; 
         sta   :mdif           ; but this apparently

         jsr   :do_imms        ; kills a bug lurking

         .include #coderel.s65
         .include #immprel.s65
