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