home *** CD-ROM | disk | FTP | other *** search
/ 64'er / 64ER_CD.iso / utilpc / cc64 / cc64.doc < prev    next >
Text File  |  1994-10-06  |  12KB  |  241 lines

  1.  
  2. About cc64
  3. ----------
  4. cc64 is a small C compiler for the C-64. The current version V0.3 is
  5. still in beta test stage. The same applies to the text editor peddi,
  6. version 0.1.
  7. cc64 and peddi may be freely copied, providing that this documentation
  8. is passed along as well.
  9. cc64 and peddi both come with ABSOLUTELY NO WARRANTY. I will take no
  10. responsibility for any damage resulting in any way from the use of
  11. cc64 or peddi.
  12.  
  13. What is there
  14. -------------
  15. cc64 comes as three programs:
  16. peddi0.1 -- a small text editor
  17. cc64v0,3 -- the compiler
  18. cc64v0.3pe -- compiler and editor together in one program
  19. They're all written in FORTH and compiled around a 60 blocks long
  20. FORTH kernel. Then there is
  21. c-charset -- load it ,8,1 and activate it with SYS52027. It will patch
  22. a few ASCII characters such as braces and backslash into the 64's
  23. charset. It will be re-activated each time peddi or cc64v0.3pe is started.
  24. bl02.x -- The base library, assembler source, object code, static
  25. variable initialization and header file. See library description below.
  26. io.c/o/i/h -- an extended library giving access to the 64's basic i/o
  27. calls. On the distribution disk it is present compiled with an
  28. out-of-date base library. Change the #include statement at the
  29. beginning into #include <bl02.h> and recompile it before use.
  30. t3.c -- a little test program. Will not compile properly because of
  31. the static variable i declared in the beginning. Just remove that
  32. declaration and it should compile correctly and run "hello, world".
  33.  
  34. How to use it
  35. -------------
  36. As said, cc64 and peddi are written in FORTH. After starting them
  37. You'll get an OK prompt, and HELP will list You the availible commands.
  38. Some commands require numeric parameters; those must be entered _before_
  39. the command. We're FORTH, so we're RPN (reversed polish notation). The
  40. commands are:
  41. help      -- list all commands
  42. cc file.c -- start the compiler for the program file.c
  43. ed file   -- edit file
  44. cat file  -- type the contents of file on the screen
  45. dos       -- read and print the floppy's error channel
  46. dos xxx   -- send the command xxx to the floppy
  47. dir       -- list the directory
  48. mem       -- show the compiler's memory setup
  49. xxx set-himem -- set the limit of the compiler's memory to xxx. Don't
  50.           change this to a value greater than $cbd0 if You want to use
  51.           c-charset. xxx may be a decimal number or a hex number,
  52.           preceeded by a $
  53. xxx set-heap -- sets the heap to xxx links. For each function in a C
  54.           program that is used before it is defined (a prototype must
  55.           exist before the first call) one link is needed.
  56. xxx set-hash -- sets the hash table size for global symbols. Needs at
  57.           least one element per global symbol in a C program. Should
  58.           be sized a bit generous otherwise hashing will be inefficient.
  59. xxx set-symtab -- sets the symbol table size (used both for local and
  60.           global symbols). Must be increased if You run into a Symbol
  61.           table overflow error.
  62. xxx set-code -- sets the size of the code buffer. The code for any C
  63.           function being compiled must fit into this buffer. Otherwise
  64.           You get a function too long error. Then increase the code
  65.           buffer size or split the long function up in two or more.
  66. The size of the static buffer is determined by the remaining memory.
  67. This size is not critical. It should be positive, though. :)
  68. xxx yyy set-stacks -- sets the size of data and return stack and
  69.           resets the system. The stacks'size determine the maximum
  70.           depth of arithmetic expressions and the maximum number of
  71.           nested compound statements the compiler can handle. Stack
  72.           overflows are checked; I hope those checks are reliable.
  73.           If the compiler should behave strangely on a complicated
  74.           (i.e. deeply nested) expression RELOAD IT FROM DISK and set
  75.           the stack sizes to higher values.
  76. saveall name -- saves the complete compiler together with its actual
  77.           memory settings.
  78. bye       -- leave to basic
  79.  
  80. Peddi - how to use
  81. ------------------
  82. Peddi is a small full screen, scrolling PETSCII editor. No limit in line
  83. length (exept memory). Memory overflow is signalled by a double flash
  84. of the screen border.
  85. You call peddi with
  86.  ed filename
  87. The peddi key bindings:
  88. cursor keys - as usual
  89. return - split line
  90. shift-return - goto begin of next line
  91. del - del left of cursor or join lines
  92. inst - insert a blank line
  93. home - redraw screen
  94. clr - kill line
  95. F1 - 20 lines up
  96. F7 - 20 lines down
  97. ctrl-a - begin of line
  98. ctrl-e - end of line
  99. ctrl-d - del under cursor
  100. ctrl-@ - del to cursor
  101. ctrl-^ - del from cursor
  102. ctrl-p - clear line
  103. ctrl-w - save text
  104. ctrl-x - exit and save text
  105. ctrl-c - quit without saving
  106.  
  107. Known bugs
  108. ----------
  109. Just one, though a pretty bad one. The linker cannot handle static
  110. variables so far. So only programs which just use local automatic
  111. variables are compiled correctly. I'll fix that as soon as I can.
  112. Please report any other bugs You find to me. Mail to zem@iwm.fhg.de
  113.  
  114. Code layout and library concept
  115. -------------------------------
  116. Since I didn't want to write a symbolic linker cc64 uses a library
  117. concept different from that of normal C compilers. It is more like
  118. that of Turbo Pascal 3.0: The code is compiled next to a fixed runtime
  119. module. But You can choose which module You want and extend any
  120. existing module.
  121. The selection of the module to use is done by a special preprocessor
  122. command: #special cc64
  123. It must appear in a program before the first code or variable is
  124. generated and is usually the first command in the library's header
  125. file. So all You have to do is to include the header file of the
  126. module/library You want to use. Put this #include as the first
  127. statement in Your programs.
  128. For those interested in the technical details: The #special cc64
  129. command tells the compiler the addresses of the software stack pointer
  130. and an additional zero page pointer the compiled code shall use, then
  131. the library's first address, the address of the jumplist described
  132. below, the library's last address + 1, the first address and the last
  133. address + 1 of the library's static variables, and the name of the
  134. library without extension (i.e. bl02 in case of the base library on
  135. the distribution disk). This way the compiler is completely flexible
  136. concerning the surrounding in which the compiled code shall run, and
  137. by creation of a suitable runtime library it is no problem to create
  138. programs which will run in the 64's BASIC memory (as bl02 does), or
  139. use all memory from $0801 to $d000, or just $c000 to $d000, or run on
  140. any other 6502-based computer.
  141. If You want to write Your own base library, this is what You must know:
  142. Th compiler accesses the library via a jumplist. This list has the
  143. following structure:
  144.  
  145. jumplist
  146. main.adr   .word 0   ; Here the main()-function's address is inserted
  147.                      ; by the compiler. The lib's init routine should
  148.                      ; call main() by a jmp (main.adr)
  149. code.last  .word 0   ; At these addresses the compiler places the last
  150. init.first .word 0   ; address + 1 of the generated code and the first
  151. init.last  .word 0   ; address and the last address + 1 of the static
  152. ; variables. Statics are allocated from the end of the used memory
  153. ; downwards. The statics' initialization values are stored by the
  154. ; compiler from code.last and in reversed order. Your initialization
  155. ; routine should copy (code.last) to (init.last) - 1, (code.last) + 1 to
  156. ; (init.last) - 2 and so an. Mark: there may be no static variables,
  157. ; then init.first will be equal to init.last.
  158.            jmp (zp)   ; Just have this explicitly standing here; it is
  159.                       ; used to emulate jsr (zp). zp is the second zero
  160.                       ; page pointer used by the compiler.
  161.            jmp switch ; Is called with a/x containing a 16 bit value.
  162.                       ; Following the calling jsr-instruction is a data
  163.                       ; structure described below containing values
  164.                       ; and addresses to jump to if a/x matches a value.
  165.                       ; The switch routine should find that data
  166.                       ; structure and jump to the corresponding
  167.                       ; address if a/x matches a value in the list.
  168.                       ; If no value matches it should jump behind the list.
  169.            jmp mult   ; Should multiply (signed) the content of a/x
  170.                       ; (a:lo-byte, x:hi-byte) with the integer in zp/zp+1
  171.                       ; leaving the result in a/x.
  172.            jmp divmod ; Should divide (signed) zp/zp+1 by a/x, leaving
  173.                       ; the result in a/x and the remainder in zp/zp+1.
  174.            jmp shl    ; Should arithmetically shift left a/x by y bits.
  175.            jmp shr    ; Should arithmetically shift right a/x by y bits.
  176.  
  177. This jumplist may be positioned anywhere in the library; it's address
  178. must be told to the compiler with the described #special command.
  179. The Your library should have a init routine which finally will call
  180. the program's main()-function. In which way this routine is called is up
  181. to You. bl02 uses a BASIC line to start init. If You want programs to
  182. run in $c000-$d000, You might want init to stand at the beginning of
  183. the library so You can call Your programs with SYS49152.
  184. However, the init routine should do two things before calling main()
  185. with a jmp (main.adr) instruction. It should copy the static
  186. variables' initialization values to the variables' actual addresses as
  187. described above. And it should set the software stack pointer to an
  188. initial value. The software stack is used for the allocation of local
  189. variables and grows to high addresses. Its stack pointer therefore
  190. should be set either to the code.last address or to
  191. code.last + init.last - init.first, i.e. behind the statics'
  192. initialization values. The former gives more memory for local
  193. variables, but the software stack will destroy the init values. bl02
  194. employs the latter alternative.
  195.  
  196. Supported subset of the C language
  197. ----------------------------------
  198. cc64 is based on the old K&R standard. No ANSI, sorry. There are,
  199. however, some restrictions. Only int and char as basic data types are
  200. supported. No structs, no unions, only one level of pointer (nothing
  201. like char **p). No type casts. No goto. #define can only give a
  202. numeric value to a macro. No proper text substitution. No macros with
  203. parameters. No #undef. No #ifdef/#ifndef. No typedef, no enum. That's
  204. it, I think.
  205.  
  206. C extensions
  207. ------------
  208. There are two non-standard declaration forms in cc64. They both
  209. include an operator, /= and *=.
  210. With /= an explicit value is assigned to a symbol, e.g.
  211. extern int i /= 0x9ffe ;
  212. extern char fgetc() /= 0xa02 ;
  213. They usually are not used explicitly in programs but appear in library
  214. header files (see below).
  215. cc64 supports a special kind of functions. They only take one argument
  216. and can be called very fast without any software stack manipulation,
  217. just with the parameter in a/x. They will normally be written in
  218. assembler and are declared with *=, e.g.
  219. extern char getchar() *= 0xffcf ;
  220. Such standard functions can be included in a base library.
  221. There's one problem. If You put a standard function's address into a
  222. function pointer and call the function pointer, the parameter won't be
  223. passed properly. This will probably be dealt with in the next compiler
  224. version. Btw, I'd like any comments if You consider this necessary.
  225. The solution would disable such elegant declarations as of getchar()
  226. above.
  227.  
  228. Building libraries
  229. ------------------
  230. Base libraries can easily be expanded with C code. If You compile a C
  231. file which contains no main() function then a new library is
  232. generated. A header file is automatically generated with a
  233. #special cc64 line and declarations of all C functions compiled. The
  234. new library can be used as a new base library, and all contained C
  235. functions can be used.
  236.  
  237. So, I hope that's enough. Have fun with cc64, and don't hesitate to
  238. contact me if any problems, bugs or questions arise.
  239.  
  240. Philip Zembrod, zem@iwm.fhg.de
  241.