Exchange of parameters between C and 6502 Code in OSDK

Questions, bug reports, features requests, ... about the Oric Software Development Kit. Please indicate clearly in the title the related element (OSDK for generic questions, PictConv, FilePack, XA, Euphoric, etc...) to make it easy to locate messages.

User avatar
coco.oric
Squad Leader
Posts: 720
Joined: Tue Aug 11, 2009 9:50 am
Location: North of France
Contact:

Exchange of parameters between C and 6502 Code in OSDK

Post by coco.oric »

Hi all,

I'm searching the different ways (and notations) of using data in C code and 6502 code with OSDK.

It's not a problem to understand the different notations (integer, .byt ...) and i've understood how to give parameters from a C main program to a 6502 routine.
I've also understand how to have common parameters in the C code section and the 6502 code section.

But i don't see how to get back parameters from a 6502 routine to the C calling function.
(and i don't see it in several routines on the miniserve)

Thanks a lot (i'll make a synthesis for next ceo-mag)
Didier
coco.oric as DidierV, CEO Member
Historic owner of Oric, Apple II, Atari ST, Amiga
JamesD
Flight Lieutenant
Posts: 358
Joined: Tue Nov 07, 2006 7:38 am

Re: Exchange of parameters between C and 6502 Code in OSDK

Post by JamesD »

coco.oric wrote:But i don't see how to get back parameters from a 6502 routine to the C calling function.
(and i don't see it in several routines on the miniserve)
C normally passes parameters on the stack. Once you return whatever changes you make to those parameters in a function are gone.
C does provide for one return code but that won't help modify several parameters. The way around this is to pass pointers to your parameters (call by reference) to the function rather than the actual parameters (call by value). Then you access the actual variables through the pointers and modify them directly. When you return, any value you change will still be there.

http://www.cplusplus.com/forum/general/7990/

If it's not documented you might look at the code generated by the compiler to see how it handles pointers and use that as a basis for your assembly.
I haven't used the OSDK C compiler myself so that's about all I can suggest.

<edit> added a comma
Last edited by JamesD on Wed Aug 11, 2010 11:03 pm, edited 1 time in total.
User avatar
Dbug
Site Admin
Posts: 4460
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Post by Dbug »

What James wrote is correct.

The OSDK behave like any other C compiler chain, you can return parameters only through the returned value (assuming the function does not return void) in the registers A and X. If you want to modify something from the function, you need to use pointers.

Example:

Code: Select all

void MyFunc(char* pMyChar)
{
   (*pMyChar)+=1;
}

main()
{
   char bla=23;
   MyFunc(&bla);
   // bla's value is now 24
}
Post Reply