In general, it is possible to use inline assembler statements within C macros, for example
#define toscreencode(C) (__AX__ = (C), \
asm("cmp #$60"),\
asm("bcc L1"), \
asm("and #$df"),\
asm("bne L2"), \
asm("L1:"), \
asm("and #$3f"),\
asm("L2:"), \
__AX__)
This works fine as long as the macro is called at most once per module. However, if the macro is called more than once, the compiler throws errors for the two labels ("Error: ASM label 'L1' is already defined") since the named labels are now used twice since the code is duplicated every time the macros is used.
Unfortunately, it is not possible to use a .scope
/ .endscope
with the inline assembler command. I also tried cheap local labels ("@L1" instead of "L1"), but the error persists.
Unnamed labels (":+", ":") are not accepted by the inline assembler.
It is also not possible to hack the branch command by replacing it with two recalculated bytes, because the .byte
command does not work with the inline assembler.
Any suggestions on how to make the macro usable more than once in a module?