Page 1 of 1
Defining Variables and Code at Absolute Addresses?
Posted: Wed Feb 11, 2015 5:48 pm
by db-electronics
Is it possible to define code, data and/or variables at absolute addresses using SGDK?
I'm used to microcontroller development where such syntax usually takes the following form:
Microchip C compiler:
Code: Select all
#pragma romdata [overlay] [section-name] [=address]
Freescale S08:
Posted: Wed Feb 11, 2015 6:36 pm
by Chilly Willy
Make a custom linker script that reserves areas of memory (for example, instead of starting the ram at 0xF00000, maybe start it at 0xF00100). Then just add things like this to the code:
C
asm
You could also make a custom segment in the linker script at a set location, then use __attribute__ in the C code to place the var or function in that segment, or use .section for assembly.
Posted: Wed Feb 11, 2015 7:53 pm
by tryphon
Are there RAM address reserved for SGDK routines ?
Posted: Thu Feb 12, 2015 9:34 am
by Stef
SGDK uses a bit of memory but everything is statically allocated in C so no special reserved area. You can find start of free heap memory with the memory manager :
Posted: Thu Feb 12, 2015 3:13 pm
by db-electronics
Thanks Chilly and Stef!
Actually I snooped around a bit more and found that I can specify data alignment with BIN in rescomp. Data alignment was my real goal when I asked about placing data at absolute locations - but for code I would need to go the linker script route.
Which leads me to ask, can an SGDK output support the Sega Mapper (a.k.a SSFII mapper)?
Posted: Thu Feb 12, 2015 6:04 pm
by Stef
SGDK supports ROM above 4 MB (i think i limited it to 10 MB) but it does not handle anything special about accessing data over the 4 MB range. If you use a special mapper you have to adapt the code to take care of that. Generally you only put data over the 4 MB range then you access it directly with absolute address.