]> Shamusworld >> Repos - rmac/blob - docs/rmac.rst
Produce error when ".opt +o" or ".opt ~o" is encountered. Also, small doc additions
[rmac] / docs / rmac.rst
1 RMAC
2 ----
3 68000 Macro Assembler
4 =====================
5 Reference Manual
6 ================
7 version 2.0.21
8 ==============
9
10 © and notes
11 ===========
12
13 *NOTE: Every effort has been made to ensure the accuracy and robustness of this
14 manual and the associated software. However, because Reboot is constantly improving
15 and updating its computer software, it is unable to guarantee
16 the accuracy of printed or duplicated material after the date of publication and
17 disclaims liability for changes, errors or omissions.*
18
19
20 *Copyright © 2011-2020, Reboot*
21
22 *All rights reserved.*
23
24 *Reboot Document number F00000K-001 Rev. A.*
25
26 Contents
27 ========
28
29 .. contents::
30
31 Introduction
32 ============
33
34 Introduction
35 ''''''''''''
36 This document describes RMAC, a fast macro assembler for the 68000. RMAC currently
37 runs on the any POSIX compatible platform and the Atari ST. It was initially written
38 at Atari Corporation by programmers who needed a high performance assembler
39 for their work. Then, more than 20 years later, because there was still a need for
40 such an assembler and what was available wasn't up to expectations, Subqmod
41 and eventually Reboot continued work on the freely released source, adding Jaguar
42 extensions and fixing bugs. Over time the assembler has been extended by adding
43 support for Motorola's 68020/30/40/60, 68881/2, DSP56001 CPUs as well as Atari's
44 Object Processor (OP) found on the Atari Jaguar.
45
46 RMAC is intended to be used by programmers who write mostly in assembly language.
47 It was not originally a back-end to a C compiler, therefore it
48 has creature comfort that are usually neglected in such back-end assemblers. It
49 supports include files, macros, symbols with limited scope, some limited control
50 structures, and other features. RMAC is also blindingly fast, another feature
51 often sadly and obviously missing in today's assemblers.\ [1]_
52
53 RMAC is not entirely compatible with the AS68 assembler provided with
54 the original Atari ST Developer's Kit, but most changes are minor and a few minutes
55 with an editor should allow you to assemble your current source files. If you are an
56 AS68 user, before you leap into the unknown please read the section on Notes for
57 AS68 Users.
58
59 .. [1] It processes 30,000 lines a minute on a lightly loaded VAX 11/780; maybe 40,000 on a 520-ST with an SH-204 hard disk. Yet it could be sped up even more with some effort and without resorting to assembly language; C doesn't have to be slow!
60
61 `Getting Started`_
62 ''''''''''''''''''
63
64
65 * The distribution disk contains a file called README that you should read.
66   This file contains important nays about the contents of the distribution disk
67   and summarizes the most recent changes to the tools.
68
69 * Hard disk users can simply copy the executable files to their work or binary
70   directories. People with floppy disks can copy the executables to ramdisks,
71   install the assembler with the -q option, or even work right off of the floppies.
72
73 * You will need an editor that can produce "normal" format text files. Micro
74   Emacs will work well, as will most other commercial program editors, but not
75   most word processors (such as First Word or Microsoft Write).
76
77 * You will probably want to examine or get a listing of the file "ATARI.S". It
78   contains lots of definitions for the Atari ST, including BIOS variables, most
79   BIOS, XBIOS and GEMDOS traps, and line-A equates. We (or you) could
80   split the file up into pieces (a file for line-A equates, a file for hardware and
81   BIOS variables and so on), but RMAC is so fast that it doesn't matter
82   much.
83
84 * Read the rest of the manual, especially the first two chapters on The Command Line and Using RMAC.
85   Also, `Notes for migrating from other 68000 assemblers`_ will save a lot of time and frustration in the long run.
86   The distribution disk contains example
87   programs that you can look at, assemble and modify.
88
89 `The Command Line`_
90 '''''''''''''''''''
91
92 The assembler is called "**rmac**" or "**rmac.prg**". The command line takes the form:
93
94                           **rmac** [*switches*] [*files* ...]
95
96 A command line consists of any number of switches followed by the names of files
97 to assemble. A switch is specified with a dash (**-**) followed immediately by a key
98 character. Key characters are not case-sensitive, so "**-d**" is the same as "**-D**". Some
99 switches accept (or require) arguments to immediately follow the key character,
100 with no spaces in between.
101
102 Switch order is important. Command lines are processed from left to right in
103 one pass, and switches usually take effect when they are encountered. In general it
104 is best to specify all switches before the names of any input files.
105
106 If the command line is entirely empty then RMAC prints a copyright message
107 along with usage info and exit.
108
109 Input files are assumed to have the extension "**.s**"; if a filename has no extension
110 (i.e. no dot) then "**.s**" will be appended to it. More than one source filename may be
111 specified: the files are assembled into one object file, as if they were concatenated.
112
113 RMAC normally produces object code in "**file.o**" if "**file.s**" is the first
114 input filename. If the first input file is a special character device, the output name
115 is noname.o. The **-o** switch (see below) can be used change the output file name.
116
117
118 ===================  ===========
119 Switch               Description
120 ===================  ===========
121 -dname\ *[=value]*   Define symbol, with optional value.
122 -e\ *[file[.err]]*   Direct error messages to the specified file.
123 -fa                  ALCYON output object file format (implied when **-ps** is enabled).
124 -fb                  BSD COFF output object file format.
125 -fe                  ELF output object file format.
126 -fr                  Absolute address. Source code is required to have one .org statement.
127 -fx                  Atari 800 com/exe/xex output object file format.
128 -i\ *path*           Set include-file directory search path.
129 -l\ *[file[prn]]*    Construct and direct assembly listing to the specified file.
130 -l\ *\*[filename]*   Create an output listing file without pagination
131 -m\ *cpu*            Switch CPU type
132
133                       `68000 - MC68000`
134
135                       `68020 - MC68020`
136
137                       `68030 - MC68030`
138
139                       `68040 - MC68040`
140
141                       `68060 - MC68060`
142
143                       `68881 - MC68881`
144
145                       `68882 - MC68882`
146
147                       `56001 - DSP56001`
148
149                       `6502 - MOS 6502`
150
151                       `tom - Jaguar GPU JRISC`
152
153                       `jerry - Jaguar DSP JRISC`
154
155                       -o\ *file[.o]*       Direct object code output to the specified file.
156 +/~oall              Turn all optimisations on/off
157 +o\ *0-10*/*p*       Enable specific optimisation
158 ~o\ *0-10*/*p*       Disable specific optimisation
159
160                       `0: Absolute long adddresses to word (on by default)`
161                       
162                       `1: move.l #x,Dn/An to moveq (on by default)`
163
164                       `2: Word branches to short (on by default)`
165                       
166                       `3: Outer displacement 0(An) to (An)`
167
168                       `4: lea to addq`
169
170                       `5: 68020+ Absolute long base/outer displacement to word`
171
172                       `6: Convert null short branches to NOP`
173
174                       `7: Convert clr.l Dn to moveq #0,Dn`
175
176                       `8: Convert adda.w/l #x,Dy to addq.w/l #x,Dy`
177
178                       `9: Convert adda.w/l #x,Dy to lea x(Dy),Dy`
179
180                       `p: Force PC-Relative mode (alternative: o10)`
181 -p                   Produce an executable (**.prg**) output file.
182 -ps                  Produce an executable (**.prg**) output file with symbols.
183 -px                  Produce an executable (**.prg**) output file with extended symbols.
184 -q                   Make RMAC resident in memory (Atari ST only).
185 -r *size*            automatically pad the size of each
186                      segment in the output file until the size is an integral multiple of the
187                      specified boundary. Size is a letter that specifies the desired boundary.
188                      
189                       `-rw Word (2 bytes, default alignment)`
190
191                       `-rl Long (4 bytes)`
192
193                       `-rp Phrase (8 bytes)`
194                       
195                       `-rd Double Phrase (16 bytes)`
196                       
197                       `-rq Quad Phrase (32 bytes)`
198 -s                   Warn about unoptimized long branches and applied optimisations.
199 -u                   Force referenced and undefined symbols global.
200 -v                   Verbose mode (print running dialogue).
201 -x                   Turn on debugging mode
202 -yn                  Set listing page size to n lines.
203 file\ *[s]*          Assemble the specified file.
204 ===================  ===========
205
206 The switches are described below. A summary of all the switches is given in
207 the table.
208
209 **-d**
210  The **-d** switch permits symbols to be defined on the command line. The name
211  of the symbol to be defined immediately follows the switch (no spaces). The
212  symbol name may optionally be followed by an equals sign (=) and a decimal
213  number. If no value is specified the symbol's value is zero. The symbol at-
214  tributes are "defined, not referenced, and absolute". This switch is most useful
215  for enabling conditionally-assembled debugging code on the command line; for
216  example:
217
218   ::
219
220       -dDEBUG -dLoopCount=999 -dDebugLevel=55
221
222 **-e**
223  The -e switch causes RMAC to send error messages to a file, instead of the
224  console. If a filename immediately follows the switch character, error messages
225  are written to the specified file. If no filename is specified, a file is created with
226  the default extension "**.err**" and with the root name taken from the first input
227  file name (e.g. error messages are written to "**file.err**" if "**file**" or "**file.s**" is
228  the first input file name). If no errors are encountered, then no error listing
229  file is created. Beware! If an assembly produces no errors, any error file from
230  a previous assembly is not removed.
231
232 **-i**
233  The **-i** switch allows automatic directory searching for include files. A list of
234  semi-colon seperated directory search paths may be mentioned immediately
235  following the switch (with no spaces anywhere). For example:
236
237   ::
238
239          -im:;c:include;c:include\sys
240
241  will cause the assembler to search the current directory of device **M**, and the
242  directories include and include\sys on drive **C**. If *-i* is not specified, and the
243  enviroment variable "**RMACPATH**" exists, its value is used in the same manner.
244  For example, users of the Mark Williams shell could put the following line in
245  their profile script to achieve the same result as the **-i** example above:
246
247   ::
248
249       setenv RMACPATH="m:;c:include;c:include\sys"
250 **-l**
251  The -l switch causes RMAC to generate an assembly listing file. If a file-
252  name immediately follows the switch character, the listing is written to the
253  specified file. If no filename is specified, then a listing file is created with the
254  default extension "**.prn**" and with the root name taken from the first input file
255  name (e.g. the listing is written to "**file.prn**" if "**file**" or "**file.s**" is the first
256  input file name).
257 **-o**
258  The -o switch causes RMAC to write object code on the specified file. No
259  default extension is applied to the filename. For historical reasons the filename
260  can also be seperated from the switch with a space (e.g. "**-o file**").
261
262 **-p**
263
264 **-ps**
265  The **-p** and **-ps** switches cause RMAC to produce an Atari ST executable
266  file with the default extension of "**.prg**". If there are any external references
267  at the end of the assembly, an error message is emitted and no executable file
268  is generated. The **-p** switch does not write symbols to the executable file. The
269  **-ps** switch includes symbols (Alcyon format) in the executable file.
270 **-q**
271   The **-q** switch is aimed primarily at users of floppy-disk-only systems. It causes
272   RMAC to install itself in memory, like a RAMdisk. Then the program
273   **m.prg** (which is very short - less than a sector) can be used instead of
274   **mac.prg**, which can take ten or twelve seconds to load. (**NOTE** not available
275   for now, might be re-implemented in the future).
276 **-s**
277   The **-s** switch causes RMAC to generate a list of unoptimized forward
278   branches as warning messages. This is used to point out branches that could
279   have been short (e.g. "bra" could be "bra.s").
280 **-u**
281   The **-u** switch takes effect at the end of the assembly. It forces all referenced
282   and undefined symbols to be global, exactly as if they had been made global
283   with a **.extern** or **.globl** directive. This can be used if you have a lot of
284   external symbols, and you don't feel like declaring them all external.
285 **-v**
286   The **-v** switch turns on a "verbose" mode in which RMAC prints out (for
287   example) the names of the files it is currently processing. Verbose mode is
288   automatically entered when RMAC prompts for input with a star.
289 **-y**
290   The **-y** switch, followed immediately by a decimal number (with no intervening
291   space), sets the number of lines in a page. RMAC will produce *N* lines
292   before emitting a form-feed. If *N* is missing or less than 10 an error message is
293   generated.
294
295 `Using RMAC`_
296 ===============
297
298 Let's assemble and link some example programs. These programs are included
299 on the distribution disk in the "**EXAMPLES**" directory - you should copy them to
300 your work area before continuing. In the following examples we adopt the conven-
301 tions that the shell prompt is a percent sign (%) and that your input (the stuff you
302 type) is presented in **bold face**.
303
304 If you have been reading carefully, you know that RMAC can generate
305 an executable file without linking. This is useful for making small, stand alone
306 programs that don't require externals or library routines. For example, the following
307 two commands:
308
309  ::
310
311       % rmac examples
312       % aln -s example.s
313
314 could be replaced by the single command:
315
316  ::
317
318       % rmac -ps example.s
319
320 since you don't need the linker for stand-alone object files.
321
322 Successive source files named in the command line are are concatenated, as in
323 this example, which assembles three files into a single executable, as if they were
324 one big file:
325
326  ::
327
328       % rmac -p bugs shift images
329
330 Of course you can get the same effect by using the **.include** directive, but sometimes
331 it is convenient to do the concatenation from the command line.
332
333    Here we have an unbelievably complex command line:
334
335     ::
336
337       % rmac -lzorf -y95 -o tmp -ehack -Ddebug=123 -ps example
338
339 This produces a listing on the file called "**zorf.prn**" with 95 lines per page, writes
340 the executable code (with symbols) to a file called "**tmp.prg**", writes an error listing
341 to the file "**hack.err**", specifies an include-file path that includes the current
342 directory on the drive "**M:**," defines the symbol "**debug**" to have the value 123, and
343 assembles the file "**example.s**". (Take a deep breath - you got all that?)
344
345 One last thing. If there are any assembly errors, RMAC will terminate
346 with an exit code of 1. If the assembly succeeds (no errors, although there may be
347 warnings) the exit code will be 0. This is primarily for use with "make" utilities.
348
349 Things You Should Be Aware Of
350 '''''''''''''''''''''''''''''
351 RMAC is a one pass assembler. This means that it gets all of its work done by
352 reading each source file exactly once and then "back-patching" to fix up forward
353 references. This one-pass nature is usually transparent to the programmer, with
354 the following important exceptions:
355
356  * In listings, the object code for forward references is not shown. Instead, lower-
357    case "xx"s are displayed for each undefined byte, as in the following example:
358
359     ::
360
361      60xx      1: bra.s.2  ;forward branch
362      xxxxxxxx     dc.l .2  ;forward reference
363      60FE     .2: bra.s.2  ;backward reference
364
365  * Forward branches (including **BSR**\s) are never optimized to their short forms.
366    To get a short forward branch it is necessary to explicitly use the ".s" suffix in
367    the source code.
368  * Error messages may appear at the end of the assembly, referring to earlier source
369    lines that contained undefined symbols.
370  * All object code generated must fit in memory. Running out of memory is a
371    fatal error that you must deal with by splitting up your source files, re-sizing
372    or eliminating memory-using programs such as ramdisks and desk accessories,
373    or buying more RAM.
374
375 Forward Branches
376 ''''''''''''''''
377 RMAC does not optimize forward branches for you, but it will tell you about
378 them if you use the -s (short branch) option:
379
380  ::
381
382      % mac -s example.s
383      "example.s", line 20: warning: unoptimized short branch
384
385 With the -e option you can redirect the error output to a file, and determine by
386 hand (or editor macros) which forward branches are safe to explicitly declare short.
387
388 `Notes for migrating from other 68000 assemblers`_
389 ''''''''''''''''''''''''''''''''''''''''''''''''''
390 RMAC is not entirely compatible with the other popular assemblers
391 like Devpac or vasm. This section
392 outlines the major differences. In practice, we have found that very few changes are
393 necessary to make other assemblers' source code assemble.
394
395 * A semicolon (;) must be used to introduce a comment,
396   except that a star (*)
397   may be used in the first column. AS68 treated anything following the operand
398   field, preceeded by whitespace, as a comment. (RMAC treats a star that
399   is not in column 1 as a multiplication operator).
400 * Labels require colons (even labels that begin in column 1).
401
402 * Conditional assembly directives are called **if**, **else** and **endif**.
403   Devpac and vasm call these
404   **ifne**, **ifeq** (etc.), and **endc**.
405 * The tilde (~) character is an operator, and back-quote (`) is an illegal character.
406   AS68 permitted the tilde and back-quote characters in symbols.
407 * There are no equivalents to org or section directives apart from .text, .data, .bss.
408   The **.xdef** and **.xref** directives are not implemented,
409   but **.globl** makes these unnecessary anyway.
410
411 * The location counter cannot be manipulated with a statement of the form:
412
413   ::
414
415                                 * = expression
416
417   Exceptions to this rule are when outputting a binary using the **-fr** switch,
418   6502 mode, and Jaguar GPU/DSP.
419 * Back-slashes in strings are "electric" characters that are used to escape C-like
420   character codes. Watch out for GEMDOS path names in ASCII constants -
421   you will have to convert them to double-backslashes.
422 * Expression evaluation is done left-to-right without operator precedence. Use parentheses to
423   force the expression evaluation as you wish.
424 * Mark your segments across files.
425   Branching to a code segment that could be identified as BSS will cause a "Error: cannot initialize non-storage (BSS) section"
426 * In 68020+ mode **Zan** and **Zri** (register suppression) is not supported.
427 * rs.b/rs.w/rs.l/rscount/rsreset can be simulated in rmac using **.abs**.
428   For example the following source:
429
430    ::
431
432     rsreset
433     label1: rs.w 1
434     label2: rs.w 10
435     label3: rs.l 5
436     label4: rs.b 2
437    
438     size_so_far equ rscount
439
440   can be converted to:
441
442    ::
443
444     abs
445     label1: ds.w 1
446     label2: ds.w 10
447     label3: ds.l 5
448     label4: ds.b 2
449    
450     size_so_far equ ^^abscount
451 * A rare case: if your macro contains something like:
452
453    ::
454
455     macro test
456     move.l #$\1,d0
457     endm
458
459     test 10
460
461   then by the assembler's design this will fail as the parameters are automatically converted to hex. Changing the code like this works:
462
463    ::
464
465     macro test
466     move.l #\1,d0
467     endm
468
469     test $10
470
471 `Text File Format`_
472 '''''''''''''''''''
473 For those using editors other than the "Emacs" style ones (Micro-Emacs, Mince,
474 etc.) this section documents the source file format that RMAC expects.
475
476  * Files must contain characters with ASCII values less than 128; it is not per-
477    missable to have characters with their high bits set unless those characters are
478    contained in strings (i.e. between single or double quotes) or in comments.
479
480  * Lines of text are terminated with carriage-return/line-feed, linefeed alone, or
481    carriage-return alone.
482
483  * The file is assumed to end with the last terminated line. If there is text beyond
484    the last line terminator (e.g. control-Z) it is ignored.
485
486 `Source Format`_
487 ================
488
489 `Statements`_
490 '''''''''''''
491 A statement may contain up to four fields which are identified by order of ap-
492 pearance and terminating characters. The general form of an assembler statement
493 is:
494
495   ::
496
497       label: operator operand(s)  ; comment
498
499 The label and comment fields are optional. An operand field may not appear
500 without an operator field. Operands are seperated with commas. Blank lines are
501 legal. If the first character on a line is an asterisk (*) or semicolon (;) then the
502 entire line is a comment. A semicolon anywhere on the line (except in a string)
503 begins a comment field which extends to the end of the line.
504
505 The label, if it appears, must be terminated with a single or double colon. If
506 it is terminated with a double colon it is automatically declared global. It is illegal
507 to declare a confined symbol global (see: `Symbols and Scope`_).
508
509 As an addition, the exclamation mark character (**!**) can be placed at the very first
510 character of a line to disbale all optimisations for that specific line, i.e.
511
512   ::
513       
514       !label: operator operand(s)  ; comment
515
516 `Equates`_
517 ''''''''''
518 A statement may also take one of these special forms:
519
520       *symbol* **equ** *expression*
521
522       *symbol* **=** *expression*
523
524       *symbol* **==** *expression*
525
526       *symbol* **set** *expression*
527
528       *symbol* **reg** *register list*
529
530 The first two forms are identical; they equate the symbol to the value of an
531 expression, which must be defined (no forward references). The third form, double-
532 equals (==), is just like an equate except that it also makes the symbol global. (As
533 with labels, it is illegal to make a confined equate global.) The fourth form allows
534 a symbol to be set to a value any number of times, like a variable. The last form
535 equates the symbol to a 16-bit register mask specified by a register list. It is possible
536 to equate confined symbols (see: `Symbols and Scope`_). For example:
537
538   ::
539
540       cr    equ    13          carriage-return
541       if    =      10          line-feed
542       DEBUG ==     1           global debug flag
543       count set    0           variable
544       count set    count + 1   increment variable
545       .rags reg    d3-d7/a3-a6 register list
546       .cr          13          confined equate
547
548 `Symbols and Scope`_
549 ''''''''''''''''''''
550 Symbols may start with an uppercase or lowercase letter (A-Z a-z), an underscore
551 (**_**), a question mark (**?**) or a period (**.**). Each remaining character may be an
552 upper or lowercase letter, a digit (**0-9**), an underscore, a dollar sign (**$**), or a question
553 mark. (Periods can only begin a symbol, they cannot appear as a symbol
554 continuation character). Symbols are terminated with a character that is not a
555 symbol continuation character (e.g. a period or comma, whitespace, etc.). Case is
556 significant for user-defined symbols, but not for 68000 mnemonics, assembler direc-
557 tives and register names. Symbols are limited to 100 characters. When symbols
558 are written to the object file they are silently truncated to eight (or sixteen) char-
559 acters (depending on the object file format) with no check for (or warnings about)
560 collisions.
561
562    For example, all of the following symbols are legal and unique:
563
564      ::
565
566       reallyLongSymbolName .reallyLongConfinedSymbolName
567       a10 ret  move  dc  frog  aa6 a9 ????
568       .a1 .ret .move .dc .frog .a9 .9 ????
569       .0  .00  .000 .1  .11. .111 . ._
570       _frog ?zippo? sys$syetem atari Atari ATARI aTaRi
571
572 while all of the following symbols are illegal:
573
574      ::
575
576       12days dc.10   dc.z   'quote  .right.here
577       @work hi.there $money$ ~tilde
578
579
580 Symbols beginning with a period (**.**) are *confined*; their scope is between two
581 normal (unconfined) labels. Confined symbols may be labels or equates. It is illegal
582 to make a confined symbol global (with the ".globl" directive, a double colon, or a
583 double equals). Only unconfined labels delimit a confined symbol's scope; equates
584 (of any kind) do not count. For example, all symbols are unique and have unique
585 values in the following:
586
587    ::
588
589       zero:: subq.w $1,d1
590              bmi.s .ret
591       .loop: clr.w (a0)+
592              dbra  d0,.loop
593       .ret:  rta
594       FF::   subq.w #1,d1
595              bmi.s .99
596       .loop: move.w -1,(a0)+
597              dbra  d0,.loop
598       .99:   its
599
600 Confined symbols are useful since the programmer has to be much less inventive
601 about finding small, unique names that also have meaning.
602
603 It is legal to define symbols that have the same names as processor mnemonics
604 (such as "**move**" or "**rts**") or assembler directives (such as "**.even**"). Indeed, one
605 should be careful to avoid typographical errors, such as this classic (in 6502 mode):
606
607     ::
608
609              .6502
610       .org   =     $8000
611
612
613 which equates a confined symbol to a hexadecimal value, rather than setting the
614 location counter, which the .org directive does (without the equals sign).
615
616 `Keywords`_
617 '''''''''''
618 The following names, in all combinations of uppercase and lowercase, are keywords
619 and may not be used as symbols (e.g. labels, equates, or the names of macros):
620
621    ::
622
623       Common:
624       equ set reg
625       MC68000:
626       sr ccr pc sp ssp usp
627       d0 d1 d2 d3 d4 d5 d6 d7
628       a0 a1 a2 a3 a4 a5 a6 a7
629       Tom/Jerry:
630       r0 r1 r2 r3 r4 r5 r6 r7
631       r8 r9 r10 r11 r12 rl3 r14 ri5
632       6502:
633       x y a
634       DSP56001:
635       x x0 x1 x2 y y0 y1 y2
636       a a0 a1 a2 b b0 b1 b2 ab ba
637       mr omr la lc ssh ssl ss
638       n0 n1 n2 n3 n4 n5 n6 n7
639       m0 m1 m2 m3 m4 m5 m6 m7
640       r0 r1 r2 r3 r4 r5 r6 r7
641       
642
643 `Constants`_
644 ''''''''''''
645 Numbers may be decimal, hexadecimal, octal, binary or concatenated ASCII. The
646 default radix is decimal, and it may not be changed. Decimal numbers are specified
647 with a string of digits (**0-9**). Hexadecimal numbers are specified with a leading
648 dollar sign (**$**) followed by a string of digits and uppercase or lowercase letters (**A-F
649 a-f**). Octal numbers are specified with a leading at-sign (**@**) followed by a string
650 of octal digits (**0-7**). Binary numbers are specified with a leading percent sign
651 (**%**) followed by a string of binary digits (**0-1**). Concatenated ASCII constants are
652 specified by enclosing from one to four characters in single or double quotes. For
653 example:
654
655     ::
656
657       1234   *decimal*
658       $1234  *hexadecimal*
659       @777   *octal*
660       %10111 *binary*
661       "z"    *ASCII*
662       'frog' *ASCII*
663
664 Negative numbers Are specified with a unary minus (**-**). For example:
665
666     ::
667
668       -5678  -@334 -$4e71
669       -%11011 -'z' -"WIND"
670
671 `Strings`_
672 ''''''''''
673 Strings are contained between double (") or single ( ') quote marks. Strings may
674 contain non-printable characters by specifying "backslash" escapes, similar to the
675 ones used in the C programming language. RMAC will generate a warning if a
676 backslash is followed by a character not appearing below:
677
678     ::
679
680       \\    $5c    backslash
681       \n    $0a    line-feed (newline)
682       \b    $08    backspace
683       \t    $09    tab
684       \r    $0c1   carriage-return
685       \f    $0c    form-feed
686       \e    $1b    escape
687       \'    $27    single-quote
688       \"    $22    double-quote
689
690 It is possible for strings (but not symbols) to contain characters with their high
691 bits set (i.e. character codes 128...255).
692
693 You should be aware that backslash characters are popular in GEMDOS path
694 names, and that you may have to escape backslash characters in your existing source
695 code. For example, to get the file "'c:\\auto\\ahdi.s'" you would specify the string
696 "`c:\\\\auto\\\\ahdi.s`".
697
698 `Register Lists`_
699 '''''''''''''''''
700 Register lists are special forms used with the **movem** mnemonic and the **.reg**
701 directive. They are 16-bit values, with bits 0 through 15 corresponding to registers
702 **D0** through **A7**. A register list consists of a series of register names or register
703 ranges seperated by slashes. A register range consists of two register names, Rm
704 and Rn,m<n, seperated by a dash. For example:
705
706      ::
707
708        register list           value
709        -------------           -----
710        d0-d7/a0-a7             $FFFF
711        d2-d7/a0/a3-a6          $39FC
712        d0/d1/a0-a3/d7/a6-a7    $CF83
713        d0                      $0001
714        r0-r16                  $FFFF
715
716 Register lists and register equates may be used in conjunction with the movem
717 mnemonic, as in this example:
718
719      ::
720
721        temps   reg     d0-d2/a0-a2     ; temp registers
722        keeps   reg     d3-d7/d3-a6     ; registers to preserve
723        allregs reg     d0-d7/a0-a7     ; all registers
724                movem.l #temps,-(sp)    ; these two lines ...
725                movem.l d0-d2/a0-a2,-(sp) ; are identical
726                movem.l #keeps,-(sp)    ; save "keep" registers
727                movem.l (sp)+,#keeps    ; restore "keep" registers
728
729
730 `Expressions`_
731 ==============
732 `Order of Evaluation`_
733 ''''''''''''''''''''''
734 All values are computed with 32-bit 2's complement arithmetic. For boolean operations
735 (such as if or **assert**) zero is considered false, and non-zero is considered
736 true.
737
738      **Expressions are evaluated strictly left-to-right, with no
739      regard for operator precedence.**
740
741 Thus the expression "1+2*3" evaluates to 9, not 7. However, precedence may be
742 forced with parenthesis (**()**) or square-brackets (**[]**).
743
744 `Types`_
745 '''''''''
746 Expressions belong to one of three classes: undefined, absolute or relocatable. An
747 expression is undefined if it involves an undefined symbol (e.g. an undeclared sym-
748 bol, or a forward reference). An expression is absolute if its value will not change
749 when the program is relocated (for instance, the number 0, all labels declared in
750 an abs section, and all Atari ST hardware register locations are absolute values).
751 An expression is relocatable if it involves exactly one symbol that is contained in a
752 text, data or BSS section.
753
754 Only absolute values may be used with operators other than addition (+) or
755 subtraction (-). It is illegal, for instance, to multiply or divide by a relocatable or
756 undefined value. Subtracting a relocatable value from another relocatable value in
757 the same section results in an absolute value (the distance between them, positive
758 or negative). Adding (or subtracting) an absolute value to or from a relocatable
759 value yeilds a relocatable value (an offset from the relocatable address).
760
761 It is important to realize that relocatable values belong to the sections they
762 are defined in (e.g. text, data or BSS), and it is not permissible to mix and match
763 sections. For example, in this code:
764
765     ::
766
767      linel:  dc.l   line2, line1+8
768      line2:  dc.l   line1, line2-8
769      line3:  dc.l   line2-line1, 8
770      error:  dc.l   line1+line2, line2 >> 1, line3/4
771
772 Line 1 deposits two longwords that point to line 2. Line 2 deposits two longwords
773 that point to line 1. Line 3 deposits two longwords that have the absolute value
774 eight. The fourth line will result in an assembly error, since the expressions (re-
775 spectively) attempt to add two relocatable values, shift a relocatable value right by
776 one, and divide a relocatable value by four.
777
778 The pseudo-symbol "*****" (star) has the value that the current section's location
779 counter had at the beginning of the current source line. For example, these two
780 statements deposit three pointers to the label "**bar**":
781
782     ::
783
784      too:    dc.l   *+4
785      bar:    dc.l   *, *
786
787 Similarly, the pseudo-symbol "**$**" has the value that the current section's location
788 counter has, and it is kept up to date as the assembler deposits information
789 "across" a line of source code. For example, these two statements deposit four
790 pointers to the label "zip":
791
792         ::
793
794           zip:      dc.l      $+8, $+4
795           zop:      dc.l      $, $-4
796
797 `Unary Operators`_
798 ''''''''''''''''''
799
800 ================================    ==========================================
801 Operator                            Description
802 ================================    ==========================================
803 **-**                               Unary minus (2's complement).
804 **!**                               Logical (boolean) NOT.
805 **~**                               Tilde: bitwise not (l's complement).
806 **^^defined** *symbol*              True if symbol has a value.
807 **^^referenced** *symbol*           True if symbol has been referenced.
808 **^^streq** *stringl*, *string2*    True if the strings are equal.
809 **^^macdef** *macroName*            True if the macro is defined.
810 **^^abscount**                      Returns the size of current .abs section
811 **^^filesize** *string_filename*    Returns the file size of supplied filename
812 ================================    ==========================================
813
814  * The boolean operators generate the value 1 if the expression is true, and 0 if it is not.
815
816  * A symbol is referenced if it is involved in an expression.
817      A symbol may have
818      any combination of attributes: undefined and unreferenced, defined and unref-
819      erenced (i.e. declared but never used), undefined and referenced (in the case
820      of a forward or external reference), or defined and referenced.
821
822
823
824 `Binary Operators`_
825 '''''''''''''''''''
826
827 ===========  ==============================================
828 Operator     Description
829 ===========  ==============================================
830 \ + - * /    The usual arithmetic operators.
831 %            Modulo. Do *not* attempt to modulo by 0 or 1.
832 & | ^        Bit-wise **AND**, **OR** and **Exclusive-OR**.
833 << >>        Bit-wise shift left and shift right.
834 < <=  >=  >  Boolean magnitude comparisons.
835 =            Boolean equality.
836 <>  !=       Boolean inequality.
837 ===========  ==============================================
838
839  * All binary operators have the same precedence:
840    expressions are evaluated strictly left to right.
841
842  * Division or modulo by zero yields an assembly error.
843
844  * The "<>" and "!=" operators are synonyms.
845
846  * Note that the modulo operator (%) is also used to introduce binary constants
847    (see: `Constants`_). A percent sign should be followed by at least one space if
848    it is meant to be a modulo operator, and is followed by a '0' or '1'.
849
850 `Special Forms`_
851 ''''''''''''''''
852
853 ============    =========================================
854 Special Form    Description
855 ============    =========================================
856 **^^date**      The current system date (Gemdos format).
857 **^^time**      The current system time (Gemdos format).
858 ============    =========================================
859
860    * The "**^^date**" special form expands to the current system date, in Gemdos
861      format. The format is a 16-bit word with bits 0 ...4 indicating the day of the
862      month (1...31), bits 5...8 indicating the month (1...12), and bits 9...15
863      indicating the year since 1980, in the range 0...119.
864
865    * The "**^^time**" special form expands to the current system time, in Gemdos
866      format. The format is a 16-bit word with bits 0...4 indicating the current
867      second divided by 2, bits 5...10 indicating the current minute 0...59. and
868      bits 11...15 indicating the current hour 0...23.
869
870 `Example Expressions`_
871 ''''''''''''''''''''''
872
873        ::
874
875         line address contents      source code
876         ---- ------- --------      -------------------------------
877            1 00000000 4480         lab1:  neg.l  d0
878            2 00000002 427900000000 lab2:  clr.w  lab1
879            3         =00000064     equ1   =      100
880            4         =00000096     equ2   =      equ1 + 50
881            5 00000008 00000064            dc.l   lab1 + equ1
882            6 0000000C 7FFFFFE6            dc.l   (equl + ~equ2) >> 1
883            7 00000010 0001                dc.w   ^^defined equl
884            8 00000012 0000                dc.w   ^^referenced lab2
885            9 00000014 00000002            dc.l   lab2
886           10 00000018 0001                dc.w   ^^referenced lab2
887           11 0000001A 0001                dc.w   lab1 = (lab2 - 6)
888
889 Lines 1 through four here are used to set up the rest of the example. Line 5 deposits
890 a relocatable pointer to the location 100 bytes beyond the label "**lab1**". Line 6 is
891 a nonsensical expression that uses the and right-shift operators. Line 7 deposits
892 a word of 1 because the symbol "**equ1**" is defined (in line 3).
893
894 Line 8 deposits a word of 0 because the symbol "**lab2**", defined in line 2, has
895 not been referenced. But the expression in line 9 references the symbol "**lab2**", so
896 line 10 (which is a copy of line-8) deposits a word of 1. Finally, line 11 deposits a
897 word of 1 because the Boolean equality operator evaluates to true.
898
899 The operators "**^^defined**" and "**^^referenced**" are particularly useful in
900 conditional assembly. For instance, it is possible to automatically include debugging
901 code if the debugging code is referenced, as in:
902
903       ::
904
905                lea    string,a0            ; AO -> message
906                jsr    debug                ; print a message
907                rts                         ; and return
908         string: dc.b  "Help me, Spock!",0  ; (the message)
909                     .
910                     .
911                     .
912                .iif ^^referenced debug, .include "debug.s"
913
914 The **jsr** statement references the symbol debug. Near the end of the source file, the
915 "**.iif**" statement includes the file "**debug.s**" if the symbol debug was referenced.
916
917 In production code, presumably all references to the debug symbol will be removed,
918 and the debug source file will not be included. (We could have as easily made the
919 symbol **debug** external, instead of including another source file).
920
921
922 `Directives`_
923 =============
924
925 Assembler directives may be any mix of upper- or lowercase. The leading periods
926 are optional, though they are shown here and their use is encouraged. Directives
927 may be preceeded by a label; the label is defined before the directive is executed.
928 Some directives accept size suffixes (**.b**, **.s**, **.w** or **.1**); the default is word (**.w**) if no
929 size is specified. The **.s** suffix is identical to **.b**. Directives relating to the 6502 are
930 described in the chapter on `6502 Support`_.
931
932
933
934 **.even**
935
936    If the location counter for the current section is odd, make it even by adding
937    one to it. In text and data sections a zero byte is deposited if necessary.
938
939 **.long**
940
941    Align the program counter to the next integral long boundary (4 bytes).
942    Note that GPU/DSP code sections are not contained in their own
943    segments and are actually part of the TEXT or DATA segments.
944    Therefore, to align GPU/DSP code, align the current section before and
945    after the GPU/DSP code.
946
947 **.print**
948    This directive is similar to the standard ‘C’ library printf() function
949    and is used to print user messages from the assembly process. You can
950    print any string or valid expression. Several format flags that can be used
951    to format your output are also supported.
952
953           ::
954
955            /x hexadecimal
956            /d signed decimal
957            /u unsigned decimal
958            /w word
959            /l long
960
961    For example:
962
963           ::
964
965            MASK .equ $FFF8
966            VALUE .equ -100000
967             .print “Mask: $”,/x/w MASK
968             .print “Value: “,/d/l VALUE
969
970 **.phrase**
971
972    Align the program counter to the next integral phrase boundary (8 bytes).
973    Note that GPU/DSP code sections are not contained in their own
974    segments and are actually part of the TEXT or DATA segments.
975    Therefore, to align GPU/DSP code, align the current section before and
976    after the GPU/DSP code.
977
978 **.dphrase**
979
980    Align the program counter to the next integral double phrase boundary (16
981    bytes). Note that GPU/DSP code sections are not contained in their own
982    segments and are actually part of the TEXT or DATA segments.
983    Therefore, to align GPU/DSP code, align the current section before and
984    after the GPU/DSP code.
985
986 **.qphrase**
987
988    Align the program counter to the next integral quad phrase boundary (32
989    bytes). Note that GPU/DSP code sections are not contained in their own
990    segments and are actually part of the TEXT or DATA segments.
991    Therefore, to align GPU/DSP code, align the current section before and
992    after the GPU/DSP code.
993
994    **.assert** *expression* [,\ *expression*...]
995
996    Assert that the conditions are true (non-zero). If any of the comma-seperated
997    expressions evaluates to zero an assembler warning is issued. For example:
998
999           ::
1000
1001            .assert *-start = $76
1002            .assert stacksize >= $400
1003
1004 **.bss**
1005
1006 **.data**
1007
1008 **.text**
1009
1010    Switch to the BSS, data or text segments. Instructions and data may not
1011    be assembled into the BSS-segment, but symbols may be defined and storage
1012    may be reserved with the **.ds** directive. Each assembly starts out in the text
1013    segment.
1014
1015 **.68000**
1016 **.68020**
1017 **.68030**
1018 **.68040**
1019 **.68060**
1020
1021    Enable different flavours of the MC68000 family of CPUs. Bear in mind that not all
1022    instructions and addressing modes are available in all CPUs so the correct CPU
1023    should be selected at all times. Notice that it is possible to switch CPUs
1024    during assembly.
1025
1026 **.68881**
1027 **.68882**
1028
1029    Enable FPU support. Note that *.68882* is on by default when selecting *.68030*.
1030
1031 **.56001**
1032
1033    Switch to Motorola DSP56001 mode.
1034
1035 **.org** *location* [*X:*/*Y:*/*P:*/*L:*]
1036
1037    This directive sets the value of the location counter (or **pc**) to location, an
1038    expression that must be defined and absolute. It is legal to use the directive in
1039    the following modes: 6502, Tom, Jerry, OP, 56001 and 680x0 (only with -fr switch).
1040    Especially for the 56001 mode the *location* field **must** be prefixed with the
1041    intended section (*X:*, *Y:*, *P:* or *L:*).
1042
1043 **.opt** *"+On"*
1044 **.opt** *"~On"*
1045 **.opt** *"+Oall"*
1046 **.opt** *"~Oall"*
1047    
1048    These directives control the optimisations that rmac applies to the source
1049    automatically. Each directive is applied immediately from the line encountered
1050    onwards. So it is possible to turn specific optimisations on and off globally
1051    (when placed at the start of the first file) or locally (by turning desired
1052    optimisations on and off at certain parts of the source). For a list of the
1053    optimisations (*n*) available please consult the table in section `The Command Line`_.
1054    **all**, as expected, turns all available optimisations on or off.
1055
1056    Lastly, as a "creature comfort" feature, if the first column of any line is prefixed
1057    with an exclamation mark (*!*) then for that line all optimisations are turned off.
1058
1059 **.abs** [*location*]
1060
1061    Start an absolute section, beginning with the specified location (or zero, if
1062    no location is specified). An absolute section is much like BSS, except that
1063    locations declared with .ds are based absolute. This directive is useful for
1064
1065    declaring structures or hardware locations.
1066    For example, the following equates:
1067
1068           ::
1069
1070            VPLANES = 0
1071            VWRAP   = 2
1072            CONTRL  = 4
1073            INTIN   = 8
1074            PTSIN   = 12
1075
1076    could be as easily defined as:
1077
1078           ::
1079
1080                    .abs
1081            VPLANES: ds.w    1
1082            VWRAP:  ds.w     1
1083            CONTRL: ds.l     1
1084            INTIE:  ds.l     1
1085            PTSIN:  ds.l     1
1086
1087    Another interesting example worth mentioning is the emulation of "C"'s "union" keyword
1088    using *.abs*. For example, the following "C" code:
1089
1090           ::
1091
1092            struct spritesheet
1093            {
1094                 short spf_w;
1095                 short spf_h;
1096                 short spf_xo;
1097                 short spf_yo;
1098                 union { int spf_em_colour;     int spf_emx_colour;    };
1099                 union { int spf_em_psmask[16]; int spf_emx_colouropt; };
1100            }
1101
1102    can be expressed as:
1103
1104           ::
1105
1106            .abs
1107            *-------------------------------------------------------*
1108            spf_w:          ds.w    1   ;<- common
1109            spf_h:          ds.w    1
1110            spf_xo:         ds.w    1
1111            spf_yo:         ds.w    1
1112            spf_data:       ds.l    0
1113            *-------------------------------------------------------*
1114            ;           .union  set
1115            spf_em_colour:      ds.l    1   ;<- union #1
1116            spf_em_psmask:      ds.l    16
1117            *-------------------------------------------------------*
1118            .68000
1119                        .abs spf_em_colour
1120            ;           .union  reset
1121            spf_emx_colour:     ds.l    1   ;<- union #2
1122            spf_emx_colouropt:  ds.l    1
1123            spf_emx_psmask:     ds.l    16
1124            spf_emx_psmaskopt:  ds.l    16
1125            
1126            .68000
1127            ;*-------------------------------------------------------*
1128            
1129                move #spf_em_colour,d0
1130                move #spf_emx_colour,d0
1131
1132    In this example, *spf_em_colour* and *spf_emx_colour* will have the same value.
1133            
1134 **.comm** *symbol*, *expression*
1135
1136    Specifies a label and the size of a common region. The label is made global,
1137    thus confined symbols cannot be made common. The linker groups all common
1138    regions of the same name; the largest size determines the real size of the
1139    common region when the file is linked.
1140
1141 **.ccdef** *expression*
1142
1143    Allows you to define names for the condition codes used by the JUMP
1144    and JR instructions for GPU and DSP code. For example:
1145
1146     ::
1147    
1148      Always .ccdef 0
1149      . . .
1150           jump Always,(r3) ; 'Always' is actually 0
1151
1152 **.ccundef** *regname*
1153
1154    Undefines a register name (regname) previously assigned using the
1155    .CCDEF directive. This is only implemented in GPU and DSP code
1156    sections.     
1157
1158 **.dc.i** *expression*
1159
1160    This directive generates long data values and is similar to the DC.L
1161    directive, except the high and low words are swapped. This is provided
1162    for use with the GPU/DSP MOVEI instruction.
1163
1164 **.dc**\ [.\ *size*] *expression* [, *expression*...]
1165
1166    Deposit initialized storage in the current section. If the specified size is word
1167    or long, the assembler will execute a .even before depositing data. If the size
1168    is .b, then strings that are not part of arithmetic expressions are deposited
1169    byte-by-byte. If no size is specified, the default is .w. This directive cannot be
1170    used in the BSS section.
1171
1172 **.dcb**\ [.\ *size*] *expression1*, *expression2*
1173
1174    Generate an initialized block of *expression1* bytes, words or longwords of the
1175    value *expression2*. If the specified size is word or long, the assembler will
1176    execute .even before generating data. If no size is specified, the default is **.w**.
1177    This directive cannot be used in the BSS section.
1178
1179 **.ds**\ [.\ *size*] *expression*
1180
1181    Reserve space in the current segment for the appropriate number of bytes,
1182    words or longwords. If no size is specified, the default size is .w. If the size
1183    is word or long, the assembler will execute .even before reserving space.
1184
1185 **.dsp**
1186
1187    Switch to Jaguar DSP assembly mode. This directive must be used
1188    within the TEXT or DATA segments.
1189
1190 **.init**\ [.\ *size*] [#\ *expression*,]\ *expression*\ [.\ *size*] [,...]
1191
1192    Generalized initialization directive. The size specified on the directive becomes
1193    the default size for the rest of the line. (The "default" default size is **.w**.) A
1194    comma-seperated list of expressions follows the directive; an expression may be
1195    followed by a size to override the default size. An expression may be preceeded
1196    by a sharp sign, an expression and a comma, which specifies a repeat count to
1197    be applied to the next expression. For example:
1198
1199       ::
1200
1201        .init.l -1, 0.w, #16,'z'.b, #3,0, 11.b
1202
1203    will deposit a longword of -1, a word of zero, sixteen bytes of lower-case 'z',
1204    three longwords of zero, and a byte of 11.
1205
1206    No auto-alignment is performed within the line, but a **.even** is done once
1207    (before the first value is deposited) if the default size is word or long.
1208
1209 **.cargs** [#\ *expression*,] *symbol*\ [.\ *size*] [, *symbol*\ [.\ *size*].. .]
1210
1211    Compute stack offsets to C (and other language) arguments. Each symbol is
1212    assigned an absolute value (like equ) which starts at expression and increases
1213    by the size of each symbol, for each symbol. If the expression is not supplied,
1214    the default starting value is 4. For example:
1215
1216     ::
1217
1218      .cargs #8, .fileliams.1, .openMode, .butPointer.l
1219
1220    could be used to declare offsets from A6 to a pointer to a filename, a word
1221    containing an open mode, and a pointer to a buffer. (Note that the symbols
1222    used here are confined). Another example, a C-style "string-length" function,
1223    could be written as:
1224
1225         ::
1226
1227          _strlen:: .cargs .string     ; declare arg
1228                move.l .string(sp),a0  ; a0 -> string
1229                moveq  #-1,d0          ; initial size = -1
1230          .1:   addq.1 #1,d0           ; bump size
1231                tst.b  (a0)+           ; at end of string?
1232                bne   .1               ; (no -- try again)
1233                rts                    ; return string length
1234
1235 **.error** ["*string*"]
1236
1237   Aborts the build, optionally printing a user defined string. Can be useful
1238   inside conditional assembly blocks in order to catch errors. For example:
1239
1240         ::
1241
1242          .if ^^defined JAGUAR
1243            .error "TOS cannot be built on Jaguar, don't be silly"
1244          .endif
1245
1246 **.end**
1247
1248    End the assembly. In an include file, end the include file and resume assembling
1249    the superior file. This statement is not required, nor are warning messages
1250    generated if it is missing at the end of a file. This directive may be used inside
1251    conditional assembly, macros or **.rept** blocks.
1252
1253 **.equr** *expression*
1254
1255    Allows you to name a register. This is only implemented for GPU/DSP
1256    code sections. For example:
1257
1258     ::
1259
1260      Clipw .equr r19
1261      . . .
1262           add ClipW,r0 ; ClipW actually is r19
1263
1264 **.if** *expression*
1265
1266 **.else**
1267
1268 **.endif**
1269
1270    Start a block of conditional assembly. If the expression is true (non-zero) then
1271    assemble the statements between the .if and the matching **.endif** or **.else**.
1272    If the expression is false, ignore the statements unless a matching .else is
1273    encountered. Conditional assembly may be nested to any depth.
1274
1275    It is possible to exit a conditional assembly block early from within an include
1276    file (with **end**) or a macro (with **endm**).
1277
1278 **.iif** *expression*, *statement*
1279
1280    Immediate version of **.if**. If the expression is true (non-zero) then the state-
1281    ment, which may be an instruction, a directive or a macro, is executed. If
1282    the expression is false, the statement is ignored. No **.endif** is required. For
1283    example:
1284
1285         ::
1286
1287          .iif age < 21, canDrink = 0
1288          .iif weight > 500, dangerFlag = 1
1289          .iif !(^^defined DEBUG), .include dbsrc
1290
1291 **.macro** *name* [*formal*, *formal*,...]
1292
1293 **.endm**
1294
1295 **.exitm**
1296
1297    Define a macro called name with the specified formal arguments. The macro
1298    definition is terminated with a **.endm** statement. A macro may be exited early
1299    with the .exitm directive. See the chapter on `Macros`_ for more information.
1300
1301 **.undefmac** *macroName* [, *macroName*...]
1302
1303    Remove the macro-definition for the specified macro names. If reference is
1304    made to a macro that is not defined, no error message is printed and the name
1305    is ignored.
1306
1307 **.rept** *expression*
1308
1309 **.endr**
1310
1311    The statements between the **.rept** and **.endr** directives will be repeated *expression*
1312    times. If the expression is zero or negative, no statements will be
1313    assembled. No label may appear on a line containing either of these directives.
1314
1315 **.globl** *symbol* [, *symbol*...]
1316
1317 **.extern** *symbol* [, *symbol*...]
1318
1319    Each symbol is made global. None of the symbols may be confined symbols
1320    (those starting with a period). If the symbol is defined in the assembly, the
1321    symbol is exported in the object file. If the symbol is undefined at the end
1322    of the assembly, and it was referenced (i.e. used in an expression), then the
1323    symbol value is imported as an external reference that must be resolved by the
1324    linker. The **.extern** directive is merely a synonym for **.globl**.
1325
1326 **.include** "*file*"
1327
1328    Include a file. If the filename is not enclosed in quotes, then a default extension
1329    of "**.s**" is applied to it. If the filename is quoted, then the name is not changed
1330    in any way.
1331
1332    Note: If the filename is not a valid symbol, then the assembler will generate an
1333              error message. You should enclose filenames such as "**atari.s**" in quotes,
1334              because such names are not symbols.
1335
1336    If the include file cannot be found in the current directory, then the directory
1337    search path, as specified by -i on the commandline, or' by the 'RMACPATH'
1338    enviroment string, is traversed.
1339
1340 **.incbin** "*file*" [, [*size*], [*offset*]]
1341
1342    Include a file as a binary. This can be thought of a series of **dc.b** statements
1343    that match the binary bytes of the included file, inserted at the location of the 
1344    directive. The directive is not allowed in a BSS section. Optional parameters
1345    control the amount of bytes to be included and offset from the start of the file.
1346    All the following lines are valid:
1347
1348               ::   
1349                 .incbin "test.bin"          ; Include the whole file
1350                 .incbin "test.bin",,$30     ; Skip the first 48 bytes
1351                 .incbin "test.bin",$70,$30  ; Include $70 bytes starting at offset $30
1352                 .incbin "test.bin",$48      ; Include the file starting at offset 48 till the end
1353                 .incbin "test.bin",,        ; Include the whole file
1354
1355 **.eject**
1356
1357    Issue a page eject in the listing file.
1358
1359 **.title** "*string*"
1360
1361 **.subttl** [-] "*string*"
1362
1363    Set the title or subtitle on the listing page. The title should be specified on
1364    the the first line of the source program in order to take effect on the first page.
1365    The second and subsequent uses of **.title** will cause page ejects. The second
1366    and subsequent uses of .subttl will cause page ejects unless the subtitle string
1367    is preceeded by a dash (-).
1368
1369 **.list**
1370
1371 **.nlist**
1372
1373    Enable or disable source code listing. These directives increment and decrement
1374    an internal counter, so they may be appropriately nested. They have no effect
1375    if the **-l** switch is not specified on the commandline.
1376
1377 **.goto** *label*
1378
1379    This directive provides unstructured flow of control within a macro definition.
1380    It will transfer control to the line of the macro containing the specified goto
1381    label. A goto label is a symbol preceeded by a colon that appears in the first
1382    column of a source line within a macro definition:
1383
1384                  :  *label*
1385
1386    where the label itself can be any valid symbol name, followed immediately by
1387    whitespace and a valid source line (or end of line). The colon **must** appear in
1388    the first column.
1389
1390    The goto-label is removed from the source line prior to macro expansion -
1391    to all intents and purposes the label is invisible except to the .goto directive
1392    Macro expansion does not take place within the label.
1393
1394    For example, here is a silly way to count from 1 to 10 without using **.rept**:
1395
1396               ::
1397
1398                                .macro Count
1399                  count         set     1
1400                  :loop         dc.w    count
1401                  count         set     count + 1
1402                                iif count <= 10, goto loop
1403                                .endm
1404
1405 **.gpu**
1406
1407    Switch to Jaguar GPU assembly mode. This directive must be used
1408    within the TEXT or DATA segments.
1409
1410 **.gpumain**
1411
1412    No. Just... no. Don't ask about it. Ever.
1413
1414 **.prgflags** *value*
1415
1416    Sets ST executable .PRG field *PRGFLAGS* to *value*. *PRGFLAGS* is a bit field defined as follows:
1417
1418 ============ ======  =======
1419 Definition   Bit(s)  Meaning
1420 ============ ======  =======
1421 PF_FASTLOAD  0       If set, clear only the BSS area on program load, otherwise clear the entire heap. 
1422 PF_TTRAMLOAD 1       If set, the program may be loaded into alternative RAM, otherwise it must be loaded into standard RAM. 
1423 PF_TTRAMMEM  2       If set, the program's Malloc() requests may be satisfied from alternative RAM, otherwise they must be satisfied from standard RAM. 
1424 --           3       Currently unused.
1425 See left.    4 & 5   If these bits are set to 0 (PF_PRIVATE), the processes' entire memory space will be considered private (when memory protection is enabled).If these bits are set to 1 (PF_GLOBAL), the processes' entire memory space will be readable and writable by any process (i.e. global).If these bits are set to 2 (PF_SUPERVISOR), the processes' entire memory space will only be readable and writable by itself and any other process in supervisor mode.If these bits are set to 3 (PF_READABLE), the processes' entire memory space will be readable by any application but only writable by itself. 
1426 --           6-15    Currently unused.
1427 ============ ======  =======
1428
1429 **.regequ** *expression*
1430    Essentially the same as **.EQUR.** Included for compatibility with the GASM
1431    assembler.
1432
1433 **.regundef**
1434    Essentially the same as **.EQURUNDEF.** Included for compatibility with
1435    the GASM assembler.
1436
1437
1438 `68000 Mnemonics`_
1439 ==================
1440
1441 `Mnemonics`_
1442 ''''''''''''
1443 All of the standard Motorola 68000 mnemonics and addressing modes are supported;
1444 you should refer to **The Motorola M68000 Programmer's Reference Manual**
1445 for a description of the instruction set and the allowable addressing modes for each
1446 instruction. With one major exception (forward branches) the assembler performs
1447 all the reasonable optimizations of instructions to their short or address register
1448 forms.
1449
1450 Register names may be in upper or lower case. The alternate forms ``R0`` through
1451 ``R15`` may be used to specify ``D0`` through ``A7``. All register names are keywords, and
1452 may not be used as labels or symbols. None of the 68010 or 68020 register names
1453 are keywords (but they may become keywords in the future).
1454
1455 `Addressing Modes`_
1456 '''''''''''''''''''
1457
1458 =====================================    ===========================================
1459 Assembler Syntax                         Description
1460 =====================================    ===========================================
1461 *Dn*                                     Data register direct
1462 *An*                                     Address register direct
1463 (*An*)                                   Address register indirect
1464 (*An*)+                                  Address register indirect postincrement
1465 -(*An*)                                  Address register indirect predecrement
1466 *disp*\ (*An*)                           Address register indirect with displacement
1467 *bdisp*\ (*An*, *Xi*\ [.\ *size*])       Address register indirect indexed
1468 *abs*.w                                  Absolute short
1469 *abs*                                    Absolute (long or short)
1470 *abs*.l                                  Forced absolute long
1471 *disp*\ (PC)                             Program counter with displacement
1472 *bdisp*\ (PC, *Xi*\ )                    Program counter indexed
1473 #\ *imm*                                 Immediate
1474 =====================================    ===========================================
1475
1476 `68020+ Addressing Modes`_
1477 ''''''''''''''''''''''''''
1478
1479 The following addressing modes are only valid for 68020 and newer CPUs. In these
1480 modes most of the parameters like Base Displacement (**bd**), Outer Displacement
1481 (**od**), Base Register (**An**) and Index Register (**Xn**) can be omitted. RMAC
1482 will detect this and *suppress* the registers in the produced code.
1483
1484 Other assemblers
1485 use a special syntax to denote register suppression like **Zan** to suppress the Base
1486 Register and **Rin** to suppress the Index Register. RMAC has no support for this
1487 behaviour nor needs it to suppress registers.
1488
1489 In addition, other assemblers will allow reordering of the parameters (for example
1490 ([*An*,\ *bd*])). This is not allowed in RMAC.
1491
1492 Also noteworthy is that the Index Register can be an address or data register.
1493
1494 To avoid internal confusion the 68040/68060 registers *DC*, *IC* and *BC* are named
1495 *DC40*, *IC40* and *BC40* respectively.
1496
1497 ======================================================    =============================================================
1498 Assembler Syntax                                          Description
1499 ======================================================    =============================================================
1500 *bd*\ (*An*, *Xi*\ [.\ *size*][*\*scale*])                Address register indirect indexed
1501 ([*bd*,\ *An*],\ *Xn*\[.\ *siz*][*\*scale*],\ *od*)       Register indirect preindexed with outer displacement
1502 ([*bd*,\ *An*,\ *Xn*\[.\ *siz*][*\*scale*],\ *od*)        Register indirect postindexed with outer displacement
1503 ([*bd*,\ *PC*],\ *Xn*\[.\ *siz*][*\*scale*],\ *od*)       Program counter indirect preindexed with outer displacement
1504 ([*bd*,\ *PC*,\ *Xn*\[.\ *siz*][*\*scale*],\ *od*)        Program counter indirect postindexed with outer displacement
1505 ======================================================    =============================================================
1506
1507 `Branches`_
1508 '''''''''''
1509 Since RMAC is a one pass assembler, forward branches cannot be automatically
1510 optimized to their short form. Instead, unsized forward branches are assumed to
1511 be long. Backward branches are always optimized to the short form if possible.
1512
1513 A table that lists "extra" branch mnemonics (common synonyms for the Motorola
1514 defined mnemonics) appears below.
1515
1516 `Linker Constraints`_
1517 '''''''''''''''''''''
1518 It is not possible to make an external reference that will fix up a byte. For example:
1519
1520                    ::
1521
1522                      extern frog
1523                     move.l frog(pc,d0),d1
1524
1525 is illegal (and generates an assembly error) when frog is external, because the
1526 displacement occupies a byte field in the 68000 offset word, which the object file
1527 cannot represent.
1528
1529 `Branch Synonyms`_
1530 ''''''''''''''''''
1531 ============== ========
1532 Alternate name Becomes:
1533 ============== ========
1534 bhs            bcc
1535 blo            bcs
1536 bse, bs        beq
1537 bns            bne
1538 dblo           dbcs
1539 dbse           dbeq
1540 dbra           dbf
1541 dbhs           dbhi
1542 dbns           dbne
1543 ============== ========
1544
1545 `Optimizations and Translations`_
1546 '''''''''''''''''''''''''''''''''
1547 The assembler provides "creature comforts" when it processes 68000 mnemonics:
1548
1549  * **CLR.x An** will really generate **SUB.x An,An**.
1550
1551  * **ADD**, **SUB** and **CMP** with an address register will really generate **ADDA**,
1552    **SUBA** and **CMPA**.
1553
1554  * The **ADD**, **AND**, **CMP**, **EOR**, **OR** and **SUB** mnemonics with immediate
1555    first operands will generate the "I" forms of their instructions (**ADDI**, etc.) if
1556    the second operand is not register direct.
1557
1558  * All shift instructions with no count value assume a count of one.
1559
1560  * **MOVE.L** is optimized to **MOVEQ** if the immediate operand is defined and
1561    in the range -128...127. However, **ADD** and **SUB** are never translated to
1562    their quick forms; **ADDQ** and **SUBQ** must be explicit.
1563
1564  * All optimisations are controllable using the **.opt** directive. Refer to its
1565    description in section `Directives`_. 
1566
1567  * All optimisations are turned off for any source line that has an exclamation mark
1568    (*!*) on their first column.
1569
1570  * Optimisation switches 0, 1 and 2 are turned on by default for legacy reasons.
1571    All other levels are off by default. (refer to section `The Command Line`_
1572    for a description of all the switches).
1573
1574  * Optimisation warnings are off by default. Invoke RMAC with the *-s* switch to
1575    turn on warnings in console and listing output.
1576
1577  * In DSP56001 mode size optimisations are on by default. Currently there is no
1578    way to disable this behaviour.
1579
1580  * In GPU/DSP code sections, you can use JUMP (Rx) in place of JUMP T, (Rx) and JR
1581    (Rx) in place of JR T,(Rx).
1582
1583  * RMAC tests all GPU/DSP restrictions and corrects them wherever possible (such as
1584    inserting a NOP instruction when needed).
1585
1586  * The *(Rx+N)* addressing mode for GPU/DSP instructions is optimized to *(Rx)*
1587    when *N* is zero.
1588
1589 `Macros`_
1590 =========
1591 `Macro declaration`_
1592 ''''''''''''''''''''
1593 A macro definition is a series of statements of the form:
1594                               ::
1595
1596                                  .macro name [ formal-arg, ...]
1597                                     .
1598                                     .
1599                                     .
1600                                  statements making up the macro body
1601                                     .
1602                                     .
1603                                     .
1604                                  .endm
1605
1606 The name of the macro may be any valid symbol that is not also a 68000 instruction
1607 or an assembler directive. (The name may begin with a period - macros cannot
1608 be made confined the way labels or equated symbols can be). The formal argument
1609 list is optional; it is specified with a comma-seperated list of valid symbol names.
1610 Note that there is no comma between the name of the macro and the name of the
1611 first formal argument. It is not advised to begin an argument name with a numeric
1612 value.
1613
1614 A macro body begins on the line after the **.macro** directive. All instructions
1615 and directives, except other macro definitions, are legal inside the body.
1616
1617 The macro ends with the **.endm** statement. If a label appears on the line with
1618 this directive, the label is ignored and a warning is generated.
1619
1620 `Parameter Substitution`_
1621 '''''''''''''''''''''''''
1622 Within the body, formal parameters may be expanded with the special forms:
1623               ::
1624
1625                 \name
1626                 \{name}
1627
1628 The second form (enclosed in braces) can be used in situations where the characters
1629 following the formal parameter name are valid symbol continuation characters. This
1630 is usually used to force concatentation, as in:
1631
1632                ::
1633
1634                 \{frog}star
1635                 \(godzilla}vs\{reagan}
1636
1637 The formal parameter name is terminated with a character that is not valid in
1638 a symbol (e.g. whitespace or puncuation); optionally, the name may be enclosed in
1639 curly-braces. The names must be symbols appearing on the formal argument list,
1640 or a single decimal digit (``\1`` corresponds to the first argument, ``\2`` to the second,
1641 ``\9`` to the ninth, and ``\0`` to the tenth). It is possible for a macro to have more than
1642 ten formal arguments, but arguments 11 and on must be referenced by name, not
1643 by number.
1644
1645         Other special forms are:
1646
1647 ============ ================================================
1648 Special Form Description
1649 ============ ================================================
1650 ``\\``       a single "\",
1651 ``\~``       a unique label of the form "Mn"
1652 ``\#``       the number of arguments actually specified
1653 ``\!``       the "dot-size" specified on the macro invocation
1654 ``\?name``   conditional expansion
1655 ``\?{name}`` conditional expansion
1656 ============ ================================================
1657
1658 The last two forms are identical: if the argument is specified and is non-empty, the
1659 form expands to a "1", otherwise (if the argument is missing or empty) the form
1660 expands to a "0".
1661
1662 The form "``\!``" expands to the "dot-size" that was specified when the macro
1663 was invoked. This can be used to write macros that behave differently depending
1664 on the size suffix they are given, as in this macro which provides a synonym for the
1665 "``dc``" directive:
1666
1667               ::
1668
1669                .macro deposit value
1670                dc\!   \value
1671                .endm
1672                deposit.b 1          ; byte of 1
1673                deposit.w 2          ; word of 2
1674                deposit.l 3          ; longvord of 3
1675                deposit   4          ; word of 4 (no explicit size)
1676
1677 `Macro Invocation`_
1678 '''''''''''''''''''
1679 A previously-defined macro is called when its name appears in the operation field of
1680 a statement. Arguments may be specified following the macro name; each argument
1681 is seperated by a comma. Arguments may be empty. Arguments are stored for
1682 substitution in the macro body in the following manner:
1683
1684   * Numbers are converted to hexadecimal.
1685
1686   * All spaces outside strings are removed.
1687
1688   * Keywords (such as register names, dot sizes and "^^" operators) are converted
1689     to lowercase.
1690
1691   * Strings are enclosed in double-quote marks (").
1692
1693 For example, a hypothetical call to the macro "``mymacro``", of the form:
1694        ``mymacro A0, , 'Zorch' / 32, "^^DEFINED foo, , , tick tock``
1695
1696 will result in the translations:
1697
1698 ========      ================= =================================================
1699 Argument      Expansion         Comment
1700 ========      ================= =================================================
1701 ``\1``        ``a0``            "``A0``" converted to lower-case
1702 ``\2``                          empty
1703 ``\3``        ``"Zorch"/$20``   "``Zorch``" in double-quotes, 32 in hexadecimal
1704 ``\4``        ``^^defined foo`` "``^^DEFINED``" converted to lower-case
1705 ``\5``                          empty
1706 ``\6``                          empty
1707 ``\7``        ``ticktock``      spaces removed (note concatenation)
1708 ========      ================= =================================================
1709
1710 The **.exitm** directive will cause an immediate exit from a macro body. Thus
1711 the macro definition:
1712
1713          ::
1714
1715           .macro foo source
1716               .iif !\?source, .exitm ; exit if source is empty
1717               move \source,d0        ; otherwise, deposit source
1718           .endm
1719
1720 will not generate the move instruction if the argument **"source"** is missing from
1721 the macro invocation.
1722
1723 The **.end**, **.endif** and **.exitm** directives all pop-out of their include levels
1724 appropriately. That is, if a macro performs a **.include** to include a source file, an
1725 executed **.exitm** directive within the include-file will pop out of both the include-file
1726 and the macro.
1727
1728 Macros may be recursive or mutually recursive to any level, subject only to
1729 the availability of memory. When writing recursive macros, take care in the coding
1730 of the termination condition(s). A macro that repeatedly calls itself will cause the
1731 assembler to exhaust its memory and abort the assembly.
1732
1733
1734 `Example Macros`_
1735 '''''''''''''''''
1736 The Gemdos macro is used to make file system calls. It has two parameters, a
1737 function number and the number of bytes to clean off the stack after the call. The
1738 macro pushes the function number onto the stack and does the trap to the file
1739 system. After the trap returns, conditional assembly is used to choose an addq or
1740 an **add.w** to remove the arguments that were pushed.
1741
1742      ::
1743
1744        .macro Gemdos trpno, clean
1745           move.w  #\trpno,-(sp)  ; push trap number
1746           trap    #1             ; do GEMDOS trap
1747           .if \clean <= 8        ;
1748           addq    #\clean,sp     ; clean-up up to 8 bytes
1749           .else                  ;
1750           add.w   #\clean,sp     ; clean-up more than 8 bytes
1751           .endif                 ;
1752        .endm
1753
1754 The Fopen macro is supplied two arguments; the address of a filename, and
1755 the open mode. Note that plain move instructions are used, and that the caller of
1756 the macro must supply an appropriate addressing mode (e.g. immediate) for each
1757 argument.
1758
1759      ::
1760
1761        .macro Fopen file, mode
1762           movs.w   \mode,-(sp)  ;push open mode
1763           move.1   \file,-(sp)  ;push address of tile name
1764           Gemdos   $3d,8        ;do the GEMDOS call
1765        .endm
1766
1767 The **String** macro is used to allocate storage for a string, and to place the
1768 string's address somewhere. The first argument should be a string or other expres-
1769 sion acceptable in a dc.b directive. The second argument is optional; it specifies
1770 where the address of the string should be placed. If the second argument is omitted,
1771 the string's address is pushed onto the stack. The string data itself is kept in the
1772 data segment.
1773
1774                   ::
1775
1776                    .macro String str,loc
1777                        .if \?loc                                        ; if loc is defined
1778                          move.l #.\~,\loc                               ; put the string's address there
1779                        .else                                            ; otherwise
1780                          pea .\~                                        ; push the string's address
1781                        .endif                                           ;
1782                        .data                                            ; put the string data
1783                    .\~: dc.b \str,0                                     ;  in the data segment
1784                        .text                                            ; and switch back to the text segment
1785                    .endm
1786
1787 The construction "``.\~``" will expand to a label of the form "``.M``\ *n*" (where *n* is
1788 a unique number for every macro invocation), which is used to tag the location of
1789 the string. The label should be confined because the macro may be used along with
1790 other confined symbols.
1791
1792 Unique symbol generation plays an important part in the art of writing fine
1793 macros. For instance, if we needed three unique symbols, we might write "``.a\~``",
1794 "``.b\~``" and "``.c\~``".
1795
1796 `Repeat Blocks`_
1797 ''''''''''''''''
1798 Repeat-blocks provide a simple iteration capability. A repeat block allows a range
1799 of statements to be repeated a specified number of times. For instance, to generate
1800 a table consisting of the numbers 255 through 0 (counting backwards) you could
1801 write:
1802
1803                   ::
1804
1805                    .count  set     255             ; initialize counter
1806                            .rept 256               ; repeat 256 times:
1807                            dc.b    .count          ;   deposit counter
1808                    .count  set     .count - 1      ;   and decrement it
1809                            .endr                   ; (end of repeat block)
1810
1811 Repeat blocks can also be used to duplicate identical pieces of code (which are
1812 common in bitmap-graphics routines). For example:
1813
1814                   ::
1815
1816                    .rept 16                        ; clear 16 words
1817                    clr.w (a0)+                     ;   starting at AO
1818                    .endr                           ;
1819
1820 `Jaguar GPU/DSP Mode`_
1821 ======================
1822
1823 RMAC will generate code for the Atari Jaguar GPU and DSP custom RISC (Reduced
1824 Instruction Set Computer) processors. See the Atari Jaguar Software reference Manual - Tom
1825 & Jerry for a complete listing of Jaguar GPU and DSP assembler mnemonics and addressing
1826 modes.
1827
1828 `Condition Codes`_
1829 ''''''''''''''''''
1830 The following condition codes for the GPU/DSP JUMP and JR instructions are built-in:
1831  
1832   ::
1833
1834    CC (Carry Clear) = %00100
1835    CS (Carry Set)   = %01000
1836    EQ (Equal)       = %00010
1837    MI (Minus)       = %11000
1838    NE (Not Equal)   = %00001
1839    PL (Plus)        = %10100
1840    HI (Higher)      = %00101
1841    T (True)         = %00000
1842
1843 `Jaguar Object Processor Mode`_
1844 ===============================
1845
1846 `What is it?`_
1847 ''''''''''''''
1848
1849 An assembler to generate object lists for the Atari Jaguar's Object processor.
1850
1851
1852 `Why is it here?`_
1853 ''''''''''''''''''
1854
1855 To really utilize the OP properly, it needs an assembler. Otherwise, what
1856 happens is you end up writing an assembler in your code to assemble the OP
1857 list, and that's a real drag--something that *should* be handled by a proper
1858 assembler.
1859
1860
1861 `How do I use it?`_
1862 ''''''''''''''''''''
1863
1864 The OP assembler works similarly to the RISC assembler; to enter the OP
1865 assembler, you put the .objproc directive in your code (N.B.: like the RISC
1866 assembler, it only works in a TEXT or DATA section). From there, you build
1867 the OP list how you want it and go from there. A few caveats: you will want
1868 to put a .org directive at the top of your list, and labels that you want to
1869 be able to address in 68xxx code (for moving from a data section to an
1870 address where it will be executed by the OP, for example) should be created
1871 in .68xxx mode.
1872
1873
1874 `What are the opcodes?`_
1875 ''''''''''''''''''''''''
1876
1877 They are **bitmap**, **scbitmap**, **gpuobj**, **branch**, **stop**, **nop**, and **jump**. **nop** and **jump**
1878 are psuedo-ops, they are there as a convenience to the coder.
1879
1880
1881 `What are the proper forms for these opcodes?`_
1882 '''''''''''''''''''''''''''''''''''''''''''''''
1883
1884 They are as follows:
1885
1886 **bitmap** *data addr*, *xloc*, *yloc*, *dwidth*, *iwidth*, *iheight*, *bpp*,
1887 *pallete idx*, *flags*, *firstpix*, *pitch*
1888
1889 **scbitmap** *data addr*, *xloc*, *yloc*, *dwidth*, *iwidth*, *iheight*,
1890 *xscale*, *yscale*, *remainder*, *bpp*, *pallete idx*,
1891 *flags*, *firstpix*, *pitch*
1892
1893 **gpuobj** *line #*, *userdata* (bits 14-63 of this object)
1894
1895 **branch** VC *condition (<, =, >)* *line #*, *link addr*
1896
1897 **branch** OPFLAG, *link addr*
1898
1899 **branch** SECHALF, *link addr*
1900
1901 **stop**
1902
1903 **nop**
1904
1905 **jump** *link addr*
1906
1907 Note that the *flags* field in bitmap and scbitmap objects consist of the
1908 following: **REFLECT**, **RMW**, **TRANS**, **RELEASE**. They can be in any order (and
1909 should be separated by whitespace **only**), and you can only put a maximum of
1910 four of them in. Further note that with bitmap and scbitmap objects, all the
1911 parameters after *data addr* are optional--if they are omitted, they will
1912 use defaults (mostly 0, but 1 is the default for pitch). Also, in the
1913 scbitmap object, the *xscale*, *yscale*, and *remainder* fields can be
1914 floating point constants/expressions. *data addr* can refer to any address
1915 defined (even external!) and the linker (rln v1.6.0 or greater) will
1916 properly fix up the address.
1917
1918
1919 `What do they do?`_
1920 '''''''''''''''''''
1921
1922 Pretty much what you expect. It's beyond the scope of this little note to
1923 explain the Jaguar's Object Processor and how it operates, so you'll have to
1924 seek explanations for how they work elsewhere.
1925
1926
1927 `Why do I want to put a *.org* directive at the top of my list?`_
1928 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1929
1930 You want to put a *.org* directive at the top of your list because otherwise
1931 the assembler will not know where in memory the object list is supposed
1932 go--then when you move it to its destination, the object link addresses will
1933 all be wrong and it won't work.
1934
1935
1936 `Why would I copy my object list to another memory location?`_
1937 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1938
1939 Simple: because the OP destroys the list as it uses it to render the screen.
1940 If you don't keep a fresh copy stashed away somewhere to refresh it before
1941 the next frame is rendered, what you see on the screen will not be what you
1942 expect, as the OP has scribbled all over it!
1943
1944
1945 `Does the assembler do anything behind my back?`_
1946 '''''''''''''''''''''''''''''''''''''''''''''''''
1947
1948 Yes, it will emit **NOP** s to ensure that bitmaps and scbitmaps are on proper
1949 memory boundaries, and fixup link addresses as necessary. This is needed
1950 because of a quirk in how the OP works (it ORs constants on the address
1951 lines to get the phrases it needs and if they are not zeroes, it will fail
1952 in bizarre ways). It will also set all *ypos* constants on the correct
1953 half-line (as that's how the OP views them).
1954
1955
1956 `Why can't I define the link addresses for all the objects?`_
1957 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1958
1959 You really, *really* don't want to do this. Trust me on this one.
1960
1961 `How about an example of an object list?`_
1962 ''''''''''''''''''''''''''''''''''''''''''
1963
1964     ::
1965
1966                 objList = $10000
1967                 bRam = $20000
1968         ;
1969                 .68000
1970         objects:            ; This is the label you will use to address this in 68K code
1971                 .objproc    ; Engage the OP assembler
1972                 .org    objList ; Tell the OP assembler where the list will execute
1973         ;
1974                 branch      VC < 69, .stahp     ; Branch to the STOP object if VC < 69
1975                 branch      VC > 241, .stahp    ; Branch to the STOP object if VC > 241
1976                 bitmap      bRAM, 22, 70, 24, 24, 22, 4
1977                 bitmap      bRAM, 20+96+96, 70, 24, 24, 22, 4, 0, REFLECT
1978                 scbitmap    tms, 20, 70, 1, 1, 8, 3.0, 3.0, 2.9999, 0, 0, TRANS
1979                 scbitmap    tmsShadow, 23, 73, 1, 1, 8, 3.0, 3.0, 2.9999, 0, 3, TRANS
1980                 bitmap      sbRelBM, 30, 108, 3, 3, 8, 0, 1, TRANS
1981                 bitmap      txt1BM, 46, 132, 3, 3, 8, 0, 2, TRANS
1982                 bitmap      txt2BM, 46, 148, 3, 3, 8, 0, 2, TRANS
1983                 bitmap      txt3BM, 22, 164, 3, 3, 8, 0, 2, TRANS
1984                 jump        .haha
1985         .stahp:
1986                 stop
1987         .haha:
1988                 jump        .stahp
1989
1990
1991 `DSP 56001 Mode`_
1992 =================
1993
1994 RMAC fully supports Motorola's DSP56001 as used on the Atari Falcon and can output
1995 binary code in the two most popular formats: *.lod* (ASCII dump, supported by the
1996 Atari Falcon XBIOS) and *.p56* (binary equivalent of *.lod*)
1997
1998 `Differences from Motorola's assembler`_
1999 ''''''''''''''''''''''''''''''''''''''''
2000
2001 - Motorola's assembler aliases **and #xxx,reg** with **andi #xxx,reg** and can
2002   distinguish between the two. rmac needs the user to be explicit and will
2003   generate an error if the programmer tries to use syntax from one instruction
2004   to the other.
2005 - Similarly Motorola's assembler can alias **move** with **movec**, **movep** 
2006   and **movem**. rmac also not accept such aliasing and generate an error.
2007 - Motorola's assembler uses the underscore character (*_*) to define local
2008   labels. In order for rmac to maintain a uniform syntax across all platforms,
2009   such labels will not be treated as local.
2010 - Macros syntax is different from Motorola's assembler. This includes local
2011   labels inside macros. The user is encouraged to study the `Macros`_ section
2012   and compare syntactical differences.
2013 - Motorola's assembler allows reordering of addressing modes **x:**, **x:r**,
2014   **r:y**, **x:y**. rmac will only accept syntax as is defined on the reference
2015   manual.
2016 - In **L:** section a dc value cannot be 12 hex digits like Motorola's assmebler.
2017   Instead, the value needs to be split into two parts separated by **:**.
2018
2019 `6502 Support`_
2020 ===============
2021 RMAC will generate code for the Motorola 6502 microprocessor. This chapter
2022 describes extra addressing modes and directives used to support the 6502.
2023
2024 As the 6502 object code is not linkable (currently there is no linker) external
2025 references may not be made. (Nevertheless, RMAC may reasonably be used for
2026 large assemblies because of its blinding speed.)
2027
2028 `6502 Addressing Modes`_
2029 ''''''''''''''''''''''''
2030 All standard 6502 addressing modes are supported, with the exception of the
2031 accumulator addressing form, which must be omitted (e.g. "ror a" becomes "ror").
2032 Five extra modes, synonyms for existing ones, are included for compatibility with
2033 the Atari Coinop assembler.
2034
2035 ============== ========================================
2036 *empty*        implied or accumulator (e.g. tsx or ror)
2037 *expr*         absolute or zeropage
2038 #\ *expr*      immediate
2039 #<\ *expr*     immediate low byte of a word
2040 #>\ *expr*     immediate high byte of a word
2041 (*expr*,x)     indirect X
2042 (*expr*),y     indirect Y
2043 (*expr*)       indirect
2044 *expr*,x       indexed X
2045 *expr*,y       indexed Y
2046 @\ *expr*\ (x) indirect X
2047 @\ *expr*\ (y) indirect Y
2048 @expr          indirect
2049 x,\ *expr*     indexed X
2050 y,\ *expr*     indexed Y
2051 ============== ========================================
2052
2053 `6502 Directives`_
2054 ''''''''''''''''''
2055 **.6502**
2056    This directive enters the 6502 section. The location counter is undefined, and
2057    must be set with ".org" before any code can be generated.
2058
2059    The "``dc.w``" directive will produce 6502-format words (low byte first). The
2060    68000's reserved keywords (``d0-d7/a0-a7/ssp/usp`` and so on) remain reserved
2061    (and thus unusable) while in the 6502 section. The directives **globl**, **dc.l**,
2062    **dcb.l**, **text**, **data**, **bss**, **abs**, **even** and **comm** are illegal in the 6502 section.
2063    It is permitted, though probably not useful, to generate both 6502 and 68000
2064    code in the same object file.
2065 **.68000**
2066    This directive leaves the 6502 segment and returns to the 68000's text segment.
2067    68000 instructions may be assembled as normal.
2068 **.org** *location*
2069    This directive sets the value of the location
2070    counter (or **pc**) to location, an expression that must be defined, absolute, and
2071    less than $10000.
2072
2073    WARNING
2074
2075    It is possible to assemble "beyond" the microprocessor's 64K address space, but
2076    attempting to do so will probably screw up the assembler. DO NOT attempt
2077    to generate code like this:
2078
2079      ::
2080
2081       .org $fffe
2082       nop
2083       nop
2084       nop
2085
2086    the third NOP in this example, at location $10000, may cause the assembler
2087    to crash or exhibit spectacular schizophrenia. In any case, RMAC will give
2088    no warning before flaking out.
2089
2090 `6502 Object Code Format`_
2091 ''''''''''''''''''''''''''
2092 Traditionally Madmac had a very kludgy way of storing object files. This has been
2093 replaced with a more standard *.exe* (or *.com* or *.xex* if you prefer). Briefly,
2094 the *.exe* format consists of chunks of this format (one after the other):
2095
2096     ::
2097
2098      Offset     Description
2099      00-01      $FFFF - Indicates a binary load file. Mandatory for first segment, optional for any other segment
2100      02-03      Start Address. The segment will load at this address
2101      04-05      End Address. The last byte to load for this segment
2102      06-..      The actual segment data to load (End Address-Start Address + 1 bytes)
2103
2104 `Error Messages`_
2105 =================
2106
2107 `When Things Go Wrong`_
2108 '''''''''''''''''''''''
2109 Most of RMAC's error messages are self-explanatory. They fall into four classes:
2110 warnings about situations that you (or the assembler) may not be happy about,
2111 errors that cause the assembler to not generate object files, fatal errors that cause
2112 the assembler to abort immediately, and internal errors that should never happen.\ [3]_
2113
2114 You can write editor macros (or sed or awk scripts) to parse the error messages
2115 RMAC generates. When a message is printed, it is of the form:
2116
2117          "*filename*" , ``line`` *line-number*: *message*
2118
2119 The first element, a filename enclosed in double quotes, indicates the file that generated
2120 the error. The filename is followed by a comma, the word "``line``", and a line
2121 number, and finally a colon and the text of the message. The filename "**(\*top\*)**"
2122 indicates that the assembler could not determine which file had the problem.
2123
2124 The following sections list warnings, errors and fatal errors in alphabetical
2125 order, along with a short description of what may have caused the problem.
2126
2127 .. [3] If you come across an internal error, we would appreciate it if you would contact the rmac development team and let us know about the problem.
2128
2129 `Warnings`_
2130 '''''''''''
2131 **bad backslash code in string**
2132   You tried to follow a backslash in a string with a character that the assembler
2133   didn't recognize. Remember that RMAC uses a C-style escape system in
2134   strings.
2135 **label ignored**
2136   You specified a label before a macro, **rept** or **endm** directive. The assembler
2137   is warning you that the label will not be defined in the assembly.
2138 **unoptimized short branch**
2139   This warning is only generated if the -s switch is specified on the command
2140   line. The message refers to a forward, unsized long branch that you could have
2141   made short (.s).
2142
2143 `Fatal Errors`_
2144 '''''''''''''''
2145
2146 **cannot continue**
2147   As a result of previous errors, the assembler cannot continue processing. The
2148   assembly is aborted.
2149 **line too long as a result of macro expansion**
2150   When a source line within a macro was expanded, the resultant line was too
2151   long for RMAC (longer than 200 characters or so).
2152
2153
2154 **memory exhausted**
2155     The assembler ran out of memory. You should (1) split up your source files
2156     and assemble them seperately, or (2) if you have any ramdisks or RAM-resident
2157     programs (like desk accessories) decrease their size so that the assembler has
2158     more RAM to work with. As a rule of thumb, pure 68000 code will use up to
2159     twice the number of bytes contained in the source files, whereas 6502 code will
2160     use 64K of ram right away, plus the size of the source files. The assembler itself
2161     uses about 80K bytes. Get out your calculator...
2162 **too many ENDMs**
2163     The assembler ran across an **endm** directive when it wasn't expecting to see
2164     one. The assembly is aborted. Check the nesting of your macro definitions -
2165     you probably have an extra **endm**.
2166
2167
2168 `Errors`_
2169 '''''''''
2170
2171 **.cargs syntax**
2172
2173     Syntax error in **.cargs** directive.
2174
2175 **.comm symbol already defined**
2176
2177     You tried to ``.comm`` a symbol that was already defined.
2178
2179 **.ds permitted only in BSS**
2180
2181     You tried to use ``.ds`` in the text or data section.
2182
2183 **.init not permitted in BSS or ABS**
2184
2185     You tried to use ``.init`` in the BSS or ABS section.
2186
2187 **Cannot create:** *filename*
2188
2189     The assembler could not create the indicated filename.
2190
2191 **External quick reference**
2192
2193     You tried to make the immediate operand of a **moveq**, **subq** or **addq** instruction external.
2194
2195 **PC-relative expr across sections**
2196
2197     You tried to make a PC-relative reference to a location contained in another
2198     section.
2199
2200 **[bwsl] must follow '.' in symbol**
2201
2202     You tried to follow a dot in a symbol name with something other than one of
2203     the four characters 'B', 'W', 'S' or 'L'.
2204
2205 **addressing mode syntax**
2206
2207     You made a syntax error in an addressing mode.
2208
2209 **assert failure**
2210
2211     One of your **.assert** directives failed!
2212
2213 **bad (section) expression**
2214
2215     You tried to mix and match sections in an expression.
2216
2217 **bad 6502 addressing mode**
2218
2219     The 6502 mnemonic will not work with the addressing mode you specified.
2220
2221 **bad expression**
2222
2223     There's a syntax error in the expression you typed.
2224
2225 **bad size specified**
2226
2227   You tried to use an inappropriate size suffix for the instruction. Check your
2228   68000 manual for allowable sizes.
2229
2230 **bad size suffix**
2231
2232   You can't use .b (byte) mode with the **movem** instruction.
2233
2234 **cannot .globl local symbol**
2235
2236   You tried to make a confined symbol global or common.
2237
2238 **cannot initialize non-storage (BSS) section**
2239
2240   You tried to generate instructions (or data, with dc) in the BSS or ABS section.
2241
2242 **cannot use '.b' with an address register**
2243
2244   You tried to use a byte-size suffix with an address register. The 68000 does not
2245   perform byte-sized address register operations.
2246
2247 **directive illegal in .6502 section**
2248
2249   You tried to use a 68000-oriented directive in the 6502 section.
2250
2251 **divide by zero**
2252
2253   The expression you typed involves a division by zero.
2254
2255 **expression out of range**
2256
2257   The expression you typed is out of range for its application.
2258
2259 **external byte reference**
2260
2261   You tried to make a byte-sized reference to an external symbol, which the
2262   object file format will not allow.
2263
2264 **external short branch**
2265
2266   You tried to make a short branch to an external symbol, which the linker cannot
2267   handle.
2268
2269 **extra (unexpected) text found after addressing mode**
2270
2271   RMAC thought it was done processing a line, but it ran up against "extra"
2272   stuff. Be sure that any comment on the line begins with a semicolon, and check
2273   for dangling commas, etc.
2274
2275 **forward or undefined .assert**
2276
2277   The expression you typed after a **.assert** directive had an undefined value.
2278   Remember that RMAC is one-pass.
2279
2280 **hit EOF without finding matching .endif**
2281
2282   The assembler fell off the end of last input file without finding a **.endif** to
2283   match an . it. You probably forgot a **.endif** somewhere.
2284
2285 **illegal 6502 addressing mode**
2286
2287   The 6502 instruction you typed doesn't work with the addressing mode you
2288   specified.
2289
2290 **illegal absolute expression**
2291
2292   You can't use an absolute-valued expression here.
2293
2294 **illegal bra.s with zero offset**
2295
2296   You can't do a short branch to the very next instruction (read your 68000
2297   manual).
2298
2299 **illegal byte-sized relative reference**
2300
2301   The object file format does not permit bytes contain relocatable values; you
2302   tried to use a byte-sized relocatable expression in an immediate addressing
2303   mode.
2304
2305 **illegal character**
2306
2307  Your source file contains a character that RMAC doesn't allow. (most
2308  control characters fall into this category).
2309
2310 **illegal initialization of section**
2311
2312  You tried to use .dc or .dcb in the BSS or ABS sections.
2313
2314 **illegal relative address**
2315
2316  The relative address you specified is illegal because it belongs to a different
2317  section.
2318
2319 **illegal word relocatable (in .PRG mode)**
2320
2321  You can't have anything other than long relocatable values when you're gener-
2322  ating a **.PRG** file.
2323
2324 **inappropriate addressing mode**
2325
2326  The mnemonic you typed doesn't work with the addressing modes you specified.
2327  Check your 68000 manual for allowable combinations.
2328
2329 **invalid addressing mode**
2330
2331  The combination of addressing modes you picked for the **movem** instruction
2332  are not implemented by the 68000. Check your 68000 reference manual for
2333  details.
2334
2335 **invalid symbol following ^^**
2336
2337  What followed the ^^ wasn't a valid symbol at all.
2338
2339 **mis-nested .endr**
2340
2341  The assembler found a **.endr** directive when it wasn't prepared to find one.
2342  Check your repeat-block nesting.
2343
2344 **mismatched .else**
2345
2346  The assembler found a **.else** directive when it wasn't prepared to find one.
2347  Check your conditional assembly nesting.
2348
2349 **mismatched .endif**
2350
2351  The assembler found a **.endif** directive when it wasn't prepared to find one.
2352  Check your conditional assembly nesting.
2353
2354 **missing '='**
2355
2356 **missing '}'**
2357
2358 **missing argument name**
2359
2360 **missing close parenthesis ')'**
2361
2362 **missing close parenthesis ']'**
2363
2364 **missing comma**
2365
2366 **missing filename**
2367
2368 **missing string**
2369
2370 **missing symbol**
2371
2372 **missing symbol or string**
2373
2374  The assembler expected to see a symbol/filename/string (etc...), but found
2375  something else instead. In most cases the problem should be obvious.
2376
2377 **misuse of '.', not allowed in symbols**
2378
2379  You tried to use a dot (.) in the middle of a symbol name.
2380
2381 **mod (%) by zero**
2382
2383  The expression you typed involves a modulo by zero.
2384
2385 **multiple formal argument definition**
2386
2387   The list of formal parameter names you supplied for a macro definition includes
2388   two identical names.
2389
2390 **multiple macro definition**
2391
2392   You tried to define a macro which already had a definition.
2393
2394 **non-absolute byte reference**
2395
2396   You tried to make a byte reference to a relocatable value, which the object file
2397   format does not allow.
2398
2399 **non-absolute byte value**
2400
2401   You tried to dc.b or dcb.b a relocatable value. Byte relocatable values are
2402   not permitted by the object file format.
2403
2404 **register list order**
2405
2406   You tried to specify a register list like **D7-D0**, which is illegal. Remember
2407   that the first register number must be less than or equal to the second register
2408   number.
2409
2410 **register list syntax**
2411
2412   You made an error in specifying a register list for a **.reg** directive or a **.movem**
2413   instruction.
2414
2415 **symbol list syntax**
2416
2417   You probably forgot a comma between the names of two symbols in a symbol
2418   list, or you left a comma dangling on the end of the line.
2419
2420 **syntax error**
2421
2422   This is a "catch-all" error.
2423
2424 **undefined expression**
2425
2426   The expression has an undefined value because of a forward reference, or an
2427   undefined or external symbol.
2428
2429 **unimplemented addressing mode**
2430
2431   You tried to use 68020 "square-bracket" notation for a 68020 addressing mode.
2432   RMAC does not support 68020 addressing modes.
2433
2434 **unimplemented directive**
2435
2436   You have found a directive that didn't appear in the documentation. It doesn't
2437   work.
2438
2439 **unimplemented mnemonic**
2440
2441   You've found a bug.
2442
2443 **unknown symbol following ^^**
2444
2445   You followed a ^^ with something other than one of the names defined, referenced
2446   or streq.
2447
2448 **unsupported 68020 addressing mode**
2449
2450   The assembler saw a 68020-type addressing mode. RMAC does not assemble
2451   code for the 68020 or 68010.
2452
2453 **unterminated string**
2454
2455   You specified a string starting with a single or double quote, but forgot to type
2456   the closing quote.
2457
2458 **write error**
2459
2460   The assembler had a problem writing an object file. This is usually caused by
2461   a full disk, or a bad sector on the media.