summaryrefslogtreecommitdiff
path: root/src/sys/io/cons/cons.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys/io/cons/cons.c')
-rw-r--r--src/sys/io/cons/cons.c63
1 files changed, 54 insertions, 9 deletions
diff --git a/src/sys/io/cons/cons.c b/src/sys/io/cons/cons.c
index f95bf0f..aab5778 100644
--- a/src/sys/io/cons/cons.c
+++ b/src/sys/io/cons/cons.c
@@ -30,6 +30,7 @@
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/syslog.h>
+#include <sys/ascii.h>
#include <io/cons/cons.h>
#include <io/cons/font.h>
#include <io/cons/consvar.h>
@@ -43,6 +44,9 @@
struct cons_scr g_root_scr;
+/* Forward declarations */
+static void fill_screen(struct cons_scr *scr, uint32_t bg);
+
/*
* Get the index into the framebuffer with an x and y
* position.
@@ -60,6 +64,26 @@ fb_get_index(uint32_t pitch, uint32_t x, uint32_t y)
}
/*
+ * Write a newline onto the console and handle
+ * Y overflows
+ *
+ * @scr: Screen to write a newline onto
+ */
+static void
+cons_newline(struct cons_scr *scr)
+{
+ scr->text_x = 0;
+ scr->text_y += FONT_HEIGHT;
+
+ /* Handle console y overflow */
+ if (scr->text_y >= scr->max_row - FONT_HEIGHT) {
+ scr->text_x = 0;
+ scr->text_y = 0;
+ fill_screen(scr, scr->scr_bg);
+ }
+}
+
+/*
* Fill a screen with a desired background
* color
*
@@ -81,6 +105,31 @@ fill_screen(struct cons_scr *scr, uint32_t bg)
}
/*
+ * Handle special ASCII characters
+ *
+ * @scr: Screen we are writing on
+ * @c: Character to handle
+ *
+ * Returns the character on success, otherwis a less than
+ * zero value on [need retransmit] / error
+ */
+static int
+cons_handle_spec(struct cons_scr *scr, int c)
+{
+ if (scr == NULL) {
+ return -EINVAL;
+ }
+
+ switch (c) {
+ case ASCII_LF:
+ cons_newline(scr);
+ return c;
+ }
+
+ return -1;
+}
+
+/*
* Plot a single character onto the screen
*
* @scr: Screen to plot onto
@@ -136,20 +185,16 @@ cons_putstr(struct cons_scr *scr, const char *str, size_t len)
spinlock_acquire(&scr->lock);
for (size_t i = 0; i < len; ++i) {
ch.c = str[i];
+ if (cons_handle_spec(scr, ch.c) == ch.c) {
+ continue;
+ }
+
cons_putch(scr, &ch);
scr->text_x += FONT_WIDTH;
/* Handle console x overflow */
if (scr->text_x >= scr->max_col - FONT_WIDTH) {
- scr->text_x = 0;
- scr->text_y += FONT_HEIGHT;
- }
-
- /* Handle console y overflow */
- if (scr->text_y >= scr->max_row - FONT_HEIGHT) {
- scr->text_x = 0;
- scr->text_y = 0;
- fill_screen(scr, scr->scr_bg);
+ cons_newline(scr);
}
}