From 4f60edc230251a1d4e7b406853b6058bd005060a Mon Sep 17 00:00:00 2001 From: ddouthitt Date: Fri, 28 Sep 2001 21:16:31 +0000 Subject: [PATCH] This file contains the beginnings of a "library" (not in the true sense) of functions to be used by drivers. Things like freeing a framebuffer, creating a frame buffer, andding characters or strings to a framebuffer, et al, are here... --- server/drivers/lcd_lib.c | 89 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 server/drivers/lcd_lib.c diff --git a/server/drivers/lcd_lib.c b/server/drivers/lcd_lib.c new file mode 100644 index 0000000..dffab27 --- /dev/null +++ b/server/drivers/lcd_lib.c @@ -0,0 +1,89 @@ +#include +#include +#include +#include +#include +#include +#include +#include "lcd.h" + +// ================================================== +// LCD library of useful functions for drivers +// ================================================== + +// Drawn from the "base driver" which really was the precursor +// to this library.... + +void +free_framebuf (struct lcd_logical_driver *driver) { + if (!driver) + return; + + if (driver->framebuf != NULL) + free (driver->framebuf); + + driver->framebuf = NULL; +} + +void +clear_framebuf (struct lcd_logical_driver *driver) { + int framebuf_size; + + if (!driver) + return; + + framebuf_size = driver->wid * driver->hgt; + memset (driver->framebuf, ' ', framebuf_size); +} + +int +new_framebuf (struct lcd_logical_driver *driver, char *oldbuf) { + if (driver->framebuf == NULL) + return 1; + if (oldbuf == NULL) + return 1; + return (strncpy(driver->framebuf, oldbuf, driver->wid * driver->hgt) != 0); +} + +void +insert_str_framebuf (struct lcd_logical_driver *driver, int x, int y, char *string) { + int i; + char buf[64]; + char *pos; + + if (!driver) + return; + + x--; y--; // convert to zero-indexing + + if (x >= driver->wid) return; + if (x < 0) x = 0; + + if (y >= driver->hgt) y = driver->hgt; + if (y < 0) y = 0; + + if ((x + strlen(string)) > driver->wid) + strncpy(buf, string, driver->wid - x - 1); + else + strncpy(buf, string, sizeof(string)); + + pos = (driver->framebuf + (y * driver->wid) + x); + strcpy(pos, buf); +} + +void +insert_chr_framebuf (struct lcd_logical_driver *driver, int x, int y, char c) { + if (!driver) + return; + + x--; y--; + + if (x >= driver->wid) driver->wid; + if (x < 0) x = 0; + + if (y >= driver->hgt) y = driver->hgt; + if (y < 0) y = 0; + + driver->framebuf[(y * driver->wid) + x] = c; +} +