term: Finish up context control work

This commit is contained in:
mintsuki 2021-08-16 20:56:39 +02:00
parent 0b1c1ccc88
commit 17c5ec43e0
8 changed files with 38 additions and 17 deletions

View File

@ -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

View File

@ -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();

View File

@ -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;

View File

@ -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

View File

@ -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;
}

View File

@ -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);

View File

@ -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;

View File

@ -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;