Initial revision
[ssr] / StraySrc / Libraries / BAS / src / sh / basicEnv
1 ;
2 ; basicEnv.sh
3 ;
4 ; Useful things in the BASIC environment
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's BASIC Assembler Supplement.
12 ;
13 ; BAS is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; BAS is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with BAS. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ; --- Notes ---
28 ;
29 ; This file contains symbolic names for the useful bits which BASIC puts
30 ; after R14 when it CALLs a piece of code.
31
32 ^ 0
33
34 ; --- Miscellaneous useful things ---
35
36 bEnv_return # 4 ;Return address after CALL
37
38 ; --- Offsets from ARGP (in R8 of all places) ---
39
40 bEnv_strAcc # 4 ;Ptr to string accumulator
41 bEnv_page # 4 ;Current program PAGE
42 bEnv_top # 4 ;Current program TOP
43 bEnv_loMem # 4 ;Current variable start
44 bEnv_hiMem # 4 ;Current stack end
45 bEnv_memLimit # 4 ;Limit of available memory
46 bEnv_fsa # 4 ;Free space start
47 bEnv_tally # 4 ;Value of COUNT
48 bEnv_timeOff # 4 ;Diff tween TIME and OS_Word
49 bEnv_escWord # 4 ;Exception flag word
50 bEnv_widthLoc # 4 ;Value of width-1
51
52 ; --- Internal routines ---
53 ;
54 ; Some corruptions documented. Bear in mind that there may
55 ; be others, though.
56
57 bEnv_varind # 4 ;Return value of lvalue
58 ;Entry: R0 == address of lv
59 ; R9 == type of lv
60 ; R12 == LINE
61 ;Exit: R0-R3 == value
62 ; R9 == magic type
63 ; 0 == str in STRACC
64 ; 4<<28 == int in R0
65 ; 8<<28 == fp in R0-R3
66
67 bEnv_storea # 4 ;Store a value in lvalue
68 ;Entry: R0-R3 == value
69 ; R4 == address of lv
70 ; R5 == type of lv
71 ; R8 == ARGP
72 ; R9 == type of value
73 ; R12 == LINE
74 ;Exit: R0-R7 corrupted
75
76 bEnv_ststore # 4 ;Stores a string in variable
77 ;Entry: Can't remember
78 ;Exit: Can't remember
79
80 bEnv_lvblnk # 4 ;Find a named lvalue
81 ;Entry: R8 == ARGP
82 ; R11 == ptr to name
83 ; R12 == LINE
84 ;Exit: R0 == address of lv
85 ; R9 == type
86 ; NE => found var OK
87 ; EQ, CS => bad name
88 ; EQ, CC => use CREATE
89
90 bEnv_create # 4 ;Creates a variable
91 ;Entry: Set up from LVBLNK
92 ;Exit: R0 == address of lv
93 ; R9 == type
94
95 bEnv_expr # 4 ;Evaluates an expression
96 ;Entry: R8 == ARGP
97 ; R11 points to string
98 ;Exit: As for VARIND
99 ; EQ => read string
100 ; NE, MI => fp value
101 ; NE, PL => int value
102
103 bEnv_match # 4 ;Tokenises a string
104 ;Entry: R1 == cr term string
105 ; R2 == dest pointer
106 ; R3 == 0 (parse lval)
107 ; 1 (parse rval)
108 ; R4 == 0/&8D (line no)
109 ;Exit: R0, R3, R4 corrupted
110 ; R1 == ptr past cr
111 ; R2 == ptr past cr
112 ; R5 == status:
113 ; >=&1000 mis-()
114 ; bit 8 => bad line no
115 ; lsb==1 => mis-""
116
117 bEnv_tokenAddr # 4 ;Untokenises a string
118 ;Entry: R0 == token
119 ; R12 == ptr to next ch
120 ;Exit: R1 == ptr to string
121 ; (term >&7f)
122 ; R12 modified
123 ; R0 corrupted
124
125 ; --- Floating point routines ---
126 ;
127 ; * means R4-R7 corrupted, and errors (e.g. overflow)
128 ; possible.
129 ;
130 ; In all cases, (R0-R3) may be modified, although the FP
131 ; value will be preserved (e.g. for normalisation).
132 ;
133 ; In FIX and FLOAT, R9 is changed to indicate the new type.
134
135 # 8 ;Ask Roger/Sophie!
136 bEnv_fSta # 4 ;[R9] <- (R0-R3)
137 bEnv_fLda # 4 ;(R0-R3) <- [R9]
138
139 bEnv_fAdd # 4 ;(R0-R3) <- [R9] + (R0-R3) *
140 bEnv_fSub # 4 ;(R0-R3) <- [R9] - (R0-R3) *
141 bEnv_fMul # 4 ;(R0-R3) <- [R9] * (R0-R3) *
142 bEnv_fDiv # 4 ;(R0-R3) <- [R9] / (R0-R3) *
143
144 bEnv_float # 4 ;(R0-R3) <- R0, R9 <- FLOAT
145 bEnv_fix # 4 ;R0 <- (R0-R3), R9 <- INT
146 bEnv_fSqrt # 4 ;(R0-R3) <- sqrt(R0-R3) *
147
148 ;----- That's all, folks ----------------------------------------------------
149
150 END