Created
February 6, 2024 12:06
-
-
Save GrenderG/13501484e9ff06fcef5edab840fbb4da to your computer and use it in GitHub Desktop.
Print log line with GBDK (needs <gbdk/console.h> and <string.h>).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void print_log(const char *__s) { | |
size_t max_length = 19; | |
char __trimmed[20]; // 19 characters + 1 for null terminator. | |
size_t len = strlen(__s); | |
size_t i; | |
// Copy characters up to max_length or until the end of the string. | |
for (i = 0; i < max_length && i < len; ++i) { | |
__trimmed[i] = __s[i]; | |
} | |
// Fill the remaining space with empty spaces. | |
for (; i < max_length; ++i) { | |
__trimmed[i] = ' '; | |
} | |
// Null-terminate the string. | |
__trimmed[max_length] = '\0'; | |
// Reset cursor position. | |
gotoxy(1, 16); | |
printf("%s", __trimmed); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment