Create readable text `.bas' for each tokenized BASIC `,ffb' file.
[ssr] / StraySrc / Utilities / b / buildstub.bas
diff --git a/StraySrc/Utilities/b/buildstub.bas b/StraySrc/Utilities/b/buildstub.bas
new file mode 100644 (file)
index 0000000..3cf476c
--- /dev/null
@@ -0,0 +1,164 @@
+REM
+REM SapphStub
+REM
+REM Build Sapphire extension stub entries
+REM
+REM © 1994-1998 Straylight
+REM
+
+REM ----- Licensing note ----------------------------------------------------
+REM
+REM This file is part of Straylight's core utilities (coreutils)
+REM
+REM Coreutils is free software; you can redistribute it and/or modify
+REM it under the terms of the GNU General Public License as published by
+REM the Free Software Foundation; either version 2, or (at your option)
+REM any later version
+REM
+REM Coreutils is distributed in the hope that it will be useful,
+REM but WITHOUT ANY WARRANTY; without even the implied warranty of
+REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+REM GNU General Public License for more details.
+REM
+REM You should have received a copy of the GNU General Public License
+REM along with Coreutils.  If not, write to the Free Software Foundation,
+REM 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+REM --- Parse arguments ---
+
+ON ERROR ERROR EXT 0,REPORT$+"["+STR$(ERL)+"]"
+PROCinit
+PROCparse(FNreadCommandLine)
+END
+
+DEF PROCinit
+DIM q% 256
+LIBRARY "libs:bas"
+PROCbas_init
+ENDPROC
+
+REM --- Read a command line ---
+
+DEF FNreadCommandLine
+LOCAL comm$
+SYS "OS_GetEnv" TO comm$
+IF INSTR(comm$,"-quit")=0 THEN ERROR 1,"SapphStub must be started using *Run"
+comm$=MID$(comm$,INSTR(comm$,"""")+1)
+comm$=MID$(comm$,INSTR(comm$," ")+1)
+comm$=LEFT$(comm$,INSTR(comm$,"""")-1)
+=comm$
+
+REM --- Remove a word from a command line ---
+
+DEF FNword(RETURN line$)
+LOCAL word$
+IF INSTR(line$," ") THEN
+  word$=LEFT$(line$,INSTR(line$," ")-1)
+  line$=MID$(line$,INSTR(line$," ")+1)
+ELSE
+  word$=line$
+  line$=""
+ENDIF
+=word$
+
+REM --- Convert a string to upper case ---
+
+DEF FNupper(line$)
+LOCAL i%
+$q%=line$
+FOR i%=0 TO LEN(line$)-1
+  IF q%?i%>=97 AND q%?i%<=122 THEN q%?i%-=32
+NEXT
+=$q%
+
+REM --- Do the command line parsing ---
+
+DEF PROCparse(line$)
+LOCAL libfn$,stub$,lib$,off%,helped%,word$
+REPEAT
+  word$=FNword(line$)
+  CASE FNupper(word$) OF
+    WHEN "-HELP"
+      PROCshowHelp
+      helped%=TRUE
+    WHEN "-LIBFN"
+      libfn$=FNword(line$)
+    WHEN "-LIB"
+      lib$=FNword(line$)
+    WHEN "-STUB"
+      stub$=FNword(line$)
+    WHEN "-OFFSET"
+      off%=VAL(FNword(line$))
+    OTHERWISE
+      CASE TRUE OF
+        WHEN lib$=""
+          lib$=word$
+        WHEN stub$=""
+          stub$=word$
+        WHEN libfn$=""
+          libfn$=word$
+        WHEN off%=0
+          off%=VAL(word$)
+      ENDCASE
+  ENDCASE
+UNTIL line$=""
+IF helped% THEN END
+IF libfn$="" OR lib$="" OR stub$="" THEN ERROR 0,"Bad arguments"
+PROCbuild(lib$,stub$,libfn$,off%)
+ENDPROC
+
+DEF PROCbuild(lib$,stub$,libfn$,off%)
+
+REM --- Build library section ---
+
+zero=0
+
+PROCbas_aofInit(&1000)
+FOR o=4 TO 6 STEP 2
+[ opt o
+  FNpass
+
+  FNimportAs("Sapphire$$LibData$$Base","sapph_base")
+  FNimportAs("Sapphire$$LibData$$Limit","sapph_limit")
+
+  FNarea("!Stub$$Code","CODE,READONLY")
+
+  FNexportAs("stubfn",libfn$)
+.stubfn
+  adr r0,stubBlock
+  ldmia r0,{r0-2}
+  movs pc,r14
+
+.stubBlock
+  dcd sapph_base
+  dcd sapph_limit
+  dcd off%
+
+  FNexportAs("zero","sapphire_init")
+  FNexportAs("zero","sapphire_libInit")
+  FNexportAs("zero","sapphire_disable")
+]
+offDiff%=off%-4
+[ opt o
+  FNexportAs("offDiff%","__sph_workoff")
+]
+NEXT
+PROCbas_aofSaveAs(lib$)
+
+REM --- Build stub section ---
+
+PROCbas_aofInit(0)
+FOR o=4 TO 6 STEP 2
+[ opt o
+  FNpass
+
+  FNimportAs(libfn$,"stubfn")
+
+  FNarea("Sapphire$$ExtTable","CODE,READONLY")
+
+  dcd stubfn
+]
+NEXT
+PROCbas_aofSaveAs(stub$)
+
+ENDPROC