summaryrefslogtreecommitdiff
path: root/src/sys/io
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-09-15 03:25:51 -0400
committerIan Moffett <ian@osmora.org>2025-09-15 03:26:17 -0400
commit5e8cf84fb8fb2821eb948ffd2fddafd18b18e8cc (patch)
treee816489c6b23afa83360faf27c0c493a1e81f0db /src/sys/io
parent40bca9deb5f81e57907e5614846678a46bcc1a49 (diff)
kern: cons: Finish string writing logic
- Wrap on X overflow - Wrap on Y overflow - Keep track of max console width and height - Add console enable/disable control Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys/io')
-rw-r--r--src/sys/io/cons/cons.c62
1 files changed, 39 insertions, 23 deletions
diff --git a/src/sys/io/cons/cons.c b/src/sys/io/cons/cons.c
index 182da95..f95bf0f 100644
--- a/src/sys/io/cons/cons.c
+++ b/src/sys/io/cons/cons.c
@@ -39,6 +39,7 @@
#define DEFAULT_BG 0x000000
#define DEFAULT_FG 0xB57614
#define FONT_WIDTH 8
+#define FONT_HEIGHT 20
struct cons_scr g_root_scr;
@@ -59,6 +60,27 @@ fb_get_index(uint32_t pitch, uint32_t x, uint32_t y)
}
/*
+ * Fill a screen with a desired background
+ * color
+ *
+ * @bg: Background color to fill screen
+ */
+static void
+fill_screen(struct cons_scr *scr, uint32_t bg)
+{
+ struct bootvar_fb *fbvars;
+ size_t len;
+
+ if (scr == NULL) {
+ return;
+ }
+
+ fbvars = &scr->fbvars;
+ len = fbvars->width * fbvars->pitch;
+ memset(fbvars->io, bg, len);
+}
+
+/*
* Plot a single character onto the screen
*
* @scr: Screen to plot onto
@@ -106,40 +128,33 @@ cons_putstr(struct cons_scr *scr, const char *str, size_t len)
return -EINVAL;
}
- spinlock_acquire(&scr->lock);
ch.bg = scr->scr_bg;
ch.fg = scr->scr_fg;
ch.y = scr->text_y;
ch.x = scr->text_x;
+ spinlock_acquire(&scr->lock);
for (size_t i = 0; i < len; ++i) {
ch.c = str[i];
cons_putch(scr, &ch);
- ch.x += FONT_WIDTH;
- }
-
- return len;
-}
+ scr->text_x += FONT_WIDTH;
-/*
- * Fill a screen with a desired background
- * color
- *
- * @bg: Background color to fill screen
- */
-static void
-fill_screen(struct cons_scr *scr, uint32_t bg)
-{
- struct bootvar_fb *fbvars;
- size_t len;
+ /* Handle console x overflow */
+ if (scr->text_x >= scr->max_col - FONT_WIDTH) {
+ scr->text_x = 0;
+ scr->text_y += FONT_HEIGHT;
+ }
- if (scr == NULL) {
- return;
+ /* 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);
+ }
}
- fbvars = &scr->fbvars;
- len = fbvars->width * fbvars->pitch;
- memset(fbvars->io, bg, len);
+ spinlock_release(&scr->lock);
+ return len;
}
/*
@@ -180,7 +195,8 @@ cons_init(void)
/* Set up screen state */
g_root_scr.scr_bg = DEFAULT_BG;
g_root_scr.scr_fg = DEFAULT_FG;
- g_root_scr.max_col = fbvars->width / 4;
+ g_root_scr.max_col = fbvars->width;
+ g_root_scr.max_row = fbvars->height;
fill_screen(&g_root_scr, g_root_scr.scr_bg);
return 0;
}