s16/s32 and sprintf/VDP_drawText

SGDK only sub forum

Moderator: Stef

Post Reply
danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

s16/s32 and sprintf/VDP_drawText

Post by danibus » Sun Apr 05, 2020 5:15 pm

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()??

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: s16/s32 and sprintf/VDP_drawText

Post by Stef » Sun Apr 05, 2020 6:49 pm

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)

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: s16/s32 and sprintf/VDP_drawText

Post by danibus » Sun Apr 05, 2020 8:10 pm

Thanks Stef :D

Post Reply