Debian Codegraph @

docs/QuickRef.txt

raw
1
2
3 ACME
4
5 ...the ACME Crossassembler for Multiple Environments
6
7 --- Quick reference ---
8
9
10 This file should give you a basic overview. More specialized stuff
11 like forcing a specific addressing mode is discussed in extra files
12 ("AddrModes.txt" in this case).
13
14
15 ----------------------------------------------------------------------
16 Section: Example of what an ACME source code file looks like
17 ----------------------------------------------------------------------
18
19 ;--- Example code fragment, start ---
20
21 !to "tiny.o", cbm ; set output file and format
22 * = $c000 ; set program counter
23
24 CLEAR = 147 ; a global symbol definition
25 !addr basout = $ffd2 ; another one, marked as an address
26
27 ; a string output loop:
28 ldx #0
29 beq + ; enter loop
30
31 - jsr basout ; output character
32 inx ; advance pointer
33 + lda .string, x ; get character
34 bne - ; check whether last
35 rts
36 .string !pet "Dumb example", 13, 0
37
38 ;--- Example code fragment, end ---
39
40
41 Here's the same fragment again, now with some additional info:
42
43 ;--- Example code fragment, start ---
44
45 !to "tiny.o", cbm ; set output file and format
46 ; This is a pseudo opcode to select the output filename and format.
47 ; This can also be done using the command line options "-o" and "-f",
48 ; respectively.
49 * = $c000 ; set program counter
50 ; This can also be done using the command line option "--setpc".
51
52 ; some global symbol definitions
53 CLEAR = 147 ; this is a simple constant
54 ; Now "CLEAR" is defined as a global symbol having the value 147.
55 !addr basout = $ffd2 ; this gets marked as an address
56 ; Now "basout" is defined as a global "address" type symbol having the
57 ; value $ffd2.
58 ; The distinction between addresses and non-addresses only
59 ; matters when the type check system gets activated using
60 ; the "-Wtype-mismatch" switch. Then, a line like
61 ; "lda CLEAR" would trigger a type mismatch warning because
62 ; of the missing '#' character.
63
64 ; a string output loop:
65 ldx #0
66 beq + ; enter loop
67 ; "+" is an anonymous forward label. Other ones are "++", "+++", etc.
68 ; They can be used like any other symbol, but they always reference
69 ; their *NEXT* definition. This saves having to think of names for
70 ; unimportant labels. As the label's value is not defined yet, ACME
71 ; will need to perform a second pass.
72 - jsr basout ; output character
73 ; "-" is an anonymous backward label. Other ones are "--", "---", etc.
74 ; They can be used like any other symbol, but they always reference
75 ; their *PREVIOUS* definition. This saves having to think of names for
76 ; unimportant labels. In the line above, the value of "-" is set to
77 ; the current program counter.
78 inx ; advance pointer
79 + lda .string,x ; get character
80 ; Here the value of "+" is set to the current program counter.
81 ; ".string" is a local symbol (because its name starts with a '.'
82 ; character), but as its value is not defined yet, ACME will need to
83 ; perform a second pass.
84 bne - ; check whether last
85 ; Here the last definition of the anonymous "-" label is referenced.
86 rts
87 .string !pet "Dumb example", 13, 0
88 ; Now the value of the local label ".string" is set to the current
89 ; program counter. All label values are defined now, so after having
90 ; done the second pass, the binary will be saved. The "!pet" pseudo
91 ; opcode stores its string argument in PetSCII encoding to memory,
92 ; followed by the given byte values.
93
94 ;--- Example code fragment, end ---
95
96 As you can see, pseudo opcodes are prefixed with an exclamation mark.
97 That's non-standard, but: Backwards compatibility is the root of all
98 evil. :)
99
100 Summary about symbols:
101
102 There are global symbols (their names starting with a letter or an
103 underscore character). These can be accessed throughout the whole
104 assembly.
105 Then there are local symbols (their names starting with a '.'
106 character). These can only be accessed from inside the macro or zone
107 they were defined in (for more about macros and zones, see the file
108 "AllPOs.txt").
109 There are also "cheap locals": their names start with an '@'.
110 The area where these can be accessed is limited automatically by the
111 previous and the following global label (cheap locals are "cheap"
112 because you don't have to put in any extra work to limit their range).
113 And then there are anonymous labels (their names being sequences of
114 either '-' or '+' characters). They are also local (bound to their
115 macro/zone), but in addition to that, the "-" labels can only be used
116 for backward references, while the "+" labels can only be used for
117 forward references.
118 In contrast to global and local labels, anonymous labels can not be
119 defined explicitly (as in SYMBOL = VALUE).
120 Each macro call automatically gets its own scope for local symbols.
121
122 Save the given example source code to a file called "tiny.a" and start
123 acme by typing
124
125 acme tiny.a
126
127 ACME will then parse the file and report any errors. An output file
128 will only be generated if there were no errors and if an output
129 filename has been given.
130
131 After assembly, the example program can be run on a C64 using
132
133 LOAD "tiny.o", 8, 1
134 SYS 49152
135
136 Note that ACME does not include any routines for transferring data to
137 a C64. Such tools exist on almost every platform, and I didn't want
138 ACME to become bloatware.
139
140
141 ----------------------------------------------------------------------
142 Section: The pseudo opcodes
143 ----------------------------------------------------------------------
144
145 A list with information on how to use all the Pseudo Opcodes can be
146 found in the file "AllPOs.txt". Here's just a short overview:
147
148 !byte !word !24 !32 !fill !align
149 ...for directly placing values into the output file.
150
151 !zone !symbollist
152 ...for defining the scope of local symbols and saving global symbols.
153
154 !convtab !pet !raw !scr !scrxor !text
155 ...for converting and outputting strings.
156
157 !do !endoffile !for !if !ifdef !ifndef !set !while
158 ...for flow control; looping assembly and conditional assembly.
159
160 !binary !source !to
161 ...for handling input and output files.
162
163 !pseudopc
164 ...for offset assembly.
165
166 !initmem *=
167 ...for segment assembly.
168
169 !macro +
170 ...for defining and calling macros.
171
172 !cpu !al !as !rl !rs
173 ...for CPU support, especially the 65816 processor.
174
175 !warn !error !serious
176 ...for generating warnings, errors and serious errors.
177
178 !address
179 ...to mark symbols as addresses, for the optional type check system.
180
181
182 ----------------------------------------------------------------------
183 Section: Command line arguments
184 ----------------------------------------------------------------------
185
186 The command line syntax for calling acme is quite simple:
187
188 acme [options] [files]
189
190 Available options are:
191 -h, --help show this help and exit
192 This is more or less useless, because the help is also shown
193 if ACME is run without any arguments at all.
194
195 -f, --format FORMAT set output file format
196 Use this with a bogus format type to get a list of all
197 supported ones (as of writing: "plain", "cbm" and "apple")
198 -o, --outfile FILE set output file name
199 Output file name and format can also be given using the "!to"
200 pseudo opcode. If the format is not specified, "!to" defaults
201 to "cbm", while the command line option defaults to "plain".
202
203 -r, --report set report file name
204 This creates a text listing containing the original line
205 number, the resulting memory address, the byte value(s) put
206 there and the original text line from the source file.
207
208 -l, --symbollist FILE set symbol list file name
209 This can also be given using the "!symbollist"/"!sl" pseudo
210 opcode. The switch was called "--labeldump" in older versions,
211 that name still works, too.
212
213 --vicelabels FILE set file name for label dump in VICE format
214 The resulting file uses a format suited for the VICE emulator.
215
216 --setpc VALUE set program counter
217 This can also be given in the source code using "* = VALUE".
218
219 --cpu CPU_TYPE set target processor
220 This can be changed in the source code using the "!cpu" pseudo
221 opcode. Defaults to 6502.
222 Use this with a bogus cpu type to get a list of all supported
223 ones.
224
225 --initmem VALUE define 'empty' memory
226 This can also be given using the "!initmem" pseudo opcode.
227 Defaults to zero.
228
229 --maxerrors NUMBER set number of errors before exiting
230 If not given, defaults to 10.
231
232 --maxdepth NUMBER set recursion depth for macro calls and !src
233 The default value for this is 64.
234
235 --ignore-zeroes do not determine number size by leading zeroes
236 Normally, using leading zeroes forces ACME to generate
237 oversized addressing modes, like 3-byte absolute instructions
238 instead of 2-byte zero page instructions.
239 Using this CLI switch disables this behavior.
240
241 --strict-segments turn segment overlap warnings into errors
242 When changing the program counter, segment overlap warnings may
243 be generated. Using this CLI switch turns those warnings into
244 errors (which is recommended).
245 This strict behavior may become the default in future releases!
246
247 -vDIGIT set verbosity level
248 Sets how much additional informational output is generated.
249 Higher values mean more output:
250 acme -v0 source.a
251 This is the default: No additional output is generated,
252 ACME will only display warnings and errors.
253 acme -v1 source.a
254 Now the start and end addresses of the generated output
255 file are displayed, along with its size (a CBM-style
256 "load address" is *not* counted).
257 acme -v2 source.a
258 In addition to the "-v1" output, ACME will announce each
259 pass, will show amount and offset of "!binary" loads, and
260 show start and end addresses and size of each segment.
261 acme -v3 source.a
262 In addition to the "-v2" output, ACME will now announce
263 each source file.
264
265 -DSYMBOL=VALUE define global symbol
266 This option is useful if you build your projects using
267 Makefiles: "-DSYSTEM=64" could build the C64 version while
268 "-DSYSTEM=128" could build the C128 version of the software
269 (using conditional assembly in your source code file).
270
271 -I PATH/TO/DIR add search path for input files
272 This option allows to add a directory to the search list for
273 input files. If an input file cannot be found in the current
274 working directory, all directories in the search list are
275 tried (the first match is used).
276
277 -W fine-tune amount and type of warnings
278 -Wno-label-indent
279 Disables warnings about labels not being in the leftmost
280 column.
281 -Wno-old-for
282 Disables warnings about the old "!for" syntax and at the
283 same time enables warnings about the _new_ "!for" syntax.
284 Internally, this does exactly the same as what happens
285 when the "--dialect 0.94.8" CLI switch is used...
286 -Wno-bin-len
287 Do not complain about unusual number of digits in a binary
288 literal.
289 -Wtype-mismatch
290 Enables type checking system (warns about wrong types).
291
292 --use-stdout fix for 'Relaunch64' IDE
293 With this option, errors are written to the standard output
294 stream instead of to the standard error stream.
295
296 --msvc output errors in MS VS format
297 This changes the format of the error output to that used by
298 a certain commercial IDE.
299
300 --color uses ANSI color codes for error output
301 If your terminal emulation supports ANSI escape codes, use
302 this option to have warnings and errors displayed in color.
303
304 --fullstop use '.' as pseudo opcode prefix
305 This changes the prefix character used to mark pseudo opcodes
306 from '!' to '.' (so sources intended for other assemblers can
307 be converted with less effort).
308
309 --dialect VERSION behave like different version
310 This CLI switch tells ACME to mimic the behavior of an older
311 version. Use this with a bogus version to get a list of all
312 supported ones.
313
314 --test enable experimental features
315 This is for people who want to help test new features before
316 they are officially announced.
317
318 -V, --version show version and exit.
319
320 Platform-specific versions of ACME might offer more options.
321 Since version 0.89, ACME accepts more than one top-level-filename
322 given on the command line.
323
324
325 ----------------------------------------------------------------------
326 Section: The expression parser
327 ----------------------------------------------------------------------
328
329 ACME has a relatively powerful maths parser. This parser is used
330 whenever ACME expects to read a value. Supported operations include
331 addition, subtraction, multiplication, divisions, comparisons, shifts,
332 negation, boolean operations and some assembler-specific stuff like
333 extracting the "low byte", the "high byte" or the "bank byte" of a
334 value.
335 Calculations are done using either signed (at least 32-bit) integer
336 arithmetic or floating point arithmetic using the C "double" data
337 type. Symbol values are stored the same way.
338
339
340 This is a list of the value formats currently known by ACME:
341
342 Examples Notes
343 ---------------------------------------------------------------------
344 128 a decimal value, integer
345 128.5 a decimal value, floating point
346 $d011 hexadecimal values are indicated by either a
347 0xffd2 leading "$" or a leading "0x".
348 &1701 an octal value, indicated by "&"
349 %1010 binary values are indicated by either a leading "%"
350 %....#... or a leading "0b". In binary values, you can
351 0b01100110 substitute the characters "0" and "1" by "." and
352 "#" respectively. This way the values are much
353 more readable, especially when building bitmapped
354 objects (like C64 sprites or fonts) in your source
355 code.
356 'p' single characters in single quotes are converted to
357 their character code. The actual numeric value
358 depends on the current conversion table chosen
359 using the "!ct" pseudo opcode.
360 "player 2" double quotes indicate text strings. See below for
361 more information on single vs. double quotes.
362 [2, 3, 5, 7] brackets indicate lists. These are useful to group
363 [0, [x, y], 9] data, for example when passing an arbitrary number
364 of arguments to a macro.
365 poll_joy2 a global symbol
366 .fail a local symbol, indicated by leading "."
367 @loop a "cheap local", indicated by leading "@"
368 * the current program counter. During offset assembly,
369 "*" gives the value of the "Pseudo PC". Just to
370 make sure: The value of the program counter is
371 always the value that was valid at the start of
372 the current statement, so
373 !word *, *, *, *
374 will give the same value four times. I think most
375 assemblers do it this way.
376
377 In older versions of ACME, 'x' and "x" were the same thing, namely the
378 character code of the letter x using the currently selected encoding
379 table.
380 Since release 0.97, anything in single quotes gives the character code
381 (as before), while anything in double quotes is treated as a string
382 object. To be compatible to those older versions, ACME keeps accepting
383 one-char strings in a lot of places where actually single characters
384 are expected.
385
386
387 This is a list of the operators currently known by ACME:
388
389 Priority Example Meaning Alias Note
390 ----------------------------------------------------------------------
391 16 is_number(v) these three functions return 1 *3
392 16 is_list(v) if v is the correct symbol *3
393 16 is_string(v) type and 0 otherwise *3
394 16 len(v) length of list or string *2
395 16 sin(v) trigonometric sine function
396 16 cos(v) trigonometric cosine function
397 16 tan(v) trigonometric tangent function
398 16 arcsin(v) inverse of sin()
399 16 arccos(v) inverse of cos()
400 16 arctan(v) inverse of tan()
401 16 address(v) mark as address addr(v)
402 16 int(v) convert to integer
403 16 float(v) convert to float
404 15 &symbol "unpseudopc" symbol (see docs on "!pseudopc")
405 14 v[w] access v with index w *2
406 13 ! v bit-wise complement NOT
407 12 v ^ w to the power of
408 11 - v negate
409 10 v * w multiply
410 10 v / w divide
411 10 v DIV w integer divide
412 10 v % w remainder of DIV MOD
413 9 v + w add *3
414 9 v - w subtract
415 8 v << w shift left ASL, LSL
416 8 v >> w arithmetic shift right ASR
417 8 v >>> w logical shift right LSR
418 7 < v low byte of
419 7 > v high byte of
420 7 ^ v bank byte of
421 6 v <= w lower or equal
422 6 v < w lower than
423 6 v >= w higher or equal
424 6 v > w higher than
425 5 v != w not equal <>, >< *3
426 4 v == w equal = *3
427 3 v & w bit-wise AND AND
428 2 bit-wise exclusive OR XOR
429 1 v | w bit-wise OR OR
430
431 Notes:
432 "*2" means this operator only works on lists and strings.
433 "*3" means this operator works on all three data types (numbers, lists
434 and strings).
435 All other operators only work on numbers.
436
437 Operations with higher priority are done first. Of course you can
438 change this using parentheses.
439 Note that though there are operators to extract the "low byte", the
440 "high byte" and the "bank byte", there is no operator to extract the
441 fourth byte. If you want to access that, shift it down using ">>>" or
442 "LSR".
443 In cases where it's not clear which operator was wanted, ACME takes
444 the longest possible one:
445 v<>w ...checks for "v not equal w"
446 v< >w ...checks for "v smaller than high byte of w"
447 So you may have to separate operators with spaces to make sure ACME
448 does what you want.
449 The "power-of" operator is right-associative, so a^b^c means a^(b^c).
450
451 Calculating 0^0 (zero to the power of zero) will give 1. If
452 you don't know why I'm telling you this, ask a mathematician. :)
453
454
455 ----------------------------------------------------------------------
456 Section: Almost, but not quite, complete syntax
457 ----------------------------------------------------------------------
458
459 Every ACME source code file consists of a non-negative number of
460 "lines". The lines have to be separated from each other using CR, LF
461 or CRLF characters.
462
463 Every line consists of a non-negative number of "statements" and an
464 optional comment. Statements have to be separated from each other
465 using colon (":") characters, the comment has to be prefixed with a
466 semicolon (";") character or two slashes ("//").
467
468 Every statement consists of an optional "label" and an optional
469 "command". These are separated from each other using any number of
470 SPACE or TAB characters. If a label has blanks before it, a warning is
471 issued (to spot typing errors - see Errors.txt for more info).
472
473 Every symbol name consists of these characters: "a" to "z", "A" to
474 "Z", "0" to "9", the underscore character "_" and all characters with
475 values beyond 127. The first character must not be a digit though. But
476 it can be '.' or '@', making the symbol a local one.
477 Local symbols beginning with '.' are only valid inside the current
478 zone (marked using the "!zone" pseudo opcode) or the current macro.
479 Local symbols beginning with '@' are only valid between the enclosing
480 global labels (or inside the current macro).
481 Two other possibilities for label names are "all-characters-are-minus"
482 (then it is an anonymous backward label) and "all-characters-are-plus"
483 (then it is an anonymous forward label).
484
485 Every command is one of the following:
486 An assembler mnemonic with an optional argument
487 A pseudo opcode, beginning with a "!" character
488 An explicit symbol definition (SYMBOL = VALUE)
489 A pc definition, beginning with a "*" character
490 A macro call, beginning with a "+" character
491 ...and the syntax of those things varies. :)
492
493 Assembler mnemonics and pseudo opcodes are case insensitive, so
494 whether you write "LDA" or "lda" or "LdA" does not make a difference.
495
496 In earlier releases of ACME, arithmetic operators like MOD, XOR, LSL
497 had to be written in UPPER CASE. This is no longer needed.
498
499 Symbol names are case sensitive, so "label" and "Label" are two
500 different things.