Using Config from Compiled SuperBASIC

It is often desirable or necessary to configure certain working parameters within a program. The Qjump Config "standard configuration system" is a good way of achieving this. The documentation and a program to configure programs containing Config level 1 configuration blocks may be found in the QUANTA library (disk SP0 the "Tebby Files"). A utility written by O. Fink, to include Config blocks in compiled SuperBASIC programs may be found on SP4. The method proposed here though, takes a different approach and is perhaps more appropriate in small programs.

A Config block consists of data and pointers (see below). The only problem is getting it in a suitable form into your program.

You can put anything into a SuperBASIC literal string so long as you don't violate the rules of the interpreter. Unfortunately, in the following implementation we do actually require the interpreter to produce two SuperBASIC lines that might look like this:

11 Config$="<<QCFX>>01##MyProg##V1.00 #H################Home directory#*##win1_progs_                               "
13 Config$=Config$(63 TO 62+CODE(Config$(62)))
  

Obviously the above is gobbeldygook to you and me, but as long as the configuration program understands it, so long as SuperBASIC doesn't care, and so long as it does the job, it will do.

Below follows a no-frills, compacted program in SuperBASIC (although it may not look like it!) that will produce the necessary Config block to your requirements. It takes care of avoiding awkward values (see Limitations below) and leaves you with nothing else to do but MERGE its output into your application and compile.

MkConfig

100 rem                 MakeConfig_bas ©PWITTE April 24th 1995
110 rem             Make a simple config block of type Qjump level 01
120 rem              for inclusion in a compiled SuperBASIC program
130 :
140 rem The following is the data that is produced:
150 rem       dc.b '<<QCFX>>01'                     ;Config header
160 rem       dc.w pl%,progname$                    ;Name of program
170 rem       dc.w vl%,version$                     ;Program version
180 rem       dc.b 0,key$                           ;Selection key for this item
190 rem       dc.w string-*                         ;Relative offset to item
200 rem       dc.w 0                                ;Ptr to pre- and post
210 rem       dc.w 0                                ; processing routines
220 rem       dc.w description-*                    ;Point to description
230 rem       dc.w attr-*                           ;Point to attributes
240 rem       dc.w -1                               ;End marker
250 rem attribute                                   ;Only one attribute here:
260 rem       dc.w attr%                            ; if 0 strip trailing spaces
270 rem description
280 rem       dc.w dl%,description$
290 rem string
300 rem       dc.w max%                             ;Max allowable length (incl lf)
310 rem       dc.w sl%,dstring$ + spare room        ; plus room up to max length
320 :
330 estrg$='Avoid string lengths of 10,34 and above 64'
340 zw$=CHR$(0)&CHR$(0):e$=CHR$(255)&CHR$(255)     :rem Word constants: 0,-1
350 n$='ram1_cfg_bas':CLS:INPUT'Output to (eg '&n$&')'!fnm$:IF fnm$='':fnm$=n$
360 PRINT \estrg$\'Enter:'                         :rem Get user settings
370 progname$=GetStrg$('the name of your program, eg Myprog')
380 version$=GetStrg$('version number, eg V1.04')
390 description$=GetStrg$('description of item to configure')
400 dstring$=GetStrg$('the default item string')
410 REPeat loop
420  INPUT'max allowable length of item string'!max%
430  IF max%<LEN(dstring$)-1:max%=LEN(dstring$)-1:PRINT'Adjusted to'!max%
440  IF max%<>10 AND max%<>34 AND max%<65:EXIT loop
450  PRINT estrg$
460 END REPeat loop
470 PRINT\'Press the selection key for this item ';:k%=CODE(INKEY$(-1))
480 IF k%>96 AND k%<123:k%=k%-32:END IF :key$=CHR$(k%):PRINT key$
490 PRINT'Are trailing spaces to be stripped? <Y/n> ';:at$=INKEY$(-1)
500 IF at$ INSTR 'y'&CHR$(10):attr%=0:PRINT'Y':ELSE :attr%=1:PRINT'N'
510 oa%=4 : od%=8 : os%=14+LEN(description$)       :rem Calculate offsets
520 line$='11 Config$="<<QCFX>>01'                 :rem Build config block string:
530 line$=line$&progname$&version$                 :rem  as shown in
540 line$=line$&CHR$(0)&key$                       :rem  assembler above
550 line$=line$&Int$(os%+2*(os%=34))               :rem Work around awkward value
560 line$=line$&zw$&zw$&Int$(od%)&Int$(oa%)&e$
570 line$=line$&Int$(attr%)&description$
580 IF os%=34:line$=line$&zw$                      :rem Workaround filler bytes
590 line$=line$&Int$(max%):ip%=LEN(line$)-10       :rem Position of config item
600 line$=line$&dstring$                           :rem The default string
610 line$=line$&FILL$(" ",max%-LEN(dstring$)+2)    :rem Room for max string + lf
620 line$=line$&'"'                                :rem End of SuperBASIC string
630 OPEN_NEW#3;fnm$:PRINT#3;line$                  :rem Write config block
640 PRINT#3;'13 Config$=Config$(';ip%+1!'to'!ip%;'+code(Config$(';ip%;')))'
650 CLOSE                                          :rem Line 13 is to find the
660 :                                              :rem  string within the program
670 DEFine FuNction GetStrg$(tx$)
680 LOCal l%,s$,loop
690 REPeat loop
700  INPUT (tx$)!s$:l%=LEN(s$)
710  IF l%<>34 AND l%<>10 AND l%<65:EXIT loop      :rem Mustn't have quotes &
720  PRINT estrg$                                  :rem  linefeeds in a SB string!
730 END REPeat loop
740 RETurn Int$(l%)&s$&FILL$(' ',l% MOD 2)         :rem Convert to internal format
750 END DEFine                                     :rem  padding odd lengthed strgs
760 :                                              :rem Integer to internal format
770 DEFine FuNction Int$(i%):RETurn CHR$(i% DIV 256)&CHR$(i% MOD 256):END DEFine
780 :
  
Generated with sb2htm on 2019 Apr 28
©pjwitte March 2oi9

If you wish to test-configure the string in uncompiled BASIC make sure the string <<QCFX>> starts at an even character position! Counting starts at zero.

Limitations:
S*BASIC interpreter: Config V1.04: Qlib V3.35:
No quotes or line feeds (chr's 34 and 10) must be used, nor anything that computes to those values, eg line lengths or offsets Descriptions must be less than 64 chr's/line. (No sweat, see no.1) Literal strings are truncated (without warning!) to 512 characters