Calling A Machine Code Routine From Basic - Dick Smith VZ200 Technical Reference Manual

Personal colour computer
Table of Contents

Advertisement

11. CALLING A MACHINE CODE ROUTINE FROM BASIC
The standard way of calling a machine language program or
routine from BASIC is to use the USR(X) command. But before
this command can be used, the starting address of the machine
language routine must be loaded into the USR program pointer,
stored at address 788E/F hex (decimal 30862/3). This can be
done using POKE statements.
To illustrate this, let's look at an example. Let's say you
want to use the INKEY$ function in your BASIC program, to
accept input character-by-character. But you'd like the VZ-200
to give its usual 'beep' each time to register input, and the
INKEY$ function doesn't provide this.
As it happens, the BEEP subroutine in VZ-200's BASIC ROM can
easily be called to do this, using the USR(X) command. The
calling address for the routine is 3450 hex, so the decimal
figures for the USR pointer bytes are 80 (low byte, equal to 50
hex) and 52 (high bytes, equal to 34 hex).
So if you want to produce a 'beep' at various places in your
BASIC program, all you need to do is put this line near the
start of the program (before the first beep is needed):
20 POKE 30862,80:POKE 30863,52
This sets up the USR pointer. Then wherever you want a 'beep'
in your program, simply use the command:
X=USR(X)
Note that before control is passed to the user routine at the
designated address, the value of the argument variable X is
stored in locations 31009/31010 (7921/2 hex). So this can be
used to 'pass' a parameter value to the user routine. If the
routine doesn't need any parameters (like the 'beep' routine
above), simply use a 'dummy' variable name like X, as shown.
The same general technique is used for calling other machine
code routines, whether they are located in ROM or RAM. It's
simply a matter of poking the start address of the routine into
30862/3, and then using the USR command.
You aren't limited to calling a single machine code routine, by
the way. You can call a number of routines in turn, simply by
poking each routine's start address into 30862/3 before you use
the USR command to call it. Just remember to POKE the right
routine address into the pointer each time!
- 16 -

Advertisement

Table of Contents
loading

Table of Contents