term: Finish up context control work
diff --git a/stage23/drivers/vga_textmode.h b/stage23/drivers/vga_textmode.h
index 8ad55d64..e679668f 100644
--- a/stage23/drivers/vga_textmode.h
+++ b/stage23/drivers/vga_textmode.h
@@ -30,5 +30,6 @@ void text_double_buffer_flush(void);
uint64_t text_context_size(void);
void text_context_save(uint64_t ptr);
void text_context_restore(uint64_t ptr);
+void text_full_refresh(void);
#endif
diff --git a/stage23/drivers/vga_textmode.s2.c b/stage23/drivers/vga_textmode.s2.c
index 2ae68322..b6bee3ad 100644
--- a/stage23/drivers/vga_textmode.s2.c
+++ b/stage23/drivers/vga_textmode.s2.c
@@ -114,7 +114,6 @@ uint64_t text_context_size(void) {
uint64_t ret = 0;
ret += sizeof(struct context);
- ret += VD_ROWS * VD_COLS; // back buffer
ret += VD_ROWS * VD_COLS; // front buffer
return ret;
@@ -124,9 +123,6 @@ void text_context_save(uint64_t ptr) {
memcpy32to64(ptr, (uint64_t)(uintptr_t)&context, sizeof(struct context));
ptr += sizeof(struct context);
- memcpy32to64(ptr, (uint64_t)(uintptr_t)back_buffer, VD_ROWS * VD_COLS);
- ptr += VD_ROWS * VD_COLS;
-
memcpy32to64(ptr, (uint64_t)(uintptr_t)front_buffer, VD_ROWS * VD_COLS);
}
@@ -134,13 +130,18 @@ void text_context_restore(uint64_t ptr) {
memcpy32to64((uint64_t)(uintptr_t)&context, ptr, sizeof(struct context));
ptr += sizeof(struct context);
- memcpy32to64((uint64_t)(uintptr_t)back_buffer, ptr, VD_ROWS * VD_COLS);
- ptr += VD_ROWS * VD_COLS;
-
memcpy32to64((uint64_t)(uintptr_t)front_buffer, ptr, VD_ROWS * VD_COLS);
for (size_t i = 0; i < VD_ROWS * VD_COLS; i++) {
- video_mem[i] = current_buffer[i];
+ video_mem[i] = front_buffer[i];
+ }
+
+ draw_cursor();
+}
+
+void text_full_refresh(void) {
+ for (size_t i = 0; i < VD_ROWS * VD_COLS; i++) {
+ video_mem[i] = front_buffer[i];
}
draw_cursor();
diff --git a/stage23/lib/gterm.c b/stage23/lib/gterm.c
index 02a17cd2..61d5a5e3 100644
--- a/stage23/lib/gterm.c
+++ b/stage23/lib/gterm.c
@@ -712,7 +712,6 @@ uint64_t gterm_context_size(void) {
ret += sizeof(struct context);
ret += last_grid_size;
- ret += last_front_grid_size;
return ret;
}
@@ -722,9 +721,6 @@ void gterm_context_save(uint64_t ptr) {
ptr += sizeof(struct context);
memcpy32to64(ptr, (uint64_t)(uintptr_t)grid, last_grid_size);
- ptr += last_grid_size;
-
- memcpy32to64(ptr, (uint64_t)(uintptr_t)front_grid, last_front_grid_size);
}
void gterm_context_restore(uint64_t ptr) {
@@ -732,9 +728,20 @@ void gterm_context_restore(uint64_t ptr) {
ptr += sizeof(struct context);
memcpy32to64((uint64_t)(uintptr_t)grid, ptr, last_grid_size);
- ptr += last_grid_size;
- memcpy32to64((uint64_t)(uintptr_t)front_grid, ptr, last_front_grid_size);
+ for (size_t i = 0; i < (size_t)rows * cols; i++) {
+ size_t x = i % cols;
+ size_t y = i / cols;
+
+ gterm_plot_char(&grid[i], x * VGA_FONT_WIDTH + frame_width,
+ y * VGA_FONT_HEIGHT + frame_height);
+ }
+
+ draw_cursor();
+}
+
+void gterm_full_refresh(void) {
+ gterm_generate_canvas();
for (size_t i = 0; i < (size_t)rows * cols; i++) {
size_t x = i % cols;
diff --git a/stage23/lib/gterm.h b/stage23/lib/gterm.h
index 3f02c63d..f1dc83c8 100644
--- a/stage23/lib/gterm.h
+++ b/stage23/lib/gterm.h
@@ -34,5 +34,6 @@ void gterm_double_buffer(bool state);
uint64_t gterm_context_size(void);
void gterm_context_save(uint64_t ptr);
void gterm_context_restore(uint64_t ptr);
+void gterm_full_refresh(void);
#endif
diff --git a/stage23/lib/term.c b/stage23/lib/term.c
index 3fde1b56..26218b87 100644
--- a/stage23/lib/term.c
+++ b/stage23/lib/term.c
@@ -45,6 +45,7 @@ void term_vbe(size_t width, size_t height) {
term_context_size = gterm_context_size;
term_context_save = gterm_context_save;
term_context_restore = gterm_context_restore;
+ term_full_refresh = gterm_full_refresh;
term_backend = VBE;
}
diff --git a/stage23/lib/term.h b/stage23/lib/term.h
index f9753105..cddcda6f 100644
--- a/stage23/lib/term.h
+++ b/stage23/lib/term.h
@@ -75,6 +75,7 @@ extern void (*term_double_buffer_flush)(void);
extern uint64_t (*term_context_size)(void);
extern void (*term_context_save)(uint64_t ptr);
extern void (*term_context_restore)(uint64_t ptr);
+extern void (*term_full_refresh)(void);
#define TERM_CB_DEC 10
#define TERM_CB_BELL 20
@@ -88,6 +89,7 @@ extern void (*term_context_restore)(uint64_t ptr);
#define TERM_CTX_SIZE ((uint64_t)(-1))
#define TERM_CTX_SAVE ((uint64_t)(-2))
#define TERM_CTX_RESTORE ((uint64_t)(-3))
+#define TERM_FULL_REFRESH ((uint64_t)(-4))
extern void (*term_callback)(uint64_t, uint64_t, uint64_t, uint64_t);
diff --git a/stage23/lib/term.s2.c b/stage23/lib/term.s2.c
index 8cb2c9a9..a54bff70 100644
--- a/stage23/lib/term.s2.c
+++ b/stage23/lib/term.s2.c
@@ -42,6 +42,7 @@ void (*term_double_buffer_flush)(void);
uint64_t (*term_context_size)(void);
void (*term_context_save)(uint64_t ptr);
void (*term_context_restore)(uint64_t ptr);
+void (*term_full_refresh)(void);
void (*term_callback)(uint64_t, uint64_t, uint64_t, uint64_t) = NULL;
@@ -126,6 +127,7 @@ void term_textmode(void) {
term_context_size = text_context_size;
term_context_save = text_context_save;
term_context_restore = text_context_restore;
+ term_full_refresh = text_full_refresh;
term_backend = TEXTMODE;
}
@@ -182,6 +184,10 @@ void term_write(uint64_t buf, uint64_t count) {
context_restore(buf);
return;
}
+ case TERM_FULL_REFRESH: {
+ term_full_refresh();
+ return;
+ }
}
bool native = false;
diff --git a/stage23/protos/stivale2.c b/stage23/protos/stivale2.c
index 7ecaf51e..497b6c41 100644
--- a/stage23/protos/stivale2.c
+++ b/stage23/protos/stivale2.c
@@ -442,6 +442,10 @@ failed_to_load_header_section:
// We provide max allowed string length
tag->flags |= (1 << 1);
+ tag->max_length = 0;
+
+ // We provide context control
+ tag->flags |= (1 << 3);
#if defined (__i386__)
if (stivale2_rt_stack == NULL) {
@@ -453,8 +457,6 @@ failed_to_load_header_section:
tag->term_write = (uintptr_t)term_write;
#endif
- tag->max_length = 0;
-
// We provide rows and cols
tag->flags |= (1 << 0);
tag->cols = term_cols;
