BASIC-80
Calling Non-BASIC-80 Subroutines
To return a single-precision floating-point, double-precision floating-point,
or
string result, you must use the appropriate data type character (see table
2-5
for a list
of
these characters) before the subroutine number in the USR
function.
For
example, to tell
BASIC-SO
that a user-written subroutine
returns a double-precision floating- point value:
240
A# = USR
#15
(VARPTR(L#), A1)
In this example, the sharp sign (#) following USR tells
BASIC-SO
to reserve an
S-
byte space for the double-precision result
of
USR #15. A#
is
also defined as
double- precision, but the parameters passed may be of any numeric type.
Your subroutine must interpret the
first
parameter passed to it as the storage
address
of
A#, and it must also place the result
of
USR
#15
there.
References to string parameters are handled in a similar manner.
V
ARPTR
of
a
string
is
the address
of
the string descriptor,
not
the string data. Thus if a user
subroutine returns a string then the user should code
USR$[n]. BASIC allocates a
255-character string and pass the address
of
the string descriptor to the subroutine.
Your routine may change the string length in the string descriptor to return a shorter
string,
but
may not change the string's address. Neither parameter strings nor
parameter string descriptors should be changed.
Array variables are passed as parameters by referencing the first element
of
the
array.
BASIC-SO follows row-major order.
To code in
8080/S0S5 assembly language, you must know the Intel format for
representing integer, single-precision floating-point, and double-precision floating
point numbers. Figure
E-l
shows these representations.
~~D~ESS
ILS_f_I~~I
________________
1_5_B_IT_S_O_F_DA_T_A
________________
~
INTEGER
REPRESENTATION:
2
BYTES,
16
BITS,
LOW
ORDER
BYTE
FIRST
8
EXPONENT
BITS
23
MANTISSA
BITS
SINGLE-PRECISION FLOATING·POINT
REPRESENTATION:
4
BYTES,
32
BITS,
LOW
ORDER
BYTE
FIRST
11
EXPONENT
BITS
52
MANTISSA
BITS
DOUBLE-PRECISION FLOATING-POINT
REPRESENTATION:
8
BYTES,
84
BITS,
LOW
ORDER
BYTE
FIRST
LENGTH
ADDRESS
STRING DESCRIPTOR REPRESENTATION: 8
BITS,
STRING
LENGTH:
16
BITS, STRING ADDRESS.
DATA DATA
DATA
DATA
STRING
DATA REPRESENTATION: 8
BIT
BYTES.
Figure B-1. Internal Representation
of
Numbers and Strings
LOW
ADDRESS
E-3