]> git.sur5r.net Git - cc65/blobdiff - doc/ca65.sgml
Fix typo in documentation for .ADDRSIZE
[cc65] / doc / ca65.sgml
index b2299c5b4bec52fb26de0805ceb541ba9befc4fd..03aa72097b7b6d0d842be7c8e69bc18c5724a0ec 100644 (file)
@@ -2,8 +2,8 @@
 
 <article>
 <title>ca65 Users Guide
-<author>Ullrich von Bassewitz, <htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org">
-<date>2000-07-19, 2000-11-29, 2001-10-02, 2005-09-08
+<author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">
+<date>2014-04-24
 
 <abstract>
 ca65 is a powerful macro assembler for the 6502, 65C02 and 65816 CPUs. It is
@@ -92,6 +92,7 @@ Short options:
   -U                            Mark unresolved symbols as import
   -V                            Print the assembler version
   -W n                          Set warning level n
+  -d                            Debug mode
   -g                            Add debug info to object file
   -h                            Help (this text)
   -i                            Ignore case of symbols
@@ -108,18 +109,18 @@ Long options:
   --cpu type                    Set cpu type
   --create-dep name             Create a make dependency file
   --create-full-dep name        Create a full make dependency file
+  --debug                       Debug mode
   --debug-info                  Add debug info to object file
   --feature name                Set an emulation feature
-  --forget-inc-paths            Forget include search paths
   --help                        Help (this text)
   --ignore-case                 Ignore case of symbols
   --include-dir dir             Set an include directory search path
   --large-alignment             Don't warn about large alignments
   --listing name                Create a listing file if assembly was ok
   --list-bytes n                Maximum number of bytes per listing line
-  --macpack-dir dir             Set a macro package directory
   --memory-model model          Set the memory model
   --pagelength n                Set the page length for the listing
+  --relax-checks                Relax some checks (see docs)
   --smart                       Enable smart mode
   --target sys                  Set the target system
   --verbose                     Increase verbosity
@@ -150,10 +151,7 @@ Here is a description of all the command line options:
   Set the default for the CPU type. The option takes a parameter, which
   may be one of
 
-               6502, 65SC02, 65C02, 65816, sunplus, sweet16, HuC6280
-
-  The sunplus cpu is not available in the freeware version, because the
-  instruction set is "proprietary and confidential".
+               6502, 65SC02, 65C02, 65816, sweet16, HuC6280
 
 
   <label id="option-create-dep">
@@ -174,6 +172,12 @@ Here is a description of all the command line options:
   information to the assembler.
 
 
+  <tag><tt>-d, --debug</tt></tag>
+
+  Enables debug mode, something that should not be needed for mere
+  mortals:-)
+
+
   <label id="option--feature">
   <tag><tt>--feature name</tt></tag>
 
@@ -186,14 +190,6 @@ Here is a description of all the command line options:
   command for a list of emulation features.
 
 
-  <label id="option--forget-inc-paths">
-  <tag><tt>--forget-inc-paths</tt></tag>
-
-  Forget the builtin include paths. This is most useful when building
-  customized assembler modules, in which case the standard header files should
-  be ignored.
-
-
   <label id="option-g">
   <tag><tt>-g, --debug-info</tt></tag>
 
@@ -242,17 +238,6 @@ Here is a description of all the command line options:
   number of printed bytes.
 
 
-  <label id="option--macpack-dir">
-  <tag><tt>--macpack-dir dir</tt></tag>
-
-  This options allows to specify a directory containing macro files that are
-  used instead of the builtin images when a <tt><ref id=".MACPACK"
-  name=".MACPACK"></tt> directive is encountered. If <tt>--macpack-dir</tt>
-  was specified, a <tt>.mac</tt> extension is added to the package name and
-  the resulting file is loaded from the given directory. This is most useful
-  when debugging the builtin macro packages.
-
-
   <label id="option-mm">
   <tag><tt>-mm model, --memory-model model</tt></tag>
 
