|★ 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.
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 FADE
|Label defined||Definition Offset (High byte)||Absolute Offset|
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|
Page créée en 148 millisecondes et consultée 1026 fois
L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.