Defining Variables and Code at Absolute Addresses?

SGDK only sub forum

Moderator: Stef

Post Reply
db-electronics
Very interested
Posts: 89
Joined: Mon Feb 24, 2014 6:04 pm
Location: Kapuskasing, Ontario, Canada
Contact:

Defining Variables and Code at Absolute Addresses?

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

Code: Select all

unsigned char buf[128]@0x2000;
What does db stand for? Well that's an excellent question...
http://www.db-electronics.ca
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post 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

Code: Select all

int *var_ptr = (int *)0xF00008;
asm

Code: Select all

    .equ     var_ptr, 0xF00008
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.
tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Post by tryphon »

Are there RAM address reserved for SGDK routines ?
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

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

Code: Select all

heap_start = MEM_alloc(1);
db-electronics
Very interested
Posts: 89
Joined: Mon Feb 24, 2014 6:04 pm
Location: Kapuskasing, Ontario, Canada
Contact:

Post 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)?
What does db stand for? Well that's an excellent question...
http://www.db-electronics.ca
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post 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.
Post Reply