home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug001.arc / C.HLP < prev    next >
Text File  |  1979-12-31  |  17KB  |  489 lines

  1. Invoking BDS C using C.SUB
  2. Overview of the BDS C Language System
  3. Overview -- C Compiler, Pass 1
  4. Overview -- C Compiler, Pass 2
  5. Overview -- C Linker
  6. Overview -- C Librarian
  7. Overview -- C Skeleton File
  8. Variable Types
  9. Braces
  10. Variable Accessing
  11. ARIES-1 C Library
  12. Special I/O using CIO
  13. :Invoking BDS C using C.SUB
  14.  
  15.      BD╙á ├á ma∙á bσ invokinτ eithe≥ b∙ thσ conventiona∞ mean≤á o≥á b∙ ì
  16. usinτá thσá SUBMI╘ filσ C.SUB«á  Iµ thσ SUBMI╘ filσá i≤á used¼á i⌠á i≤ ì
  17. engaged as follows --
  18.  
  19.           SUBMIT C filename
  20.  
  21. wherσá 'filenameºá i≤ thσ namσ oµ 'filename.C'¼á thσ filσ t∩á compile«  ì
  22. Notσ tha⌠ thσ use≥ i≤ NO╘ t∩ t∩ typσ filename.C¼á bu⌠ i≤ jus⌠ t∩á typσ ì
  23. filename.
  24.  
  25.      A≤á executioεá oµ thσ tw∩ passe≤ oµ thσ compile≥ anΣá thσá linke≥ ì
  26. proceeds¼á thσá use≥á wil∞ bσ giveε thσ chancσ t∩ abor⌠ processinτá a⌠ ì
  27. variou≤á critica∞á point≤á iεá thσ proces≤ b∙á thσá executioεá oµá thσ ì
  28. ABORTSU┬á program«á  Iµá aεá erro≥ ha≤ occurreΣá durinτá thσá previou≤ ì
  29. processing, ABORT when this program is executed.
  30.  
  31.  
  32. :Overview of the BDS C Language System
  33.  
  34.     The main components of C are: 4 executable programs,
  35. a standard library file, and one skeleton run-time subroutine
  36. file.
  37.  
  38. A description of each follows:
  39. :Overview -- C Compiler, Pass 1
  40.  
  41. CC1:    Because C loads the entire source file into memory
  42.     in one shot, the compilation is broken up into two
  43.     phases (not "passes", strictly; The two phases end
  44.     up taking about 8 passes to actually implement),
  45.     maximizing the amount of memory available for the
  46.     source file.
  47.     CC1, the first half of the compiler, accepts a C
  48.     source file with any filename and extension (say,
  49.     "foo.c") and writes out a temporary file (with the
  50.     same filename and extension ".CCI") containg a symbol
  51.     table and an encoded form of the source code.
  52.  
  53.     The file extension ".C" is NOT assumed for the
  54.     input file, so saying "FOO" for "FOO.C" would not
  55.     work.è
  56.  
  57.     If the source file name is preceded by a disk
  58.     designation, then the input is taken from the specified
  59.     disk and the ouput is also written to that disk.
  60.  
  61.     If any errors are detected during CC1, the output
  62.     file will not be written.
  63.  
  64.     In addition to the name of the source file, a few
  65.     options may also be specified on the command line
  66.     by preceding the option list with a dash (-):
  67.  
  68.     s     causes undeclared identifiers to be implicitly
  69.             declared as integer variables, wherever possible.
  70.  
  71.     hex digit (4-f)  sets symbol table size to the 
  72.              specified value (in K bytes);
  73.              default is 8 (5 for versions x.xT.)
  74.     
  75.  
  76.     For example,
  77.         A>cc1 foobar.c -s6
  78.     supresses errors for undefined variables and sets 
  79.     symbol table size to 6K bytes;
  80.         A>cc1 zot.c -e
  81.     sets symbol table size to 14K bytes.
  82.     Note that the option list must contain no blanks.
  83.         A>cc1 b:td.c
  84.     takes the source file from disk B and writes the .CCI
  85.     file to disk B (regardless of what the currently logged
  86.     disk is.)
  87.  
  88.     On an 8080, speed is about 12 lines source/sec.
  89.  
  90. :Overview -- C Compiler, Pass 2
  91.  
  92. CC2:    This is the second half of the compiler. CC2 accepts
  93.     a ".CCI" file as input, and writes out a ".CRL" file
  94.     if no errors are detected. (CRL is mnemonic for
  95.     'C ReLocatable')
  96.  
  97.     If all goes well, writing out of the CRL file is
  98.     followed by deletion of the "CCI" file, and 
  99.     compilation is complete.
  100.  
  101.     As for CC1, if a disk is specified explicitly as in
  102.         A>cc2 c:yahoo
  103.     then the .CCI file is loaded from the specified disk
  104.     and the .CRL file is written to that same disk.
  105.  
  106.     On an 8080, execution time =  about 35 lines/sec.
  107.  
  108. :Overview -- C Linker
  109.  
  110. CLINK:    This program links a "main" function from some
  111.     CRL file together with C.CCC (for common system
  112.     subroutines) and any subordinate functions which
  113.     "main" may require (from perhaps many CRL files).
  114.  
  115.     A successful linkage causes a ".COM" file to be
  116.     generated. At this point, the 8080 absolute
  117.     machine code file is ready to be executed (for
  118.     better or worse) as a transient command by CP/M.
  119.  
  120.     The first argument on the command line must be the
  121.     name of a CRL file containing a "main" function. If
  122.     the name is specified with an extension, then that
  123.     extension is interpreted specially as indicating
  124.     which disks are to be involved in the operation (this
  125.     is akin to the mechanism ASM uses to determine source
  126.     and destination disks.)
  127.  
  128.     For example, if the first argument to CLINK were
  129.     given as:
  130.         A>clink foo.bc
  131.     then CLINK would interpret the "b" in ".bc" as 
  132.     specifying the disk on which "DEFF.CRL" and "C.CCC" are
  133.     to be found, and the "c" in ".bc" as specifying which
  134.     disk the .COM file is to be written to. Both of these
  135.     values, if omitted, default to the currently logged in
  136.     disk.
  137.     The first argument may also be preceded by a disk
  138.     designation, to specify where all .CRL files are to be
  139.     searched for (by default). For example, the command
  140.         A>clink b:zot.ac
  141.     tells CLINK to get C.CCC and DEFF.CRL from disk A; to
  142.     write the ouput file to disk C; and to find ZOT.CRL on
  143.     disk B.
  144.  
  145.  
  146.     Any other CRL files to search may also be specified
  147.     on the command line (WITHOUT their .CRL suffixes),
  148.     causing those to be searched in the order specified.
  149.     The default disk to search will be the same disk from
  150.     which the original CRL file was taken; this default
  151.     can be overridden by specifying an explicit disk
  152.     designation for any appropriate CRL file name needing
  153.     it. For example,
  154.         A>clink c:foo.bb bar a:zot fraz
  155.     causes disk C to be searched for the files FOO.CRL,
  156.     BAR.CRL and FRAZ.CRL, while disk A would be searched
  157.     to find ZOT.CRL. Disk B is where CLINK would expect
  158.     DEFF.CRL and C.CCC to reside, and the output would go
  159.     to disk B also.
  160.  
  161.  
  162.     When all given CRL files have been searched, CLINK
  163.     will automatically search DEFF.CRL.
  164.  
  165.     If there are still some unresolved references, then
  166.     CLINK will ask for input from the keyboard to try
  167.     resolving them.
  168.  
  169.     There are also several options which may be
  170.     specified on the command line. Each option must
  171.     be preceded by a dash (-); the space between
  172.     options and their argument (if needed) is optional.
  173.     The presently supported options are:
  174.  
  175.     -s        Prints out load statistics;
  176.     -t nnnn        Reserves location nnnn (hex) and
  177.             above for user; default is to 
  178.             reserve no space. What this really
  179.             does is to cause the first op in
  180.             the object file to be
  181.                 lxi sp,nnnn
  182.             instead of
  183.                 lxi sp,bdos.
  184.     -o name        Causes the .COM file generated to
  185.             have the given name. Default is 
  186.             the name of the first .CRL file
  187.             given (the one with the "main"
  188.             function.)
  189.  
  190.     -e xxxx        Sets start of data area to address
  191.             xxxx, to maintain consistency between
  192.             several separate .COM files when
  193.             chaining (via the library function
  194.             "exec") is used.
  195.     -c        Specifies that the .COM file is to
  196.             be chained to from another .COM file.
  197.             If the resultant .COM file is invoked
  198.             directly from CP/M instead of via the
  199.             "exec" function, then ARGC & ARGV
  200.             processing is suspended, since upon
  201.             being chained to you wouldn't want
  202.             ARGC & ARGV processing to take place.
  203.                 Note that if you use this
  204.             option, you should also use the -e
  205.             option to set the data area address
  206.             equal to that of the chaining .COM
  207.             file.
  208.     
  209.  
  210.  
  211.     Examples:
  212.         A>clink foo bar
  213.     gets "main" from the file FOO.CRL, searches for
  214.     needed functions first in FOO.CRL and then, if needed,
  215.     in BAR.CRL and DEFF.CRL. All files are assumed to 
  216.     reside on the currently logged in disk.
  217.  
  218.         A>clink b:ihtfp belle -s
  219.     searches for IHTFP.CRL and BELLE.CRL on disk B; prints
  220.     a statistics summary when linkage is complete. The 
  221.     files DEFF.CRL and C.CCC are assumed to reside on the
  222.     currently logged in disk; output also goes to the
  223.     currently logged in disk.
  224.  
  225.         A>clink b:ihtfp.aa -s belle -o zot
  226.     is the same as the last example except: the output
  227.     file is called ZOT.COM, DEFF.CRL and C.CCC are assumed
  228.     to reside on A, and output goes to A.
  229.  
  230.  
  231.         A>clink stoned -t7000 -s
  232.     sets top of memory to 7000h and prints out load
  233.     statistics. Current disk used for everything.
  234.  
  235.     Note that if the load statistics tell you that
  236.     the "LAST ADDRESS" is greater than the "TOP OF
  237.     MEMORY", the program hasn't got the chance of a
  238.     snowball in hell of running correctly.
  239.  
  240. :Oveview -- C Librarian
  241.  
  242. CLIB:    This program maintains .CRL files, allows transfer
  243.     of functions from one CRL file to another, etc. To
  244.     invoke CLIB, just type 
  245.             A>clib
  246.     Clib will print a line such as
  247.         FUNCTION BUFFER SIZE = nnnnn
  248.     specifying the largest function size that can be
  249.     handled. Attempting to "transfer" or "extract" a 
  250.     function larger than this size could be destructive.
  251.  
  252.     Next CLIB will prompt with a "*". Typing "h" at 
  253.     this point will give you a command summary.
  254.  
  255.     Basically, you work CLIB by opening one to six
  256.     CRL files (which then become associated with    
  257.     "file numbers"), diddling the files to your hearts
  258.     content, closing all files which you altered, and
  259.     typing control-C.
  260.  
  261.  
  262.     The old version of any CRL file you change with CLIB
  263.     is renamed to name.BRL (for Backup ReLative).
  264.  
  265.     A sample session of CLIB to, say, transfer the 
  266.     functions named "FOO", "BAR", and "ZOT" from
  267.     a .CRL file named "DSSR" to one named "RTS" would
  268.     go as follows:
  269.  
  270.  
  271.     A>clib
  272.  
  273.     BD SOFTWARE C LIBRARIAN VERSION x.x
  274.     FUNCTION BUFFER SIZE = xxxx BYTES
  275.  
  276.     * open 0 dssr
  277.     * open 1 rts
  278.     * t 0 1 foo
  279.     * t 0 1 bar
  280.     * t 0 1 zot
  281.     * c 1
  282.     * ^C
  283.  
  284.     A> ...
  285.  
  286.  
  287.     The "open" commands prepare to do work on a .CRL file,
  288.     and associate each .CRL file opened with a digit (0-5).
  289.     The "transfer" commands tell CLIB to transfer the
  290.     named function from the first file (named by file #)
  291.     to the second file (also named by number).
  292.     The "close" command need only be given for files
  293.     which have been altered; since DSSR wasn't written
  294.     to in the above example, it didn't need to be closed,
  295.     but RTS did need to be closed.
  296.  
  297.  
  298. DEFF.CRL:  This file contains the standard function library...
  299.        all 60+ functions worth. See the BDS C User's Guide
  300.        for documentation on these functions.
  301. :Overview -- C Skeleton File
  302.  
  303. C.CCC:    The run-time skeleton file, containing code for
  304.     processing the command line (generating argc and
  305.     argv, for you UNIX lovers), room for file I/O
  306.     buffers, some math subroutines, etc.
  307.  
  308.  
  309.  
  310.     Note on the BDS C compiler:
  311.  
  312.     THIS IS NOT AN INTERPRETER.
  313.  
  314.     Some hacks, such as BASIC-E, are billed as compilers
  315.     but actually just do some preprocessing and then
  316.     interpret the program. BDS C is a true compiler,
  317.     generating not-too-optimal but nevertheless quick
  318.     8080 code.
  319.  
  320.     For the gory details on the BDS C implementation, see
  321.     my notes to APPENDIX A of the EXCELLENT book  
  322.         "The C Programming Language."
  323.  
  324. :Variable Types
  325.  
  326.     Variable types supported:
  327.     int     char    unsigned    struct    union
  328.     arrays (of one or two dimensions)
  329.     pointers
  330.     simple combinations of the above
  331.  
  332.     For example,
  333.             char *foo[10][15];
  334.     declares foo to be a two dimensional array of
  335.     pointers to characters;
  336.  
  337.             char (*foo)();
  338.     declares foo to be a pointer to a function returning
  339.     a character;
  340.  
  341.             char *foo, bar, zot[10];
  342.     declares foo to be a pointer to characters, bar to
  343.     be a single char variable, ant zot to be an array
  344.     of 10 characters.
  345.  
  346. :Braces
  347.  
  348.     If your keyboard doesn't support the '{' and '}'
  349.     characters (open and close brace, for those of
  350.     you whose printer doesn't know about ascii 7B and
  351.     7D), the symbols 'begin' and 'end' may be 
  352.     substituted. Don't unless you have to; '{' and '}'
  353.     take up less memory.
  354.     The CONVERT program will perform this conversion,
  355.     if necessary.
  356.  
  357. :Variable Accessing
  358.  
  359.     Since all functions in C may be used recursively, all
  360.     variable accessing is done relative to a base-of-
  361.     stack-frame pointer, kept in the BC register pair
  362.     during execution. Note that it takes 8 bytes of code
  363.     to transfer a simple local variable whose address isè        (Base of stack pointer) + foo
  364.     to the HL register pair; The code appears as:
  365.  
  366.         lxi h,foo
  367.         dad b
  368.         mov a,m
  369.         inx h
  370.         mov h,m
  371.         mov m,a .
  372.     To get an array element or structure element is even
  373.     more hairy. Facts like this are enough to make me 
  374.     REALLY wish Intel had bothered to implement a double
  375.     byte indirect load instruction. Oh well.
  376.  
  377. :ARIES-1 C Library
  378.  
  379.      Thσá followinτá arσ thσ name≤ oµ thσ routine≤ availablσ iε thσá ├ ì
  380. Librar∙ DEFF.CRL«á  The∙ arσ listeΣ herσ a≤ ß memor∙ convenience¼á anΣ ì
  381. refer to the manual for further details.
  382.  
  383. 1.  General Purpose Functions
  384.  
  385.      csw()          exit()         bdos(c,de)          peek(n)
  386.      poke(n,b)      inp(n)         outp(n,b)           pause()
  387.      sleep(n)       call(adr,h,a,b,d)                  abs(n)
  388.      srand(n)       rand()         setmem(adr,count,byte)
  389.      movmem(source,dest,count)     qsort(base,nel,width,compar)
  390.        char *source, *dest;          char *base; int(*compar)();
  391.      exec(name)
  392.        char *name;
  393.  
  394. 2.  Character Input/Output
  395.  
  396.      getchar()      ungetch(c)     kbhit()             putchar(c)
  397.      puts(str)      char *gets(str)
  398.        char *str;     char *str;
  399.      printf(format,arg1,arg2,...)  scanf(format,arg1,arg2,...)
  400.        char *format;                 char *format;
  401.  
  402. 3.  String and Character Processing
  403.  
  404.      isalpha(c)     isupper(c)     islower(c)     isdigit(c)
  405.        char c;        char c;        char c;        char c;
  406.      touppper(c)    tolower(c)     isspace(c)     strcat(s1,s2)
  407.        char c;        char c;        char c;        char *s1, *s2;
  408.      strcmp(s1,s2)  strcpy(s1,s2)  strlen(str)    atoi(str)
  409.       char *s1,*s2;  char *s1,*s2;  char *str;     char *str;
  410.      initw(array,string)           initb(array,string)
  411.        int *array; char *string;     char *array, *string;
  412.      getval(strptr)
  413.        char **strptr;
  414.  
  415. 4.  File I/O
  416.  
  417.      creat(filename)               unlink(filename)
  418.        char *filename;               char *filename;
  419.      open(filename,mode)           close(fd)
  420.        char *filename;
  421.        {mode=0 - input, mode=1 - output, mode=2 - input and output}
  422.      read(fd,buf,nbl)              write(fd,buf,nbl)
  423.        char *buf;                    char *buf;
  424.      seek(fd,offset,code)          tell(fd)
  425.      fopen(filename,iobuf)         fcreat(filename,iobuf)
  426.        char *filename;               char *filename;
  427.        struct buf *iobuf;            struct buf *iobuf;
  428.      getc(iobuf)                   putc(c,iobuf)
  429.        struct buf *iobuf;            char c; struct buf *iobuf;
  430.      getw(iobuf)                   putw(w,iobuf)
  431.        struct buf *iobuf;            struct buf *iobuf;
  432.      fflush(iobuf)
  433.        struct buf *iobuf;
  434.  
  435. 5.  Plotting Functions (for Memory-Mapped Video Boards)
  436.  
  437.      setplot(base,xsize,ysize)
  438.      clrplot()
  439.      plot(x,y,chr)
  440.        char chr;
  441.      txtplot(string,x,y,ropt)
  442.        char *string;
  443.      line(c,x1,y1,x2,y2)
  444.  
  445. 6.  Plotting Functions for Hazeltine 1500
  446.  
  447.      clear()
  448.      cplot(x,y,chr)
  449.        char chr;
  450.      ctxtplot(x,y,string)
  451.        char *string;
  452.  
  453. 7.  Special I/O -- CIO
  454.  
  455.      cio(fn) or cio(fn,arg)
  456.  
  457.           CI╧ indexe≤ directl∙ int∩ thσ BIO╙ Jum≡ Table«á  'fnº i≤ thσ ì
  458. inde° offset¼á anΣ 'argº i≤ aε argumen⌠ passeΣ (u≡ t∩ 1╢á bits)«á  Thσ ì
  459. offsets and functions permitted are --
  460.  
  461.      Offset    Function
  462.  
  463.        ░       CONS╘ -- Consolσ status╗á ReturneΣ valuσ ╜ ░ iµ n∩ cha≥ ì
  464.                  ready, 255 if char ready
  465.        1       CONIN -- Console input; Returned value = char typed
  466.        2       CONOUT -- Console output; Input value = char to output
  467.        3       LIST -- List output; Input value = char to output
  468.        4       PUNCH -- Punch output; Input value = char to output
  469.        5       READER -- Reader input; Returned value = char input
  470. :Special I/O using CIO
  471.  
  472.      CIO is called by --
  473.  
  474.                cio(fn) or cio(fn,arg)
  475.  
  476.      CI╧ indexe≤ directl∙ int∩ thσ BIO╙ Jum≡ Table«  'fnº i≤ thσ inde° ì
  477. offset¼á anΣ 'argº i≤ aε argumen⌠ passeΣ (u≡ t∩ 1╢ bits)«  Thσ offset≤ ì
  478. anΣ function≤ permitteΣ arσ --
  479.  
  480.      Offset    Function
  481.  
  482.        ░       CONS╘ -- Consolσ status╗á ReturneΣ valuσ ╜ ░ iµ n∩ cha≥ ì
  483.                  ready, 255 if char ready
  484.        1       CONIN -- Console input; Returned value = char typed
  485.        2       CONOUT -- Console output; Input value = char to output
  486.        3       LIST -- List output; Input value = char to output
  487.        4       PUNCH -- Punch output; Input value = char to output
  488.        5       READER -- Reader input; Returned value = char input
  489.