[C] Passing parameters by registers

SGDK only sub forum

Moderator: Stef

Post Reply
tryphon
Very interested
Posts: 303
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

[C] Passing parameters by registers

Post by tryphon » Fri Jul 17, 2015 8:56 am

Hello,

my question is not really SGDK related, but I've read some sources of SGDK and saw some functions implemented in asm.

But it seems that the parameters of the functions are sent using the stack.

Is it possible to make the compiler send parameters using registers, as it's more often done when programming in asm ?

Stef
Very interested
Posts: 2976
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: [C] Passing parameters by registers

Post by Stef » Fri Jul 17, 2015 11:51 am

tryphon wrote:Hello,

my question is not really SGDK related, but I've read some sources of SGDK and saw some functions implemented in asm.

But it seems that the parameters of the functions are sent using the stack.

Is it possible to make the compiler send parameters using registers, as it's more often done when programming in asm ?
Actually the GCC version provided in SGDK does not allow it even by forcing maximum optimization level or using the fastcall keyword.
I tried to force it by using some asm pragma but it was not really easy to implement your function then.
The problem with fastcall is that is not a standardized calling convention method and maybe for 68000 it doesn't even exist (which explain why it doesn't make any difference). Honestly except for function you use more than one hundred of time *per frame* it is not a big issue of passing parameters through the stack. When you have many parameters (more than 4/5 parameters) it may be better to pass a pointer to a structure owing all the parameters though.

tryphon
Very interested
Posts: 303
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Post by tryphon » Sat Jul 18, 2015 6:39 pm

OK, not a big deal for the moment.
Thanks :)

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Sun Jul 19, 2015 5:53 pm

Wait. So it couldn't be done by including pre assembled .asm code? Would I have trouble mixing asm and C using SGDK?

Stef
Very interested
Posts: 2976
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Sun Jul 19, 2015 8:50 pm

Count SymphoniC wrote:Wait. So it couldn't be done by including pre assembled .asm code? Would I have trouble mixing asm and C using SGDK?
Of course you can do it by using assembly code, it's just that you cannot force C code to use registers when calling functions.

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Mon Jul 20, 2015 4:04 am

Stef wrote:
Count SymphoniC wrote:Wait. So it couldn't be done by including pre assembled .asm code? Would I have trouble mixing asm and C using SGDK?
Of course you can do it by using assembly code, it's just that you cannot force C code to use registers when calling functions.
Hey Stef :D

Interesting... well it's not something I've tried yet, but plan on doing so very soon. So if I was linking asm with my C code and I was calling an asm subroutine from within C, would I want to make sure that I wiped my data and address registers before returning to the C portion or does it really even matter? Btw, did you ever solve the .xgm pausing instruments issue?

Stef
Very interested
Posts: 2976
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Mon Jul 20, 2015 9:21 am

Count SymphoniC wrote: Hey Stef :D

Interesting... well it's not something I've tried yet, but plan on doing so very soon. So if I was linking asm with my C code and I was calling an asm subroutine from within C, would I want to make sure that I wiped my data and address registers before returning to the C portion or does it really even matter?
When you call asm subroutine from C, you have to make sure the subroutine you call fetch parameters from stack.
What you can do is to have sort of 2 methods enter point depending you call it from C or asm :

Code: Select all

myMethodC:
    move.l (sp)+, d0-d1/a0-a1

myMethodASM:
    ...
Do when you call 'myMethodC' you take care of loading registers with the parameters as myMethodASM expect it.
Btw, did you ever solve the .xgm pausing instruments issue?
I don't specifically remember this issue, do you have a music example producing it ? I made some fixes on the XGM driver (and still i am) so hopefully i got this one fixed =)

Count SymphoniC
Very interested
Posts: 149
Joined: Sat Nov 17, 2012 3:58 am

Post by Count SymphoniC » Tue Jul 21, 2015 5:43 am

No I remember you asking how to get the song to stop properly when pausing. I wasn't sure if you ever got that figured out but it was last year so I don't blame you for not remembering.

Stef
Very interested
Posts: 2976
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue Jul 21, 2015 8:16 am

Oh yeah this one, it's fixed since a long time now ;)
Actually in some very few case, you may still heard a little buzzing note staying but setting min D1L / max RR + key OFF is enough to stop a channel.

Post Reply