How can I make a Z80 relocatable code aware of its position in memory?
In the "Machine Code for Beginners" program header there is an error:
1 ALLOCATE 40
2 LET B$="F7,18.............
3 LET C$="F7,01.............
4 LET D$="00,CA.............
5 CODE MC=HEX$(B$&C$&D$)&"MACHINEC"
6 CALL USR(MC,0)
Then, in memory, the code is allocated on different position depending of the configuration of the EP:
exos 24 !Allocate segment
ld A,C
ld (0xBFF8), A
out (0xB2),A
ld A,0x6A !channel 106 (file io)
ld DE,0x12EA ! <----------------Here the programmer assumes the allocated area is immovable.
exos 1 !open channel
ld A,0x6A
ld BC,0x18B2
ld DE,0x8151
exos 6 !read block
jp z,0x87B5
di
hang: jp hang
defstring:8,"MACHINEC" ! here points the buggy instruction
Is easy to search the string in the Basic program and then modify the code before the USR call, but I have though if I know the value of PC inside the code I only need to add the direction of the string. Then the basic header would work on all the configurations of the EP...