home *** CD-ROM | disk | FTP | other *** search
/ Amiga Computing 57 / ac057a.adf / Demos / ConvertFD.bas < prev    next >
BASIC Source File  |  1989-03-16  |  5KB  |  206 lines

  1. 'Program: ConvertFd - created Aug 9, 1985
  2. 'This program converts .fd files, like 'graphics_lib.fd' to
  3. ' .bmap format files, like 'graphics.bmap', so BASIC
  4. ' programs can access libraries of machine language routines
  5. ' by name via the LIBRARY statement.
  6. '
  7. ' Modified  01/86 by Carolyn Scheppner  CBM
  8. '   Prepends an x to all function names which
  9. '    conflict with AmigaBasic keywords.
  10. '    See data statements at end of program for
  11. '    known conflicts.  To call these functions,
  12. '    prepend an x  (example  xRead).
  13. '   Saves the .bmap file in current or specified
  14. '    directory (previously saved in LIBS:).
  15. '    For your program to access the .bmap via
  16. '    LIBRARY, it must be in the current dir
  17. '    or the LIBS: dir.
  18. '   The name of a .bmap file must match its
  19. '    library's name.  The libraryname is the
  20. '    part of the .fd file name before the _.
  21. '    (example   dos.bmap from dos_lib.fd)
  22. ' 27.1.89 AMP added CLI options
  23.  
  24. ' disable window, turn break checks on and error messages
  25. REM $OPTION y,b+,e+
  26.  
  27.   DEFINT a-Z    'by default, all variables ares integer
  28.  
  29.   REM ******** for conflicting tokens ********
  30.   READ cnt       'count of conflicting tokens
  31.   DIM con$(cnt)
  32.   FOR k = 0 TO cnt-1: READ con$(k): NEXT
  33.   REM ****************************************
  34.  
  35. IF SYSTAB THEN
  36.     POKEB SYSTAB+33,0    'disable icon files
  37.     IF PEEKL(SYSTAB+8) THEN
  38.         WINDOW 1,"ConvertFD",(0,0)-(640,100),31+256
  39.     END IF
  40. END IF
  41.  
  42. PRINT "ConvertFD for BASIC (compiled with HiSoft BASIC)"
  43.  
  44. IF LEN(COMMAND$) THEN
  45.     OPEN COMMAND$+"_lib.fd" FOR INPUT AS #1
  46.     OPEN "libs:"+COMMAND$+".bmap" FOR OUTPUT AS #2
  47.     PRINT "Converting ";COMMAND$
  48. ELSE
  49.     INPUT "Enter name of .fd file to read > ",fdFilename$
  50.     OPEN fdFilename$ FOR INPUT AS #1
  51.     INPUT "Enter name of .bmap file to produce > ",bmapFilename$
  52.      OPEN bmapFilename$ FOR OUTPUT AS #2
  53. END IF
  54.  
  55.   WHILE NOT EOF(1)
  56.     GetLine
  57.     IF char$ = "#" THEN
  58.       'lines which begin with "#" are command lines
  59.       GOSUB GotCommand
  60.     ELSEIF char$ = "*" THEN
  61.       'lines which begin with "*" are comment lines
  62.     ELSEIF char$ = CHR$(10) OR char$ = CHR$(13) THEN
  63.       'blank line
  64.     ELSE
  65.       'all other lines define a function in the library
  66.       GOSUB GotFunction
  67.     END IF
  68.   WEND
  69.   CLOSE
  70.   END
  71.  
  72. GotCommand:
  73.   GetChar  'skip 1st "#"
  74.   GetChar  'skip 2nd "#"
  75.   GetToken
  76.   IF token$ = "bias" THEN
  77.     GetNum
  78.     offset = -num
  79.   END IF
  80.  ram: RETURN
  81.  
  82. GotFunction:
  83.   GetToken  'token$=function's name
  84.  
  85.   REM **** prepend conflicting tokens with 'x' ****
  86.   k$ = token$
  87.   FOR k = 0 TO cnt-1
  88.      IF k$ = con$(k) THEN token$ = "x" + token$ 
  89.   NEXT   
  90.   REM **********************************************
  91.  
  92.   funcOffset=offset
  93.   offset=offset-6
  94.   parms$=""
  95.   SkipTill "(": IF char$="" THEN BadFileFormat
  96.   SkipTill ")": IF char$="" THEN BadFileFormat
  97.   GetChar
  98.   IF char$<>"" THEN
  99.     SkipTill "(": IF char$="" THEN BadFileFormat
  100.     WHILE char$ <> ")"
  101.       GetChar 'skip ( or , or /
  102.       IF char$<>")" THEN
  103.         GOSUB GetRegister
  104.         IF register=0 THEN BadFileFormat
  105.         IF register=-1 THEN
  106.           PRINT "Warning: Function ";token$;" not included because it"
  107.           PRINT " needs a parameter passed in a register BASIC cannot"
  108.           PRINT " conform to."
  109.           PRINT
  110.           RETURN
  111.         END IF
  112.         parms$ = parms$+CHR$(register)
  113.          'tells BASIC which register to put this parm into
  114.       END IF
  115.     WEND
  116.   END IF
  117.   AddEntry token$,funcOffset
  118.   PRINT #2,parms$;   'tells BASIC what registers to pass parms in
  119.   PRINT #2,CHR$(0);  'marks end of function entry
  120.   RETURN
  121.  
  122. BadFileFormat:
  123.   PRINT "Error: ";fdFilename$;" has a format error"
  124.   PRINT "In line:";lineNum;":";buf$
  125.   PRINT "In column:";column
  126.   CLOSE
  127.   STOP
  128.   
  129.  
  130. 'map {d0,d1,d2,d3,d4,d5,d6,d7,a0,a1,a2,a3,a4} to {1,..,13}
  131. GetRegister:
  132.   uchar$=UCASE$(char$)
  133.   IF uchar$="D" THEN
  134.     register=1
  135.   ELSEIF uchar$="A" THEN
  136.     register = 9
  137.   ELSE
  138.     register=0  'error
  139.     RETURN
  140.   END IF
  141.   GetChar  'skip a or d
  142.   i=ASC(char$)-48
  143.   IF i<0 OR i>7 THEN register=0: RETURN  'error
  144.   GetChar  'skip digit
  145.   register=register+i
  146.   IF register>13 THEN register=-1  'error
  147.   RETURN
  148.  
  149. SUB AddEntry(nam$, liboffset%) STATIC
  150.   highByte = PEEK(VARPTR(liboffset%))
  151.   lowByte = PEEK(VARPTR(liboffset%)+1)
  152.   PRINT #2,nam$; CHR$(0); CHR$(highByte); CHR$(lowByte);
  153.   END SUB
  154.  
  155. SUB GetLine STATIC
  156.   SHARED buf$,column,lineNum
  157.   LINE INPUT #1,buf$
  158.   column = 0
  159.   GetChar
  160.   lineNum = lineNum+1
  161.   END SUB
  162.  
  163. SUB GetNum STATIC
  164.   SHARED num,token$
  165.   GetToken
  166.   num = VAL(token$)
  167.   END SUB
  168.  
  169. SUB GetToken STATIC
  170.   SHARED buf$,char$,token$
  171.   SkipWhiteSpace
  172.   token$=""
  173.   uchar$=UCASE$(char$)
  174.   WHILE ((uchar$>="A") AND (uchar$<="Z")) OR ((uchar$>="0") AND (uchar$<="9")) OR (uchar$="-")
  175.     token$=token$+char$
  176.     GetChar
  177.     uchar$ = UCASE$(char$)
  178.   WEND
  179.   END SUB
  180.  
  181. SUB SkipTill(stopChar$) STATIC
  182.   SHARED char$
  183.   WHILE (char$ <> stopChar$) AND (char$ <> "")
  184.     GetChar
  185.   WEND
  186.   END SUB
  187.  
  188. SUB SkipWhiteSpace STATIC
  189.   SHARED char$
  190.   WHILE (char$=" ") OR (char$=CHR$(9))
  191.     GetChar
  192.   WEND
  193.   END SUB
  194.  
  195. SUB GetChar STATIC
  196.   SHARED column,char$,buf$
  197.   column = column + 1
  198.   char$ = MID$(buf$,column,1)
  199.   END SUB
  200.        
  201. REM **** conficting token count and tokens ****                
  202. DATA 11                
  203. DATA abs, Close, Exit, Input, Open, Output
  204. DATA Read, tan, Translate, Wait, Write
  205.  
  206.