On Thu, Aug 09, 2012 at 07:16:49AM -0600, Egan Ford wrote: > I'm stumped here. I would like to match a leading double quote (") to > identify if I have an inline string vs. a pointer to a string. The macro concept in ca65 is based on tokens, not on characters. A token has a type and sometimes an attribute (which is the value). Examples are: Token Attribute Example ---------------------------------------------------------------------------- literal number the value of the number 3 string the value of the string "foo" accumulator - A plus operator - + left parenthesis - ( ... and so on. What you do with .MATCH is to check two token lists against each other. .XMATCH checks not only the tokens but also their attributes. So if you've passed something to your macro and want to check if it's a string, you will want to use .MATCH with a string: .match (arg, "") Please note that any string as second argument will do, because the token attributes (the contents of the string) aren't compared by .MATCH. Because "arg" may be a token list that includes something that would confuse the parser in this place, like a comma or a closing paren, you can and should protect the token list by including it in curly braces like this: .match ({arg}, "") If you want to know if it's a string that has the value "foo", you will use .XMATCH: .match ({arg}, "foo") The reason for doing macros on token and not on character level is that it simplifies things for you, because the parser does all the conversions and checking necessary. If you expect a number, you don't have to care if it's specified in decimal, hexadecimal or binary. Back to your question. Here is an example for a macro that can be used with either a literal string as argument or a label that is the address of a string in memory. The macro will output the string using a routine named printstring that expects the address of the string in A/X: .macro foo arg .local L .if .match ({arg}, "") ; String given .data L: .byte arg, 0 .code lda #<(L) ldx #>(L) jsr printstring .else ; Already existing label given lda #<(arg) ldx #<(arg) jsr printstring .endif .endmacro .data world: .byte "world", 0 .code foo "Hello " foo world Regards Uz -- Ullrich von Bassewitz uz@musoftware.de ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo@musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.Received on Thu Aug 9 23:25:11 2012
This archive was generated by hypermail 2.1.8 : 2012-08-09 23:25:15 CEST