term: Reimplement context control

This commit is contained in:
mintsuki 2022-10-04 20:39:50 +02:00
parent 48a7c12e5b
commit f977548e84
3 changed files with 114 additions and 23 deletions

View File

@ -11,26 +11,7 @@
#include <lib/term.h>
#include <mm/pmm.h>
struct textmode_context {
struct term_context term;
volatile uint8_t *video_mem;
uint8_t *back_buffer;
uint8_t *front_buffer;
size_t cursor_offset;
size_t old_cursor_offset;
bool cursor_status;
uint8_t text_palette;
uint8_t saved_state_text_palette;
size_t saved_state_cursor_offset;
};
#define VIDEO_BOTTOM ((VD_ROWS * VD_COLS) - 1)
#define VD_COLS (80 * 2)
#define VD_ROWS 25
static void draw_cursor(struct textmode_context *ctx) {
uint8_t pal = ctx->back_buffer[ctx->cursor_offset + 1];

View File

@ -3,7 +3,30 @@
#if defined (BIOS)
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <term/term.h>
#define VD_COLS (80 * 2)
#define VD_ROWS 25
struct textmode_context {
struct term_context term;
volatile uint8_t *video_mem;
uint8_t *back_buffer;
uint8_t *front_buffer;
size_t cursor_offset;
size_t old_cursor_offset;
bool cursor_status;
uint8_t text_palette;
uint8_t saved_state_text_palette;
size_t saved_state_cursor_offset;
};
void vga_textmode_init(bool managed);

View File

@ -6,6 +6,8 @@
#include <lib/misc.h>
#include <lib/print.h>
#include <mm/pmm.h>
#include <drivers/vga_textmode.h>
#include <term/backends/framebuffer.h>
int current_video_mode = -1;
int term_backend = _NOT_READY;
@ -263,19 +265,104 @@ extern void set_cursor_pos_helper(size_t x, size_t y);
static uint8_t xfer_buf[TERM_XFER_CHUNK];
#endif
static uint64_t context_size(void) {
switch (term_backend) {
case TEXTMODE:
return sizeof(struct textmode_context) + (VD_ROWS * VD_COLS) * 2;
case GTERM: {
struct fbterm_context *ctx = (void *)term;
return sizeof(struct fbterm_context) +
ctx->font_bits_size +
ctx->font_bool_size +
ctx->canvas_size +
ctx->grid_size +
ctx->queue_size +
ctx->map_size;
}
default:
return 0;
}
}
static void context_save(uint64_t buf) {
switch (term_backend) {
case TEXTMODE: {
struct textmode_context *ctx = (void *)term;
memcpy32to64(buf, (uintptr_t)ctx, sizeof(struct textmode_context));
buf += sizeof(struct textmode_context);
memcpy32to64(buf, (uintptr_t)ctx->back_buffer, VD_ROWS * VD_COLS);
buf += VD_ROWS * VD_COLS;
memcpy32to64(buf, (uintptr_t)ctx->front_buffer, VD_ROWS * VD_COLS);
buf += VD_ROWS * VD_COLS;
break;
}
case GTERM: {
struct fbterm_context *ctx = (void *)term;
memcpy32to64(buf, (uintptr_t)ctx, sizeof(struct fbterm_context));
buf += sizeof(struct fbterm_context);
memcpy32to64(buf, (uintptr_t)ctx->font_bits, ctx->font_bits_size);
buf += ctx->font_bits_size;
memcpy32to64(buf, (uintptr_t)ctx->font_bool, ctx->font_bool_size);
buf += ctx->font_bool_size;
memcpy32to64(buf, (uintptr_t)ctx->canvas, ctx->canvas_size);
buf += ctx->canvas_size;
memcpy32to64(buf, (uintptr_t)ctx->grid, ctx->grid_size);
buf += ctx->grid_size;
memcpy32to64(buf, (uintptr_t)ctx->queue, ctx->queue_size);
buf += ctx->queue_size;
memcpy32to64(buf, (uintptr_t)ctx->map, ctx->map_size);
buf += ctx->map_size;
break;
}
}
}
static void context_restore(uint64_t buf) {
switch (term_backend) {
case TEXTMODE: {
struct textmode_context *ctx = (void *)term;
memcpy32to64((uintptr_t)ctx, buf, sizeof(struct textmode_context));
buf += sizeof(struct textmode_context);
memcpy32to64((uintptr_t)ctx->back_buffer, buf, VD_ROWS * VD_COLS);
buf += VD_ROWS * VD_COLS;
memcpy32to64((uintptr_t)ctx->front_buffer, buf, VD_ROWS * VD_COLS);
buf += VD_ROWS * VD_COLS;
break;
}
case GTERM: {
struct fbterm_context *ctx = (void *)term;
memcpy32to64((uintptr_t)ctx, buf, sizeof(struct fbterm_context));
buf += sizeof(struct fbterm_context);
memcpy32to64((uintptr_t)ctx->font_bits, buf, ctx->font_bits_size);
buf += ctx->font_bits_size;
memcpy32to64((uintptr_t)ctx->font_bool, buf, ctx->font_bool_size);
buf += ctx->font_bool_size;
memcpy32to64((uintptr_t)ctx->canvas, buf, ctx->canvas_size);
buf += ctx->canvas_size;
memcpy32to64((uintptr_t)ctx->grid, buf, ctx->grid_size);
buf += ctx->grid_size;
memcpy32to64((uintptr_t)ctx->queue, buf, ctx->queue_size);
buf += ctx->queue_size;
memcpy32to64((uintptr_t)ctx->map, buf, ctx->map_size);
buf += ctx->map_size;
break;
}
}
}
void _term_write(uint64_t buf, uint64_t count) {
switch (count) {
case TERM_CTX_SIZE: {
//uint64_t ret = context_size();
//memcpy32to64(buf, (uint64_t)(uintptr_t)&ret, sizeof(uint64_t));
uint64_t ret = context_size();
memcpy32to64(buf, (uint64_t)(uintptr_t)&ret, sizeof(uint64_t));
return;
}
case TERM_CTX_SAVE: {
//context_save(buf);
context_save(buf);
return;
}
case TERM_CTX_RESTORE: {
//context_restore(buf);
context_restore(buf);
return;
}
case TERM_FULL_REFRESH: {