Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
I've tried several implementation to get var args forwarding to work in GBDK - none seem to work. Has anyone experienced the same?
Compiles fine but PlayFx doesn't product audio now
void PlaySound(SOUND_CHANNEL channel, UINT8 mute_frames, ...){ va_list args; va_start(args, mute_frames); PlayFx(channel, mute_frames, args); va_end(args); }
Doesn't compile because caller arguments don't match the function signature:
void PlaySound(SOUND_CHANNEL channel, UINT8 mute_frames, va_list args){ PlayFx(channel, mute_frames, args); }
Offline
You can find examples of it's use in both Print.c and Sound.c in the ZGB:
https://github.com/Zal0/ZGB/blob/master … rc/Print.c
https://github.com/Zal0/ZGB/blob/master … rc/Sound.c
void PlayFx(SOUND_CHANNEL channel, UINT8 mute_frames, ...) { UINT8 i; UINT8* reg = (UINT8*)FX_ADDRESS[channel]; va_list list; va_start(list, mute_frames); for(i = 0; i < FX_REG_SIZES[channel]; ++i, ++reg) { *reg = va_arg(list, INT16); } va_end(list); if(channel != CHANNEL_5) { gbt_enable_channels(~(0xF & (1 << channel))); } music_mute_frames = mute_frames; }
Last edited by bbbbbr (2019-12-17 23:32:08)
Offline
Thanks for the response on that - my use case is one where I'm just forwarding the argument list. My first example matches examples from SO etc... but doesn't seem to work correctly. I'll have to dig a little deeper to see where it's failing - I just wanted to poll the group to see if this might be a known sdcc issue.
Offline
The example's simplified. I was trying to mute sound effects by not forwarding the args to your PlayFx(). The forwarding doesn't seem to work they way I expected. I ended just muting the sfx directly in PlayFx() as a workaround for the moment.
BTW - thanks for creating ZGB. Having the tool chain work out-of-the-box is priceless.
Offline
I was guessing so...
But are you sure you want to mute sound effects? What I do is exactly the opposite, muting the channel for the music player so fx are played
Anyways, I am not sure if this an specific GBDK issue or is something related to C itself
Maybe another approach is using variadic macros which let you reuse the params using __VA_ARGS__
I am glad you liked the engine
Offline
Muting sfx was just an options menu item I threw in thinking it would take a second to do - to answer your question, it's not super useful for this game.
I am making use of the mute frames for sfx + music - that's nice.
I'll take a look at the variadic macros ref.
Offline
Ohh, I see what you were asking.
You may need to change the argument type for PlayFx() to accept a va_args list. For example, making an alternate version of PlayFx. Maybe that defeats the purpose for you though?
void PlaySound(SOUND_CHANNEL channel, UINT8 mute_frames, ...){ va_list args; va_start(args, mute_frames); PlayFxArgs(channel, mute_frames, args); va_end(args); } void PlayFxArgs(SOUND_CHANNEL channel, UINT8 mute_frames, va_list list) { UINT8 i; UINT8* reg = (UINT8*)FX_ADDRESS[channel]; for(i = 0; i < FX_REG_SIZES[channel]; ++i, ++reg) { *reg = va_arg(list, INT16); } if(channel != CHANNEL_5) { gbt_enable_channels(~(0xF & (1 << channel))); } music_mute_frames = mute_frames; }
You might also reference this part of SDCC for another example:
https://github.com/darconeous/sdcc/blob … asprintf.c
Offline
I will give it a try - thanks!
Offline