lol commaDRW wrote:What do I have to do if I want to use the same constant value in both, my C and Assembly code? (I'm using of course CC65.)
In Assembly, I would write this:And in C, I would write this:Code: Select all
GAMESTATE_TITLE = $01 GAMESTATE_RUNNING = $02But how can I make these values known in both code files without declaring them twice?Code: Select all
#define GAMESTATE_TITLE 0x01 #define GAMESTATE_RUNNING 0x02
O.k., I could declare a constant in C:This then translates to an actual memory address which can be used in Assembly:Code: Select all
const unsigned char GAMESTATE_TITLE = 0x01; const unsigned char GAMESTATE_RUNNING = 0x02;But that's the problem: A const would occupy actual space in the ROM. And this is what I don't want since my constants are just supposed to be possible values for a variable.Code: Select all
_GAMESTATE_TITLE: .byte $01 _GAMESTATE_RUNNING: .byte $02
Sure, I want them to be declared in one location in the source code, so in case the value changes, I only have to change it in one location.
But in the actual compiled binary, all comparisons shall of course work directly with the numeric value (i.e. the value appears more than once in the ROM), not with a value at an address in the ROM.
Is there a possibility to do this?
Constant value for both, C and Assembly
Moderator: Moderators