When you have determined the optimum starting address for your subroutine, you can LOCATE it there with this command. LOCATE converts the relocatable object code to absolute object code, according to the starting address given. An example of giving the starting address for your subroutine code is shown below.
LOCATE :F1 :PLMSUB.OBJ TO :F1 :PLMSUB.LD CODE (OEECOH)
This example converts the relocatable object code in :Fl :PLMSUB.OBJ to absolute object code in the output file :Fl :PLMSUB.LD, and makes all addresses in the subroutine relative to OEECOH. Refer to the ISIS-II User's Guide for further details of using LOCATE.
After LOCATE has converted your relocatable code to absolute object code, you can load it into memory with the ISIS-II Monitor DEBUG command. When you enter DEBUG followed by the filename of the load module, the subroutine is loaded into memory at the address specified in the load module. The starting address displays on your terminal. You then enter GS, which returns you to ISIS-II with the subroutine loaded at the specified address. From here.you can invoke BASIC-SO and call the subroutine.
NOTE
You must give the MEMTOP option to reserve memory each time BASIC-SO is invoked.
Calling Subroutines
After a subroutine is loaded into memory, you can call it from BASIC-80. First, invoke BASIC-SO as you normally do, and give the MEMTOP option as previously specified.
The first step in calling a subroutine is defining its address with the DEFUSR func- tion. Up to 25 subroutines can be addressed in this way, with an integer in the range
0-24. The starting address of the subroutine is given in hexadecimal:
DEFUSR5=OEECOH
Once BASIC-SO knows where USR5 is located, you can call it. When you call it, you must supply any needed variables. Since the protocol for passing parameters follows PL/M conventions, you can only directly pass 2-byte integer variables or 2-byte addresses. If you specify a floating-point variable or a string variable you must use the VARPTR function to pass the address of the desired variable. For example, to pass the addresses of two floating-point numbers (Kl and K2):
120 A = USR5 (VARPTR(K1), (VARPTR(K2»
BASIC-SO goes to the address where Kl is stored (VARPTR(Kl) and the address where K2 is stored (VARPTR(K2». Once it has found these two values, it passes them to the subroutine.
If BASIC-SO encounters new variables after executing line 120 above, the memory locations of Kl and K2 can change, causing errors. Be sure that all variables are defined before using the VARPTR instruction.
In the example shown, once the parameters are passed, the subroutine executes. Because of PL/M-80calling conventions BASIC-80 expects the returned result to be a two-byte integer in the HL register-pair, and assigns this 16-bit value to A.