···
5
-
#include "framebuffer.h"
4
+
#include "../flanterm.h"
void *memset(void *, int, size_t);
void *memcpy(void *, const void *, size_t);
···
357
-
static void fbterm_save_state(struct term_context *_ctx) {
358
-
struct fbterm_context *ctx = (void *)_ctx;
357
+
static void flanterm_fb_save_state(struct flanterm_context *_ctx) {
358
+
struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->saved_state_text_fg = ctx->text_fg;
ctx->saved_state_text_bg = ctx->text_bg;
ctx->saved_state_cursor_x = ctx->cursor_x;
ctx->saved_state_cursor_y = ctx->cursor_y;
365
-
static void fbterm_restore_state(struct term_context *_ctx) {
366
-
struct fbterm_context *ctx = (void *)_ctx;
365
+
static void flanterm_fb_restore_state(struct flanterm_context *_ctx) {
366
+
struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_fg = ctx->saved_state_text_fg;
ctx->text_bg = ctx->saved_state_text_bg;
ctx->cursor_x = ctx->saved_state_cursor_x;
ctx->cursor_y = ctx->saved_state_cursor_y;
373
-
static void fbterm_swap_palette(struct term_context *_ctx) {
374
-
struct fbterm_context *ctx = (void *)_ctx;
373
+
static void flanterm_fb_swap_palette(struct flanterm_context *_ctx) {
374
+
struct flanterm_fb_context *ctx = (void *)_ctx;
uint32_t tmp = ctx->text_bg;
ctx->text_bg = ctx->text_fg;
380
-
static void plot_char(struct term_context *_ctx, struct fbterm_char *c, size_t x, size_t y) {
381
-
struct fbterm_context *ctx = (void *)_ctx;
380
+
static void plot_char(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) {
381
+
struct flanterm_fb_context *ctx = (void *)_ctx;
if (x >= _ctx->cols || y >= _ctx->rows) {
···
408
-
static void plot_char_fast(struct term_context *_ctx, struct fbterm_char *old, struct fbterm_char *c, size_t x, size_t y) {
409
-
struct fbterm_context *ctx = (void *)_ctx;
408
+
static void plot_char_fast(struct flanterm_context *_ctx, struct flanterm_fb_char *old, struct flanterm_fb_char *c, size_t x, size_t y) {
409
+
struct flanterm_fb_context *ctx = (void *)_ctx;
if (x >= _ctx->cols || y >= _ctx->rows) {
···
439
-
static inline bool compare_char(struct fbterm_char *a, struct fbterm_char *b) {
439
+
static inline bool compare_char(struct flanterm_fb_char *a, struct flanterm_fb_char *b) {
return !(a->c != b->c || a->bg != b->bg || a->fg != b->fg);
443
-
static void push_to_queue(struct term_context *_ctx, struct fbterm_char *c, size_t x, size_t y) {
444
-
struct fbterm_context *ctx = (void *)_ctx;
443
+
static void push_to_queue(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) {
444
+
struct flanterm_fb_context *ctx = (void *)_ctx;
if (x >= _ctx->cols || y >= _ctx->rows) {
···
size_t i = y * _ctx->cols + x;
452
-
struct fbterm_queue_item *q = ctx->map[i];
452
+
struct flanterm_fb_queue_item *q = ctx->map[i];
if (compare_char(&ctx->grid[i], c)) {
···
467
-
static void fbterm_revscroll(struct term_context *_ctx) {
468
-
struct fbterm_context *ctx = (void *)_ctx;
467
+
static void flanterm_fb_revscroll(struct flanterm_context *_ctx) {
468
+
struct flanterm_fb_context *ctx = (void *)_ctx;
for (size_t i = (_ctx->scroll_bottom_margin - 1) * _ctx->cols - 1;
i >= _ctx->scroll_top_margin * _ctx->cols; i--) {
475
-
struct fbterm_char *c;
476
-
struct fbterm_queue_item *q = ctx->map[i];
475
+
struct flanterm_fb_char *c;
476
+
struct flanterm_fb_queue_item *q = ctx->map[i];
···
// Clear the first line of the screen.
486
-
struct fbterm_char empty;
486
+
struct flanterm_fb_char empty;
···
495
-
static void fbterm_scroll(struct term_context *_ctx) {
496
-
struct fbterm_context *ctx = (void *)_ctx;
495
+
static void flanterm_fb_scroll(struct flanterm_context *_ctx) {
496
+
struct flanterm_fb_context *ctx = (void *)_ctx;
for (size_t i = (_ctx->scroll_top_margin + 1) * _ctx->cols;
i < _ctx->scroll_bottom_margin * _ctx->cols; i++) {
500
-
struct fbterm_char *c;
501
-
struct fbterm_queue_item *q = ctx->map[i];
500
+
struct flanterm_fb_char *c;
501
+
struct flanterm_fb_queue_item *q = ctx->map[i];
···
// Clear the last line of the screen.
511
-
struct fbterm_char empty;
511
+
struct flanterm_fb_char empty;
···
520
-
static void fbterm_clear(struct term_context *_ctx, bool move) {
521
-
struct fbterm_context *ctx = (void *)_ctx;
520
+
static void flanterm_fb_clear(struct flanterm_context *_ctx, bool move) {
521
+
struct flanterm_fb_context *ctx = (void *)_ctx;
523
-
struct fbterm_char empty;
523
+
struct flanterm_fb_char empty;
···
537
-
static void fbterm_set_cursor_pos(struct term_context *_ctx, size_t x, size_t y) {
538
-
struct fbterm_context *ctx = (void *)_ctx;
537
+
static void flanterm_fb_set_cursor_pos(struct flanterm_context *_ctx, size_t x, size_t y) {
538
+
struct flanterm_fb_context *ctx = (void *)_ctx;
···
558
-
static void fbterm_get_cursor_pos(struct term_context *_ctx, size_t *x, size_t *y) {
559
-
struct fbterm_context *ctx = (void *)_ctx;
558
+
static void flanterm_fb_get_cursor_pos(struct flanterm_context *_ctx, size_t *x, size_t *y) {
559
+
struct flanterm_fb_context *ctx = (void *)_ctx;
*x = ctx->cursor_x >= _ctx->cols ? _ctx->cols - 1 : ctx->cursor_x;
*y = ctx->cursor_y >= _ctx->rows ? _ctx->rows - 1 : ctx->cursor_y;
565
-
static void fbterm_move_character(struct term_context *_ctx, size_t new_x, size_t new_y, size_t old_x, size_t old_y) {
566
-
struct fbterm_context *ctx = (void *)_ctx;
565
+
static void flanterm_fb_move_character(struct flanterm_context *_ctx, size_t new_x, size_t new_y, size_t old_x, size_t old_y) {
566
+
struct flanterm_fb_context *ctx = (void *)_ctx;
if (old_x >= _ctx->cols || old_y >= _ctx->rows
|| new_x >= _ctx->cols || new_y >= _ctx->rows) {
···
size_t i = old_x + old_y * _ctx->cols;
575
-
struct fbterm_char *c;
576
-
struct fbterm_queue_item *q = ctx->map[i];
575
+
struct flanterm_fb_char *c;
576
+
struct flanterm_fb_queue_item *q = ctx->map[i];
···
push_to_queue(_ctx, c, new_x, new_y);
586
-
static void fbterm_set_text_fg(struct term_context *_ctx, size_t fg) {
587
-
struct fbterm_context *ctx = (void *)_ctx;
586
+
static void flanterm_fb_set_text_fg(struct flanterm_context *_ctx, size_t fg) {
587
+
struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_fg = ctx->ansi_colours[fg];
592
-
static void fbterm_set_text_bg(struct term_context *_ctx, size_t bg) {
593
-
struct fbterm_context *ctx = (void *)_ctx;
592
+
static void flanterm_fb_set_text_bg(struct flanterm_context *_ctx, size_t bg) {
593
+
struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_bg = ctx->ansi_colours[bg];
598
-
static void fbterm_set_text_fg_bright(struct term_context *_ctx, size_t fg) {
599
-
struct fbterm_context *ctx = (void *)_ctx;
598
+
static void flanterm_fb_set_text_fg_bright(struct flanterm_context *_ctx, size_t fg) {
599
+
struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_fg = ctx->ansi_bright_colours[fg];
604
-
static void fbterm_set_text_bg_bright(struct term_context *_ctx, size_t bg) {
605
-
struct fbterm_context *ctx = (void *)_ctx;
604
+
static void flanterm_fb_set_text_bg_bright(struct flanterm_context *_ctx, size_t bg) {
605
+
struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_bg = ctx->ansi_bright_colours[bg];
610
-
static void fbterm_set_text_fg_rgb(struct term_context *_ctx, uint32_t fg) {
611
-
struct fbterm_context *ctx = (void *)_ctx;
610
+
static void flanterm_fb_set_text_fg_rgb(struct flanterm_context *_ctx, uint32_t fg) {
611
+
struct flanterm_fb_context *ctx = (void *)_ctx;
616
-
static void fbterm_set_text_bg_rgb(struct term_context *_ctx, uint32_t bg) {
617
-
struct fbterm_context *ctx = (void *)_ctx;
616
+
static void flanterm_fb_set_text_bg_rgb(struct flanterm_context *_ctx, uint32_t bg) {
617
+
struct flanterm_fb_context *ctx = (void *)_ctx;
622
-
static void fbterm_set_text_fg_default(struct term_context *_ctx) {
623
-
struct fbterm_context *ctx = (void *)_ctx;
622
+
static void flanterm_fb_set_text_fg_default(struct flanterm_context *_ctx) {
623
+
struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_fg = ctx->default_fg;
628
-
static void fbterm_set_text_bg_default(struct term_context *_ctx) {
629
-
struct fbterm_context *ctx = (void *)_ctx;
628
+
static void flanterm_fb_set_text_bg_default(struct flanterm_context *_ctx) {
629
+
struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_bg = 0xffffffff;
634
-
static void fbterm_set_text_fg_default_bright(struct term_context *_ctx) {
635
-
struct fbterm_context *ctx = (void *)_ctx;
634
+
static void flanterm_fb_set_text_fg_default_bright(struct flanterm_context *_ctx) {
635
+
struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_fg = ctx->default_fg_bright;
640
-
static void fbterm_set_text_bg_default_bright(struct term_context *_ctx) {
641
-
struct fbterm_context *ctx = (void *)_ctx;
640
+
static void flanterm_fb_set_text_bg_default_bright(struct flanterm_context *_ctx) {
641
+
struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_bg = ctx->default_bg_bright;
646
-
static void draw_cursor(struct term_context *_ctx) {
647
-
struct fbterm_context *ctx = (void *)_ctx;
646
+
static void draw_cursor(struct flanterm_context *_ctx) {
647
+
struct flanterm_fb_context *ctx = (void *)_ctx;
if (ctx->cursor_x >= _ctx->cols || ctx->cursor_y >= _ctx->rows) {
···
size_t i = ctx->cursor_x + ctx->cursor_y * _ctx->cols;
655
-
struct fbterm_char c;
656
-
struct fbterm_queue_item *q = ctx->map[i];
655
+
struct flanterm_fb_char c;
656
+
struct flanterm_fb_queue_item *q = ctx->map[i];
···
672
-
static void fbterm_double_buffer_flush(struct term_context *_ctx) {
673
-
struct fbterm_context *ctx = (void *)_ctx;
672
+
static void flanterm_fb_double_buffer_flush(struct flanterm_context *_ctx) {
673
+
struct flanterm_fb_context *ctx = (void *)_ctx;
if (_ctx->cursor_enabled) {
for (size_t i = 0; i < ctx->queue_i; i++) {
680
-
struct fbterm_queue_item *q = &ctx->queue[i];
680
+
struct flanterm_fb_queue_item *q = &ctx->queue[i];
size_t offset = q->y * _ctx->cols + q->x;
if (ctx->map[offset] == NULL) {
685
-
struct fbterm_char *old = &ctx->grid[offset];
685
+
struct flanterm_fb_char *old = &ctx->grid[offset];
if (q->c.bg == old->bg && q->c.fg == old->fg) {
plot_char_fast(_ctx, old, &q->c, q->x, q->y);
···
707
-
static void fbterm_raw_putchar(struct term_context *_ctx, uint8_t c) {
708
-
struct fbterm_context *ctx = (void *)_ctx;
707
+
static void flanterm_fb_raw_putchar(struct flanterm_context *_ctx, uint8_t c) {
708
+
struct flanterm_fb_context *ctx = (void *)_ctx;
if (ctx->cursor_x >= _ctx->cols && (ctx->cursor_y < _ctx->scroll_bottom_margin - 1 || _ctx->scroll_enabled)) {
if (ctx->cursor_y == _ctx->scroll_bottom_margin) {
715
-
fbterm_scroll(_ctx);
715
+
flanterm_fb_scroll(_ctx);
if (ctx->cursor_y >= _ctx->cols) {
ctx->cursor_y = _ctx->cols - 1;
722
-
struct fbterm_char ch;
722
+
struct flanterm_fb_char ch;
push_to_queue(_ctx, &ch, ctx->cursor_x++, ctx->cursor_y);
729
-
static void fbterm_full_refresh(struct term_context *_ctx) {
730
-
struct fbterm_context *ctx = (void *)_ctx;
729
+
static void flanterm_fb_full_refresh(struct flanterm_context *_ctx) {
730
+
struct flanterm_fb_context *ctx = (void *)_ctx;
for (size_t y = 0; y < ctx->height; y++) {
for (size_t x = 0; x < ctx->width; x++) {
···
750
-
static void fbterm_deinit(struct term_context *_ctx, void (*_free)(void *, size_t)) {
751
-
struct fbterm_context *ctx = (void *)_ctx;
750
+
static void flanterm_fb_deinit(struct flanterm_context *_ctx, void (*_free)(void *, size_t)) {
751
+
struct flanterm_fb_context *ctx = (void *)_ctx;
_free(ctx->font_bits, ctx->font_bits_size);
_free(ctx->font_bool, ctx->font_bool_size);
···
_free(ctx->queue, ctx->queue_size);
_free(ctx->map, ctx->map_size);
_free(ctx->canvas, ctx->canvas_size);
759
-
_free(ctx, sizeof(struct fbterm_context));
759
+
_free(ctx, sizeof(struct flanterm_fb_context));
762
-
struct term_context *fbterm_init(
762
+
struct flanterm_context *flanterm_fb_init(
void *(*_malloc)(size_t),
uint32_t *framebuffer, size_t width, size_t height, size_t pitch,
···
size_t font_scale_x, size_t font_scale_y,
773
-
struct fbterm_context *ctx = _malloc(sizeof(struct fbterm_context));
773
+
struct flanterm_fb_context *ctx = _malloc(sizeof(struct flanterm_fb_context));
775
-
struct term_context *_ctx = (void *)ctx;
775
+
struct flanterm_context *_ctx = (void *)ctx;
777
-
memset(ctx, 0, sizeof(struct fbterm_context));
777
+
memset(ctx, 0, sizeof(struct flanterm_fb_context));
if (ansi_colours != NULL) {
memcpy(ctx->ansi_colours, ansi_colours, sizeof(ctx->ansi_colours));
···
837
-
#define FONT_BYTES ((font_width * font_height * FBTERM_FONT_GLYPHS) / 8)
837
+
#define FONT_BYTES ((font_width * font_height * FLANTERM_FB_FONT_GLYPHS) / 8)
ctx->font_width = font_width;
···
ctx->font_width += font_spacing;
858
-
ctx->font_bool_size = FBTERM_FONT_GLYPHS * font_height * ctx->font_width * sizeof(bool);
858
+
ctx->font_bool_size = FLANTERM_FB_FONT_GLYPHS * font_height * ctx->font_width * sizeof(bool);
ctx->font_bool = _malloc(ctx->font_bool_size);
861
-
for (size_t i = 0; i < FBTERM_FONT_GLYPHS; i++) {
861
+
for (size_t i = 0; i < FLANTERM_FB_FONT_GLYPHS; i++) {
uint8_t *glyph = &ctx->font_bits[i * font_height];
for (size_t y = 0; y < font_height; y++) {
···
ctx->offset_x = margin + ((ctx->width - margin * 2) % ctx->glyph_width) / 2;
ctx->offset_y = margin + ((ctx->height - margin * 2) % ctx->glyph_height) / 2;
902
-
ctx->grid_size = _ctx->rows * _ctx->cols * sizeof(struct fbterm_char);
902
+
ctx->grid_size = _ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_char);
ctx->grid = _malloc(ctx->grid_size);
for (size_t i = 0; i < _ctx->rows * _ctx->cols; i++) {
···
ctx->grid[i].bg = ctx->text_bg;
910
-
ctx->queue_size = _ctx->rows * _ctx->cols * sizeof(struct fbterm_queue_item);
910
+
ctx->queue_size = _ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_queue_item);
ctx->queue = _malloc(ctx->queue_size);
memset(ctx->queue, 0, ctx->queue_size);
915
-
ctx->map_size = _ctx->rows * _ctx->cols * sizeof(struct fbterm_queue_item *);
915
+
ctx->map_size = _ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_queue_item *);
ctx->map = _malloc(ctx->map_size);
memset(ctx->map, 0, ctx->map_size);
···
929
-
_ctx->raw_putchar = fbterm_raw_putchar;
930
-
_ctx->clear = fbterm_clear;
931
-
_ctx->set_cursor_pos = fbterm_set_cursor_pos;
932
-
_ctx->get_cursor_pos = fbterm_get_cursor_pos;
933
-
_ctx->set_text_fg = fbterm_set_text_fg;
934
-
_ctx->set_text_bg = fbterm_set_text_bg;
935
-
_ctx->set_text_fg_bright = fbterm_set_text_fg_bright;
936
-
_ctx->set_text_bg_bright = fbterm_set_text_bg_bright;
937
-
_ctx->set_text_fg_rgb = fbterm_set_text_fg_rgb;
938
-
_ctx->set_text_bg_rgb = fbterm_set_text_bg_rgb;
939
-
_ctx->set_text_fg_default = fbterm_set_text_fg_default;
940
-
_ctx->set_text_bg_default = fbterm_set_text_bg_default;
941
-
_ctx->set_text_fg_default_bright = fbterm_set_text_fg_default_bright;
942
-
_ctx->set_text_bg_default_bright = fbterm_set_text_bg_default_bright;
943
-
_ctx->move_character = fbterm_move_character;
944
-
_ctx->scroll = fbterm_scroll;
945
-
_ctx->revscroll = fbterm_revscroll;
946
-
_ctx->swap_palette = fbterm_swap_palette;
947
-
_ctx->save_state = fbterm_save_state;
948
-
_ctx->restore_state = fbterm_restore_state;
949
-
_ctx->double_buffer_flush = fbterm_double_buffer_flush;
950
-
_ctx->full_refresh = fbterm_full_refresh;
951
-
_ctx->deinit = fbterm_deinit;
929
+
_ctx->raw_putchar = flanterm_fb_raw_putchar;
930
+
_ctx->clear = flanterm_fb_clear;
931
+
_ctx->set_cursor_pos = flanterm_fb_set_cursor_pos;
932
+
_ctx->get_cursor_pos = flanterm_fb_get_cursor_pos;
933
+
_ctx->set_text_fg = flanterm_fb_set_text_fg;
934
+
_ctx->set_text_bg = flanterm_fb_set_text_bg;
935
+
_ctx->set_text_fg_bright = flanterm_fb_set_text_fg_bright;
936
+
_ctx->set_text_bg_bright = flanterm_fb_set_text_bg_bright;
937
+
_ctx->set_text_fg_rgb = flanterm_fb_set_text_fg_rgb;
938
+
_ctx->set_text_bg_rgb = flanterm_fb_set_text_bg_rgb;
939
+
_ctx->set_text_fg_default = flanterm_fb_set_text_fg_default;
940
+
_ctx->set_text_bg_default = flanterm_fb_set_text_bg_default;
941
+
_ctx->set_text_fg_default_bright = flanterm_fb_set_text_fg_default_bright;
942
+
_ctx->set_text_bg_default_bright = flanterm_fb_set_text_bg_default_bright;
943
+
_ctx->move_character = flanterm_fb_move_character;
944
+
_ctx->scroll = flanterm_fb_scroll;
945
+
_ctx->revscroll = flanterm_fb_revscroll;
946
+
_ctx->swap_palette = flanterm_fb_swap_palette;
947
+
_ctx->save_state = flanterm_fb_save_state;
948
+
_ctx->restore_state = flanterm_fb_restore_state;
949
+
_ctx->double_buffer_flush = flanterm_fb_double_buffer_flush;
950
+
_ctx->full_refresh = flanterm_fb_full_refresh;
951
+
_ctx->deinit = flanterm_fb_deinit;
953
-
term_context_reinit(_ctx);
954
-
fbterm_full_refresh(_ctx);
953
+
flanterm_context_reinit(_ctx);
954
+
flanterm_fb_full_refresh(_ctx);