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