★ CODING ★ Anatomy of an RSX (2/2) ★![]() |
Rsx - Anatomy Of An Rsx - Part 1 (Amstrad Action) | Rsx - Anatomy Of An Rsx - Part 2 (Amstrad Action) |
Relocating RSXs is a toughie, but in Part 2 of his RSX tutorial, DAVID HOLMES reckons he has the answer... It can be difficult to arrange for RSX routines to be relocatable as the code involves several absolute addresses which will require alteration unless the code is run at the address to which it was originally assembled. It is not always easy to predict where in memory each user may wish to place the code as the presence of external ROMs or other RSX routines, for example, alter the value of HIMEM to a considerable degree. For this reason it is desirable to allow the code to be as flexible as possible. There are two ways of achieving this. One way is to use a machine code relocator program which is added to the RSX code. This can be quite complex, however, and may involve a considerable amount of effort which is not justified in a short routine. BASIC solution The method used here is to use the BASIC loader program Listing 1 to relocate the code as described below. When the program has been developed the code can be assembled to any reasonable position and then the bytes relating to any absolute address can be noted. It may be easiest to assemble to two different locations and then use the assembler to compare the two blocks of code. The addresses noted as different are those referring to absolute addresses. An absolute address is an address that is defined as a fixed point in the memory rather than a point relative to the start of the code. Such an address will be always at the same distance from the start of the code but its actual value will depend upon the code origin. It is this value which must be adjusted to allow the code to run at any specific load address. The problems occur in the first section of code which sets up the RSX. For example, the address of the command table defined in bytes two and three is an absolute address. The same applies to the address of the workspace defined in bytes five and six, the address of the name table defined in bytes &d and &e and the address of the label .fade defined in bytes &10 and &11. The remainder of the code contains no absolute addresses (other than Firmware calls) and is completely relocatable. LISTING 1: RSX RELOCATION (INCOMPLET) 10 REM SCREEN FADEOnly absolute addresses referring to locations within the code itself require relocation for different load addresses. Absolute addresses are used when registers are loaded from memory locations (either numbered or labelled), when memory locations are loaded from registers and when calls or jumps (not relative jumps) are made to labelled locations. For this reason relative jumps (jr instructions) should be used when possible to reduce the amount of relocation work to be done. Firmware calls cause no problem as they are not affected by the position of the RSX code in memory. |
Label defined | Definition Offset (High byte) | Absolute Offset |
command _table | &2 | &d |
space | &5 | &9 |
name_table | &e | &12 |
fade | &11 | &17 |
As BASIC now knows the start address, it is easy to find each AOA by adding the value of the AO to start. If this is calculated in hexadecimal, the low and high bytes can be separated using the RIGHTS and LEFT$ funtions.
The high byte of the DOA can be found by adding the value of the DO to start. The low byte can be found by subtracting one from this value.
The low byte of the AOA is poked into the low byte of the DOA and the high byte of the AOA is poked into the high byte of the DOA.
This procedure is performed for each DOA and the code is then CALLed. This installs the RSX and the loader program is deleted to prevent it from being run again.
It is worth spending a little time adding a relocator to any RSX programs which are designed to store code just below HIMEM as this allows a library of routines to be built up. These can then be used when required with the minimum usage of memory as each routine can be added at the highest available location.
![]() | Page précédente : Rsx - Anatomy Of An Rsx - Part 1 |
|