Jérémy Compostella has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/70277 )
Change subject: drivers/pc80/vga: display a string centered on a line ......................................................................
drivers/pc80/vga: display a string centered on a line
This patch introduces the `vga_line_write_centered(unsigned int line, const char *string)' function to display a centered line of text. The string length is limited to eighy characters.
BUG=b:252792591 BRANCH=firmware-brya-14505.B TEST=TO-BE-COMPLETED
Change-Id: Ie742795bb44bbea8cf24222e7bd4f355a6fece2f Signed-off-by: Jeremy Compostella jeremy.compostella@intel.com --- M src/drivers/pc80/vga/vga.c M src/include/pc80/vga.h 2 files changed, 41 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/77/70277/1
diff --git a/src/drivers/pc80/vga/vga.c b/src/drivers/pc80/vga/vga.c index d970fea..1719cba 100644 --- a/src/drivers/pc80/vga/vga.c +++ b/src/drivers/pc80/vga/vga.c @@ -274,6 +274,28 @@ }
/* + * fills a line centering the given string. + * The string is truncated it exceeds 80 characters. + */ +void +vga_line_write_centered(unsigned int line, const char *string) +{ + unsigned short *p = (unsigned short *) VGA_FB + (80 * line); + size_t i, margin, len = strlen(string); + + if (len > 80) + len = 80; + margin = 40 - (len / 2); + + for (i = 0; i < 80; i++) { + if (i < margin || i > 80 - margin) + p[i] = 0x0F00; + else + p[i] = 0x0F00 | string[i - margin]; + } +} + +/* * set up everything to get a basic 80x25 textmode. */ void diff --git a/src/include/pc80/vga.h b/src/include/pc80/vga.h index 4b7b26c..9e72f6f 100644 --- a/src/include/pc80/vga.h +++ b/src/include/pc80/vga.h @@ -19,5 +19,6 @@ void vga_frame_set(unsigned int line, unsigned int character);
void vga_line_write(unsigned int line, const char *string); +void vga_line_write_centered(unsigned int line, const char *string);
#endif /* VGA_H */