function calls in machine page

11 views
Skip to first unread message

james cardona

unread,
Dec 17, 2012, 9:13:52 AM12/17/12
to fre...@googlegroups.com
there is a note about the machine page:

# GAME_PAGED_OBJS = page 59 =    Preferably, game functions go here.
# This works safely for any file that only uses CALLSET_ENTRY functions, deffs, and leffs. 

Does this "ONLY" mean that function calls are not allowed in this page?  and if so, is that function calls outside of the page?  or all function calls?

Brian Dominy

unread,
Dec 17, 2012, 9:24:07 AM12/17/12
to fre...@googlegroups.com
On Mon, Dec 17, 2012 at 9:13 AM, james cardona <JAMES....@pseg.com> wrote:

Does this "ONLY" mean that function calls are not allowed in this page?  and if so, is that function calls outside of the page?  or all function calls?

No, this comment is a little misleading.  As long as you use a correct prototype, with a section attribute added, e.g.

__machine3__ void foo (void);

then you can use make calls to it from anywhere.  Without such a prototype, it can only safely be called from code inside the same page.  (Intra-page calls don't change the ROM bank.)  The prototypes are not used for a few cases of calls from outside: callsets, deff functions, and leff functions don't require them.  (Technical point: callsets auto-detect the section, and for deffs/leffs you put the section in the md file inside a page() parameter.)

The only thing that won't work is if you have a function in one page X, called foo(), without a prototype, and from a different page Y you say:

foo();

The compiler will assume foo() is also in page Y, and generate incorrect calling code, which will usually lead to a crash pretty quickly.

If you define a prototype without the section header, like this:

void foo (void);

it will still fail, because the compiler needs to know that foo() is in page X instead.

If you know a function will never be called outside of the file it is defined in, it is good practice to add "static" to it, which will enforce that and keep you from mistakenly calling it.

- Brian

james cardona

unread,
Dec 18, 2012, 9:39:19 AM12/18/12
to fre...@googlegroups.com, br...@oddchange.com
thanks
Reply all
Reply to author
Forward
0 new messages