Create readable text `.bas' for each tokenized BASIC `,ffb' file.
[ssr] / StraySrc / Utilities / b / buildstub.bas
CommitLineData
c1b567d8
MW
1REM
2REM SapphStub
3REM
4REM Build Sapphire extension stub entries
5REM
6REM © 1994-1998 Straylight
7REM
8
9REM ----- Licensing note ----------------------------------------------------
10REM
11REM This file is part of Straylight's core utilities (coreutils)
12REM
13REM Coreutils is free software; you can redistribute it and/or modify
14REM it under the terms of the GNU General Public License as published by
15REM the Free Software Foundation; either version 2, or (at your option)
16REM any later version
17REM
18REM Coreutils is distributed in the hope that it will be useful,
19REM but WITHOUT ANY WARRANTY; without even the implied warranty of
20REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21REM GNU General Public License for more details.
22REM
23REM You should have received a copy of the GNU General Public License
24REM along with Coreutils. If not, write to the Free Software Foundation,
25REM 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27REM --- Parse arguments ---
28
29ON ERROR ERROR EXT 0,REPORT$+"["+STR$(ERL)+"]"
30PROCinit
31PROCparse(FNreadCommandLine)
32END
33
34DEF PROCinit
35DIM q% 256
36LIBRARY "libs:bas"
37PROCbas_init
38ENDPROC
39
40REM --- Read a command line ---
41
42DEF FNreadCommandLine
43LOCAL comm$
44SYS "OS_GetEnv" TO comm$
45IF INSTR(comm$,"-quit")=0 THEN ERROR 1,"SapphStub must be started using *Run"
46comm$=MID$(comm$,INSTR(comm$,"""")+1)
47comm$=MID$(comm$,INSTR(comm$," ")+1)
48comm$=LEFT$(comm$,INSTR(comm$,"""")-1)
49=comm$
50
51REM --- Remove a word from a command line ---
52
53DEF FNword(RETURN line$)
54LOCAL word$
55IF INSTR(line$," ") THEN
56 word$=LEFT$(line$,INSTR(line$," ")-1)
57 line$=MID$(line$,INSTR(line$," ")+1)
58ELSE
59 word$=line$
60 line$=""
61ENDIF
62=word$
63
64REM --- Convert a string to upper case ---
65
66DEF FNupper(line$)
67LOCAL i%
68$q%=line$
69FOR i%=0 TO LEN(line$)-1
70 IF q%?i%>=97 AND q%?i%<=122 THEN q%?i%-=32
71NEXT
72=$q%
73
74REM --- Do the command line parsing ---
75
76DEF PROCparse(line$)
77LOCAL libfn$,stub$,lib$,off%,helped%,word$
78REPEAT
79 word$=FNword(line$)
80 CASE FNupper(word$) OF
81 WHEN "-HELP"
82 PROCshowHelp
83 helped%=TRUE
84 WHEN "-LIBFN"
85 libfn$=FNword(line$)
86 WHEN "-LIB"
87 lib$=FNword(line$)
88 WHEN "-STUB"
89 stub$=FNword(line$)
90 WHEN "-OFFSET"
91 off%=VAL(FNword(line$))
92 OTHERWISE
93 CASE TRUE OF
94 WHEN lib$=""
95 lib$=word$
96 WHEN stub$=""
97 stub$=word$
98 WHEN libfn$=""
99 libfn$=word$
100 WHEN off%=0
101 off%=VAL(word$)
102 ENDCASE
103 ENDCASE
104UNTIL line$=""
105IF helped% THEN END
106IF libfn$="" OR lib$="" OR stub$="" THEN ERROR 0,"Bad arguments"
107PROCbuild(lib$,stub$,libfn$,off%)
108ENDPROC
109
110DEF PROCbuild(lib$,stub$,libfn$,off%)
111
112REM --- Build library section ---
113
114zero=0
115
116PROCbas_aofInit(&1000)
117FOR o=4 TO 6 STEP 2
118[ opt o
119 FNpass
120
121 FNimportAs("Sapphire$$LibData$$Base","sapph_base")
122 FNimportAs("Sapphire$$LibData$$Limit","sapph_limit")
123
124 FNarea("!Stub$$Code","CODE,READONLY")
125
126 FNexportAs("stubfn",libfn$)
127.stubfn
128 adr r0,stubBlock
129 ldmia r0,{r0-2}
130 movs pc,r14
131
132.stubBlock
133 dcd sapph_base
134 dcd sapph_limit
135 dcd off%
136
137 FNexportAs("zero","sapphire_init")
138 FNexportAs("zero","sapphire_libInit")
139 FNexportAs("zero","sapphire_disable")
140]
141offDiff%=off%-4
142[ opt o
143 FNexportAs("offDiff%","__sph_workoff")
144]
145NEXT
146PROCbas_aofSaveAs(lib$)
147
148REM --- Build stub section ---
149
150PROCbas_aofInit(0)
151FOR o=4 TO 6 STEP 2
152[ opt o
153 FNpass
154
155 FNimportAs(libfn$,"stubfn")
156
157 FNarea("Sapphire$$ExtTable","CODE,READONLY")
158
159 dcd stubfn
160]
161NEXT
162PROCbas_aofSaveAs(stub$)
163
164ENDPROC