From 2d04eba931ac84e2f09d3c8391125f8a991ca7d3 Mon Sep 17 00:00:00 2001 From: XaviDCR92 Date: Sun, 5 Nov 2017 18:00:57 +0100 Subject: Deprecated use of sprintf() in favor of custom routine Systemitoa(). When B button is released and showActionsMenu == true, showActionsMenu = false. --- System.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) (limited to 'System.c') diff --git a/System.c b/System.c index 43f2c91..68742d4 100644 --- a/System.c +++ b/System.c @@ -104,7 +104,7 @@ void SystemRunTimers(void) void SystemCheckTimer(bool * timer, uint64_t * last_timer, uint8_t step) { - if (*timer == true) + if (*timer != false) { *timer = false; *last_timer = global_timer; @@ -215,9 +215,9 @@ void SystemUserTimersHandler(void) for (i = 0; i < SYSTEM_MAX_TIMERS; i++) { - if (timer_array[i].busy == true) + if (timer_array[i].busy != false) { - if (System1SecondTick() == true) + if (System1SecondTick() != false) { timer_array[i].time--; @@ -225,7 +225,7 @@ void SystemUserTimersHandler(void) { timer_array[i].Timeout_Callback(); - if (timer_array[i].repeat_flag == true) + if (timer_array[i].repeat_flag != false) { timer_array[i].time = timer_array[i].orig_time; } @@ -276,3 +276,53 @@ bool SystemCollisionCheck(TYPE_COLLISION_BLOCK* c1, TYPE_COLLISION_BLOCK* c2) return (bool)check_bb_collision( c1->x, c1->y, c1->w, c1->h, c2->x, c2->y, c2->w, c2->h ); } + +bool Systemitoa(char* str, size_t sz, int16_t value) +{ + if (sz != 0) + { + bool first_digit_found = false; + uint16_t i; + uint8_t j = 0; + + /* Example: 65535 */ + /* Another example: -32767 */ + + if (value & 0x8000) + { + /* Sign bit */ + str[j++] = '-'; + } + + for (i = 10000; i >= 1; i /= 10) + { + uint8_t digit = (uint8_t)(value / i); + value -= (uint16_t)(digit * i); + + if (digit != 0) + { + if (first_digit_found == false) + { + first_digit_found = true; + } + } + else if (first_digit_found == false) + { + continue; + } + + str[j++] = digit + '0'; + + if (j >= (sz - 1)) + { + return false; + } + } + + str[j] = '\0'; + + return true; + } + + return false; +} -- cgit v1.2.3