USR User SubRoutine
Function
USR is used to call a machine code subroutine that has been placed in memory at a specified address. It is also used to place the data for a user-defined graphics character in the reserved locations at the top of the memory.
USR and machine code
To use machine code, USR is followed by a numeric value, for example
80 PRINT USR 65000
100 RANDOMIZE USR 65000
An expression should be enclosed in brackets. The value following USR is rounded down to the nearest integer and is then the starting address in the memory at which the machine code subroutine has been placed. Any statement containing USR then calls the subroutine at this address and USR returns the contents of the BC register pair. RANDOMIZE USR or RESTORE USR, for example runs the subroutine only (though bear in mind that any command that takes a numeric parameter will act on the result of the USR call), whereas PRINT USR additionally displays the BC register value.
USR and user-defined graphics
To create user-defined graphics, USR is used with POKE. It is followed by a string constant or variable to return an address for the POKE, for example
50 POKE USR "a",255
the string value following USR may be a single letter ranging from A to U, or a to u, capital letters not being distinguished from lower-case letters.
USR then returns the starting address of one of the 21 sections of memory reserved for user-defined graphics. Each section contains eight addresses to which eight bytes are POKEd to create one graphics character. The bytes may be given in decimal form or in binary (see BIN).
Format
- USR int-num-const
- USR int-num-var
- USR (int-num-expr)
- USR string-const
- USR string-var
- USR (string-expr)
See also