[z88dk-dev] sccz80 and const

Bridge to the z88dk-developers mailing list
Post Reply
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

[z88dk-dev] sccz80 and const

Post by alvin »

Would it be difficult to add meaning to the const qualifier in sccz80?

It can make a difference in whether a read-only data structure is allocated as part of the data segment or the rodata segment. If the target is a ROM, anything in the data segment has to be bundled with the code in ROM and then copied into RAM at startup. In other words there are two copies of the data segment in memory. If the structure is allocated as rodata then the copy at startup does not occur and the reads come directly from ROM.

sdcc is placing const data into the code_compiler section. sccz80 is currently ignores const and always places in the data section.

Example:

const effects_t beepfx[] = {

{BEEPFX_SHOT_1, "BEEPFX_SHOT_1"},
{BEEPFX_SHOT_2, "BEEPFX_SHOT_2"},
{BEEPFX_JUMP_1, "BEEPFX_JUMP_1"},
{BEEPFX_JUMP_2, "BEEPFX_JUMP_2"},
{BEEPFX_PICK, "BEEPFX_PICK"},
...
{BEEPFX_YEAH, "BEEPFX_YEAH"},
{BEEPFX_AWW, "BEEPFX_AWW"}

};

This is a read-only structure that occupies somewhere around 1000 bytes. If the program is targetted at ROM, sdcc will place it into the code_compiler section but sccz80 will leave it in the data section. In the data section means this structure will appear as part of the ROM and then copied into RAM at startup, occupying twice as much memory assuming the data section is not compressed.



------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
Post Reply