I'm interested in relocatable code, programs that can work independently of the configuration of the EP.
The problem is when you want to make it easily in Basic. RESTORE or ALLOCATE can give you spare memory for your code, but the direction can be different if you have been running another program before or have made immediately a reset.
But if you want the code to work on every EP you must think about relocatable modules.
No, I talk about tiny code with some jumps or calls inside. The Z80 wasn't engineered with relocatable code in mind( except the useful JP(HL) widely used in the EXOS, or the relative jumps, too shorts to be useful).
Then I've though about an easy way to do the trick:
100 ALLOCATE 20
110 CODE ORIGEN=HEX$("00,00,00,01,00,02,00,03,00,04,00,05,00,06,00,07,00,08,00,09")
120 LET CODH=INT(ORIGEN/255)
130 LET CODL=REM(ORIGEN,255)
140 FOR A=0 TO 9
150 READ B,C
160 LET DIREC=(B*255)+C+ORIGEN
170 LET H=PEEK(DIREC)
180 LET L=PEEK(DIREC+1)
190 LET L=L+CODL
200 LET H=H+CODH+INT(L/255)
210 LET L=REM(L,255)
215 PRINT DIREC,PEEK(DIREC),PEEK(DIREC+1)
220 POKE DIREC,H
230 POKE (DIREC+1),L
240 NEXT A
250 DATA 0,0,0,2,0,4,0,6,0,8,0,10,0,12,0,14,0,16,0,18
255 PRINT
260 FOR A=0 TO 9
270 PRINT ORIGEN+(A*2),PEEK(ORIGEN+(A*2)),PEEK(ORIGEN+(A*2)+1)
280 NEXT A
In lines 100-110 we put a test code in the Basic variable memory as usual.
In 120-130 we extract the H and L bytes of the new ORG direction.
Then, in the 140-240 loop we read from DATA in line 250 the absolute directions(ORG=0) we need to relocate .
Then the content of the memory is compared before and after.