I'm using EASy68K to write software for the Sega Genesis/Mega Drive. Even a modest program written for the Genesis platform entails a hefty amount of complexity, so I'm trying to think of ways to make my code more readable, manageable, and easier to debug. In the case of debugging, one idea I had was to implement bounds checking on arguments passed to macros. I was hoping I could use conditional assembly directives to do the checking, but I'm having a hard time figuring out how, if it's even possible at all. Here's a pseudocode example of what I'm trying to do:
Code:
TestMac MACRO
; move some immediate data \1 to a register \2, but only if \1 is in the range of #0-#23, and \2 is one of d0-d7
IF \1 > #23, OR \1 < #0
FAIL arg 1 is out of range - enter a value from #0-#23
MEXIT
ELSE
IFNC \2 'd'?, OR \2 'D'? ; ? represents single character wild card
FAIL arg 2 is invalid - enter a data register symbol from d0-d7
MEXIT
ENDC
ENDIF
move.b \1, \2 ; args are in range if we've made it here
ENDM
ORG $1000
StartLabel:
TestMac #0, d4 ; this works, d4 = $xxxxxx00
TestMac #24, d0 ; won't work, arg 1 is > #23
TestMac #-1, d7 ; won't work, arg 1 is < #0
TestMac #23, a0 ; won't work, arg 2 isn't a data register
END StartLabel
After fiddling with this on my development PC, I get the sense that conditional assembly isn't suited to this task, but I'm still not sure. Does this approach to bounds checking for macro arguments make sense? If so, how would I make it work?