]> git.sur5r.net Git - cc65/blobdiff - doc/cc65.sgml
Since we have now builtin search paths, we need to be able to forget them,
[cc65] / doc / cc65.sgml
index e89fc842eeaa3932352dbc880c86315db2872267..443f12798b87b145ee15028c074b27e00876e271 100644 (file)
@@ -3,7 +3,7 @@
 <article>
 <title>cc65 Users Guide
 <author>Ullrich von Bassewitz, <htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org">
-<date>03.09.2000, 02.10.2001
+<date>03.09.2000, 02.10.2001, 2005-8-1
 
 <abstract>
 cc65 is a C compiler for 6502 targets. It supports several 6502 based home
@@ -29,21 +29,22 @@ next release, since there are too many limitations in the current code,
 and removing these limitations would mean a rewrite of many more parts of
 the compiler.
 
-There is a separate document named "library.txt" that covers the library
-available for the compiler. If you know C and are interested in doing
-actual programming, the library documentation is probably of much more use
-than this document.
+There are separate documents named <url url="library.html"> and <url
+url="funcref.html"> that cover the library that is available for the compiler.
+If you know C, and are interested in doing actual programming, the library
+documentation is probably of much more use than this document.
 
 If you need some hints for getting the best code out of the compiler, you
-may have a look at "coding.txt" which covers some code generation issues.
+may have a look at <url url="coding.html"> which covers some code generation
+issues.
 
 
 
 <sect>Usage<p>
 
-The compiler translates C files into files containing assembler code that
+The compiler translates C files into files containing assembly code that
 may be translated by the ca65 macroassembler (for more information about
-the assembler, have a look at ca65.txt).
+the assembler, have a look at <url url="ca65.html">).
 
 
 <sect1>Command line option overview<p>
@@ -115,7 +116,7 @@ Here is a description of all the command line options:
   <tag><tt>--check-stack</tt></tag>
 
   Tells the compiler to generate code that checks for stack overflows. See
-  <tt><ref id="pragma-checkstack" name="#pragma checkstack"></tt> for an
+  <tt><ref id="pragma-checkstack" name="#pragma&nbsp;checkstack"></tt> for an
   explanation of this feature.
 
 
@@ -130,7 +131,7 @@ Here is a description of all the command line options:
   This options allows finer control about speed vs. size decisions in the code
   generation and optimization phases. It gives the allowed size increase
   factor (in percent). The default is 100 when not using <tt/-Oi/ and 200 when
-  using <tt/-Oi/ (<tt/-Oi/ is the same as <tt/--codesize 200/).
+  using <tt/-Oi/ (<tt/-Oi/ is the same as <tt/-O --codesize&nbsp;200/).
 
 
   <tag><tt>--cpu CPU</tt></tag>
@@ -200,7 +201,7 @@ Here is a description of all the command line options:
   name="register variables">.
 
   The compiler setting can also be changed within the source file by using
-  <tt><ref id="pragma-regvars" name="#pragma regvars"></tt>.
+  <tt><ref id="pragma-regvars" name="#pragma&nbsp;regvars"></tt>.
 
 
   <tag><tt>--register-space</tt></tag>
@@ -227,8 +228,8 @@ Here is a description of all the command line options:
   6502 has no provisions for sign extending characters (which is needed on
   almost any load operation), this will make the code larger and slower. A
   better way is to declare characters explicitly as "signed" if needed. You
-  can also use <tt><ref id="pragma-signedchars" name="#pragma
-  signedchars"></tt> for better control of this option.
+  can also use <tt><ref id="pragma-signedchars"
+  name="#pragma&nbsp;signedchars"></tt> for better control of this option.
 
 
   <label id="option--standard">
@@ -242,6 +243,10 @@ Here is a description of all the command line options:
   <item>cc65
   </itemize>
 
+  Please note that the compiler does not support the c99 standard and never
+  will. c99 mode is actually c89 mode with a few selected c99 extensions
+  (// comments for example).
+
 
   <tag><tt>-t target, --target target</tt></tag>
 
@@ -262,10 +267,12 @@ Here is a description of all the command line options:
   <item>cbm610 (all CBM-II II computers with 80 column video)
   <item>geos
   <item>lunix
+  <item>lynx
   <item>nes
   <item>pet (all CBM PET systems except the 2001)
   <item>plus4
   <item>supervision
+  <item>vic20
   </itemize>
 
   <tag><tt>-v, --verbose</tt></tag>
@@ -297,8 +304,8 @@ Here is a description of all the command line options:
        }
   </verb></tscreen>
 
