CALL USR
This page was last modified 15:22, 10 November 2021 by Mars2000you.

Contents

Effect

Allows the execution of assembler code from BASIC code.

It is equivalent to the standard DEF USR instruction and the USR() function, but with an added feature: it allows to specify the input values of the Z80 registers for the code to execute, and to read the output values after the execution.

Syntax

CALL USR(<CodeAddress>,<RegistersAddress>)

Parameters

When used without any parameter, this instruction will display some info about itself.

<CodeAddress> is the address of the assembler code to be executed.

Value -1 is treated as a special case: _USR(-1) will do nothing but will not throw an error. You can use this feature together with ON ERROR GOTO to detect the presence of Nextor from within a BASIC program.

<RegistersAddress> is the address of a 12 byte buffer for the Z80 registers values. This parameter is optional.

If this parameter is specified, the registers will be loaded with the contents of this area before the code is invoked; after the code execution, the reverse process is performed: the buffer is updated with the values hold by the registers. The order of the registers in the buffer is: F, A, C, B, E, D, L, H, IXl, IXh, IYl, IYh.

Example

Note: You can change the registers assignment in lines 40-90 and the address of the code to be invoked in line 100 as appropriate to invoke different code (the MSX BIOS itself is a good source of routines to play around).

10 ON ERROR GOTO 20: _USR(-1): ON ERROR GOTO 0: GOTO 30
20 PRINT "Nextor not found!": END
30 DEFINT R: DIM R(12)
40 R(0)=&H2100 'AF
50 R(1)=&H3040 'BC
60 R(2)=&H5060 'DE
70 R(3)=&H7080 'HL
80 R(4)=&H90A0 'IX
90 R(5)=&HB0C0 'IY
100 CALL USR(&H00A2, VARPTR(R(0))): 'Prints a "!" (passed in A as &H21) 
110 PRINT "AF=&H";HEX$(R(0))
120 PRINT "BC=&H";HEX$(R(1))
130 PRINT "DE=&H";HEX$(R(2))
140 PRINT "HL=&H";HEX$(R(3))
150 PRINT "IX=&H";HEX$(R(4))
160 PRINT "IY=&H";HEX$(R(5))

Related to

DEF USR, ON ERROR GOTO, USR(), VARPTR()

Compatibility

Disk BASIC only when using Nextor OS (both modes)