diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 751662b01..5dd1e3e13 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -2671,6 +2671,42 @@ parameters: +Detecting parameter types

+ +Sometimes it is nice to write a macro that acts differently depending on the +type of the argument supplied. An example would be a macro that loads a 16 bit +value from either an immediate operand, or from memory. The / and / +functions will allow you to do exactly this: + + + .macro ldax arg + .if (.match (.left (1, arg), #)) + ; immediate mode + lda #<(.right (.tcount (arg)-1, arg)) + ldx #>(.right (.tcount (arg)-1, arg)) + .else + ; assume absolute or zero page + lda arg + ldx 1+(arg) + .endif + .endmacro + + +Using the / function, the macro is able to +check if its argument begins with a hash mark. If so, two immediate loads are +emitted, Otherwise a load from an absolute zero page memory location is +assumed. So this macro can be used as + + + foo: .word $5678 + ... + ldax #$1234 ; X=$12, A=$34 + ... + ldax foo ; X=$56, A=$78 + + + Recursive macros

Macros may be used recursively: @@ -3161,7 +3197,7 @@ notice that other than the original TASS, ca65 can never move the programmcounter backwards - think of it as if you are assembling to disc with TASS. -Conditional assembly (Conditional assembly (.