From 38ad5c67e18dbbdf61bed21b7592eb4e71ffa71e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 10 Nov 2014 15:14:25 -0600 Subject: BAS: Add support for color command --- apps/interpreters/bas/fs.c | 29 +++++++++++++++++++----- apps/interpreters/bas/main.c | 1 + apps/interpreters/bas/vt100.c | 52 +++++++++++++++++++++++++++++++++++++++++-- apps/interpreters/bas/vt100.h | 20 +++++++++++++++++ 4 files changed, 95 insertions(+), 7 deletions(-) diff --git a/apps/interpreters/bas/fs.c b/apps/interpreters/bas/fs.c index 9f3489755..79834bf10 100644 --- a/apps/interpreters/bas/fs.c +++ b/apps/interpreters/bas/fs.c @@ -79,6 +79,7 @@ #include #include +#include #include "vt100.h" #include "fs.h" @@ -102,6 +103,14 @@ static int g_used; static const int g_open_mode[4] = { 0, O_RDONLY, O_WRONLY, O_RDWR }; static char g_errmsgbuf[80]; +#ifdef CONFIG_INTERPREPTER_BAS_VT100 +static const uint8_t g_vt100_colormap[8] = +{ + VT100_BLACK, VT100_BLUE, VT100_GREEN, VT100_CYAN, + VT100_RED, VT100_MAGENTA, VT100_YELLOW, VT100_WHITE +}; +#endif + /**************************************************************************** * Public Data ****************************************************************************/ @@ -411,18 +420,28 @@ static int locate(int chn, int line, int column) static int colour(int chn, int foreground, int background) { #ifdef CONFIG_INTERPREPTER_BAS_VT100 - /* REVISIT: Use VT100 commands to color */ -#warning Missing Logic -#endif + if (foreground >= 0) + { + vt100_foreground_color(chn, foreground); + } + + if (background >= 0) + { + vt100_background_color(chn, background); + } + + return 0; +#else FS_errmsg = _("Set color operation no implemented"); return -1; +#endif } static int resetcolour(int chn) { #ifdef CONFIG_INTERPREPTER_BAS_VT100 - /* REVISIT: Use VT100 commands to reset color */ -#warning Missing Logic + vt100_foreground_color(chn, VT100_DEFAULT); + vt100_background_color(chn, VT100_DEFAULT); #endif return 0; } diff --git a/apps/interpreters/bas/main.c b/apps/interpreters/bas/main.c index fce6dd672..bf8dd4e65 100644 --- a/apps/interpreters/bas/main.c +++ b/apps/interpreters/bas/main.c @@ -69,6 +69,7 @@ #include #include +#include "fs.h" #include "bas.h" /**************************************************************************** diff --git a/apps/interpreters/bas/vt100.c b/apps/interpreters/bas/vt100.c index 45bee9852..592db95ec 100644 --- a/apps/interpreters/bas/vt100.c +++ b/apps/interpreters/bas/vt100.c @@ -75,7 +75,9 @@ static const char g_reverseoff[] = VT100_REVERSEOFF; static const char g_blinkoff[] = VT100_BLINKOFF; #endif -static const char g_fmtcursorpos[] = VT100_FMT_CURSORPOS; +static const char g_fmt_cursorpos[] = VT100_FMT_CURSORPOS; +static const char g_fmt_forecolor[] = VT100_FMT_FORE_COLOR; +static const char g_fmt_backcolor[] = VT100_FMT_BACK_COLOR; /**************************************************************************** * Private Functions @@ -235,7 +237,7 @@ void vt100_setcursor(int chn, uint16_t row, uint16_t column) /* Format the cursor position command. The origin is (1,1). */ - len = snprintf(buffer, 16, g_fmtcursorpos, row + 1, column + 1); + len = snprintf(buffer, 16, g_fmt_cursorpos, row + 1, column + 1); /* Send the VT100 CURSORPOS command */ @@ -317,3 +319,49 @@ void vt100_scrolldown(int chn, uint16_t nlines) vt100_write(chn, g_revindex, sizeof(g_revindex)); } #endif + +/**************************************************************************** + * Name: vt100_foreground_color + * + * Description: + * Set the foreground color + * + ****************************************************************************/ + +void vt100_foreground_color(int chn, uint8_t color) +{ + char buffer[16]; + int len; + + /* Format the foreground color command. */ + + DEBUGASSERT(color < 10); + len = snprintf(buffer, 16, g_fmt_forecolor, color); + + /* Send the VT100 foreground color command */ + + vt100_write(chn, buffer, len); +} + +/**************************************************************************** + * Name: vt100_background_color + * + * Description: + * Set the background color + * + ****************************************************************************/ + +void vt100_background_color(int chn, uint8_t color) +{ + char buffer[16]; + int len; + + /* Format the background color command. */ + + DEBUGASSERT(color < 10); + len = snprintf(buffer, 16, g_fmt_backcolor, color); + + /* Send the VT100 background color command */ + + vt100_write(chn, buffer, len); +} diff --git a/apps/interpreters/bas/vt100.h b/apps/interpreters/bas/vt100.h index 28fb227ed..32dbb683f 100644 --- a/apps/interpreters/bas/vt100.h +++ b/apps/interpreters/bas/vt100.h @@ -209,6 +209,26 @@ void vt100_scrollup(int chn, uint16_t nlines); void vt100_scrolldown(int chn, uint16_t nlines); #endif +/**************************************************************************** + * Name: vt100_foreground_color + * + * Description: + * Set the foreground color + * + ****************************************************************************/ + +void vt100_foreground_color(int chn, uint8_t color); + +/**************************************************************************** + * Name: vt100_background_color + * + * Description: + * Set the background color + * + ****************************************************************************/ + +void vt100_background_color(int chn, uint8_t color); + #undef EXTERN #ifdef __cplusplus } -- cgit v1.2.3