From 7825f7d4a47007d9a5267ee57f5841822fdc3068 Mon Sep 17 00:00:00 2001 From: cuz Date: Sun, 30 Nov 2003 18:22:33 +0000 Subject: [PATCH] New section covering detection of macro parameter types git-svn-id: svn://svn.cc65.org/cc65/trunk@2698 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- doc/ca65.sgml | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) 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 (. -- 2.39.5