diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2018-04-24 14:11:01 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2018-04-24 14:11:01 -0400 |
commit | c47485371ac69797b487f9549368fab62859de78 (patch) | |
tree | f10077a503379ada25c9f57622d9edd319c9c63d /src/display_text.c | |
parent | 5df5c67397e2800182e5016ab89bbd17e4e67a5b (diff) |
file cleanup, better text, documentation
Diffstat (limited to 'src/display_text.c')
-rw-r--r-- | src/display_text.c | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/src/display_text.c b/src/display_text.c index 8a41fa5..880485e 100644 --- a/src/display_text.c +++ b/src/display_text.c @@ -1,3 +1,22 @@ +/* + * @file display_text.c + * A text-rendering/managing library to work with the display + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <clock.h> #include <task.h> @@ -8,8 +27,6 @@ #define WIDTH 40 #define HEIGHT 18 -#define TTY_COUNT 2 - typedef struct { char *buf; uint8_t x; @@ -51,25 +68,19 @@ void text_init(void) void text_redraw(void) { - for (unsigned int i = 0; i < WIDTH; i++) { - //unsigned int zc = 0; - for (unsigned int j = 0; j < HEIGHT; j++) { - int c = text_current->buf[i + j * WIDTH]; - /*if (c == '\0') { - if (++zc == 3) - break; - } else if (zc > 0) { - zc = 0; - }*/ - - dsp_putchar(c, i, j); + for (unsigned int j = 0; j < HEIGHT; j++) { + unsigned int i = WIDTH; + //for (; i > 0 && text_current->buf[j * WIDTH + i - 1] == '\0'; i--); + for (; i > 0; i--) { + int c = text_current->buf[j * WIDTH + i - 1]; + dsp_putchar(c, i - 1, j); } } } void text_switch(unsigned int i) { - if (i >= TTY_COUNT) + if (i >= TTY_COUNT || text_current == text_tty + i) return; text_current = &text_tty[i]; @@ -78,10 +89,14 @@ void text_switch(unsigned int i) void text_clear(void) { - for (unsigned int i = 0; i < WIDTH; i++) { - for (unsigned int j = 0; j < HEIGHT; j++) { - text_current->buf[i + j * WIDTH] = 0; - dsp_putchar(' ', i, j); + + for (unsigned int j = 0; j < HEIGHT; j++) { + for (unsigned int i = 0; i < WIDTH; i++) { + //int c = text_current->buf[j * WIDTH + 1]; + //if (c != 0) { + text_current->buf[j * WIDTH + i] = 0; + dsp_putchar(' ', i, j); + //} } } text_current->x = 0; @@ -131,7 +146,21 @@ void text_putchar(int c) for (int i = 0; i < WIDTH; i++) text_current->buf[i + y * WIDTH] = 0; - text_redraw(); + for (int j = HEIGHT - 1; j >= 0; j--) { + int i = WIDTH - 1; + if (j > 0) { + for (; i >= 0; i--) { + int p = text_current->buf[(j - 1) * WIDTH + i]; + int c = text_current->buf[j * WIDTH + i]; + if (p != '\0' || c != '\0') + break; + } + } + for (; i >= 0; i--) { + int c = text_current->buf[j * WIDTH + i]; + dsp_putchar(c, i, j); + } + } } text_current->x = x; |