@@ -276,6 +261,20 @@ Here is a description of all the command line options:
   id=".PAGELENGTH" name=".PAGELENGTH"></tt> directive for more information.
 
 
+  <label id="option--relax-checks">
+  <tag><tt>--relax-checks</tt></tag>
+
+  Relax some checks done by the assembler. This will allow code that is an
+  error in most cases and flagged as such by the assembler, but can be valid
+  in special situations.
+
+  Examples are:
+<itemize>
+<item>Short branches between two different segments.
+<item>Byte sized address loads where the address is not a zeropage address.
+</itemize>
+
+
   <label id="option-s">
   <tag><tt>-s, --smart-mode</tt></tag>
 
@@ -370,20 +369,19 @@ Here is a description of all the command line options:
 Normal include files are searched in the following places:
 
 <enum>
-<item>The current directory.
-<item>A compiled-in directory, which is often <tt>/usr/lib/cc65/asminc</tt>
-      on Linux systems.
+<item>The current file's directory.
+<item>Any directory added with the <tt/<ref id="option-I" name="-I">/ option
+on the command line.
 <item>The value of the environment variable <tt/CA65_INC/ if it is defined.
 <item>A subdirectory named <tt/asminc/ of the directory defined in the
       environment variable <tt/CC65_HOME/, if it is defined.
-<item>Any directory added with the <tt/<ref id="option-I" name="-I">/ option
-on the command line.
+<item>An optionally compiled-in directory.
 </enum>
 
 Binary include files are searched in the following places:
 
 <enum>
-<item>The current directory.
+<item>The current file's directory.
 <item>Any directory added with the <tt/<ref id="option--bin-include-dir"
 name="--bin-include-dir">/ option on the command line.
 </enum>
@@ -427,8 +425,6 @@ The assembler accepts
       <tt><ref id=".PC02" name=".PC02"></tt> command was given).
 <item>all valid 65618 mnemonics when in 65816 mode (after the
       <tt><ref id=".P816" name=".P816"></tt> command was given).
-<item>all valid SunPlus mnemonics when in SunPlus mode (after the
-      <tt><ref id=".SUNPLUS" name=".SUNPLUS"></tt> command was given).
 </itemize>
 
 
@@ -457,9 +453,8 @@ mnemonics:
 6502X mode is an extension to the normal 6502 mode. In this mode, several
 mnemonics for illegal instructions of the NMOS 6502 CPUs are accepted. Since
 these instructions are illegal, there are no official mnemonics for them. The
-unofficial ones are taken from <htmlurl
-url="http://www.oxyron.de/html/opcodes02.html"
-name="http://www.oxyron.de/html/opcodes02.html">. Please note that only the
+unofficial ones are taken from <url
+url="http://www.oxyron.de/html/opcodes02.html">. Please note that only the
 ones marked as "stable" are supported. The following table uses information
 from the mentioned web page, for more information, see there.
 
