|
ForumsSega Master System / Mark III / Game GearSG-1000 / SC-3000 / SF-7000 / OMV |
Home - Forums - Games - Scans - Maps - Cheats - Credits Music - Videos - Development - Hacks - Translations - Homebrew |
Author | Message |
---|---|
|
constant list of pointers
Posted: Thu Aug 08, 2019 9:34 am
|
I would like to do something like that:
const unsigned char tab[16] = {50,138,22,46, 55,99,200,155, 230,111,222,65, 48,99,40,10};
const unsigned char* tabPtr[2] = {tab,tab+1}; Is it even possible? I think it will required to mess with the linker. Any thoughts? |
|
|
Posted: Thu Aug 08, 2019 10:23 am |
tab is already a constant so why would you save an array of pointer constants? :| | |
|
Posted: Thu Aug 08, 2019 10:57 am |
To save some instructions. To do: unsigned char* currentPtr = tabPtr[myIndex];
someStuff = *currrentPtr; Instead of: unsigned char ptrIndex = ptrIndexList[myIndex];
unsigned char* currentPtr = tab + ptrIndex; someStuff = *currrentPtr; |
|
|
Posted: Thu Aug 08, 2019 11:54 am |
maybe I'm not getting it but - why don't you just use the & operator?
unsigned char* currentPtr = &tabPtr[myIndex];
someStuff = *currrentPtr; |
|
|
Posted: Thu Aug 08, 2019 1:44 pm |
But how do you declare tabPtr to make it a constant? Because this: const unsigned char* tabPtr[2] = {tab,tab+1};
This doesn"t produce a constant. Ho and for the exemple "tabPtr" is small but what I would like to have is a big list of pointers. One way would be to find the actual adress of the "tabPtr" in the rom. Perhaps ihx2sms can provide this info. What are all this number in .sym? By the way sverx. Thank you for your lib. It's realy awesome. I just realize you're the guy who made all the stuff I use. |
|
|
Posted: Thu Aug 08, 2019 2:09 pm |
oh sorry I got it. try: unsigned char* const test[2]
(because you were declaring (variable) pointers to const chars, not constant pointers...) |
|
|
Posted: Thu Aug 08, 2019 2:41 pm |
It actualy works. |
|
|
Posted: Thu Aug 08, 2019 5:25 pm |
It works but the it takes a very long time to compile for an "unsigned char* const" with 256 values. Is it normal? | |
|
Posted: Thu Aug 08, 2019 9:54 pm |
Do you want those values to be constant, or to be changeable? You might be able to ensure they get cooked into ROM by making not only the pointer but also the data constant:
unsigned char const * const ^ ^ data is const pointer is const |
|
|
Posted: Thu Aug 08, 2019 10:16 pm |
last 'const' is enough but, well, two is formally more correct as also the pointed data is const.
as per the compilation time: can you measure with and without it? then we'll likely ask the SDCC guys... |
|
|
Posted: Fri Aug 09, 2019 6:21 am |
The "unsigned char const *" is enought. Datas are "cooked into ROM" :) But it is the compile time that is too long. Normaly the compile time is about 4secs but with a unsigned char const * of 256 values the compile time become 1min and it freeze my computer :( How can I contact them? |
|
|
Posted: Fri Aug 09, 2019 7:48 am |
the SDCC forum is here.
BTW first try using const unsigned char* const
and see if something changes (I doubt it anyway) |
|
|
Posted: Fri Aug 09, 2019 2:34 pm |
Thanks for the link. No, nothing changes. :( I'll try the forum. |
|