Stephane-D / SGDK

SGDK - A free and open development kit for the Sega Mega Drive
https://www.patreon.com/SGDK
MIT License
1.78k stars 189 forks source link

New u16 and u32 to BCD conversion routines. #312

Closed iratahack closed 9 months ago

iratahack commented 9 months ago

intToBCD() does not work correctly. A quick test is to pass in 256, the BCD output is 0x100 rather than 0x256. Instead of trying to debug and fix this routine I offer 2 new routines u16ToBCD() and u32ToBCD(). The u16ToBCD() routine uses 68K mod and div for speed optimization, while the u32ToBCD() uses normal C-style operations.

Feel free to decline these changes in favor of fixing intToBCD().

Cheers, IH.