Skip to content

Instantly share code, notes, and snippets.

@GrenderG
Created February 6, 2024 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrenderG/13501484e9ff06fcef5edab840fbb4da to your computer and use it in GitHub Desktop.
Save GrenderG/13501484e9ff06fcef5edab840fbb4da to your computer and use it in GitHub Desktop.
Print log line with GBDK (needs <gbdk/console.h> and <string.h>).
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