1Ah DV$LOAD load a code block
Input D register - Address to load the overlay.
X register - Address on pack of overlay.
UTW_S0 - Relocation address.
Output - none -
Description

This service will load code from a pack which is in the Psion relocatable object format. It loads the code into memory and then applies any fix-ups that are required, thus relocating the code to the address as specified in UTW_S0.

The D register has the address in memory where the code is to be loaded. This can be anywhere that the code will be safe from overwriting but will normally be in the PERMANENT cell or above the LANGUAGE stack.

The X register has the address on the pack at which the relocatable object code starts. The first two bytes of the relocatable object code is of course the size of the code block.

UTW_S0 has the address at which to relocate the code (ie. the intended execution address. For code produced by the Psion assembler and in almost all cases this address will be the same as the address passed in the D register.

This routine assumes that the correct slot has already been selected with the PK$SETP service.

Example Assume that there is a device to be loaded from a pack in slot B and that the code starts at address $2400 on the pack. This device can be added to the other devices in the PERMANENT CELL with the following code fragment:
        CLRA                    ; DONT REPORT PACK CHANGED
        LDAB    #PAKB           ; SELECT SLOT B
        OS      PK$SETP
        BCS     ERROR           ; PACK ERROR
        CLRB
        LDX     #2400h          ; ADDRESS $2400 ON PACK
        OS      PK$SADD
        OS      PK$RWRD         ; READ THE SIZE OF THE CODE
        STD     UTW_R1          ; SAVE THE CODE SIZE
        LDX     #ALT_BASE       ; TAG OF PERMANENT CELL
        PSHX                    ; SAVE IT
        OS      AL$SIZE         ; GET THE CURRENT SIZE
        STD     UTW_S0          ; GROW AT END OF CELL
        STD     UTW_R0          ; SAVE THE CURRENT CELL SIZE
        LDD     UTW_R1          ; GET THE CODE SIZE
        PULX                    ; RESTORE IT
        OS      AL$GROW         ; GROW THE CELL
        BCS     ERROR           ; NOT ENOUGH MEMORY
        LDD     UTW_R0          ; GET OLD CELL SIZE
        ADDD    ALT_BASE        ; ADD THE BASE OF THE CELL
        STD     UTW_R0          ; SAVE THE LOAD ADDRESS
        STD     UTW_S0          ; RELOCATE ADDRESS
        LDX     #2400h          ; ADDRESS ON PACK
        OS      DV$LOAD         ; LOAD THE CODE
        BCS     ERROR           ; FAILED TO LOAD
        LDX     UTW_R0          ; BASE ADDRESS OF CODE
        LDD     UTW_R1          ; SIZE OF CODE BLOCK
        STD     0,X             ; PATCH THE DEVICE CODE
        LDAA    #PAKB          ; DEVICE LOADED FROM
        STAA    2,X            ; PATCH THE DEVICE CODE
        ; DEVICE NOW LOADED INTO MEMORY
Errors 229 - code checksum error
246 - no pack in slot
243 - bad device name
242 - pack changed
240 - unknown pack type
200 - pack bad read error