Enhanced BASIC, useful routines By Lee Davison.

Introduction.

There are many subroutines within BASIC that can be useful if you wish to use your own assembly routines with it. Here are some of them with a brief description of their function. For full details see the source code.

Note that most, if not all, of these routines need EhBASIC to be initialised before they will work properly and can not be used in isolation from EhBASIC.

The routines.
LAB_IGBY
BASIC increment and get byte routine. gets the next byte from the BASIC command stream. If the byte is a numeric character then the carry flag will be set, if the byte is a termination byte, either null or a statement separator, then the zero flag will be set. Spaces in the command stream will automatically be ignored.
LAB_GBYT
BASIC get byte routine. Gets the current byte from the BASIC command stream but does not change the pointer. Otherwise the same as above.
LAB_COLD
Performs a cold start. BASIC is reset and all BASIC memory is cleared.
LAB_WARM
Performs a warm start. Execution is stopped and BASIC returns to immediate mode.
LAB_OMER
Do "Out of memory" error, then warm start. The same as error $0C below.
LAB_XERR
With X set, do error #X, then warm start.

XError XError
$00NEXT without FOR $02syntax
$04RETURN without GOSUB $06out of data
$08function call $0Aoverflow
$0Cout of memory $0Eundefined statement
$10array bounds $12double dimension array
$14divide by 0 $16illegal direct
$18type mismatch $1Along string
$1Cstring too complex $1Econtinue error
$20undefined function $22LOOP without DO
LAB_INLN
Print "? " and get BASIC input. Returns XY (low/high) as a pointer to the start of the input line. The input is null terminated.
LAB_SSLN
Search Basic for a line, the line number required is held in the temporary integer, from start of program memory. Returns carry set and a pointer to the line in Baslnl/Baslnh if found, if not it returns carry and a pointer to the next numbered line in Baslnl/Baslnh.
LAB_SHLN
Search Basic for temporary integer line number from AX. Same as above but starts the search from AX (low/high).
LAB_SNBS
Scan for next BASIC statement (: or [EOL]). Returns Y as index to : or [EOL] from (Bpntrl).
LAB_SNBL
Scan for next BASIC line. Same as above but only returns on [EOL].
LAB_REM
Perform REM, skip (rest of) line.
LAB_GFPN
Get fixed-point number into temporary integer.
LAB_CRLF
Print [CR]/[LF] to output device.
LAB_PRNA
Print character in A to output device.
LAB_GVAR
Get variable address. Returns a pointer to the variable in Lvarpl/h and sets the data type flag, $FF=string, $00=numeric.
LAB_EVNM
Evaluates an expression and checks the result is numeric, if not it does a type mismatch. The result of the expression is returned in FAC1.
LAB_CTNM
Check if source is numeric, else do type mismatch.
LAB_CTST
Check if source is string, else do type mismatch.
LAB_CKTM
Type match check, set carry for string, clear carry for numeric.
LAB_EVEX
Evaluate expression.
LAB_GVAL
Get numeric value from line. Returns the result in FAC1.
LAB_SCCA
Scan for the byte in A as the next byte. If so return here, else do syntax error then warm start.
LAB_SNER
Do syntax error, then warm start.
LAB_CASC
Check byte is alpha ("A" to "Z" or "a" to "z"), return carry clear if so.
LAB_EVIN
Evaluate integer expression. Return integer in FAC1_3/FAC1_2 (low/high).
LAB_EVPI
Evaluate +ve integer expression.
LAB_EVIR
Evaluate integer expression, check is in range -32786 to 32767
LAB_FCER
Do function call error, then warm start.
LAB_CKRN
Check that the interpreter is not in immediate mode. If not then return, if so do illegal direct error.
LAB_GARB
Perform garbage collection routine.
LAB_EVST
Evaluate string.
LAB_ESGL
Evaluate string, return string length in Y.
LAB_SGBY
Scan and get byte parameter, return the byte in X.
LAB_GTBY
Get byte parameter and ensure numeric type, else do type mismatch error. Return the byte in X.
LAB_EVBY
Evaluate byte expression, return the byte in X.
LAB_GADB
Get two parameters as in POKE or WAIT. Return the byte (second parameter) in X and the integer (first parameter) in the temporary integer pair, Itempl/Itemph.
LAB_SCGB
Scan for "," and get byte, else do Syntax error then warm start. Return the byte in X.
LAB_F2FX
New convert float to fixed routine. accepts any value that fits into 24 bits, +ve or -ve and converts it into a right truncated integer in the temporary integer pair, Itempl/Itemph.
LAB_UFAC
Unpack the four bytes starting (AY) into FAC1 as a floating point number.
LAB_PFAC
Pack the floating point number in FAC1 into the current variable (Lvarpl).
LAB_STFA
Stores a 16 bit number in FAC1. Set X to the exponent required (usually $90) and the carry set for +ve numbers and clear for -ve numbers. The routine will clear FAC1 mantissa3 and then normalise it.
LAB_AYFC
Save integer AY (A = high byte, Y = low byte) in FAC1 and convert to float. The result will be -32768 to +32767.
LAB_MSSP
Make string space A bytes long. This returns the following. str_ln = A = string length str_pl = Sutill = string pointer low byte str_ph = Sutilh = string pointer high byte
LAB_RTST
Return string. Takes the string described instr_ln, str_pl and str_ph and puts it on the string stack. This is how you return a string to BASIC.

Last page update: 14th July, 2003. e-mail me