-  the variable a will always have the value 1 when entering the function
-  and using <tt/-Cl/, while in
+  the variable <tt/a/ will always have the value <tt/1/ when entering the
+  function and using <tt/-Cl/, while in
 
   <tscreen><verb>
        void f (void)
@@ -308,12 +315,13 @@ Here is a description of all the command line options:
        }
   </verb></tscreen>
 
-  the variable a will have the value 1 only the first time, the function
-  is entered, and will keep the old value from one call of the function to
-  the next.
+  the variable <tt/a/ will have the value <tt/1/ only the first time that the
+  function is entered, and will keep the old value from one call of the
+  function to the next.
 
-  You may also use <tt><ref id="pragma-staticlocals" name="#pragma
-  staticlocals"></tt> to change this setting in your sources.
+  You may also use <tt><ref id="pragma-staticlocals"
+  name="#pragma&nbsp;staticlocals"></tt> to change this setting in your
+  sources.
 
 
   <tag><tt>-I dir, --include-dir dir</tt></tag>
@@ -332,7 +340,7 @@ Here is a description of all the command line options:
   runtime functions would have been called, even if the generated code is
   larger. This will not only remove the overhead for a function call, but will
   make the code visible for the optimizer. <tt/-Oi/ is an alias for
-  <tt/--codesize 200/.
+  <tt/-O --codesize&nbsp;200/.
 
   <tt/-Or/ will make the compiler honor the <tt/register/ keyword. Local
   variables may be placed in registers (which are actually zero page
@@ -350,8 +358,9 @@ Here is a description of all the command line options:
        <tt/-Os/ will actually break things.
        <p>
   <item>The inlined string and memory functions will not handle strings or
-       memory areas larger than 255 bytes. Similar, the inlined <tt/is..()/
-       functions will not work with values outside char range.
+       memory areas larger than 255 bytes. Similarly, the inlined <tt/is..()/
+       functions will not work with values outside the char. range (such as
+       <tt/EOF/).
        <p>
   </itemize>
   <p>
@@ -389,57 +398,56 @@ The compiler will accept one C file per invocation and create a file with
 the same base name, but with the extension replaced by ".s". The output
 file contains assembler code suitable for the use with the ca65 macro
 assembler.
+                                               
+Include files in single quotes are searched in the following places:
+<enum>
+<item>The current directory.
+<item>The value of the environment variable <tt/CC65_INC/ if it is defined.
+<item>Any directory added with the <tt/-I/ option on the command line.
+</enum>
 
-In addition to the paths named in the <tt/-I/ option on the command line, the
-directory named in the environment variable <tt/CC65_INC/ is added to the
-search path for include files on startup.
+Include files in angle brackets are searched in the following places:
+<enum>
+<item>A compiled in directory which is often <tt>/usr/lib/cc65/include</tt> on
+      Linux systems.
+<item>The value of the environment variable <tt/CC65_INC/ if it is defined.
+<item>A subdirectory named <tt/include/ of the directory defined in the 
+      environment variable <tt/CC65_HOME/, if it is defined.
+<item>Any directory added with the <tt/-I/ option on the command line.
+</enum>
 
 
 
 <sect>Differences to the ISO standard<p>
 
+Apart from the things listed below, the compiler does support additional
+keywords, has several functions in the standard headers with names outside the
+reserved namespace and a few syntax extensions. All these can be disabled with
+the <tt><ref id="option--standard" name="--standard"></tt> command line
+option. Its use for maximum standards compatibility is advised.
+
 Here is a list of differences between the language, the compiler accepts,
 and the one defined by the ISO standard:
 
 <itemize>
 
-<item> The compiler allows unnamed parameters in parameter lists. The
-       compiler will not issue warnings about unused parameters that don't
-       have a name. This feature can be disabled with the <tt><ref
-        id="option--standard" name="--standard"></tt> command line option.
-       <p>
-<item> The compiler has some additional keywords:
-       <p>
-       <itemize>
-       <item><tt/asm/
-       <item><tt/__asm__/
-       <item><tt/fastcall/
-       <item><tt/__fastcall__/
-       <item><tt/__AX__/
-       <item><tt/__EAX__/
-       <item><tt/__func__/
-       <item><tt/__attribute__/
-       </itemize>
-       <p>
-       The keywords without the underlines can be disabled with the
-        <tt><ref id="option--standard" name="--standard"></tt> command line
-        option.
-       <p>
 <item> The datatypes "float" and "double" are not available.
        <p>
-<item> The compiler does not support bit fields.
-       <p>
 <item>         C Functions may not return structs (or unions), and structs may not
         be passed as parameters by value. However, struct assignment *is*
        possible.
        <p>
 <item> Part of the C library is available only with fastcall calling
-       conventions (see below). This means, that you may not mix pointers to
-       those functions with pointers to user written functions.
+       conventions (see below).  It means that you must not mix pointers to
+       those functions with pointers to user-written, not-fastcall functions.
+       <p>
+<item> The <tt/volatile/ keyword doesn't have an effect. This is not as bad
+        as it sounds, since the 6502 has so few registers that it isn't
+        possible to keep values in registers anyway.
        <p>
 </itemize>
 
-There may be some more minor differences, I'm currently not aware off. The
+There may be some more minor differences I'm currently not aware of. The
 biggest problem is the missing float data type. With this limitation in
 mind, you should be able to write fairly portable code.
 
@@ -469,9 +477,8 @@ This cc65 version has some extensions to the ISO C standard.
        <ref id="inline-asm" name="see there">.
        <p>
 
-<item> There is a special calling convention named "fastcall". This calling
-       convention is currently only usable for functions written in
-       assembler. The syntax for a function declaration using fastcall is
+<item> There is a special calling convention named "fastcall".
+       The syntax for a function declaration using fastcall is
 
        <tscreen><verb>
        &lt;return type&gt; fastcall &lt;function name&gt; (&lt;parameter list&gt;)
@@ -547,27 +554,28 @@ This cc65 version has some extensions to the ISO C standard.
        However, taking the address of the variable results in a <tt/void*/
        which may be passed to any function expecting a pointer.
 
-       See the <htmlurl url="geos.html" name="GEOS library"> for examples on
-       how to use this feature.
+       See the <url url="geos.html" name="GEOS library document"> for examples
+       on how to use this feature.
        <p>
 
 <item>  cc65 implements flexible array struct members as defined in the C99 ISO
         standard. As an extension, these fields may be initialized. There are
         several exceptions, however (which is probably the reason why the
         standard does not define this feature, because it is highly
-        unorthogonal). Flexible array members cannot be initialized...
+        unorthogonal). Flexible array members cannot be initialized ...
 
         <itemize>
