The idea is for a user of the macros to write a simple macro that results in some flag being set (in the CPU) and then set that flag so the conditional check knows what code to generate. You can achieve some nice things with it, and as an example and for my own use I've written both a signed and unsigned comparison function.
First, how to make a function - a simple example:
.macro reg_is_negative reg
.if .xmatch(reg,a) pha pla .elseif .xmatch(reg,x) txa .elseif .xmatch(reg,y) tya .else .error "no register" .endif set_flag_test N set .endmacroYou can do anything you want like a normal macro, just add set_flag_test followed by the flag you want to test. You can still use all the .defines as well form the first post on this: http://mynesdev.blogspot.ca/2012/09/ca65-highlevel-macros.html So in this example you could:
if reg_is_negative a ;code endifThe if macro "knows" to check for the status of the N flag, where N set means TRUE.
Macros comp and scomp
Both of these macros accept the same values and can evaluate anything on either side of one comparison operator except for a comparison of two registers (they can only evaluate one comparison, no and or or). If using a greater or less compare with a low byte or high byte operator, you must enclose the operator in brackets: Use would be like this:
if scomp a >= #(<-29) ; code endifThere is not much more to it, operators supported are the standard <, >, <=, >=, =, <>. You can also use not at the beginning as so:
if not scomp a >= #(<-29) ; code endifAnother example..
if comp my_var1 >= #29 ; code endifFull example code here: https://app.dumptruck.goldenfrog.com/p/b9UI5-8_ck
No comments:
Post a Comment