;
; vars.s
;
; Setting up useful variables for BAS
;
;  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.

;----- Standard header ------------------------------------------------------

		GET	libs:header
		GET	libs:swis

		GET	libs:stream

;----- External dependencies ------------------------------------------------

		GET	sh.bas
		GET	sh.basTalk

;----- Main code ------------------------------------------------------------

		AREA	|BAS$$Code|,CODE,READONLY

; --- vars__setAscending ---
;
; On entry:	R3 == pointer to a name table
;
; On exit:	R3 points past the table
;
; Use:		Sets the variables named in the given table to have integer
;		values from 0 upwards.  The table contains null-terminated
;		strings and is terminated by a null string.

vars__setAscending ROUT

		STMFD	R13!,{R0-R2,R4,R14}	;Save some registers
		MOV	R4,#0			;Start counting at 0
00		MOV	R0,R3			;Point at the string
		MOV	R2,R4			;Get the next value to set
		LDRB	R14,[R3],#1		;Load first byte from string
		CMP	R14,#0			;Is it the end of the table?
		LDMEQFD	R13!,{R0-R2,R4,PC}^	;Yes -- we've finished then
		ADD	R4,R4,#1		;Increment the counter
10		LDRB	R14,[R3],#1		;Load next byte from string
		CMP	R14,#1			;Alternative name?
		SUBEQ	R4,R4,#1		;Yes -- don't bump counter
		CMPNE	R14,#0			;Is it the end yet?
		BNE	%10vars__setAscending	;No -- go round for more
		BL	bTalk_create		;Create the variable
		BL	bTalk_store		;Store the value away
		B	%00vars__setAscending	;Set the next variable

		LTORG

; --- vars_set ---
;
; On entry:	--
;
; On exit:	--
;
; Use:		Sets up variable names for registers (normal and APCS) and
;		also for condition codes.

		EXPORT	vars_set
vars_set	ROUT

		STMFD	R13!,{R0,R14}		;Save some registers
		ADR	R3,vars__names		;Point to big name table
		BL	vars__setAscending	;Standard registers
		BL	vars__setAscending	;APCS registers
		BL	vars__setAscending	;Standard condition names
		LDMFD	R13!,{R0,PC}^		;And return to caller

vars__names	DCB	"R0",1,"r0",0
		DCB	"R1",1,"r1",0
		DCB	"R2",1,"r2",0
		DCB	"R3",1,"r3",0
		DCB	"R4",1,"r4",0
		DCB	"R5",1,"r5",0
		DCB	"R6",1,"r6",0
		DCB	"R7",1,"r7",0
		DCB	"R8",1,"r8",0
		DCB	"R9",1,"r9",0
		DCB	"R10",1,"r10",0
		DCB	"R11",1,"r11",0
		DCB	"R12",1,"r12",0
		DCB	"R13",1,"SP",1,"r13",1,"sp",0
		DCB	"R14",1,"LR",1,"LK",1,"r14",1,"lr",1,"lk",0
		DCB	"R15",1,"PC",1,"r15",1,"pc",0
		DCB	0

		DCB	"a1",0
		DCB	"a2",0
		DCB	"a3",0
		DCB	"a4",0
		DCB	"v1",0
		DCB	"v2",0
		DCB	"v3",0
		DCB	"v4",0
		DCB	"v5",0
		DCB	"v6",1,"sb",0
		DCB	"v7",1,"sl",0
		DCB	"fp",0
		DCB	"ip",0
		DCB	"sp",0
		DCB	"lr",0
		DCB	"pc",0
		DCB	0

		DCB	"EQ",1,"eq",1,"ZS",1,"zs",0
		DCB	"NE",1,"ne",1,"ZC",1,"zc",0
		DCB	"CS",1,"cs",1,"HS",1,"hs",0
		DCB	"CC",1,"cc",1,"LO",1,"lo",0
		DCB	"MI",1,"mi",1,"NS",1,"ns",0
		DCB	"PL",1,"pl",1,"NC",1,"nc",0
		DCB	"VS",1,"vs",0
		DCB	"VC",1,"vc",0
		DCB	"HI",1,"hi",0
		DCB	"LS",1,"ls",0
		DCB	"GE",1,"ge",0
		DCB	"LT",1,"lt",0
		DCB	"GT",1,"gt",0
		DCB	"LE",1,"le",0
		DCB	"AL",1,"al",0
		DCB	"NV",1,"nv",0
		DCB	0

		LTORG

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

		END
