;
; basicEnv.sh
;
; Useful things in the BASIC environment
;
;  1994-1998 Straylight
;

;----- Licensing note -------------------------------------------------------
;
; This file is part of Straylight's BASIC Assembler Supplement.
;
; BAS is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2, or (at your option)
; any later version.
;
; BAS is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with BAS.  If not, write to the Free Software Foundation,
; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

; --- Notes ---
;
; This file contains symbolic names for the useful bits which BASIC puts
; after R14 when it CALLs a piece of code.

		^	0

		; --- Miscellaneous useful things ---

bEnv_return	#	4			;Return address after CALL

		; --- Offsets from ARGP (in R8 of all places) ---

bEnv_strAcc	#	4			;Ptr to string accumulator
bEnv_page	#	4			;Current program PAGE
bEnv_top	#	4			;Current program TOP
bEnv_loMem	#	4			;Current variable start
bEnv_hiMem	#	4			;Current stack end
bEnv_memLimit	#	4			;Limit of available memory
bEnv_fsa	#	4			;Free space start
bEnv_tally	#	4			;Value of COUNT
bEnv_timeOff	#	4			;Diff tween TIME and OS_Word
bEnv_escWord	#	4			;Exception flag word
bEnv_widthLoc	#	4			;Value of width-1

		; --- Internal routines ---
		;
		; Some corruptions documented.  Bear in mind that there may
		; be others, though.

bEnv_varind	#	4			;Return value of lvalue
						;Entry:	R0 == address of lv
						;	R9 == type of lv
						;	R12 == LINE
						;Exit:	R0-R3 == value
						;	R9 == magic type
						;	 0 == str in STRACC
						;	 4<<28 == int in R0
						;	 8<<28 == fp in R0-R3

bEnv_storea	#	4			;Store a value in lvalue
						;Entry:	R0-R3 == value
						;	R4 == address of lv
						;	R5 == type of lv
						;	R8 == ARGP
						;	R9 == type of value
						;	R12 == LINE
						;Exit:	R0-R7 corrupted

bEnv_ststore	#	4			;Stores a string in variable
						;Entry:	Can't remember
						;Exit:	Can't remember

bEnv_lvblnk	#	4			;Find a named lvalue
						;Entry:	R8 == ARGP
						;	R11 == ptr to name
						;	R12 == LINE
						;Exit:	R0 == address of lv
						;	R9 == type
						;	NE => found var OK
						;	EQ, CS => bad name
						;	EQ, CC => use CREATE

bEnv_create	#	4			;Creates a variable
						;Entry:	Set up from LVBLNK
						;Exit:	R0 == address of lv
						;	R9 == type

bEnv_expr	#	4			;Evaluates an expression
						;Entry:	R8 == ARGP
						;	R11 points to string
						;Exit:	As for VARIND
						;	EQ => read string
						;	NE, MI => fp value
						;	NE, PL => int value

bEnv_match	#	4			;Tokenises a string
						;Entry:	R1 == cr term string
						;	R2 == dest pointer
						;	R3 == 0 (parse lval)
						;	      1 (parse rval)
						;	R4 == 0/&8D (line no)
						;Exit:	R0, R3, R4 corrupted
						;	R1 == ptr past cr
						;	R2 == ptr past cr
						;	R5 == status:
						;	 >=&1000 mis-()
						;	 bit 8 => bad line no
						;	 lsb==1 => mis-""

bEnv_tokenAddr	#	4			;Untokenises a string
						;Entry:	R0 == token
						;	R12 == ptr to next ch
						;Exit:	R1 == ptr to string
						;	      (term >&7f)
						;	R12 modified
						;	R0 corrupted

		; --- Floating point routines ---
		;
		; * means R4-R7 corrupted, and errors (e.g. overflow)
		; possible.
		;
		; In all cases, (R0-R3) may be modified, although the FP
		; value will be preserved (e.g. for normalisation).
		;
		; In FIX and FLOAT, R9 is changed to indicate the new type.

		#	8			;Ask Roger/Sophie!
bEnv_fSta	#	4			;[R9] <- (R0-R3)
bEnv_fLda	#	4			;(R0-R3) <- [R9]

bEnv_fAdd	#	4			;(R0-R3) <- [R9] + (R0-R3)  *
bEnv_fSub	#	4			;(R0-R3) <- [R9] - (R0-R3)  *
bEnv_fMul	#	4			;(R0-R3) <- [R9] * (R0-R3)  *
bEnv_fDiv	#	4			;(R0-R3) <- [R9] / (R0-R3)  *

bEnv_float	#	4			;(R0-R3) <- R0, R9 <- FLOAT
bEnv_fix	#	4			;R0 <- (R0-R3), R9 <- INT
bEnv_fSqrt	#	4			;(R0-R3) <- sqrt(R0-R3)     *

;----- That's all, folks ----------------------------------------------------

		END
