term: depreciate rt, and switch to flanterm

This commit is contained in:
RaphProductions 2025-05-08 21:57:31 +02:00
parent 020d4f092f
commit 621f268f5b
23 changed files with 3201 additions and 9941 deletions

85
deprecated/rt.c Executable file
View file

@ -0,0 +1,85 @@
#include "rt.h"
#include <font.h>
#include <stdint.h>
#include <mm/memop.h>
static rt_context _curctx;
void _rt_drawchar(unsigned char c, int x, int y, int fgcolor, int bgcolor)
{
int cx,cy;
int mask[8]={128, 64, 32, 16, 8, 4, 2, 1};
unsigned char *glyph=VGA8+(int)c*16;
uint32_t *buf = _curctx.framebuffer;
for(cy=0;cy<16;cy++){
for(cx=0;cx<8;cx++){
buf[((y + cy) * _curctx.framebuffer_width) + (x + cx)] = glyph[cy]&mask[cx]?fgcolor:bgcolor;
}
}
}
void _rt_draw_fillchar(int x, int y, int bgcolor, int fgcolor) {
int cx,cy;
uint32_t *buf = _curctx.framebuffer;
for(cy=0;cy<16;cy++){
for(cx=0;cx<8;cx++){
buf[((y + cy) * _curctx.framebuffer_width) + (x + cx)] = cy > 12 ? fgcolor : bgcolor;
}
}
}
int _rt_strlen(char *str) {
int i = 0;
while (str[i] != '\0') i++;
return i;
}
void rt_init(rt_context ctx) {
// Copy the structure
char *src = (char*)&ctx;
char *dst = (char*)&_curctx;
for (unsigned long i = 0; i < sizeof(rt_context); i++) {
dst[i] = src[i];
}
// Fill fields
_curctx.term_width = _curctx.framebuffer_width / 8;
_curctx.term_height = _curctx.framebuffer_height / 16;
}
void rt_print(char *str) {
_rt_draw_fillchar(_curctx.x * 8, _curctx.y * 16, 0x0, 0x0);
for (int i = 0; i < _rt_strlen(str); i++) {
if (str[i] == '\n' && _curctx.use_crlf_ending)
if (_curctx.y * 16 >= (int)_curctx.framebuffer_height) {
_curctx.y = 0;
memset(
_curctx.framebuffer, _curctx.bg_color,
_curctx.framebuffer_width * _curctx.framebuffer_height * sizeof(uint32_t));
} else {
_curctx.y++;
}
else if (str[i] == '\n')
{
if (_curctx.y * 16 >= (int)_curctx.framebuffer_height) {
_curctx.y = 0;
memset(
_curctx.framebuffer, _curctx.bg_color,
_curctx.framebuffer_width * _curctx.framebuffer_height * sizeof(uint32_t));
} else {
_curctx.y++;
}
_curctx.x = 0;
}
else if (str[i] == '\r')
_curctx.x = 0;
else {
_rt_drawchar(str[i], _curctx.x * 8, _curctx.y * 16, 0xFFFFFF, 0x0);
_curctx.x++;
}
}
_rt_draw_fillchar(_curctx.x * 8, _curctx.y * 16, 0x0, 0xFFFFFF);
}

41
deprecated/rt.h Executable file
View file

@ -0,0 +1,41 @@
#pragma once
#include <stdint.h>
typedef struct _rt_ctx {
// A pointer to the framebuffer.
void *framebuffer;
// The framebuffer width, in pixels.
uint32_t framebuffer_width;
// The framebuffer height, in pixels.
uint32_t framebuffer_height;
// Set this to 1 if you prefer using DOS line endings to UNIX line endings.
int use_crlf_ending;
// Do we need to show a cursor after printing text?
int show_cursor;
// The background color
uint32_t bg_color;
// The foreground color
uint32_t fg_color;
/*
* Do NOT modify everything below me!
*/
// The terminal's width, in columns of 8 pixels.
int term_width;
// The terminal's height, in rows of 16 pixels.
int term_height;
// The X position of the cursor, in columns of 8 pixels.
int x;
// The Y position of the cursor, in rows of 16 pixels.
int y;
} rt_context;
void rt_init(rt_context ctx);
void rt_print(char *str);