It is currently Fri Feb 23, 2018 7:30 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Wed Oct 28, 2015 3:39 pm 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1570
What can I do when I use a library (like FamiTone) and I want to call the functions from within C in CC65?
The function names don't start with an underscore, so unless I modify the source code myself, I don't see a way to use the FamiTone functions in C.

I created a wrapper file that does the following since the FamiTone library doesn't include the export commands:
Code:
.segment "CODE"

   .include "famitone2.s"
   .export FamiToneInit
   .export FamiToneUpdate
   .export FamiToneMusicPlay
   .export FamiToneMusicStop

Now, is there a way to export the functions with an alias?
After all, this version here is not the best solution:
Code:
_FamiToneMusicPlay:
   JSR FamiToneMusicPlay
   RTS

_FamiToneMusicStop:
   JSR FamiToneMusicStop
   RTS

And I don't really want to use inline assembly in my code for a mere function call if I can avoid it.

_________________
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: Wed Oct 28, 2015 3:46 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19666
Location: NE Indiana, USA (NTSC)
Something to try:
Code:
.segment "CODE"

   .include "famitone2.s"
   _FamiToneInit=FamiToneInit
   _FamiToneUpdate=FamiToneUpdate
   _FamiToneMusicPlay=FamiToneMusicPlay
   _FamiToneMusicStop=FamiToneMusicStop
   .export _FamiToneInit
   .export _FamiToneUpdate
   .export _FamiToneMusicPlay
   .export _FamiToneMusicStop


Top
 Profile  
 
PostPosted: Wed Oct 28, 2015 3:57 pm 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1570
Thanks. Yeah, that works.

_________________
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: Wed Oct 28, 2015 4:09 pm 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 3011
Location: Tampere, Finland
tepples wrote:
Something to try:

This can be simplified down to:
Code:
.segment "CODE"

   .include "famitone2.s"
   .export _FamiToneInit=FamiToneInit
   .export _FamiToneUpdate=FamiToneUpdate
   .export _FamiToneMusicPlay=FamiToneMusicPlay
   .export _FamiToneMusicStop=FamiToneMusicStop

(You could also use ":=" since it's a label, but there's no technical difference.)

And of course, make sure that the calling conventions match.

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


Top
 Profile  
 
PostPosted: Wed Oct 28, 2015 4:14 pm 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1570
Yup, that's even more compact.

_________________
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: Wed Oct 28, 2015 4:18 pm 
Offline
User avatar

Joined: Sun May 27, 2012 8:43 pm
Posts: 1330
If the function has been defined elsewhere, you should be able to throw this in a header:

Code:
#ifndef FAMITONE_INTERFACE_H
#define FAMITONE_INTERFACE_H

extern void FamiToneInit(uint8_t arg);
// So on and so forth - modify arguments and return types appropriately based on what stack jazz the functions are doing

#endif


Include a header like that, and since famitone2.s has defined the functions this should allow them to be used. This is how I've integrated a few assembly functions into my Genesis project and I didn't need the .export directive. Perhaps that's a better way, though, so I ought to look into that.


Top
 Profile  
 
PostPosted: Thu Oct 29, 2015 1:59 am 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1570
I know. But the problem is that CC65 transforms every function and variable name into the same name, but with an underscore. Therefore, an assembly function has to have an undersore to be usable with C.

Also, the .export command is necessary so that the function is usable in other translation units. I don't know how you can use an Assembly function in C (or in another assembly translation unit) without having the original code file use .export.

_________________
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 Oct 29, 2015 6:31 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19666
Location: NE Indiana, USA (NTSC)
To put it another way: A label that is not exported is treated as if it were static.


Top
 Profile  
 
PostPosted: Thu Oct 29, 2015 9:20 am 
Offline
User avatar

Joined: Sun May 27, 2012 8:43 pm
Posts: 1330
tepples wrote:
To put it another way: A label that is not exported is treated as if it were static.

I realize I've forgotten the ever-crucial reason mine worked; rather than .export, I was using .global.

Source (for Kosinki decompression algorithm): https://github.com/Mikejmoffitt/LICS/bl ... stem/kos.s

And on line 25 of this source file you can see the function being externally declared: https://github.com/Mikejmoffitt/LICS/bl ... /cdaudio.c


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 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