6 ; © 1994-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's BASIC Assembler Supplement.
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)
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.
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.
27 ;----- Standard Header ------------------------------------------------------
34 ;----- External dependencies ------------------------------------------------
49 ;----- Branch table header --------------------------------------------------
51 AREA |!BAS$$Header|,CODE,READONLY
53 B bas__workSize ;Find workspace requirements
54 B bas__init ;Initialise workspace
55 B aof_init ;Initialise AOF generation
56 B aof_pass ;Signal start of new pass
57 B aof_iImport ;Import a symbol
58 B aof_export ;Export a symbol
59 B get ;Read in a header file
60 B aof_area ;Define start of new area
61 B aof_reloc ;Mark start of reloc area
62 B aof_noReloc ;Mark start of non-reloc area
63 B aof_entry ;Define entry point of image
64 B aof_save ;Save AOF file
65 B insert_align ;Align and add zeroes
66 B insert_reserve ;Reserve lots of zeroes
67 B lit_add ;Add data to literal pool
68 B lit_ltorg ;Insert a literal pool
69 B bas__saveOpt ;Read the current OPT value
70 B bas__restoreOpt ;Restore the OPT value
72 ;----- Main code ------------------------------------------------------------
74 AREA |BAS$$Code|,CODE,READONLY
76 ; --- bas__workSize ---
80 ; On exit: R0 == size of workspace required (picked up by USR())
82 ; Use: Allows the BASIC component to allocate a workspace block of
83 ; the right size. This will then be passed to us in R7 when
84 ; we get called later.
88 LDR R0,=bas_wSize ;Get the workspace size
89 MOVS PC,R14 ;And return to caller
95 ; On entry: R7 == address of workspace
96 ; R8-R14 from BASIC's CALL
100 ; Use: Initialises the code component of BAS.
104 STMFD R13!,{R12,R14} ;Save some registers
105 STR R12,[R7,#:INDEX:be__line] ;Store line value
106 MOV R12,R7 ;Point to my workspace
108 ; --- Fill in the BASIC environment things ---
110 STR R8,be__argp ;Save BASIC's workspace addr
111 STR R14,be__interface ;And save the interface ptr
113 ; --- Set up some special bits ---
115 MOV R14,#0 ;Set up string's buffer
116 STR R14,str__buffNum ;Tell it to use the first one
117 STR R14,aof__objHead ;We're not generating AOF
119 ; --- Work out address of A% ---
121 ADR R0,bas__aPercent ;Find the variable name
122 BL bTalk_lvblnk ;Find the address of it
123 STR R0,be__percents ;Save this address
125 ; --- Start up our memory manager ---
127 BL flex_init ;Initialise flex
128 BL vars_set ;Set up register names etc.
130 LDMFD R13!,{R12,PC}^ ;And return to caller
132 bas__aPercent DCB "A%",0
136 ; --- bas__saveOpt ---
138 ; On entry: R8 == BASIC's ARGP pointer
140 ; On exit: R0 == current value of OPT
142 ; Use: Returns the current value of BASIC's assembler options. This
143 ; is handy, because BASIC doesn't seem terribly good at
144 ; handling this by itself. The value -38 used here is stolen
149 LDRB R0,[R8,#-38] ;Load the OPT value
150 MOVS PC,R14 ;And return to caller
154 ; --- bas__restoreOpt ---
156 ; On entry: R0 == OPT value to restore
157 ; R8 == BASIC's ARGP pointer
161 ; Use: Sets the value of BASIC's assembler options to the given
162 ; value. This is necessary because BASIC isn't terribly good
163 ; at nesting the option values.
167 STRB R0,[R8,#-38] ;Store the OPT value
168 MOVS PC,R14 ;And return to caller
172 ; --- bas_argString ---
174 ; On entry: R1 == address of destination buffer
175 ; R9 == pointer to argument entry
176 ; R10 == number of arguments left
178 ; On exit: R9 increased by 8
181 ; Use: Reads a string argument into a buffer and null terminates
182 ; it sensibly so we can use it.
187 STMFD R13!,{R0-R3,R14} ;Save some registers
188 SUBS R10,R10,#1 ;Decrement R10 as promised
189 BCC bas_badCall ;If there wasn't one, die
190 LDR R14,[R9,#4] ;Load the argument type
191 CMP R14,#&81 ;Is this a $(addr) string?
192 BEQ %50bas_argString ;Yes -- handle that then
193 CMP R14,#&80 ;Is it a normal string?
194 BNE bas_badCall ;No -- the make an error
196 ; --- Handle a normal string variable ---
198 MOV R0,R1 ;Point to caller's buffer
199 LDR R3,[R9],#8 ;Load the string pointer
200 ANDS R14,R3,#3 ;Get non-word-alignedness
201 BIC R1,R3,#3 ;Word align anyway
202 LDMIA R1,{R1,R2} ;Load the possible bytes
203 MOV R14,R14,LSL #3 ;Convert bytes to bits
204 MOVNE R1,R1,LSR R14 ;Shove the bytes down
205 RSB R14,R14,#32 ;Get the other shift size
206 ORRNE R1,R1,R2,LSL R14 ;And work that out
207 LDRB R2,[R3,#4] ;Load the string length
208 BL fastMove ;(This is overkill)
209 MOV R14,#0 ;Terminate the string
210 STRB R14,[R0,R2] ;Do this nicely
211 B %90bas_argString ;And return to caller
213 ; --- Handle a $(addr) type string ---
215 50bas_argString MOV R2,R1 ;Keep the buffer pointer
216 MOV R0,R1 ;And point to it for str_cpy
217 LDR R1,[R9],#8 ;Point to caller's string
218 BL str_cpy ;Copy it over (and null term)
220 90bas_argString LDMFD R13!,{R0-R3,PC}^ ;Return to caller
224 ; --- bas_badCall ---
228 ; On exit: Generates an error
230 ; Use: Generates an error about bad arguments. It saves space to
231 ; just have this here.
236 ADRL R0,msg_errBadArg
245 ; On exit: Generates an error
247 ; Use: Generates an error about not having any memory left.
253 ADRL R0,msg_errNoMoreMem
258 ;----- That's all, folks ----------------------------------------------------