]> git.sur5r.net Git - cc65/blob - doc/ca65.sgml
Converted cc65.txt to SGML (incomplete). Several corrections in the other
[cc65] / doc / ca65.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4 <title>ca65 Users Guide
5 <author>Ullrich von Bassewitz, <htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org">
6 <date>19.07.2000
7
8 <abstract>
9 ca65 is a macro assembler for the 6502, 65C02 and 65816 CPUs. It is used as a
10 companion assembler for the cc65 crosscompiler, but it may also be used as a
11 standalone product.
12 </abstract>
13
14 <!-- Table of contents -->
15 <toc>
16
17 <!-- Begin the document -->
18
19 <sect>Overview<p>
20
21 ca65 is a replacement for the ra65 assembler that was part of the cc65 C
22 compiler, originally developed by John R. Dunning. I had some problems with
23 ra65 and the copyright does not permit some things which I wanted to be
24 possible, so I decided to write a completely new assembler/linker/archiver
25 suite for the cc65 compiler. ca65 is part of this suite.
26
27 Some parts of the assembler (code generation and some routines for symbol
28 table handling) are taken from an older crossassembler named a816 written
29 by me a long time ago.
30
31 Here's a list of the design criteria, that I considered important for the
32 development:
33
34 <itemize>
35
36 <item>  The assembler must support macros. Macros are not essential, but they
37         make some things easier, especially when you use the assembler in the
38         backend of a compiler.
39 <item>  The assembler must support the newer 65C02 and 65816 CPUs. I have been
40         thinking about a 65816 backend for the C compiler, and even my old
41         a816 assembler had support for these CPUs, so this wasn't really a
42         problem.
43 <item>  The assembler must produce relocatable code. This necessary for the
44         compiler support, and it is more convenient.
45 <item>  Conditional assembly must be supported. This is a must for bigger
46         projects written in assembler (like Elite128).
47 <item>  The assembler must support segments, and it must support more than
48         three segments (this is the count, most other assemblers support).
49         Having more than one code segments helps developing code for systems
50         with a divided ROM area (like the C64).
51 <item>  The linker must be able to resolve arbitrary expressions. It should
52         be able to get things like
53 <tscreen><verb>
54         .import S1, S2
55         .export Special
56         Special = 2*S1 + S2/7
57 </verb></tscreen>
58         right.
59 <item>  True lexical nesting for symbols. This is very convenient for larger
60         assembly projects.
61 <item>  "Cheap" local symbols without lexical nesting for those quick, late
62         night hacks.
63 <item>  I liked the idea of "options" as Anre Fachats .o65 format has it, so I
64         introduced the concept into the object file format use by the new cc65
65         binutils.
66 <item>  The assembler will be a one pass assembler. There was no real need for
67         this decision, but I've written several multipass assemblers, and it
68         started to get boring. A one pass assembler needs much more elaborated
69         data structures, and because of that it's much more fun:-)
70 <item>  Non-GPLed code that may be used in any project without restrictions or
71         fear of "GPL infecting" other code.
72 </itemize>
73 <p>
74
75
76 <sect>Usage<p>
77
78 The assembler accepts the following options:
79
80 <tscreen><verb>
81 ---------------------------------------------------------------------------
82 Usage: ca65 [options] file
83 Short options:
84   -g                    Add debug info to object file
85   -h                    Help (this text)
86   -i                    Ignore case of symbols
87   -l                    Create a listing if assembly was ok
88   -o name               Name the output file
89   -s                    Enable smart mode
90   -t sys                Set the target system
91   -v                    Increase verbosity
92   -D name[=value]       Define a symbol
93   -I dir                Set an include directory search path
94   -U                    Mark unresolved symbols as import
95   -V                    Print the assembler version
96   -W n                  Set warning level n
97
98 Long options:
99   --auto-import         Mark unresolved symbols as import
100   --cpu type            Set cpu type
101   --debug-info          Add debug info to object file
102   --feature name        Set an emulation feature
103   --help                Help (this text)
104   --ignore-case         Ignore case of symbols
105   --include-dir dir     Set an include directory search path
106   --listing             Create a listing if assembly was ok
107   --pagelength n        Set the page length for the listing
108   --smart               Enable smart mode
109   --target sys          Set the target system
110   --verbose             Increase verbosity
111   --version             Print the assembler version
112 ---------------------------------------------------------------------------
113 </verb></tscreen>
114
115 Here is a description of all the command line options:
116
117 <descrip>
118
119   <tag><tt>--cpu type</tt></tag>
120
121   Set the default for the CPU type. The option takes a parameter, which
122   may be one of
123
124         6502, 65C02, 65816 and sunplus
125
126   The latter (sunplus) is not available in the freeware version, because the
127   instruction set of the sunplus CPU is "confidential".
128
129
130   <tag><tt>--feature name</tt></tag>
131
132   Enable an emulation feature. This is identical as using <tt/.FEATURE/
133   in the source with two exceptions: Feature names must be lower case, and
134   each feature must be specified by using an extra <tt/--feature/ option,
135   comma separated lists are not allowed.
136
137   See the discussion of the <tt/.FEATURE/ command for a list of emulation
138   features.
139
140
141   <tag><tt>-g, --debug-info</tt></tag>
142
143   When this option (or the equivalent control command <tt/.DEBUGINFO/) is
144   used, the assembler will add a section to the object file that contains
145   all symbols (including local ones) together with the symbol values and
146   source file positions. The linker will put these additional symbols into
147   the VICE label file, so even local symbols can be seen in the VICE
148   monitor.
149
150
151   <tag><tt>-h, --help</tt></tag>
152
153   Print the short option summary shown above.
154
155
156   <tag><tt>-i, --ignore-case</tt></tag>
157
158   This option makes the assembler case insensitive on identifiers and
159   labels. This option will override the default, but may itself be
160   overriden by the <tt/.CASE/ control command (see section 6).
161
162
163   <tag><tt>-l, --listing</tt></tag>
164
165   Generate an assembler listing. The listing file will always have the
166   name of the main input file with the extension replaced by ".lst". This
167   may change in future versions.
168
169
170   <tag><tt>-o name</tt></tag>
171
172   The default output name is the name of the input file with the extension
173   replaced by ".o". If you don't like that, you may give another name with
174   the -o option. The output file will be placed in the same directory as
175   the source file, or, if -o is given, the full path in this name is used.
176
177
178   <tag><tt>--pagelength n</tt></tag>
179
180   sets the length of a listing page in lines. See the <tt/.PAGELENGTH/
181   directive for more information.
182
183
184   <tag><tt>-s, --smart-mode</tt></tag>
185
186   In smart mode (enabled by -s or the <tt/.SMART/ pseudo instruction) the
187   assembler will track usage of the REP and SEP instructions in 65816 mode
188   and update the operand sizes accordingly. If the operand of such an
189   instruction cannot be evaluated by the assembler (for example, because
190   the operand is an imported symbol), a warning is issued.
191
192   Beware: Since the assembler cannot trace the execution flow this may
193   lead to false results in some cases. If in doubt, use the .ixx and .axx
194   instructions to tell the assembler about the current settings. Smart
195   mode is off by default.
196
197
198   <tag><tt>-t sys, --target sys</tt></tag>
199
200   Set the target system. This will enable translation of character strings
201   and character constants into the character set of the target platform.
202   The default for the target system is "none", which means that no translation
203   will take place. The assembler supports the same target systems as the
204   compiler, see there for a list.
205
206
207   <tag><tt>-v, --verbose</tt></tag>
208
209   Increase the assembler verbosity. Usually only needed for debugging
210   purposes. You may use this option more than one time for even more
211   verbose output.
212
213
214   <tag><tt>-D</tt></tag>
215
216   This option allows you to define symbols on the command line. Without a
217   value, the symbol is defined with the value zero. When giving a value,
218   you may use the '&dollar;' prefix for hexadecimal symbols. Please note
219   that for some operating systems, '&dollar;' has a special meaning, so
220   you may have to quote the expression.
221
222
223   <tag><tt>-I dir, --include-dir dir</tt></tag>
224
225   Name a directory which is searched for include files. The option may be
226   used more than once to specify more than one directory to search. The
227   current directory is always searched first before considering any
228   additional directores.
229
230
231   <tag><tt>-U, --auto-import</tt></tag>
232
233   Mark symbols that are not defined in the sources as imported symbols.
234   This should be used with care since it delays error messages about typos
235   and such until the linker is run. The compiler uses the equivalent of
236   this switch (<tt/.AUTOIMPORT/, see control command section below) to enable
237   auto imported symbols for the runtime library. However, the compiler is
238   supposed to generate code that runs through the assembler without
239   problems, something which is not always true for assembler programmers.
240
241
242   <tag><tt>-V, --version</tt></tag>
243
244   Print the version number of the assembler. If you send any suggestions
245   or bugfixes, please include the version number.
246
247
248   <tag><tt>-Wn</tt></tag>
249
250   Set the warning level for the assembler. Using -W2 the assembler will
251   even warn about such things like unused imported symbols. The default
252   warning level is 1, and it would probably be silly to set it to
253   something lower.
254
255 </descrip>
256 <p>
257
258
259 <sect>Input format<p>
260
261 The assembler accepts the standard 6502/65816 assembler syntax. One line
262 may contain a label (which is identified by a colon), and, in addition to
263 the label, an assembler mnemonic, a macro, or a control command (see
264 section 6 for supported control commands). Alternatively, the line may
265 contain a symbol definition using the '=' token. Everything after a
266 semicolon is handled as a comment (that is, it is ignored).
267
268 Here are some examples for valid input lines:
269
270 <tscreen><verb>
271         Label:                          ; A label and a comment
272                 lda     #$20            ; A 6502 instruction plus comment
273         L1:     ldx     #$20            ; Same with label
274         L2:     .byte   "Hello world"   ; Label plus control command
275                 mymac   $20             ; Macro expansion
276                 MySym = 3*L1            ; Symbol definition
277         MaSym   = Label                 ; Another symbol
278 </verb></tscreen>
279
280 The assembler accepts all valid 6502 mnemonics when in 6502 mode (the
281 default). The assembler accepts all valid 65SC02 mnemonics when in 65SC02
282 mode (after a <tt/.PC02/ command is found). The assembler accepts all valid
283 65816 mnemonics with a few exceptions after a .P816 command is found.
284 These exceptions are listed below.
285
286 In 65816 mode several aliases are accepted in addition to the official
287 mnemonics:
288
289 <tscreen><verb>
290         BGE is an alias for BCS
291         BLT is an alias for BCC
292         CPA is an alias for CMP
293         DEA is an alias for DEC A
294         INA is an alias for INC A
295         SWA is an alias for XBA
296         TAD is an alias for TCD
297         TAS is an alias for TCS
298         TDA is an alias for TDC
299         TSA is an alias for TSC
300 </verb></tscreen>
301
302 Evaluation of banked expressions in 65816 mode differs slightly from the
303 official syntax:
304
305 Instead of accepting a 24 bit address (something that is difficult for
306 the assembler to determine and would have required one more special
307 .import command), the bank and the absolute address in that bank are
308 separated by a dot:
309
310 <tscreen><verb>
311         jsl     3.$1234         ; Call subroutine at $1234 in bank 3
312 </verb></tscreen>
313
314 For literal values, the assembler accepts the widely used number formats:
315 A preceeding '&dollar;' denotes a hex value, a preceeding '%' denotes a
316 binary value, and a bare number is interpeted as a decimal. There are
317 currently no octal values and no floats.
318 <p>
319
320
321 <sect>Expressions
322
323 <p>
324 All expressions are evaluated with (at least) 32 bit precision. An
325 expression may contain constant values and any combination of internal and
326 external symbols. Expressions that cannot be evaluated at assembly time
327 are stored inside the object file for evaluation by the linker.
328 Expressions referencing imported symbols must always be evaluated by the
329 linker.
330
331 Sometimes, the assembler must know about the size of the value that is the
332 result of an expression. This is usually the case, if a decision has to be
333 made, to generate a zero page or an absolute memory references. In this
334 case, the assembler has to make some assumptions about the result of an
335 expression:
336
337 <itemize>
338 <item>  If the result of an expression is constant, the actual value is
339         checked to see if it's a byte sized expression or not.
340 <item>  If the expression is explicitly casted to a byte sized expression by
341         one of the '&gt;'/'&lt;' operators, it is a byte expression.
342 <item>  If this is not the case, and the expression contains a symbol,
343         explicitly declared as zero page symbol (by one of the .importzp or
344         .exportzp instructions), then the whole expression is assumed to be
345         byte sized.
346 <item>  If the expression contains symbols that are not defined, and these
347         symbols are local symbols, the enclosing scopes are searched for a
348         symbol with the same name. If one exists and this symbol is defined,
349         it's attributes are used to determine the result size.
350 <item>  In all other cases the expression is assumed to be word sized.
351 </itemize>
352
353 Note: If the assembler is not able to evaluate the expression at assembly
354 time, the linker will evaluate it and check for range errors as soon as
355 the result is known.
356
357
358 <bf>Boolean expressions:</bf>
359
360 In the context of a boolean expression, any non zero value is evaluated as
361 true, any other value to false. The result of a boolean expression is 1 if
362 it's true, and zero if it's false. There are boolean operators with extrem
363 low precedence with version 2.x (where x &gt; 0). The <tt/.AND/ and <tt/.OR/
364 operators are shortcut operators. That is, if the result of the expression is
365 already known, after evaluating the left hand side, the right hand side is
366 not evaluated.
367
368
369 Available operators sorted by precedence:
370
371 <tscreen><verb>
372     Op          Description                             Precedence
373   -------------------------------------------------------------------
374     .CONCAT     Builtin function                        0
375     .LEFT       Builtin function                        0
376     .MID        Builtin function                        0
377     .RIGHT      Builtin function                        0
378     .STRING     Builtin function                        0
379
380     *           Builtin pseudo variable (r/o)           1
381     .BLANK      Builtin function                        1
382     .CONST      Builtin function                        1
383     .CPU        Builtin pseudo variable (r/o)           1
384     .DEFINED    Builtin function                        1
385     .MATCH      Builtin function                        1
386     .TCOUNT     Builtin function                        1
387     .XMATCH     Builtin function                        1
388     .PARAMCOUNT Builtin pseudo variable (r/o)           1
389     .REFERENCED Builtin function                        1
390     ::          Global namespace override               1
391     +           Unary plus                              1
392     -           Unary minus                             1
393     ~           Unary bitwise not                       1
394     .BITNOT     Unary bitwise not                       1
395     &lt;        Low byte operator                       1
396     &gt;        High byte operator                      1
397
398     *           Multiplication                          2
399     /           Division                                2
400     .MOD        Modulo operation                        2
401     &amp;       Bitwise and                             2
402     .BITAND     Bitwise and                             2
403     ^           Bitwise xor                             2
404     .BITXOR     Bitwise xor                             2
405     &lt;&lt;    Shift left operator                     2
406     .SHL        Shift left operator                     2
407     &gt;&gt;    Shift right operator                    2
408     .SHR        Shift right operator                    2
409
410     +           Binary plus                             3
411     -           Binary minus                            3
412     |           Binary or                               3
413     .BITOR      Binary or                               3
414
415     =           Compare operation (equal)               4
416     &lt;&gt;    Compare operation (not equal)           4
417     &lt;        Compare operation (less)                4
418     &gt;        Compare operation (greater)             4
419     &lt;=       Compare operation (less or equal)       4
420     &gt;=       Compare operation (greater or equal)    4
421
422     &amp;&amp;          Boolean and                             5
423     .AND        Boolean and                             5
424     .XOR        Boolean xor                             5
425
426     ||          Boolean or                              6
427     .OR         Boolean or                              6
428
429     !           Boolean not                             7
430     .NOT        Boolean not                             7
431 </verb></tscreen>
432
433
434 To force a specific order of evaluation, braces may be used as usual.
435
436 Some of the pseudo variables mentioned above need some more explanation:
437
438 <tscreen><verb>
439   *             This symbol is replaced by the value of the program
440                 counter at start of the current instruction. Note, that
441                 '*' yields a rvalue, that means, you cannot assign to it.
442                 Use <tt/.ORG/ to set the program counter in sections with
443                 absolute code.
444 </verb></tscreen>
445 <p>
446
447
448
449 <sect>Symbols and labels
450
451 <p>
452 The assembler allows you to use symbols instead of naked values to make
453 the source more readable. There are a lot of different ways to define and
454 use symbols and labels, giving a lot of flexibility.
455
456 <descrip>
457
458
459 <tag/Numeric constants/
460
461     Numeric constants are defined using the equal sign. After doing
462
463     <tscreen><verb>
464           two = 2
465     </verb></tscreen>
466
467     may use the symbol "two" in every place where a number is expected,
468     and it is evaluated to the value 2 in this context. An example would be
469
470     <tscreen><verb>
471           four = two * two
472     </verb></tscreen>
473
474
475 <tag/Standard labels/
476
477     A label is defined by writing the name of the label at the start of
478     the line (before any instruction mnemonic, macro or pseudo
479     directive), followed by a colon. This will declare a symbol with the
480     given name and the value of the current program counter.
481
482
483 <tag/Local labels and symbols/
484
485     Using the <tt/.PROC/ directive, it is possible to create regions of code
486     where the names of labels and symbols are local to this region. They
487     are not know outside and cannot be accessed from there. Such regions
488     may be nested like PROCEDUREs in Pascal.
489
490     See the description of the <tt/.PROC/ directive for more information.
491
492 <tag/Cheap local labels/
493
494     Cheap local labels are defined like standard labels, but the name of
495     the label must begin with a special symbol (usually '@', but this can
496     be changed by the <tt/.LOCALCHAR/ directive).
497
498     Cheap local labels are visible only between two no cheap labels. As
499     soon as a standard symbol is encountered (this may also be a local
500     symbol if inside a region defined with the .PROC directive), the
501     cheap local symbol goes out of scope.
502
503     You may use cheap local labels as an easy way to reuse common label
504     names like "Loop". Here is an example:
505
506     <tscreen><verb>
507         Clear:  lda     #$00            ; Global label
508                 ldy     #$20
509         @Loop:  sta     Mem,y           ; Local label
510                 dey
511                 bne     @Loop           ; Ok
512                 rts
513         Sub:    ...                     ; New global label
514                 bne     @Loop           ; ERROR: Unknown identifier!
515     </verb></tscreen>
516
517 <tag/Unnamed labels/
518
519     If you really want to write messy code, there are also unnamed
520     labels. These labels do not have a name (you guessed that already,
521     didn't you?). A colon is used to mark the absence of the name.
522
523     Unnamed labels may be accessed by using the colon plus several minus
524     or plus characters as a label designator. Using the '-' characters
525     will create a back reference (use the n'th label backwards), using
526     '+' will create a forward reference (use the n'th label in forward
527     direction). An example will help to understand this:
528
529     <tscreen><verb>
530         :       lda     (ptr1),y        ; #1
531                 cmp     (ptr2),y
532                 bne     :+              ; -> #2
533                 tax
534                 beq     :+++            ; -> #4
535                 iny
536                 bne     :-              ; -> #1
537                 inc     ptr1+1
538                 inc     ptr2+1
539                 bne     :-              ; -> #1
540
541         :       bcs     :+              ; #2 -> #3
542                 ldx     #$FF
543                 rts
544
545         :       ldx     #$01            ; #3
546         :       rts                     ; #4
547     </verb></tscreen>
548
549     As you can see from the example, unnamed labels will make even short
550     sections of code hard to understand, because you have to count labels
551     to find branch targets (this is the reason why I for my part do
552     prefer the "cheap" local labels). Nevertheless, unnamed labels are
553     convenient in some situations, so it's your decision.
554
555 <tag/Using macros to define labels and constants/
556
557     While there are drawbacks with this approach, it may be handy in some
558     situations. Using <tt/.DEFINE/, it is possible to define symbols or
559     constants that may be used elsewhere. Since the macro facility works
560     on a very low level, there is no scoping. On the other side, you may
561     also define string constants this way (this is not possible with the
562     other symbol types).
563
564     Example:
565
566     <tscreen><verb>
567         .DEFINE two     2
568         .DEFINE version "SOS V2.3"
569
570         four = two * two        ; Ok
571         .byte   version         ; Ok
572
573         .PROC                   ; Start local scope
574         two = 3                 ; Will give "2 = 3" - invalid!
575         .ENDPROC
576     </verb></tscreen>
577
578 </descrip>
579
580
581 If <tt/.DEBUGINFO/ is enabled (or -g is given on the command line), global,
582 local and cheap local labels are written to the object file and will be
583 available in the symbol file via the linker. Unnamed labels are not
584 written to the object file, because they don't have a name which would
585 allow to access them.
586
587
588
589 <sect>Control commands
590
591 <p>
592 Here's a list of all control commands and a description, what they do:
593
594 <descrip>
595
596 <tag><tt><idx>.A16</idx></tt></tag>
597
598   Valid only in 65816 mode. Switch the accumulator to 16 bit.
599
600   Note: This command will not emit any code, it will tell the assembler to
601   create 16 bit operands for immediate accumulator adressing mode.
602
603   See also: <tt/.SMART/
604
605
606 <tag><tt><idx>.A8</idx></tt></tag>
607
608   Valid only in 65816 mode. Switch the accumulator to 8 bit.
609
610   Note: This command will not emit any code, it will tell the assembler to
611   create 8 bit operands for immediate accu adressing mode.
612
613   See also: <tt/.SMART/
614
615
616 <tag><tt><idx>.ADDR</idx></tt></tag>
617
618   Define word sized data. In 6502 mode, this is an alias for <tt/.WORD/ and
619   may be used for better readability if the data words are address values.
620   In 65816 mode, the address is forced to be 16 bit wide to fit into the
621   current segment. See also <tt/.FARADDR/. The command must be followed by a
622   sequence of (not necessarily constant) expressions.
623
624   Example:
625
626   <tscreen><verb>
627         .addr   $0D00, $AF13, _Clear
628   </verb></tscreen>
629
630
631 <tag><tt><idx>.ALIGN</idx></tt></tag>
632
633   Align data to a given boundary. The command expects a constant integer
634   argument that must be a power of two, plus an optional second argument
635   in byte range. If there is a second argument, it is used as fill value,
636   otherwise the value defined in the linker configuration file is used
637   (the default for this value is zero).
638
639   Since alignment depends on the base address of the module, you must
640   give the same (or a greater) alignment for the segment when linking.
641   The linker will give you a warning, if you don't do that.
642
643   Example:
644
645   <tscreen><verb>
646         .align  256
647   </verb></tscreen>
648
649
650 <tag><tt><idx>.ASCIIZ</idx></tt></tag>
651
652   Define a string with a trailing zero.
653
654   Example:
655
656   <tscreen><verb>
657         Msg:    .asciiz "Hello world"
658   </verb></tscreen>
659
660   This will put the string "Hello world" followed by a binary zero into
661   the current segment. There may be more strings separated by commas, but
662   the binary zero is only appended once (after the last one).
663
664
665 <tag><tt><idx>.AUTOIMPORT</idx></tt></tag>
666
667   Is followd by a plus or a minus character. When switched on (using a
668   +), undefined symbols are automatically marked as import instead of
669   giving errors. When switched off (which is the default so this does not
670   make much sense), this does not happen and an error message is
671   displayed. The state of the autoimport flag is evaluated when the
672   complete source was translated, before outputing actual code, so it is
673   <em/not/ possible to switch this feature on or off for separate sections
674   of code. The last setting is used for all symbols.
675
676   You should probably not use this switch because it delays error
677   messages about undefined symbols until the link stage. The cc65
678   compiler (which is supposed to produce correct assembler code in all
679   circumstances, something which is not true for most assembler
680   programmers) will insert this command to avoid importing each and every
681   routine from the runtime library.
682
683   Example:
684
685   <tscreen><verb>
686         .autoimport     +       ; Switch on auto import
687   </verb></tscreen>
688
689
690 <tag><tt><idx>.BLANK</idx></tt></tag>
691
692   Builtin function. The function evaluates its argument in braces and
693   yields "false" if the argument is non blank (there is an argument), and
694   "true" if there is no argument. As an example, the <tt/.IFBLANK/ statement
695   may be replaced by
696
697   <tscreen><verb>
698         .if     .blank(arg)
699   </verb></tscreen>
700
701
702 <tag><tt><idx>.BSS</idx></tt></tag>
703
704   Switch to the BSS segment. The name of the BSS segment is always "BSS",
705   so this is a shortcut for
706
707   <tscreen><verb>
708         .segment  "BSS"
709   </verb></tscreen>
710
711   See also the <tt/.SEGMENT/ command.
712
713
714 <tag><tt><idx>.BYTE</idx></tt></tag>
715
716   Define byte sized data. Must be followed by a sequence of (byte ranged)
717   expressions or strings.
718
719   Example:
720
721   <tscreen><verb>
722         .byte   "Hello world", $0D, $00
723   </verb></tscreen>
724
725
726 <tag><tt><idx>.CASE</idx></tt></tag>
727
728   Switch on or off case sensitivity on identifiers. The default is off
729   (that is, identifiers are case sensitive), but may be changed by the
730   -i switch on the command line.
731   The command must be followed by a '+' or '-' character to switch the
732   option on or off respectively.
733
734   Example:
735
736   <tscreen><verb>
737         .case   -               ; Identifiers are not case sensitive
738   </verb></tscreen>
739
740
741 <tag><tt><idx>.CODE</idx></tt></tag>
742
743   Switch to the CODE segment. The name of the CODE segment is always
744   "CODE", so this is a shortcut for
745
746   <tscreen><verb>
747         .segment  "CODE"
748   </verb></tscreen>
749
750   See also the <tt/.SEGMENT/ command.
751
752
753 <tag><tt><idx>.CONCAT</idx></tt></tag>
754
755   Builtin function. The function allows to concatenate a list of string
756   constants separated by commas. The result is a string constant that
757   is the concatentation of all arguments. This function is most useful
758   in macros and when used together with the <tt/.STRING/ builtin function.
759   The function may be used in any case where a string constant is
760   expected.
761
762   Example:
763
764   <tscreen><verb>
765         .include        .concat ("myheader", ".", "inc)
766   </verb></tscreen>
767
768   This is the same as the command
769
770   <tscreen><verb>
771         .include        "myheader.inc"
772   </verb></tscreen>
773
774
775 <tag><tt><idx>.CONST</idx></tt></tag>
776
777   Builtin function. The function evaluates its argument in braces and
778   yields "true" if the argument is a constant expression (that is, an
779   expression that yields a constant value at assembly time) and "false"
780   otherwise. As an example, the .IFCONST statement may be replaced by
781
782   <tscreen><verb>
783         .if     .const(a + 3)
784   </verb></tscreen>
785
786
787 <tag><tt><idx>.CPU</idx></tt></tag>
788
789   Reading this pseudo variable will give a constant integer value that
790   tells which instruction set is currently enabled. Possible values are:
791
792   <tscreen><verb>
793         0 -->   6502
794         1 -->   65SC02
795         2 -->   65SC816
796         3 -->   SunPlus SPC
797   </verb></tscreen>
798
799   It may be used to replace the .IFPxx pseudo instructions or to construct
800   even more complex expressions.
801
802   Example:
803
804   <tscreen><verb>
805         .if     (.cpu = 0) .or (.cpu = 1)
806                 txa
807                 pha
808                 tya
809                 pha
810         .else
811                 phx
812                 phy
813         .endif
814   </verb></tscreen>
815
816
817 <tag><tt><idx>.DATA</idx></tt></tag>
818
819   Switch to the DATA segment. The name of the DATA segment is always
820   "DATA", so this is a shortcut for
821
822   <tscreen><verb>
823         .segment  "DATA"
824   </verb></tscreen>
825
826   See also the <tt/.SEGMENT/ command.
827
828
829 <tag><tt><idx>.DBYT</idx></tt></tag>
830
831   Define word sized data with the hi and lo bytes swapped (use <tt/.WORD/ to
832   create word sized data in native 65XX format). Must be followed by a
833   sequence of (word ranged) expressions.
834
835   Example:
836
837   <tscreen><verb>
838         .dbyt   $1234, $4512
839   </verb></tscreen>
840
841   This will emit the bytes
842
843   <tscreen><verb>
844         $12 $34 $45 $12
845   </verb></tscreen>
846
847   into the current segment in that order.
848
849
850 <tag><tt><idx>.DEBUGINFO</idx></tt></tag>
851
852   Switch on or off debug info generation. The default is off (that is,
853   the object file will not contain debug infos), but may be changed by the
854   -g switch on the command line.
855   The command must be followed by a '+' or '-' character to switch the
856   option on or off respectively.
857
858   Example:
859
860   <tscreen><verb>
861         .debuginfo      +       ; Generate debug info
862   </verb></tscreen>
863
864
865 <tag><tt><idx>.DEFINE</idx></tt></tag>
866
867   Start a define style macro definition. The command is followed by an
868   identifier (the macro name) and optionally by a list of formal arguments
869   in braces.
870   See separate section about macros.
871
872
873 <tag><tt><idx>.DEF,</idx> <idx>.DEFINED</idx></tt></tag>
874
875   Builtin function. The function expects an identifier as argument in
876   braces. The argument is evaluated, and the function yields "true" if the
877   identifier is a symbol that is already defined somewhere in the source
878   file up to the current position. Otherwise the function yields false. As
879   an example, the <tt/.IFDEF/ statement may be replaced by
880
881   <tscreen><verb>
882         .if     .defined(a)
883   </verb></tscreen>
884
885
886 <tag><tt><idx>.DWORD</idx></tt></tag>
887
888   Define dword sized data (4 bytes) Must be followed by a sequence of
889   expressions.
890
891   Example:
892
893   <tscreen><verb>
894         .dword  $12344512, $12FA489
895   </verb></tscreen>
896
897
898 <tag><tt><idx>.ELSE</idx></tt></tag>
899
900   Conditional assembly: Reverse the current condition.
901
902
903 <tag><tt><idx>.ELSEIF</idx></tt></tag>
904
905   Conditional assembly: Reverse current condition and test a new one.
906
907
908 <tag><tt><idx>.END</idx></tt></tag>
909
910   Forced end of assembly. Assembly stops at this point, even if the command
911   is read from an include file.
912
913
914 <tag><tt><idx>.ENDIF</idx></tt></tag>
915
916   Conditional assembly: Close a <tt/.IF.../ or <tt/.ELSE/ branch.
917
918
919 <tag><tt><idx>.ENDMAC,</idx> <idx>.ENDMACRO</idx></tt></tag>
920
921   End of macro definition (see separate section).
922
923
924 <tag><tt><idx>.ENDPROC</idx></tt></tag>
925
926   End of local lexical level (see <tt/.PROC/).
927
928
929 <tag><tt><idx>.ENDREP,</idx> <idx>.ENDREPEAT</idx></tt></tag>
930
931   End a <tt/.REPEAT/ block. See the <tt/.REPEAT/ command.
932
933
934 <tag><tt><idx>.ERROR</idx></tt></tag>
935
936   Force an assembly error. The assembler will output an error message
937   preceeded by "User error" and will <em/not/ produce an object file.
938
939   This command may be used to check for initial conditions that must be
940   set before assembling a source file.
941
942   Example:
943
944   <tscreen><verb>
945         .if     foo = 1
946         ...
947         .elseif bar = 1
948         ...
949         .else
950         .error  "Must define foo or bar!"
951         .endif
952   </verb></tscreen>
953
954   See also the <tt/.WARNING/ and <tt/.OUT/ directives.
955
956
957 <tag><tt><idx>.EXITMAC,</idx> <idx>.EXITMACRO</idx></tt></tag>
958
959   Abort a macro expansion immidiately. This command is often useful in
960   recursive macros. See separate chapter about macros.
961
962
963 <tag><tt><idx>.EXPORT</idx></tt></tag>
964
965   Make symbols accessible from other modules. Must be followed by a comma
966   separated list of symbols to export.
967
968   Example:
969
970   <tscreen><verb>
971         .export foo, bar
972   </verb></tscreen>
973
974
975 <tag><tt><idx>.EXPORTZP</idx></tt></tag>
976
977   Make symbols accessible from other modules. Must be followed by a comma
978   separated list of symbols to export. The exported symbols are explicitly
979   marked as zero page symols.
980
981   Example:
982
983   <tscreen><verb>
984         .exportzp  foo, bar
985   </verb></tscreen>
986
987
988 <tag><tt><idx>.FARADDR</idx></tt></tag>
989
990   Define far (24 bit) address data. The command must be followed by a
991   sequence of (not necessarily constant) expressions.
992
993   Example:
994
995   <tscreen><verb>
996         .faraddr        DrawCircle, DrawRectangle, DrawHexagon
997   </verb></tscreen>
998
999
1000 <tag><tt><idx>.FEATURE</idx></tt></tag>
1001
1002   This directive may be used to enable one or more compatibility features
1003   of the assembler. While the use of <tt/.FEATURE/ should be avoided when
1004   possible, it may be useful when porting sources written for other
1005   assemblers. There is no way to switch a feature off, once you have
1006   enabled it, so using
1007
1008   <tscreen><verb>
1009         .FEATURE        xxx
1010   </verb></tscreen>
1011
1012   will enable the feature until end of assembly is reached.
1013
1014   The following features are available:
1015
1016   <descrip>
1017
1018   <tag><tt><idx>dollar_is_pc</idx></tt></tag>
1019
1020     The dollar sign may be used as an alias for the star (`*'), which
1021     gives the value of the current PC in expressions.
1022     Note: Assignment to the pseudo variable is not allowed.
1023
1024   <tag><tt><idx>labels_without_colons</idx></tt></tag>
1025
1026     Allow labels without a trailing colon. These labels are only accepted,
1027     if they start at the beginning of a line (no leading white space).
1028
1029   <tag><tt><idx>loose_string_term</idx></tt></tag>
1030
1031     Accept single quotes as well as double quotes as terminators for string
1032     constants.
1033
1034   <tag><tt><idx>at_in_identifiers</idx></tt></tag>
1035
1036     Accept the at character (`@') as a valid character in identifiers. The
1037     at character is not allowed to start an identifier, even with this
1038     feature enabled.
1039
1040   <tag><tt><idx>dollar_in_identifiers</idx></tt></tag>
1041
1042     Accept the dollar sign (`&dollar;') as a valid character in identifiers. The
1043     at character is not allowed to start an identifier, even with this
1044     feature enabled.
1045
1046   <tag><tt><idx>pc_assignment</idx></tt></tag>
1047
1048     Allow assignments to the PC symbol (`*' or `&dollar;' if dollar_is_pc is
1049     enabled). Such an assignment is handled identical to the <tt/.ORG/
1050     command (which is usually not needed, so just removing the lines with
1051     the assignments may also be an option when porting code written for older
1052     assemblers).
1053
1054   </descrip>
1055
1056
1057 <tag><tt><idx>.FILEOPT,</idx> <idx>.FOPT</idx></tt></tag>
1058
1059   Insert an option string into the object file. There are two forms of
1060   this command, one specifies the option by a keyword, the second
1061   specifies it as a number. Since usage of the second one needs knowledge
1062   of the internal encoding, its use is not recommended and I will only
1063   describe the first form here.
1064
1065   The command is followed by one of the keywords
1066
1067   <tscreen><verb>
1068         author
1069         comment
1070         compiler
1071   </verb></tscreen>
1072
1073   a comma and a string. The option is written into the object file
1074   together with the string value. This is currently unidirectional and
1075   there is no way to actually use these options once they are in the
1076   object file.
1077
1078   Examples:
1079
1080   <tscreen><verb>
1081         .fileopt        comment, "Code stolen from my brother"
1082         .fileopt        compiler, "BASIC 2.0"
1083         .fopt           author, "J. R. User"
1084   </verb></tscreen>
1085
1086
1087 <tag><tt><idx>.GLOBAL</idx></tt></tag>
1088
1089   Declare symbols as global. Must be followed by a comma separated list
1090   of symbols to declare. Symbols from the list, that are defined somewhere
1091   in the source, are exported, all others are imported. An additional
1092   explicit <tt/.IMPORT/ or <tt/.EXPORT/ command for the same symbol is
1093   allowed.
1094
1095   Example:
1096
1097   <tscreen><verb>
1098         .global foo, bar
1099   </verb></tscreen>
1100
1101
1102 <tag><tt><idx>.GLOBALZP</idx></tt></tag>
1103
1104   Declare symbols as global. Must be followed by a comma separated list
1105   of symbols to declare. Symbols from the list, that are defined
1106   somewhere in the source, are exported, all others are imported. An
1107   additional explicit <tt/.IMPORT/ or <tt/.EXPORT/ command for the same
1108   symbol is explicitly allowed. The symbols in the list are explicitly
1109   marked as zero page symols.
1110
1111   Example:
1112
1113   <tscreen><verb>
1114         .globalzp foo, bar
1115   </verb></tscreen>
1116
1117
1118 <tag><tt><idx>.I16</idx></tt></tag>
1119
1120   Valid only in 65816 mode. Switch the index registers to 16 bit.
1121
1122   Note: This command will not emit any code, it will tell the assembler to
1123   create 16 bit operands for immediate operands.
1124
1125   See also the <tt/.SMART/ command.
1126
1127
1128 <tag><tt><idx>.I8</idx></tt></tag>
1129
1130   Valid only in 65816 mode. Switch the index registers to 8 bit.
1131
1132   Note: This command will not emit any code, it will tell the assembler to
1133   create 8 bit operands for immediate operands.
1134
1135   See also the <tt/.SMART/ command.
1136
1137
1138 <tag><tt><idx>.IF</idx></tt></tag>
1139
1140   Conditional assembly: Evalute an expression and switch assembler output
1141   on or off depending on the expression. The expression must be a constant
1142   expression, that is, all operands must be defined.
1143
1144   A expression value of zero evaluates to FALSE, any other value evaluates
1145   to TRUE.
1146
1147
1148 <tag><tt><idx>.IFBLANK</idx></tt></tag>
1149
1150   Conditional assembly: Check if there are any remaining tokens in this
1151   line, and evaluate to FALSE if this is the case, and to TRUE otherwise.
1152   If the condition is not true, further lines are not assembled until
1153   an <tt/.ELSE/, <tt/.ELSEIF/ or <tt/.ENDIF/ directive.
1154
1155   This command is often used to check if a macro parameter was given.
1156   Since an empty macro parameter will evaluate to nothing, the condition
1157   will evaluate to FALSE if an empty parameter was given.
1158
1159   Example:
1160
1161   <tscreen><verb>
1162         .macro     arg1, arg2
1163         .ifblank   arg2
1164                    lda     #arg1
1165         .else
1166                    lda     #arg2
1167         .endif
1168         .endmacro
1169   </verb></tscreen>
1170
1171   See also: <tt/.BLANK/
1172
1173
1174 <tag><tt><idx>.IFCONST</idx></tt></tag>
1175
1176   Conditional assembly: Evaluate an expression and switch assembler output
1177   on or off depending on the constness of the expression.
1178
1179   A const expression evaluates to to TRUE, a non const expression (one
1180   containing an imported or currently undefined symbol) evaluates to
1181   FALSE.
1182
1183   See also: <tt/.CONST/
1184
1185
1186 <tag><tt><idx>.IFDEF</idx></tt></tag>
1187
1188   Conditional assembly: Check if a symbol is defined. Must be followed by
1189   a symbol name. The condition is true if the the given symbol is already
1190   defined, and false otherwise.
1191
1192   See also: <tt/.DEFINED/
1193
1194
1195 <tag><tt><idx>.IFNBLANK</idx></tt></tag>
1196
1197   Conditional assembly: Check if there are any remaining tokens in this
1198   line, and evaluate to TRUE if this is the case, and to FALSE otherwise.
1199   If the condition is not true, further lines are not assembled until
1200   an <tt/.ELSE/, <tt/.ELSEIF/ or <tt/.ENDIF/ directive.
1201
1202   This command is often used to check if a macro parameter was given.
1203   Since an empty macro parameter will evaluate to nothing, the condition
1204   will evaluate to FALSE if an empty parameter was given.
1205
1206   Example:
1207
1208   <tscreen><verb>
1209         .macro     arg1, arg2
1210                    lda     #arg1
1211         .ifnblank  arg2
1212                    lda     #arg2
1213         .endif
1214         .endmacro
1215   </verb></tscreen>
1216
1217   See also: <tt/.BLANK/
1218
1219
1220 <tag><tt><idx>.IFNDEF</idx></tt></tag>
1221
1222   Conditional assembly: Check if a symbol is defined. Must be followed by
1223   a symbol name. The condition is true if the the given symbol is not
1224   defined, and false otherwise.
1225
1226   See also: <tt/.DEFINED/
1227
1228
1229 <tag><tt><idx>.IFNREF</idx></tt></tag>
1230
1231   Conditional assembly: Check if a symbol is referenced. Must be followed
1232   by a symbol name. The condition is true if if the the given symbol was
1233   not referenced before, and false otherwise.
1234
1235   See also: <tt/.REFERENCED/
1236
1237
1238 <tag><tt><idx>.IFP02</idx></tt></tag>
1239
1240   Conditional assembly: Check if the assembler is currently in 6502 mode
1241   (see <tt/.P02/ command).
1242
1243
1244 <tag><tt><idx>.IFP816</idx></tt></tag>
1245
1246   Conditional assembly: Check if the assembler is currently in 65816 mode
1247   (see <tt/.P816/ command).
1248
1249
1250 <tag><tt><idx>.IFPC02</idx></tt></tag>
1251
1252   Conditional assembly: Check if the assembler is currently in 65C02 mode
1253   (see <tt/.PC02/ command).
1254
1255
1256 <tag><tt><idx>.IFREF</idx></tt></tag>
1257
1258   Conditional assembly: Check if a symbol is referenced. Must be followed
1259   by a symbol name. The condition is true if if the the given symbol was
1260   referenced before, and false otherwise.
1261
1262   This command may be used to build subroutine libraries in include files
1263   (you may use separate object modules for this purpose too).
1264
1265   Example:
1266
1267   <tscreen><verb>
1268         .ifref  ToHex                   ; If someone used this subroutine
1269         ToHex:  tay                     ; Define subroutine
1270                 lda     HexTab,y
1271                 rts
1272         .endif
1273   </verb></tscreen>
1274
1275   See also: <tt/.REFERENCED/
1276
1277
1278 <tag><tt><idx>.IMPORT</idx></tt></tag>
1279
1280   Import a symbol from another module. The command is followed by a comma
1281   separated list of symbols to import.
1282
1283   Example:
1284
1285   <tscreen><verb>
1286         .import foo, bar
1287   </verb></tscreen>
1288
1289
1290 <tag><tt><idx>.IMPORTZP</idx></tt></tag>
1291
1292   Import a symbol from another module. The command is followed by a comma
1293   separated list of symbols to import. The symbols are explicitly imported
1294   as zero page symbols (that is, symbols with values in byte range).
1295
1296   Example:
1297
1298   <tscreen><verb>
1299         .includezp  foo, bar
1300   </verb></tscreen>
1301
1302
1303 <tag><tt><idx>.INCBIN</idx></tt></tag>
1304
1305   Include a file as binary data. The command expects a string argument
1306   that is the name of a file to include literally in the current segment.
1307
1308   Example:
1309
1310   <tscreen><verb>
1311         .incbin         "sprites.dat"
1312   </verb></tscreen>
1313
1314
1315 <tag><tt><idx>.INCLUDE</idx></tt></tag>
1316
1317   Include another file. Include files may be nested up to a depth of 16.
1318
1319   Example:
1320
1321   <tscreen><verb>
1322         .include        "subs.inc"
1323   </verb></tscreen>
1324
1325
1326 <tag><tt><idx>.LEFT</idx></tt></tag>
1327
1328   Builtin function. Extracts the left part of a given token list.
1329
1330   Syntax:
1331
1332   <tscreen><verb>
1333         .LEFT (&lt;int expr&gt;, &lt;token list&gt;)
1334   </verb></tscreen>
1335
1336   The first integer expression gives the number of tokens to extract from
1337   the token list. The second argument is the token list itself.
1338
1339   Example:
1340
1341   To check in a macro if the given argument has a '#' as first token
1342   (immidiate addressing mode), use something like this:
1343
1344   <tscreen><verb>
1345         .macro  ldax    arg
1346                 ...
1347                 .if (.match (.left (1, arg), #))
1348
1349                 ; ldax called with immidiate operand
1350                 ...
1351
1352                 .endif
1353                 ...
1354         .endmacro
1355   </verb></tscreen>
1356
1357   See also the <tt/.MID/ and <tt/.RIGHT/ builtin functions.
1358
1359
1360 <tag><tt><idx>.LINECONT</idx></tt></tag>
1361
1362   Switch on or off line continuations using the backslash character
1363   before a newline. The option is off by default.
1364   Note: Line continuations do not work in a comment. A backslash at the
1365   end of a comment is treated as part of the comment and does not trigger
1366   line continuation.
1367   The command must be followed by a '+' or '-' character to switch the
1368   option on or off respectively.
1369
1370   Example:
1371
1372   <tscreen><verb>
1373         .linecont       +               ; Allow line continuations
1374
1375         lda     \
1376                 #$20                    ; This is legal now
1377   </verb></tscreen>
1378
1379
1380 <tag><tt><idx>.LIST</idx></tt></tag>
1381
1382   Enable output to the listing. The command must be followed by a boolean
1383   switch ("on", "off", "+" or "-") and will enable or disable listing
1384   output.
1385   The option has no effect if the listing is not enabled by the command line
1386   switch -l. If -l is used, an internal counter is set to 1. Lines are output
1387   to the listing file, if the counter is greater than zero, and suppressed if
1388   the counter is zero. Each use of <tt/.LIST/ will increment or decrement the
1389   counter.
1390
1391   Example:
1392
1393   <tscreen><verb>
1394         .list   on              ; Enable listing output
1395   </verb></tscreen>
1396
1397
1398 <tag><tt><idx>.LISTBYTES</idx></tt></tag>
1399
1400   Set, how many bytes are shown in the listing for one source line. The
1401   default is 12, so the listing will show only the first 12 bytes for any
1402   source line that generates more than 12 bytes of code or data.
1403   The directive needs an argument, which is either "unlimited", or an
1404   integer constant in the range 4..255.
1405
1406   Examples:
1407
1408   <tscreen><verb>
1409         .listbytes      unlimited       ; List all bytes
1410         .listbytes      12              ; List the first 12 bytes
1411         .incbin         "data.bin"      ; Include large binary file
1412   </verb></tscreen>
1413
1414
1415 <tag><tt><idx>.LOCAL</idx></tt></tag>
1416
1417   This command may only be used inside a macro definition. It declares a
1418   list of identifiers as local to the macro expansion.
1419
1420   A problem when using macros are labels: Since they don't change their
1421   name, you get a "duplicate symbol" error if the macro is expanded the
1422   second time. Labels declared with <tt/.LOCAL/ have their name mapped to
1423   an internal unique name (<tt/___ABCD__/) with each macro invocation.
1424
1425   Some other assemblers start a new lexical block inside a macro
1426   expansion. This has some drawbacks however, since that will not allow
1427   <em/any/ symbol to be visible outside a macro, a feature that is sometimes
1428   useful. The <tt/.LOCAL/ command is in my eyes a better way to address
1429   the problem.
1430
1431   You get an error when using <tt/.LOCAL/ outside a macro.
1432
1433
1434 <tag><tt><idx>.LOCALCHAR</idx></tt></tag>
1435
1436   Defines the character that start "cheap" local labels. You may use one
1437   of '@' and '?' as start character. The default is '@'.
1438
1439   Cheap local labels are labels that are visible only between two non
1440   cheap labels. This way you can reuse identifiers like "<tt/loop/" without
1441   using explicit lexical nesting.
1442
1443   Example:
1444
1445   <tscreen><verb>
1446         .localchar      '?'
1447
1448         Clear:  lda     #$00            ; Global label
1449         ?Loop:  sta     Mem,y           ; Local label
1450                 dey
1451                 bne     ?Loop           ; Ok
1452                 rts
1453         Sub:    ...                     ; New global label
1454                 bne     ?Loop           ; ERROR: Unknown identifier!
1455   </verb></tscreen>
1456
1457
1458 <tag><tt><idx>.MACPACK</idx></tt></tag>
1459
1460   Insert a predefined macro package. The command is followed by an
1461   identifier specifying the macro package to insert. Available macro
1462   packages are:
1463
1464         generic         Defines generic macros like add and sub.
1465         longbranch      Defines conditional long jump macros.
1466
1467   Including a macro package twice, or including a macro package that
1468   redefines already existing macros will lead to an error.
1469
1470   Example:
1471
1472   <tscreen><verb>
1473         .macpack        longbranch      ; Include macro package
1474
1475                 cmp     #$20            ; Set condition codes
1476                 jne     Label           ; Jump long on condition
1477   </verb></tscreen>
1478
1479   See separate section about macros packages.
1480
1481
1482 <tag><tt><idx>.MAC,</idx> <idx>.MACRO</idx></tt></tag>
1483
1484   Start a classic macro definition. The command is followed by an identifier
1485   (the macro name) and optionally by a comma separated list of identifiers
1486   that are macro parameters.
1487   See separate section about macros.
1488
1489
1490 <tag><tt><idx>.MATCH</idx></tt></tag>
1491
1492   Builtin function. Matches two token lists against each other. This is
1493   most useful within macros, since macros are not stored as strings, but
1494   as lists of tokens.
1495
1496   The syntax is
1497
1498   <tscreen><verb>
1499         .MATCH(&lt;token list #1&gt;, &lt;token list #2&gt;)
1500   </verb></tscreen>
1501
1502   Both token list may contain arbitrary tokens with the exception of the
1503   terminator token (comma resp. right parenthesis) and
1504
1505   <itemize>
1506   <item>end-of-line
1507   <item>end-of-file
1508   </itemize>
1509
1510   Often a macro parameter is used for any of the token lists.
1511
1512   Please note that the function does only compare tokens, not token
1513   attributes. So any number is equal to any other number, regardless of
1514   the actual value. The same is true for strings. If you need to compare
1515   tokens <em/and/ token attributes, use the <tt/.XMATCH/ function.
1516
1517   Example:
1518
1519   Assume the macro <tt/ASR/, that will shift right the accumulator by one, while
1520   honoring the sign bit. The builtin processor instructions will allow an
1521   optional "A" for accu addressing for instructions like <tt/ROL/ and <tt/ROR/.
1522   We will use the <tt/.MATCH/ function to check for this and print and error
1523   for invalid calls.
1524
1525   <tscreen><verb>
1526         .macro  asr     arg
1527
1528                 .if (.not .blank(arg)) .and (.not .match (arg, a))
1529                 .error "Syntax error"
1530                 .endif
1531
1532                 cmp     #$80            ; Bit 7 into carry
1533                 lsr     a               ; Shit carry into bit 7
1534
1535         .endmacro
1536   </verb></tscreen>
1537
1538   The macro will only accept no arguments, or one argument that must be the
1539   reserved keyword "A".
1540
1541
1542 <tag><tt><idx>.MID</idx></tt></tag>
1543
1544   Builtin function. Takes a starting index, a count and a token list as
1545   arguments. Will return part of the token list.
1546
1547   Syntax:
1548
1549   <tscreen><verb>
1550         .MID (&lt;int expr&gt;, &lt;int expr&gt;, &lt;token list&gt;)
1551   </verb></tscreen>
1552
1553   The first integer expression gives the starting token in the list (the
1554   first token has index 0). The second integer expression gives the number
1555   of tokens to extract from the token list. The third argument is the
1556   token list itself.
1557
1558   Example:
1559
1560   To check in a macro if the given argument has a '<tt/#/' as first token
1561   (immidiate addressing mode), use something like this:
1562
1563     <tscreen><verb>
1564         .macro  ldax    arg
1565                 ...
1566                 .if (.match (.mid (0, 1, arg), #))
1567
1568                 ; ldax called with immidiate operand
1569                 ...
1570
1571                 .endif
1572                 ...
1573         .endmacro
1574   </verb></tscreen>
1575
1576   See also the <tt/.LEFT/ and <tt/.RIGHT/ builtin functions.
1577
1578
1579 <tag><tt><idx>.ORG</idx></tt></tag>
1580
1581   Start a section of absolute code. The command is followed by a constant
1582   expression that gives the new PC counter location for which the code is
1583   assembled. Use <tt/.RELOC/ to switch back to relocatable code.
1584
1585   You may not switch segments while inside a section of absolute code.
1586
1587   Example:
1588
1589   <tscreen><verb>
1590         .org    $7FF            ; Emit code starting at $7FF
1591   </verb></tscreen>
1592
1593
1594 <tag><tt><idx>.OUT</idx></tt></tag>
1595
1596   Output a string to the console without producing an error. This command
1597   is similiar to <tt/.ERROR/, however, it does not force an assembler error
1598   that prevents the creation of an object file.
1599
1600   Example:
1601
1602   <tscreen><verb>
1603         .out    "This code was written by the codebuster(tm)"
1604   </verb></tscreen>
1605
1606   See also the <tt/.WARNING/ and <tt/.ERROR/ directives.
1607
1608
1609 <tag><tt><idx>.P02</idx></tt></tag>
1610
1611   Enable the 6502 instruction set, disable 65C02 and 65816 instructions.
1612   This is the default if not overridden by the <tt/--cpu/ command line
1613   option.
1614
1615
1616 <tag><tt><idx>.P816</idx></tt></tag>
1617
1618   Enable the 65816 instruction set. This is a superset of the 65C02 and
1619   6502 instruction sets.
1620
1621
1622 <tag><tt><idx>.PAGELEN,</idx> <idx>.PAGELENGTH</idx></tt></tag>
1623
1624   Set the page length for the listing. Must be followed by an integer
1625   constant. The value may be "unlimited", or in the range 32 to 127. The
1626   statement has no effect if no listing is generated. The default value
1627   is -1 but may be overridden by the <tt/--pagelength/ command line option.
1628   Beware: Since the listing is generated after assembly is complete, you
1629   cannot use multiple line lengths with one source. Instead, the value
1630   set with the last <tt/.PAGELENGTH/ is used.
1631
1632   Examples:
1633
1634   <tscreen><verb>
1635         .pagelength     66              ; Use 66 lines per listing page
1636
1637         .pagelength     unlimited       ; Unlimited page length
1638   </verb></tscreen>
1639
1640
1641 <tag><tt><idx>.PARAMCOUNT</idx></tt></tag>
1642
1643   This builtin pseudo variable is only available in macros. It is replaced
1644   by the actual number of parameters that were given in the macro
1645   invocation.
1646
1647   Example:
1648
1649   <tscreen><verb>
1650         .macro  foo     arg1, arg2, arg3
1651         .if     .paramcount <> 3
1652         .error  "Too few parameters for macro foo"
1653         .endif
1654         ...
1655         .endmacro
1656   </verb></tscreen>
1657
1658
1659 <tag><tt><idx>.PC02</idx></tt></tag>
1660
1661   Enable the 65C02 instructions set. This instruction set includes all
1662   6502 instructions.
1663
1664
1665 <tag><tt><idx>.PROC</idx></tt></tag>
1666
1667   Start a nested lexical level. All new symbols from now on are in the
1668   local lexical level and are not accessible from outside. Symbols defined
1669   outside this local level may be accessed as long as their names are not
1670   used for new symbols inside the level. Symbols names in other lexical
1671   levels do not clash, so you may use the same names for identifiers. The
1672   lexical level ends when the <tt/.ENDPROC/ command is read. Lexical levels
1673   may be nested up to a depth of 16.
1674
1675   The command may be followed by an identifier, in this case the
1676   identifier is declared in the outer level as a label having the value of
1677   the program counter at the start of the lexical level.
1678
1679   Note: Macro names are always in the global level and in a separate name
1680   space. There is no special reason for this, it's just that I've never
1681   had any need for local macro definitions.
1682
1683   Example:
1684
1685   <tscreen><verb>
1686         .proc   Clear           ; Define Clear subroutine, start new level
1687                 lda     #$00
1688         L1:     sta     Mem,y   ; L1 is local and does not cause a
1689                                 ; duplicate symbol error if used in other
1690                                 ; places
1691                 dey
1692                 bne     L1      ; Reference local symbol
1693                 rts
1694         .endproc                ; Leave lexical level
1695   </verb></tscreen>
1696
1697
1698 <tag><tt><idx>.REF,</idx> <idx>.REFERENCED</idx></tt></tag>
1699
1700   Builtin function. The function expects an identifier as argument in
1701   braces. The argument is evaluated, and the function yields "true" if the
1702   identifier is a symbol that has already been referenced somewhere in the
1703   source file up to the current position. Otherwise the function yields
1704   false. As an example, the <tt/.IFREF/ statement may be replaced by
1705
1706   <tscreen><verb>
1707         .if     .referenced(a)
1708   </verb></tscreen>
1709
1710
1711 <tag><tt><idx>.REPEAT</idx></tt></tag>
1712
1713   Repeat all commands between <tt/.REPEAT/ and <tt/.ENDREPEAT/ a constant
1714   number of times. The command is followed by a constant expression that tells
1715   how many times the commands in the body should get repeated. Optionally, a
1716   comma and an identifier may be specified. If this identifier is found in
1717   the body of the repeat statement, it is replaced by the current repeat
1718   count (starting with zero for the first time the body is repeated).
1719
1720   <tt/.REPEAT/ statements may be nested. If you use the same repeat count
1721   identifier for a nested <tt/.REPEAT/ statement, the one from the inner
1722   level will be used, not the one from the outer level.
1723
1724   Example:
1725
1726   The following macro will emit a string that is "encrypted" in that all
1727   characters of the string are XORed by the value $55.
1728
1729   <tscreen><verb>
1730         .macro  Crypt   Arg
1731                 .repeat strlen(Arg), I
1732                 .byte   strat(Arg, I) .xor $55
1733                 .endrep
1734         .endmacro
1735   </verb></tscreen>
1736
1737
1738 <tag><tt><idx>.RELOC</idx></tt></tag>
1739
1740   Switch back to relocatable mode. See the <tt/.ORG/ command.
1741
1742
1743 <tag><tt><idx>.RES</idx></tt></tag>
1744
1745   Reserve storage. The command is followed by one or two constant
1746   expressions. The first one is mandatory and defines, how many bytes of
1747   storage should be defined. The second, optional expression must by a
1748   constant byte value that will be used as value of the data. If there
1749   is no fill value given, the linker will use the value defined in the
1750   linker configuration file (default: zero).
1751
1752   Example:
1753
1754   <tscreen><verb>
1755         ; Reserve 12 bytes of memory with value $AA
1756         .res    12, $AA
1757   </verb></tscreen>
1758
1759
1760 <tag><tt><idx>.RIGHT</idx></tt></tag>
1761
1762   Builtin function. Extracts the right part of a given token list.
1763
1764   Syntax:
1765
1766   <tscreen><verb>
1767         .RIGHT (&lt;int expr&gt;, &lt;token list&gt;)
1768   </verb></tscreen>
1769
1770   The first integer expression gives the number of tokens to extract from
1771   the token list. The second argument is the token list itself.
1772
1773   See also the <tt/.LEFT/ and <tt/.MID/ builtin functions.
1774
1775
1776 <tag><tt><idx>.RODATA</idx></tt></tag>
1777
1778   Switch to the RODATA segment. The name of the RODATA segment is always
1779   "RODATA", so this is a shortcut for
1780
1781   <tscreen><verb>
1782         .segment  "RODATA"
1783   </verb></tscreen>
1784
1785   The RODATA segment is a segment that is used by the compiler for
1786   readonly data like string constants. See also the <tt/.SEGMENT/ command.
1787
1788
1789 <tag><tt><idx>.SEGMENT</idx></tt></tag>
1790
1791   Switch to another segment. Code and data is always emitted into a
1792   segment, that is, a named section of data. The default segment is
1793   "CODE". There may be up to 254 different segments per object file
1794   (and up to 65534 per executable). There are shortcut commands for
1795   the most common segments ("CODE", "DATA" and "BSS").
1796
1797   The command is followed by a string containing the segment name (there
1798   are some constraints for the name - as a rule of thumb use only those
1799   segment names that would also be valid identifiers). There may also be
1800   an optional attribute separated by a comma. Valid attributes are
1801   "<tt/zeropage/" and "<tt/absolute/".
1802
1803   When specifying a segment for the first time, "absolute" is the
1804   default. For all other uses, the attribute specified the first time
1805   is the default.
1806
1807   "absolute" means that this is a segment with absolute addressing. That
1808   is, the segment will reside somewhere in core memory outside the zero
1809   page. "zeropage" means the opposite: The segment will be placed in the
1810   zero page and direct (short) addressing is possible for data in this
1811   segment.
1812
1813   Beware: Only labels in a segment with the zeropage attribute are marked
1814   as reachable by short addressing. The `*' (PC counter) operator will
1815   work as in other segments and will create absolute variable values.
1816
1817   Example:
1818
1819   <tscreen><verb>
1820         .segment "ROM2"                 ; Switch to ROM2 segment
1821         .segment "ZP2", zeropage        ; New direct segment
1822         .segment "ZP2"                  ; Ok, will use last attribute
1823         .segment "ZP2", absolute        ; Error, redecl mismatch
1824   </verb></tscreen>
1825
1826
1827 <tag><tt><idx>.SMART</idx></tt></tag>
1828
1829   Switch on or off smart mode. The command must be followed by a '+' or
1830   '-' character to switch the option on or off respectively. The default
1831   is off (that is, the assembler doesn't try to be smart), but this
1832   default may be changed by the -s switch on the command line.
1833
1834   In smart mode the assembler will track usage of the <tt/REP/ and <tt/SEP/
1835   instructions in 65816 mode and update the operand sizes accordingly. If
1836   the operand of such an instruction cannot be evaluated by the assembler
1837   (for example, because the operand is an imported symbol), a warning is
1838   issued. Beware: Since the assembler cannot trace the execution flow this
1839   may lead to false results in some cases. If in doubt, use the <tt/.Inn/ and
1840   <tt/.Ann/ instructions to tell the assembler about the current settings.
1841
1842   Example:
1843
1844   <tscreen><verb>
1845         .smart                          ; Be smart
1846         .smart  -                       ; Stop being smart
1847   </verb></tscreen>
1848
1849
1850 <tag><tt><idx>.STRAT</idx></tt></tag>
1851
1852   Builtin function. The function accepts a string and an index as
1853   arguments and returns the value of the character at the given position
1854   as an integer value. The index is zero based.
1855
1856   Example:
1857
1858   <tscreen><verb>
1859         .macro  M       Arg
1860                 ; Check if the argument string starts with '#'
1861                 .if (.strat (Arg, 0) = '#')
1862                 ...
1863                 .endif
1864         .endmacro
1865   </verb></tscreen>
1866
1867
1868 <tag><tt><idx>.STRING</idx></tt></tag>
1869
1870   Builtin function. The function accepts an argument in braces and
1871   converts this argument into a string constant. The argument may be an
1872   identifier, or a constant numeric value.
1873   Since you can use a string in the first place, the use of the function
1874   may not be obvious. However, it is useful in macros, or more complex
1875   setups.
1876
1877   Example:
1878
1879   <tscreen><verb>
1880         ; Emulate other assemblers:
1881         .macro  section name
1882                 .segment        .string(name)
1883         .endmacro
1884   </verb></tscreen>
1885
1886
1887 <tag><tt><idx>.STRLEN</idx></tt></tag>
1888
1889   Builtin function. The function accepts a string argument in braces and
1890   eveluates to the length of the string.
1891
1892   Example:
1893
1894   The following macro encodes a string as a pascal style string with
1895   a leading length byte.
1896
1897   <tscreen><verb>
1898         .macro  PString Arg
1899                 .byte   .strlen(Arg), Arg
1900         .endmacro
1901   </verb></tscreen>
1902
1903
1904 <tag><tt><idx>.TCOUNT</idx></tt></tag>
1905
1906   Builtin function. The function accepts a token list in braces. The
1907   function result is the number of tokens given as argument.
1908
1909   Example:
1910
1911   The <tt/ldax/ macro accepts the '#' token to denote immidiate addressing (as
1912   with the normal 6502 instructions). To translate it into two separate 8 bit
1913   load instructions, the '#' token has to get stripped from the argument:
1914
1915   <tscreen><verb>
1916         .macro  ldax    arg
1917                 .if (.match (.mid (0, 1, arg), #))
1918                 ; ldax called with immidiate operand
1919                 lda     #<(.right (.tcount (arg)-1, arg))
1920                 ldx     #>(.right (.tcount (arg)-1, arg))
1921                 .else
1922                 ...
1923                 .endif
1924         .endmacro
1925   </verb></tscreen>
1926
1927
1928 <tag><tt><idx>.WARNING</idx></tt></tag>
1929
1930   Force an assembly warning. The assembler will output a warning message
1931   preceeded by "User warning". This warning will always be output, even
1932   if other warnings are disabled with the <tt/-W0/ command line option.
1933
1934   This command may be used to output possible problems when assembling
1935   the source file.
1936
1937   Example:
1938
1939   <tscreen><verb>
1940         .macro  jne     target
1941                 .local L1
1942                 .ifndef target
1943                 .warning "Forward jump in jne, cannot optimize!"
1944                 beq     L1
1945                 jmp     target
1946         L1:
1947                 .else
1948                 ...
1949                 .endif
1950         .endmacro
1951   </verb></tscreen>
1952
1953   See also the <tt/.ERROR/ and <tt/.OUT/ directives.
1954
1955
1956 <tag><tt><idx>.WORD</idx></tt></tag>
1957
1958   Define word sized data. Must be followed by a sequence of (word ranged,
1959   but not necessarily constant) expressions.
1960
1961   Example:
1962
1963   <tscreen><verb>
1964         .word   $0D00, $AF13, _Clear
1965   </verb></tscreen>
1966
1967
1968 <tag><tt><idx>.ZEROPAGE</idx></tt></tag>
1969
1970   Switch to the ZEROPAGE segment and mark it as direct (zeropage) segment.
1971   The name of the ZEROPAGE segment is always "ZEROPAGE", so this is a
1972   shortcut for
1973
1974   <tscreen><verb>
1975         .segment  "ZEROPAGE", zeropage
1976   </verb></tscreen>
1977
1978   Because of the "zeropage" attribute, labels declared in this segment are
1979   addressed using direct addressing mode if possible. You <em/must/ instruct
1980   the linker to place this segment somewhere in the address range 0..$FF
1981   otherwise you will get errors.
1982
1983 </descrip>
1984
1985
1986
1987 <sect>Macros
1988
1989 <p>
1990 Macros may be thought of as "parametrized super instructions". Macros are
1991 sequences of tokens that have a name. If that name is used in the source
1992 file, the macro is "expanded", that is, it is replaced by the tokens that
1993 were specified when the macro was defined.
1994
1995 In it's simplest form, a macro does not have parameters. Here's an
1996 example:
1997
1998 <tscreen><verb>
1999         .macro  asr             ; Arithmetic shift right
2000                 cmp     #$80    ; Put bit 7 into carry
2001                 ror             ; Rotate right with carry
2002         .endmacro
2003 </verb></tscreen>
2004
2005 The macro above consists of two real instructions, that are inserted into
2006 the code, whenever the macro is expanded. Macro expansion is simply done
2007 by using the name, like this:
2008
2009 <tscreen><verb>
2010         lda     $2010
2011         asr
2012         sta     $2010
2013 </verb></tscreen>
2014
2015 When using macro parameters, macros can be even more useful:
2016
2017 <tscreen><verb>
2018         .macro  inc16   addr
2019                 clc
2020                 lda     addr
2021                 adc     #$01
2022                 sta     addr
2023                 lda     addr+1
2024                 adc     #$00
2025                 sta     addr+1
2026         .endmacro
2027 </verb></tscreen>
2028
2029 When calling the macro, you may give a parameter, and each occurence of
2030 the name "addr" in the macro definition will be replaced by the given
2031 parameter. So
2032
2033 <tscreen><verb>
2034         inc16   $1000
2035 </verb></tscreen>
2036
2037 will be expanded to
2038
2039 <tscreen><verb>
2040                 clc
2041                 lda     $1000
2042                 adc     #$01
2043                 sta     $1000
2044                 lda     $1000+1
2045                 adc     #$00
2046                 sta     $1000+1
2047 </verb></tscreen>
2048
2049 A macro may have more than one parameter, in this case, the parameters
2050 are separated by commas. You are free to give less parameters than the
2051 macro actually takes in the definition. You may also leave intermediate
2052 parameters empty. Empty parameters are replaced by empty space (that is,
2053 they are removed when the macro is exanded). If you have a look at our
2054 macro definition above, you will see, that replacing the "addr" parameter
2055 by nothing will lead to wrong code in most lines. To help you, writing
2056 macros with a variable parameter list, there are some control commands:
2057
2058 <tt/.IFBLANK/ tests the rest of the line and returns true, if there are any
2059 tokens on the remainder of the line. Since empty parameters are replaced by
2060 nothing, this may be used to test if a given parameter is empty.
2061 <tt/.IFNBLANK/ tests the opposite.
2062
2063 Look at this example:
2064
2065 <tscreen><verb>
2066         .macro  ldaxy   a, x, y
2067         .ifnblank       a
2068                 lda     #a
2069         .endif
2070         .ifnblank       x
2071                 ldx     #x
2072         .endif
2073         .ifnblank       y
2074                 ldy     #y
2075         .endif
2076         .endmacro
2077 </verb></tscreen>
2078
2079 This macro may be called as follows:
2080
2081 <tscreen><verb>
2082         ldaxy   1, 2, 3         ; Load all three registers
2083
2084         ldaxy   1, , 3          ; Load only a and y
2085
2086         ldaxy   , , 3           ; Load y only
2087 </verb></tscreen>
2088
2089 There's another helper command for determining, which macro parameters are
2090 valid: <tt/.PARAMCOUNT/. This command is replaced by the parameter count
2091 given, <em/including/ intermediate empty macro parameters:
2092
2093 <tscreen><verb>
2094         ldaxy   1               ; .PARAMCOUNT = 1
2095         ldaxy   1,,3            ; .PARAMCOUNT = 3
2096         ldaxy   1,2             ; .PARAMCOUNT = 2
2097         ldaxy   1,              ; .PARAMCOUNT = 2
2098         ldaxy   1,2,3           ; .PARAMCOUNT = 3
2099 </verb></tscreen>
2100
2101 Macros may be used recursively:
2102
2103 <tscreen><verb>
2104         .macro  push    r1, r2, r3
2105                 lda     r1
2106                 pha
2107         .if     .paramcount > 1
2108                 push    r2, r3
2109         .endif
2110         .endmacro
2111 </verb></tscreen>
2112
2113 There's also a special macro to help writing recursive macros:
2114 <tt/.EXITMACRO/. This command will stop macro expansion immidiately:
2115
2116 <tscreen><verb>
2117         .macro  push    r1, r2, r3, r4, r5, r6, r7
2118         .ifblank        r1
2119                 ; First parameter is empty
2120                 .exitmacro
2121         .else
2122                 lda     r1
2123                 pha
2124         .endif
2125                 push    r2, r3, r4, r5, r6, r7
2126         .endmacro
2127 </verb></tscreen>
2128
2129 When expanding this macro, the expansion will push all given parameters
2130 until an empty one is encountered. The macro may be called like this:
2131
2132 <tscreen><verb>
2133         push    $20, $21, $32           ; Push 3 ZP locations
2134         push    $21                     ; Push one ZP location
2135 </verb></tscreen>
2136
2137 Now, with recursive macros, <tt/.IFBLANK/ and <tt/.PARAMCOUNT/, what else do
2138 you need? Have a look at the inc16 macro above. Here is it again:
2139
2140 <tscreen><verb>
2141         .macro  inc16   addr
2142                 clc
2143                 lda     addr
2144                 adc     #$01
2145                 sta     addr
2146                 lda     addr+1
2147                 adc     #$00
2148                 sta     addr+1
2149         .endmacro
2150 </verb></tscreen>
2151
2152 If you have a closer look at the code, you will notice, that it could be
2153 written more efficiently, like this:
2154
2155 <tscreen><verb>
2156         .macro  inc16   addr
2157                 clc
2158                 lda     addr
2159                 adc     #$01
2160                 sta     addr
2161                 bcc     Skip
2162                 inc     addr+1
2163         Skip:
2164         .endmacro
2165 </verb></tscreen>
2166
2167 But imagine what happens, if you use this macro twice? Since the label
2168 "Skip" has the same name both times, you get a "duplicate symbol" error.
2169 Without a way to circumvent this problem, macros are not as useful, as
2170 they could be. One solution is, to start a new lexical block inside the
2171 macro:
2172
2173 <tscreen><verb>
2174         .macro  inc16   addr
2175         .proc
2176                 clc
2177                 lda     addr
2178                 adc     #$01
2179                 sta     addr
2180                 bcc     Skip
2181                 inc     addr+1
2182         Skip:
2183         .endproc
2184         .endmacro
2185 </verb></tscreen>
2186
2187 Now the label is local to the block and not visible outside. However,
2188 sometimes you want a label inside the macro to be visible outside. To make
2189 that possible, there's a new command that's only usable inside a macro
2190 definition: <tt/.LOCAL/. <tt/.LOCAL/ declares one or more symbols as local to
2191 the macro expansion. The names of local variables are replaced by a unique
2192 name in each separate macro expansion. So we could also solve the problem
2193 above by using <tt/.LOCAL/:
2194
2195 <tscreen><verb>
2196         .macro  inc16   addr
2197                 .local  Skip            ; Make Skip a local symbol
2198                 clc
2199                 lda     addr
2200                 adc     #$01
2201                 sta     addr
2202                 bcc     Skip
2203                 inc     addr+1
2204         Skip:                           ; Not visible outside
2205         .endmacro
2206 </verb></tscreen>
2207
2208 Starting with version 2.5 of the assembler, there is a second macro type
2209 available: C style macros using the <tt/.DEFINE/ directive. These macros are
2210 similar to the classic macro type speified above, but behaviour is sometimes
2211 different:
2212
2213 <itemize>
2214
2215 <item>  Macros defined with <tt/.DEFINE/ may not span more than a line. You
2216         may use line continuation (see <tt/.LINECONT/) to spread the
2217         definition over more than one line for increased readability, but the
2218         macro itself does not contain an end-of-line token.
2219
2220 <item>  Macros defined with <tt/.DEFINE/ share the name space with classic
2221         macros, but they are detected and replaced at the scanner level. While
2222         classic macros may be used in every place, where a mnemonic or other
2223         directive is allowed, <tt/.DEFINE/ style macros are allowed anywhere
2224         in a line. So they are more versatile in some situations.
2225
2226 <item>  <tt/.DEFINE/ style macros may take parameters. While classic macros
2227         may have empty parameters, this is not true for <tt/.DEFINE/ style
2228         macros. For this macro type, the number of actual parameters must
2229         match exactly the number of formal parameters.
2230
2231         To make this possible, formal parameters are enclosed in braces when
2232         defining the macro. If there are no parameters, the empty braces may
2233         be omitted.
2234
2235 <item>  Since <tt/.DEFINE/ style macros may not contain end-of-line tokens,
2236         there are things that cannot be done. They may not contain several
2237         processor instructions for example. So, while some things may be done
2238         with both macro types, each type has special usages. The types
2239         complement each other.
2240
2241 </itemize>
2242
2243 Let's look at a few examples to make the advantages and disadvantages
2244 clear.
2245
2246 To emulate assemblers that use "<tt/EQU/" instead of "<tt/=/" you may use the
2247 following <tt/.DEFINE/:
2248
2249 <tscreen><verb>
2250         .define EQU     =
2251
2252         foo     EQU     $1234           ; This is accepted now
2253 </verb></tscreen>
2254
2255 You may use the directive to define string constants used elsewhere:
2256
2257 <tscreen><verb>
2258         ; Define the version number
2259         .define VERSION         "12.3a"
2260
2261         ; ... and use it
2262         .asciiz VERSION
2263 </verb></tscreen>
2264
2265 Macros with parameters may also be useful:
2266
2267 <tscreen><verb>
2268         .define DEBUG(message)  .out    message
2269
2270         DEBUG   "Assembling include file #3"
2271 </verb></tscreen>
2272
2273 Note that, while formal parameters have to be placed in braces, this is
2274 not true for the actual parameters. Beware: Since the assembler cannot
2275 detect the end of one parameter, only the first token is used. If you
2276 don't like that, use classic macros instead:
2277
2278 <tscreen><verb>
2279         .macro  message
2280                 .out    message
2281         .endmacro
2282 </verb></tscreen>
2283
2284 (This is an example where a problem can be solved with both macro types).
2285
2286
2287
2288 <sect>Macro packages
2289
2290 <p>
2291 Using the <tt/.MACPACK/ directive, predefined macro packages may be included
2292 with just one command. Available macro packages are:
2293
2294 <descrip>
2295
2296 <tag><tt><idx>generic</idx></tt></tag>
2297
2298   This macro package defines macros that are useful in almost any program.
2299   Currently, two macros are defined:
2300
2301   <tscreen><verb>
2302         .macro  add     Arg
2303                 clc
2304                 adc     Arg
2305         .endmacro
2306
2307         .macro  sub     Arg
2308                 sec
2309                 sbc     Arg
2310         .endmacro
2311   </verb></tscreen>
2312
2313
2314 <tag><tt><idx>longbranch</idx></tt></tag>
2315
2316   This macro package defines long conditional jumps. They are named like the
2317   short counterpart but with the 'b' replaced by a 'j'. Here is a sample
2318   definition for the "<tt/jeq/" macro, the other macros are built using the
2319   same scheme:
2320
2321   <tscreen><verb>
2322         .macro  jeq     Target
2323                 .if     .def(Target) .and ((*+2)-(Target) <= 127)
2324                 beq     Target
2325                 .else
2326                 bne     *+5
2327                 jmp     Target
2328                 .endif
2329         .endmacro
2330   </verb></tscreen>
2331
2332   All macros expand to a short branch, if the label is already defined (back
2333   jump) and is reachable with a short jump. Otherwise the macro expands to a
2334   conditional branch with the branch condition inverted, followed by an
2335   absolute jump to the actual branch target.
2336
2337   The package defines the following macros:
2338
2339   <tscreen><verb>
2340         jeq, jne, jmi, jpl, jcs, jcc, jvs, jvc
2341   </verb></tscreen>
2342
2343 </descrip>
2344
2345
2346 <sect>Bugs/Feedback<p>
2347
2348 If you have problems using the assembler, if you find any bugs, or if
2349 you're doing something interesting with the assembler, I would be glad to
2350 hear from you. Feel free to contact me by email
2351 (<htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org">).
2352
2353
2354
2355 <sect>Copyright<p>
2356
2357 ca65 (and all cc65 binutils) are (C) Copyright 1998-2000 Ullrich von
2358 Bassewitz. For usage of the binaries and/or sources the following
2359 conditions do apply:
2360
2361 This software is provided 'as-is', without any expressed or implied
2362 warranty.  In no event will the authors be held liable for any damages
2363 arising from the use of this software.
2364
2365 Permission is granted to anyone to use this software for any purpose,
2366 including commercial applications, and to alter it and redistribute it
2367 freely, subject to the following restrictions:
2368
2369 <enum>
2370 <item>  The origin of this software must not be misrepresented; you must not
2371         claim that you wrote the original software. If you use this software
2372         in a product, an acknowledgment in the product documentation would be
2373         appreciated but is not required.
2374 <item>  Altered source versions must be plainly marked as such, and must not
2375         be misrepresented as being the original software.
2376 <item>  This notice may not be removed or altered from any source
2377         distribution.
2378 </enum>
2379
2380
2381
2382 </article>
2383
2384
2385