I'm trying to add a compact #define macro in a cc65 program for performing various low-level tasks efficiently. For some of the macros, I need to pass a non-constant value to the assembler part. I studied the cc65 guide about inline assembler but could not get it to work.
Here is a minimal example
#include <stdio.h>
#include <stdlib.h>
#define set_bgcolor(C) (asm("lda #%b",C),asm("sta $D021"))
int main (void)
{
int x=3;
set_bgcolor(1); //this works
set_bgcolor(1+1); //this works as well
set_bgcolor(x); //this fails to compile "Error: Constant integer expression expected"
return EXIT_SUCCESS;
}
What is the proper definition of the macro in line 4 to make this work?