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
Exchange of parameters between C and 6502 Code in OSDK
- 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
coco.oric as DidierV, CEO Member
Historic owner of Oric, Apple II, Atari ST, Amiga
Historic owner of Oric, Apple II, Atari ST, Amiga
Re: Exchange of parameters between C and 6502 Code in OSDK
C normally passes parameters on the stack. Once you return whatever changes you make to those parameters in a function are gone.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 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.
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:
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
}