-        <item>  ...when defining an array of structs with flexible members.
-        <item>  ...if such a struct is a member field of another struct which
-                is not the last field.
-        <item>  If the struct which contains a flexible array member is
-                declared as <tt/register/ and the size and compiler settings
-                do allow the compiler to actually place the struct into the
+        <item>... when defining an array of structs with flexible
+                members.
+        <item>... if such a struct is a member field of another struct
+                which is not the last field.
+        <item>... if the struct which contains a flexible array member is
+                declared as <tt/register/, and the size and compiler settings
+                do allow the compiler actually to place the struct into the
                 register bank in the zero page.
         </itemize>
 
-        Please note that - as defined in the ISO C standard - the <tt/sizeof/
+        Please note that -- as defined in the ISO C standard -- the <tt/sizeof/
         operator returns the struct size with the flexible array member having
         size zero, even if it is initialized.
         <p>
@@ -585,13 +593,17 @@ The compiler defines several macros at startup:
   <tag><tt>__CC65__</tt></tag>
 
   This macro is always defined. Its value is the version number of the
-  compiler in hex. Version 2.0.1 of the compiler will have this macro defined
-  as 0x0201.
+  compiler in hex.  For example, version 2.10.1 of the compiler has this macro
+  defined as <tt/0x02A1/.
 
   <tag><tt>__APPLE2__</tt></tag>
 
   This macro is defined if the target is the Apple ][ (-t apple2).
 
+  <tag><tt>__APPLE2ENH__</tt></tag>
+
+  This macro is defined if the target is the enhanced Apple //e (-t apple2enh).
+
   <tag><tt>__ATARI__</tt></tag>
 
   This macro is defined if the target is one of the Atari computers
@@ -630,6 +642,18 @@ The compiler defines several macros at startup:
 
   This macro is defined if you are compiling for the GEOS system (-t geos).
 
+  <tag><tt>__LUNIX__</tt></tag>
+
+  This macro is defined if you are compiling for the LUnix system (-t lunix).
+
+  <tag><tt>__LYNX__</tt></tag>
+
+  This macro is defined if the target is the Atari Lynx (-t lynx).
+
+  <tag><tt>__NES__</tt></tag>
+
+  This macro is defined if the target is the NES (-t nes).
+
   <tag><tt>__PET__</tt></tag>
 
   This macro is defined if the target is the PET family of computers (-t pet).
@@ -638,6 +662,10 @@ The compiler defines several macros at startup:
 
   This macro is defined if the target is the plus/4 (-t plus4).
 
+  <tag><tt>__SUPERVISION__</tt></tag>
+
+  This macro is defined if the target is the supervision (-t supervision).
+
   <tag><tt>__VIC20__</tt></tag>
 
   This macro is defined if the target is the vic20 (-t vic20).
@@ -679,7 +707,7 @@ The compiler defines several macros at startup:
 </descrip>
 
 
-<sect>#pragmas<label id="pragmas"><p>
+<sect>&num;pragmas<label id="pragmas"><p>
 
 The compiler understands some pragmas that may be used to change code
 generation and other stuff. Some of these pragmas understand a special form:
@@ -687,7 +715,7 @@ If the first parameter is <tt/push/, the old value is saved onto a stack
 before changing it. The value may later be restored by using the <tt/pop/
 parameter with the <tt/#pragma/.
 
-<sect1><tt>#pragma bssseg (&lt;name&gt;)</tt><p>
+<sect1><tt>#pragma bssseg (&lsqb;push,&rsqb;&lt;name&gt;)</tt><p>
 
   This pragma changes the name used for the BSS segment (the BSS segment
   is used to store uninitialized data). The argument is a string enclosed
@@ -728,8 +756,8 @@ parameter with the <tt/#pragma/.
     <itemize>
     <item>The character index is actually the code of the character in the
          C source, so character mappings do always depend on the source
-         character set. This means that <tt/#pragma charmap/ is not portable
-         - it depends on the build environment.
+         character set. This means that <tt/#pragma&nbsp;charmap/ is not
+         portable -- it depends on the build environment.
     <item>While it is possible to use character literals as indices, the
          result may be somewhat unexpected, since character literals are
          itself translated. For this reason I would suggest to avoid
@@ -847,7 +875,7 @@ parameter with the <tt/#pragma/.
   declared as register. So your programs become non-portable if you use
   this pragma. In addition, your program may not work. This is usually the
   case if a subroutine is called with the address of a register variable,
-  and this subroutine (or a subroutine called from there) uses itself
+  and this subroutine (or a subroutine called from there) uses
   register variables. So be careful with this #pragma.
 
   The <tt/#pragma/ understands the push and pop parameters as explained above.
@@ -902,7 +930,7 @@ parameter with the <tt/#pragma/.
 
 <sect1><tt>#pragma zpsym (&lt;name&gt;)</tt><p>
 
-  Tell the compiler that the - previously as external declared - symbol with
+  Tell the compiler that the -- previously as external declared -- symbol with
   the given name is a zero page symbol (usually from an assembler file).
   The compiler will create a matching import declaration for the assembler.
 
@@ -998,9 +1026,9 @@ each format specifier, an argument is expected which is inserted instead of
 the format specifier before passing the assembly code line to the backend.
 
 <itemize>
-  <item><tt/%b/ - Numerical 8 bit value
-  <item><tt/%w/ - Numerical 16 bit value
-  <item><tt/%l/ - Numerical 32 bit value
+  <item><tt/%b/ - Numerical 8-bit value
+  <item><tt/%w/ - Numerical 16-bit value
+  <item><tt/%l/ - Numerical 32-bit value
   <item><tt/%v/ - Assembler name of a (global) variable or function
   <item><tt/%o/ - Stack offset of a (local) variable
   <item><tt/%g/ - Assembler name of a C label
@@ -1054,11 +1082,19 @@ a future version. Instead use the format specifiers from the table above:
 <p>
 
 
+<sect>Implementation-defined behavior<p>
+
+This section describes the behavior of cc65 when the standard describes the
+behavior as implementation-defined.
+
+(to be done)
+
 <sect>Bugs/Feedback<p>
 
 If you have problems using the compiler, if you find any bugs, or if you're
 doing something interesting with it, I would be glad to hear from you. Feel
-free to contact me by email (<htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org">).
+free to contact me by email (<htmlurl url="mailto:uz@cc65.org"
+name="uz@cc65.org">).