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:
But how can I make these values known in both code files without declaring them twice?
O.k., I could declare a constant in C:
This then translates to an actual memory address which can be used in Assembly:
[code]_GAMESTATE_TITLE:
.byte $01
_GAMESTATE_RUNNING:
.byte $02[/quote]
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.
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?
In Assembly, I would write this:
Code:
GAMESTATE_TITLE = $01
GAMESTATE_RUNNING = $02
GAMESTATE_RUNNING = $02
And in C, I would write this:
Code:
#define GAMESTATE_TITLE 0x01
#define GAMESTATE_RUNNING 0x02
#define GAMESTATE_RUNNING 0x02
But how can I make these values known in both code files without declaring them twice?
O.k., I could declare a constant in C:
Code:
const unsigned char GAMESTATE_TITLE = 0x01;
const unsigned char GAMESTATE_RUNNING = 0x02;
const unsigned char GAMESTATE_RUNNING = 0x02;
This then translates to an actual memory address which can be used in Assembly:
[code]_GAMESTATE_TITLE:
.byte $01
_GAMESTATE_RUNNING:
.byte $02[/quote]
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.
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?