@@ -506,8 +501,7 @@ nor does it call the interpreter. All this must be done by your program. Apple
 ][ programmers do probably know how to use sweet16 mode.
 
 For more information about SWEET 16, see
-<htmlurl url="http://www.6502.org/source/interpreters/sweet16.htm"
-name="http://www.6502.org/source/interpreters/sweet16.htm">.
+<url url="http://www.6502.org/source/interpreters/sweet16.htm">.
 
 
 <sect1>Number format<p>
@@ -704,7 +698,7 @@ The right side can of course be an expression:
 </verb></tscreen>
 
 
-<label id=".SET">
+<label id="variables">
 <sect1>Numeric variables<p>
 
 Within macros and other control structures (<tt><ref id=".REPEAT"
@@ -820,6 +814,10 @@ to find branch targets (this is the reason why I for my part do
 prefer the "cheap" local labels). Nevertheless, unnamed labels are
 convenient in some situations, so it's your decision.
 
+<em/Note:/ <ref id="scopes" name="Scopes"> organize named symbols, not
+unnamed ones, so scopes don't have an effect on unnamed labels.
+
+
 
 <sect1>Using macros to define labels and constants<p>
 
@@ -986,7 +984,7 @@ is actually the same as
 This is the reason why a procedure must have a name. If you want a scope
 without a name, use <tt/<ref id=".SCOPE" name=".SCOPE">/.
 
-<bf/Note:/ As you can see from the example above, scopes and symbols live in
+<em/Note:/ As you can see from the example above, scopes and symbols live in
 different namespaces. There can be a symbol named <tt/foo/ and a scope named
 <tt/foo/ without any conflicts (but see the section titled <ref
 id="scopesearch" name="&quot;Scope search order&quot;">).
@@ -1263,14 +1261,14 @@ writable.
   Reading this pseudo variable will give the assembler version according to
   the following formula:
 
-        VER_MAJOR*$100 + VER_MINOR*$10 + VER_PATCH
+        VER_MAJOR*$100 + VER_MINOR*$10
 
   It may be used to encode the assembler version or check the assembler for
   special features not available with older versions.
 
   Example:
 
-  Version 2.11.1 of the assembler will return $2B1 as numerical constant when
+  Version 2.14 of the assembler will return $2E0 as numerical constant when
   reading the pseudo variable <tt/.VERSION/.
 
 
@@ -1281,6 +1279,35 @@ Pseudo functions expect their arguments in parenthesis, and they have a result,
 either a string or an expression.
 
 
+<sect1><tt>.ADDRSIZE</tt><label id=".ADDRSIZE"><p>
+
+  The <tt/.ADDRSIZE/ function is used to return the interal address size 
+  associated with a symbol. This can be helpful in macros when knowing the address 
+  size of symbol can help with custom instructions.
+
+  Example:
+
+  <tscreen><verb>
+        .macro myLDA foo
+                .if .ADDRSIZE(foo) = 1
+                        ;do custom command based on zeropage addressing:
+                        .byte 0A5h, foo
+                .elseif .ADDRSIZE(foo) = 2
+                        ;do custom command based on absolute addressing:
+                        .byte 0ADh
+                        .word foo
+                .elseif .ADDRSIZE(foo) = 0
+                        ; no address size defined for this symbol:
+                        .out .sprintf("Error, address size unknown for symbol %s", .string(foo))
+                .endif
+        .endmacro
+  </verb></tscreen>
+
+  This command is new and must be enabled with the <tt/.FEATURE addrsize/ command.
+
+  See: <tt><ref id=".FEATURE" name=".FEATURE"></tt>
+
+
 <sect1><tt>.BANK</tt><label id=".BANK"><p>
 
   The <tt/.BANK/ function is used to support systems with banked memory. The
@@ -1667,7 +1694,7 @@ either a string or an expression.
   <tscreen><verb>
         .struct Point                   ; Struct size = 4
                 xcoord  .word
-                xcoord  .word
+                ycoord  .word
         .endstruct
 
         P:      .tag    Point           ; Declare a point
@@ -2103,10 +2130,10 @@ Here's a list of all control commands and a description, what they do:
 <sect1><tt>.CHARMAP</tt><label id=".CHARMAP"><p>
 
   Apply a custom mapping for characters. The command is followed by two
-  numbers in the range 1..255. The first one is the index of the source
-  character, the second one is the mapping. The mapping applies to all
-  character and string constants when they generate output, and overrides
-  mapping table specified with the <tt><ref id="option-t" name="-t"></tt>
+  numbers. The first one is the index of the source character (range 1..255),
+  the second one is the mapping (range 0..255). The mapping applies to all
+  character and string constants when they generate output, and overrides a
+  mapping table specified with the <tt><ref id="option-t" name="-t"></tt>
   command line switch.
 
   Example:
@@ -2598,6 +2625,12 @@ Here's a list of all control commands and a description, what they do:
 
   <descrip>
 
+  <tag><tt>addrsize</tt><label id="addrsize"></tag>
+
+    Enables the .ADDRSIZE pseudo function. This function is experimental and not enabled by default.
+
+    See also: <tt><ref id=".ADDRSIZE" name=".ADDRSIZE"></tt>
+
   <tag><tt>at_in_identifiers</tt><label id="at_in_identifiers"></tag>
 
     Accept the at character (`@') as a valid character in identifiers. The
@@ -2667,7 +2700,7 @@ Here's a list of all control commands and a description, what they do:
     <tscreen><verb>
         lda     #'a
     </verb></tscreen>
-    <bf/Note:/ This does not work in conjunction with <tt/.FEATURE
+    <em/Note:/ This does not work in conjunction with <tt/.FEATURE
     loose_string_term/, since in this case the input would be ambiguous.
 
   <tag><tt>org_per_seg</tt><label id="org_per_seg"></tag>
@@ -2692,6 +2725,17 @@ Here's a list of all control commands and a description, what they do:
     same name. This does also make it possible to introduce hard to find errors
     in your code, so be careful!
 
+  <tag><tt>underline_in_numbers</tt><label id="underline_in_numbers"></tag>
+
+    Allow underlines within numeric constants. These may be used for grouping
+    the digits of numbers for easier reading.
+    Example:
+    <tscreen><verb>
+        .feature        underline_in_numbers
+        .word           %1100001110100101
+        .word           %1100_0011_1010_0101    ; Identical but easier to read
+    </verb></tscreen>
+
   </descrip>
 
   It is also possible to specify features on the command line using the
@@ -2873,7 +2917,7 @@ Here's a list of all control commands and a description, what they do:
 
   This command is often used to check if a macro parameter was given. Since an
   empty macro parameter will evaluate to nothing, the condition will evaluate
-  to FALSE if an empty parameter was given.
+  to TRUE if an empty parameter was given.
 
   Example:
 
@@ -3625,15 +3669,18 @@ Here's a list of all control commands and a description, what they do:
   id=".RODATA" name=".RODATA"></tt>
 
 
+<sect1><tt>.SET</tt><label id=".SET"><p>
+
+  <tt/.SET/ is used to assign a value to a variable. See <ref id="variables"
+  name="Numeric variables"> for a full description.
+
+
 <sect1><tt>.SETCPU</tt><label id=".SETCPU"><p>
 
   Switch the CPU instruction set. The command is followed by a string that
   specifies the CPU. Possible values are those that can also be supplied to
   the <tt><ref id="option--cpu" name="--cpu"></tt> command line option,
-  namely: 6502, 6502X, 65SC02, 65C02, 65816, sunplus and HuC6280. Please
-  note that support for the sunplus CPU is not available in the freeware
-  version, because the instruction set of the sunplus CPU is "proprietary
-  and confidential".
+  namely: 6502, 6502X, 65SC02, 65C02, 65816 and HuC6280.
 
   See: <tt><ref id=".CPU" name=".CPU"></tt>,
        <tt><ref id=".IFP02" name=".IFP02"></tt>,
@@ -3692,17 +3739,6 @@ Here's a list of all control commands and a description, what they do:
             <tt><ref id=".UNION" name=".UNION"></tt>
 
 
-<sect1><tt>.SUNPLUS</tt><label id=".SUNPLUS"><p>
-
-  Enable the SunPlus instructions set. This command will not work in the
-  freeware version of the assembler, because the instruction set is
-  "proprietary and confidential".
-
-  See: <tt><ref id=".P02" name=".P02"></tt>, <tt><ref id=".PSC02"
-  name=".PSC02"></tt>, <tt><ref id=".PC02" name=".PC02"></tt>, and
-  <tt><ref id=".P816" name=".P816"></tt>
-
-
 <sect1><tt>.TAG</tt><label id=".TAG"><p>
 
   Allocate space for a struct or union.
@@ -4059,16 +4095,31 @@ written more efficiently, like this:
                .endmacro
 </verb></tscreen>
 
-But imagine what happens, if you use this macro twice? Since the label
-"Skip" has the same name both times, you get a "duplicate symbol" error.
-Without a way to circumvent this problem, macros are not as useful, as
-they could be. One solution is, to start a new lexical block inside the
-macro:
+But imagine what happens, if you use this macro twice? Since the label "Skip"
+has the same name both times, you get a "duplicate symbol" error. Without a
+way to circumvent this problem, macros are not as useful, as they could be.
+One possible solution is the command <tt><ref id=".LOCAL" name=".LOCAL"></tt>.
+It declares one or more symbols as local to the macro expansion. The names of
+local variables are replaced by a unique name in each separate macro
+expansion. So we can solve the problem above by using <tt/.LOCAL/:
+
+<tscreen><verb>
+       .macro  inc16   addr
+                       .local  Skip            ; Make Skip a local symbol
+               inc     addr
+                       bne     Skip
+               inc     addr+1
+       Skip:                           ; Not visible outside
+       .endmacro
+</verb></tscreen>
+
+Another solution is of course to start a new lexical block inside the macro
+that hides any labels:
 
 <tscreen><verb>
        .macro  inc16   addr
        .proc
-                       inc     addr
+                       inc     addr
                        bne     Skip
                        inc     addr+1
        Skip:
@@ -4076,27 +4127,6 @@ macro:
        .endmacro
 </verb></tscreen>
 
-Now the label is local to the block and not visible outside. However,
-sometimes you want a label inside the macro to be visible outside. To make
-that possible, there's a new command that's only usable inside a macro
-definition: <tt><ref id=".LOCAL" name=".LOCAL"></tt>. <tt/.LOCAL/ declares one
-or more symbols as local to the macro expansion. The names of local variables
-are replaced by a unique name in each separate macro expansion. So we could
-also solve the problem above by using <tt/.LOCAL/:
-
-<tscreen><verb>
-       .macro  inc16   addr
-                       .local  Skip            ; Make Skip a local symbol
-               clc
-               lda     addr
-               adc     #$01
-               sta     addr
-               bcc     Skip
-               inc     addr+1
-       Skip:                           ; Not visible outside
-       .endmacro
-</verb></tscreen>
-
 
 <sect1>C style macros<p>
 
@@ -4174,7 +4204,7 @@ detect the end of one parameter, only the first token is used. If you
 don't like that, use classic macros instead:
 
 <tscreen><verb>
-       .macro  message
+       .macro  DEBUG   message
                .out    message
        .endmacro
 </verb></tscreen>
@@ -4281,6 +4311,15 @@ Currently defined macros are:
                 beq     Arg
                 bcc     Arg
         .endmacro
+
+        .macro  bnz     Arg
+                bne     Arg
+        .endmacro
+
+        .macro  bze     Arg
+                beq     Arg
+        .endmacro
+
 </verb></tscreen>
 
 
@@ -4317,16 +4356,14 @@ The package defines the following macros:
 
 <sect1><tt>.MACPACK atari</tt><p>
 
-The atari macro package will define a macro named <tt/scrcode/. It takes a
-string as argument and places this string into memory translated into screen
-codes.
+This macro package defines a macro named <tt/scrcode/. It takes a string
+as argument and places this string into memory translated into screen codes.
 
 
 <sect1><tt>.MACPACK cbm</tt><p>
 
-The cbm macro package will define a macro named <tt/scrcode/. It takes a
-string as argument and places this string into memory translated into screen
-codes.
+This macro package defines a macro named <tt/scrcode/. It takes a string
+as argument and places this string into memory translated into screen codes.
 
 
 <sect1><tt>.MACPACK cpu</tt><p>
@@ -4340,7 +4377,6 @@ each supported CPU a constant similar to
     CPU_65SC02
     CPU_65C02
     CPU_65816
-    CPU_SUNPLUS
     CPU_SWEET16
     CPU_HUC6280
 </verb></tscreen>
@@ -4354,7 +4390,6 @@ another constant is defined:
     CPU_ISET_65SC02
     CPU_ISET_65C02
     CPU_ISET_65816
-    CPU_ISET_SUNPLUS
     CPU_ISET_SWEET16
     CPU_ISET_HUC6280
 </verb></tscreen>
@@ -4384,6 +4419,13 @@ it is possible to determine if the
 instruction is supported, which is the case for the 65SC02, 65C02 and 65816
 CPUs (the latter two are upwards compatible to the 65SC02).
 
+  
+<sect1><tt>.MACPACK module</tt><p>
+
+This macro package defines a macro named <tt/module_header/. It takes an
+identifier as argument and is used to define the header of a module both
+in the dynamic and static variant.
+
 
 
 <sect>Predefined constants<label id="predefined-constants"><p>
@@ -4392,22 +4434,30 @@ For better orthogonality, the assembler defines similar symbols as the
 compiler, depending on the target system selected:
 
 <itemize>
-<item><tt/__APPLE2__/ - Target system is <tt/apple2/
+<item><tt/__APPLE2__/ - Target system is <tt/apple2/ or <tt/apple2enh/
 <item><tt/__APPLE2ENH__/ - Target system is <tt/apple2enh/
-<item><tt/__ATARI__/ - Target system is <tt/atari/
+<item><tt/__ATARI5200__/ - Target system is <tt/atari5200/
+<item><tt/__ATARI__/ - Target system is <tt/atari/ or <tt/atarixl/
+<item><tt/__ATARIXL__/ - Target system is <tt/atarixl/
 <item><tt/__ATMOS__/ - Target system is <tt/atmos/
 <item><tt/__BBC__/ - Target system is <tt/bbc/
 <item><tt/__C128__/ - Target system is <tt/c128/
-<item><tt/__C16__/ - Target system is <tt/c16/
+<item><tt/__C16__/ - Target system is <tt/c16/ or <tt/plus4/
 <item><tt/__C64__/ - Target system is <tt/c64/
 <item><tt/__CBM__/ - Target is a Commodore system
 <item><tt/__CBM510__/ - Target system is <tt/cbm510/
 <item><tt/__CBM610__/ - Target system is <tt/cbm610/
-<item><tt/__GEOS__/ - Target system is <tt/geos/
+<item><tt/__GEOS__/ - Target is a GEOS system
+<item><tt/__GEOS_APPLE__/ - Target system is <tt/geos-apple/
+<item><tt/__GEOS_CBM__/ - Target system is <tt/geos-cbm/
 <item><tt/__LUNIX__/ - Target system is <tt/lunix/
+<item><tt/__LYNX__/ - Target system is <tt/lynx/
 <item><tt/__NES__/ - Target system is <tt/nes/
+<item><tt/__OSIC1P__/ - Target system is <tt/osic1p/
 <item><tt/__PET__/ - Target system is <tt/pet/
 <item><tt/__PLUS4__/ - Target system is <tt/plus4/
+<item><tt/__SIM6502__/ - Target system is <tt/sim6502/
+<item><tt/__SIM65C02__/ - Target system is <tt/sim65c02/
 <item><tt/__SUPERVISION__/ - Target system is <tt/supervision/
 <item><tt/__VIC20__/ - Target system is <tt/vic20/
 </itemize>
@@ -4522,7 +4572,7 @@ useful for assembler programs.
 
 Using the <tt><ref id=".CONSTRUCTOR" name=".CONSTRUCTOR"></tt>, <tt><ref
 id=".DESTRUCTOR" name=".DESTRUCTOR"></tt> and <tt><ref id=".INTERRUPTOR"
-name=".INTERRUPTOR"></tt> keywords it it possible to export functions in a
+name=".INTERRUPTOR"></tt> keywords it is possible to export functions in a
 special way. The linker is able to generate tables with all functions of a
 specific type. Such a table will <em>only</em> include symbols from object
 files that are linked into a specific executable. This may be used to add
@@ -4706,15 +4756,6 @@ are used for the cbm load address.
 </enum>
 
 
-<sect>Bugs/Feedback<p>
-
-If you have problems using the assembler, if you find any bugs, or if
-you're doing something interesting with the assembler, 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">).
-
-
-
 <sect>Copyright<p>
 
 ca65 (and all cc65 binutils) are (C) Copyright 1998-2003 Ullrich von