Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - constant list of pointers

Reply to topic
Author Message
  • Joined: 18 Jul 2019
  • Posts: 24
Reply with quote
constant list of pointers
Post 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?
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2507
Reply with quote
Post Posted: Thu Aug 08, 2019 10:23 am
tab is already a constant so why would you save an array of pointer constants? :|
  View user's profile Send private message Visit poster's website
  • Joined: 18 Jul 2019
  • Posts: 24
Reply with quote
Post Posted: Thu Aug 08, 2019 10:57 am
sverx wrote
tab is already a constant so why would you save an array of pointer constants? :|


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;
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2507
Reply with quote
Post 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;
  View user's profile Send private message Visit poster's website
  • Joined: 18 Jul 2019
  • Posts: 24
Reply with quote
Post Posted: Thu Aug 08, 2019 1:44 pm
sverx wrote
maybe I'm not getting it but - why don't you just use the & operator?

unsigned char* currentPtr = &tabPtr[myIndex];
someStuff = *currrentPtr;


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.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2507
Reply with quote
Post Posted: Thu Aug 08, 2019 2:09 pm
Yuguzu wrote
But how do you declare tabPtr to make it a constant?


oh sorry I got it. try:

unsigned char* const test[2]


(because you were declaring (variable) pointers to const chars, not constant pointers...)
  View user's profile Send private message Visit poster's website
  • Joined: 18 Jul 2019
  • Posts: 24
Reply with quote
Post Posted: Thu Aug 08, 2019 2:41 pm
sverx wrote
I got it. try:

unsigned char* const test[2]


(because you were declaring (variable) pointers to const chars, not constant pointers...)


It actualy works.
  View user's profile Send private message
  • Joined: 18 Jul 2019
  • Posts: 24
Reply with quote
Post 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?
  View user's profile Send private message
  • Joined: 23 Aug 2009
  • Posts: 67
  • Location: Seattle, WA
Reply with quote
Post 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

[/code]
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2507
Reply with quote
Post 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...
  View user's profile Send private message Visit poster's website
  • Joined: 18 Jul 2019
  • Posts: 24
Reply with quote
Post Posted: Fri Aug 09, 2019 6:21 am
SavagePencil wrote
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


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 :(

SavagePencil wrote
then we'll likely ask the SDCC guys
How can I contact them?
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2507
Reply with quote
Post 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)
  View user's profile Send private message Visit poster's website
  • Joined: 18 Jul 2019
  • Posts: 24
Reply with quote
Post Posted: Fri Aug 09, 2019 2:34 pm
sverx wrote
the SDCC forum is here.

BTW first try using
const unsigned char* const

and see if something changes (I doubt it anyway)


Thanks for the link. No, nothing changes. :( I'll try the forum.
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!