Skip to content
This repository has been archived by the owner on May 12, 2024. It is now read-only.

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinAlavik committed Apr 2, 2024
1 parent 58fda90 commit f94631f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
1 change: 0 additions & 1 deletion initrd/usr/share/paradox/bible_votd

This file was deleted.

2 changes: 1 addition & 1 deletion kernel/entry/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void init()
tty_init(vfs, framebuffer);

keyboard.out = false;
tty_spawn(0, FONT_SMALL);
tty_spawn(0, FONT_BIG);
register_pci();

int kstatus = kmain(); // Launch the kernel
Expand Down
67 changes: 43 additions & 24 deletions kernel/tty/tty.c
Original file line number Diff line number Diff line change
@@ -1,49 +1,60 @@
#include "tty.h"

tty* ttys[MAX_TTYS] = { NULL };
tty *ttys[MAX_TTYS] = {NULL};

uint8_t cur_tty_id = 0;
tty* cur_tty = NULL;
tty *cur_tty = NULL;

VFS_t *vfs_b = NULL;
struct limine_framebuffer *framebuffer_b = NULL;

void tty_init(VFS_t *vfs, struct limine_framebuffer *framebuffer) {
if (vfs != NULL && framebuffer != NULL) {
void tty_init(VFS_t *vfs, struct limine_framebuffer *framebuffer)
{
if (vfs != NULL && framebuffer != NULL)
{
vfs_b = vfs;
framebuffer_b = framebuffer;
}
}

void tty_flush() {
if (cur_tty != NULL && cur_tty->context != NULL) {
nighterm_flush(cur_tty->context, 0, 0, 0);
void tty_flush()
{
if (cur_tty != NULL && cur_tty->context != NULL)
{
nighterm_flush(cur_tty->context, 22, 22, 22);
nighterm_set_cursor_position(cur_tty->context, 0, 0);
nighterm_set_bg_color(cur_tty->context, 22, 22, 22);
}
}

int tty_spawn(uint8_t id, char* font_path) {
if (id >= MAX_TTYS || ttys[id] != NULL) {
if (ttys[id] != NULL) {
int tty_spawn(uint8_t id, char *font_path)
{
if (id >= MAX_TTYS || ttys[id] != NULL)
{
if (ttys[id] != NULL)
{
tty_switch(id);
}
return 0;
}

tty* temp = malloc(sizeof(tty));
if (temp == NULL) {
tty *temp = malloc(sizeof(tty));
if (temp == NULL)
{
return -2;
}

struct nighterm_ctx *context = malloc(sizeof(struct nighterm_ctx));
if (context == NULL) {
if (context == NULL)
{
free(temp);
return -2;
}

char *font_data;
vfs_op_status status = driver_read(vfs_b, 0x00000000, font_path, &font_data);
if (status != STATUS_OK) {
if (status != STATUS_OK)
{
free(temp);
free(context);
return -3;
Expand All @@ -60,7 +71,8 @@ int tty_spawn(uint8_t id, char* font_path) {

free(font_data);

if (s != NIGHTERM_SUCCESS) {
if (s != NIGHTERM_SUCCESS)
{
free(temp);
free(context);
return -4;
Expand All @@ -74,40 +86,47 @@ int tty_spawn(uint8_t id, char* font_path) {
return 0;
}

int tty_destroy(uint8_t id) {
if (id >= MAX_TTYS || ttys[id] == NULL) {
int tty_destroy(uint8_t id)
{
if (id >= MAX_TTYS || ttys[id] == NULL)
{
return -1;
}

free(ttys[id]->context);
free(ttys[id]);
ttys[id] = NULL;

if (cur_tty_id == id) {
if (cur_tty_id == id)
{
cur_tty_id = 0;
cur_tty = NULL;
}

return 0;
}

int tty_get_cur() {
int tty_get_cur()
{
return cur_tty_id;
}

void tty_switch(uint8_t id) {
if (id >= MAX_TTYS || ttys[id] == NULL) {
void tty_switch(uint8_t id)
{
if (id >= MAX_TTYS || ttys[id] == NULL)
{
return;
}

cur_tty = ttys[id];
cur_tty_id = id;
tty_flush();
printf("Paradox 1.4.1-dev (tty%d)\n\n", cur_tty_id);
}

void tty_write(char ch) {
if (cur_tty != NULL && cur_tty->context != NULL) {
void tty_write(char ch)
{
if (cur_tty != NULL && cur_tty->context != NULL)
{
nighterm_write(cur_tty->context, ch);
}
}

0 comments on commit f94631f

Please sign in to comment.