I have been playing with C code in cc65 these days and I have a small issue that right now doesn't hinder my testing but would like to know what I'm doing wrong. I didn't write C code for ages so it may be something that I don't know anymore about.
I will explain with some example so it will be easier to understand. First, what works.
For example, the smallest element, a list of sprite that forms a meta-sprite, ends up in rodata:
My list of meta-sprite that makes an animation list ends up in rodata:
But my list of animation ends up in data:
The goal is to able to retrieve the proper animation list based on the current state of the actor:
My guess is on how I define my list with const but I didn't work in C for ages that I cannot see what is the subtle error I have. At the least for now the logic work, it just it takes ram for nothing.
I'm sure right now my code is quite complex too but for now I do not mind much. If some code does cause issues I will change the structure after examinating the resulting .s files.
I will explain with some example so it will be easier to understand. First, what works.
For example, the smallest element, a list of sprite that forms a meta-sprite, ends up in rodata:
Code:
const unsigned char standing1[] = {
0x00, 0x00, 0x0B, 0x40, // Head top 1
...
128};
0x00, 0x00, 0x0B, 0x40, // Head top 1
...
128};
My list of meta-sprite that makes an animation list ends up in rodata:
Code:
const unsigned char* const standingAnim[2] = {
standing1,
standing2
};
standing1,
standing2
};
But my list of animation ends up in data:
Code:
const unsigned char* const *heroAnimList[5] = { standingAnim, ..., runningAnim };
The goal is to able to retrieve the proper animation list based on the current state of the actor:
Code:
// List of animation
typedef enum {
STANDING = 0,
WALKING,
WALKING_GUN,
JUMPING,
JUMPING_GUN
} animState_t;
....
hero.anim.frameList = heroAnimList[STANDING];
typedef enum {
STANDING = 0,
WALKING,
WALKING_GUN,
JUMPING,
JUMPING_GUN
} animState_t;
....
hero.anim.frameList = heroAnimList[STANDING];
My guess is on how I define my list with const but I didn't work in C for ages that I cannot see what is the subtle error I have. At the least for now the logic work, it just it takes ram for nothing.
I'm sure right now my code is quite complex too but for now I do not mind much. If some code does cause issues I will change the structure after examinating the resulting .s files.