Page 1 of 1

s16/s32 and sprintf/VDP_drawText

Posted: Sun Apr 05, 2020 5:15 pm
by danibus
Good day folks

Very stupid question. This is working well:

Code: Select all

u16 var_a = 65000; 
char my_string[32]; 
sprintf(my_string, "%u", var_a); 
VDP_drawText(my_string, x, y); //x,y position in tiles
I can see 65000 on TV.
Also works with s16 with i.e. a = 32000 (as we need space for negative numbers).

Why this is not working:

Code: Select all

s32 var_a = 70000; 
char my_string[32]; 
sprintf(my_string, "%ld", var_a); 
VDP_drawText(my_string, x, y); //x,y position in tiles
No error here, just see 4464 not 70000. Same happens with u32.
Of course var_a is 70000 internally, just not sure if sprintf() or VDP_drawText() breaks something.

Why I can play with 16bit numbers but not with 32bit numbers with sprintf() or VDP_drawText()??

Re: s16/s32 and sprintf/VDP_drawText

Posted: Sun Apr 05, 2020 6:49 pm
by Stef
it's the sprintf(..) function which doesn't support long type (u32 / s32), even by using %ld unfortunately.
You can use intToStr(..) method to avoid the problem (note that intToStr(..) is limited to [-500000000..500000000] range)

Re: s16/s32 and sprintf/VDP_drawText

Posted: Sun Apr 05, 2020 8:10 pm
by danibus
Thanks Stef :D