Info

End

In lines 640 and 650, the program loads one of the addresses in the relocation table into the HL register pair. A quick test (lines 660-680) determines if the program has reached the end of the relocation table. If not, the program moves the current value in HL to IY and loads the contents of the address into HL. The program adds the offset value, stored in BC, to HL, and puts the new value back in the program. Then it increments IX twice to point to the next entry in the relocation table.

The process isn't hard to follow, but the logic can be confusing. The relocation table contains a list of addresses in the main program. Each of those addresses contains an absolute reference to another address in the program. Therefore, IX is a pointer to a pointer to an address the program must change. This double indirect addressing has caused problems for more than one 2 a.m. programmer.

Lines 830-860 and 890 are unique to this program. Normally, 4004 hex and 4005 hex point to 1D78 hex, the RST 10H ROM routine. However, some versions of Disk Basic (and some packages that add extensions to Basic) change that address to suit their own extended commands. The program needs to know how to return to normal RST 10H processing. The relocation module must find the pointer and insert it into the program. It must also put the program's address into the RST 10H vector, so that the program becomes a filter to the normal RST 10H routine.

Finally, by line 910, everything is ready and the program module can move itself to high memory. HL points to the current beginning of the program, DE points to the first address in protected high memory, and BC contains the length of the program. After executing a simple LDIR, the program relocates itself. Normally, it could pass control back to Basic or DOS with a RET instruction. However, the program has loaded itself on top of Basic's stack, so you need to use an alternate exit. The return through 19AE hex, with BC containing 1A18 hex, is the most reliable and works on both the Models I and III.

The only remaining part of the relocation module is the table of absolute addresses in the program itself.

Was this article helpful?

0 0

Post a comment