It is currently Mon Dec 18, 2017 12:06 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Aug 03, 2017 5:56 am 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1517
Is there a way to position a RAM segment after the C software stack without having to declare an absolute size for it?

If we take this cfg file (ROM and zeropage have been removed since they are not relevant here):
Code:
SYMBOLS
{
   __STACKSIZE__  = $0100;
   __RAMSTART__   = $0200;
   __RAMSIZE__    = $0800 - __RAMSTART__ - __STACKSIZE__;
   __STACKSTART__ = __RAMSTART__ + __RAMSIZE__;
}

MEMORY
{
   RAM:     type = rw, start = __RAMSTART__,   size = __RAMSIZE__,   file = "";
   STACK:   type = rw, start = __STACKSTART__, size = __STACKSIZE__, file = "", define = yes;
}

SEGMENTS
{
   SPRITES:  load = RAM, type = bss, align = $0100;
   BSS:      load = RAM, type = bss;
}


I'd like to declare a code part that comes after the stack, but I don't want to declare a size for it here in the config file. The size shall be dependent on the actual number of bytes that are used for variables in this segment/memory location. (Just like the size of two segments in the same memory location is dependent on their actual use.)

So, the three RAM sections shall be calculated like this:

Post-stack-segment:
Size: The actual number of variables declared for this segment, not more.
Start = RAM end minus post-stack-segment size.

Stack:
Size = Defined by me, for example 256 or 512
Start = RAM end minus post-stack-segment size minus stack size.

Regular RAM:
Size: RAM size minus stack size minus post-stack-segment size as a maximum.
Start: RAM start

Is it possible to declare this in a cfg file?

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
PostPosted: Thu Aug 03, 2017 7:32 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2983
Location: Tampere, Finland
If you set define=yes for a specific SEGMENT or MEMORY declaration, the linker will define symbols which give you some information about their addresses and sizes. You can utilize those in further MEMORY/SEGMENT declarations.

See http://www.cc65.org/doc/ld65.html#toc5.2 and http://www.cc65.org/doc/ld65.html#toc5.5 for details.

See here for one example from a while ago: viewtopic.php?f=2&t=13434&p=158354#p158354

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Thu Aug 03, 2017 7:52 am 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1517
So, I can use the defined symbols within the CGF file? I thought they are only for Assembly files.

However, I'm still not sure how I can declare a segment "right-aligned" in memory. The segment that I'm using is supposed to be situated at the end of the RAM.

Pseudo code declaration:
MySegment.Start = RAM.Start + RAM.Size - MySegment.Size

Is this possible at all? The start location of a segment being calculated depending on its own size?

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group