This repository has been archived by the owner on May 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added TTY switching using 0-9 on the keyboard
- Loading branch information
1 parent
655f42a
commit be51253
Showing
6 changed files
with
119 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,113 @@ | ||
#include "tty.h" | ||
|
||
tty* ttys[MAX_TTYS]; | ||
tty* ttys[MAX_TTYS] = { NULL }; | ||
|
||
uint8_t cur_tty_id; | ||
tty* cur_tty; | ||
uint8_t cur_tty_id = 0; | ||
tty* cur_tty = NULL; | ||
|
||
VFS_t *vfs_b; | ||
struct limine_framebuffer *framebuffer_b; | ||
VFS_t *vfs_b = NULL; | ||
struct limine_framebuffer *framebuffer_b = NULL; | ||
|
||
void tty_init(VFS_t *vfs, struct limine_framebuffer *framebuffer) { | ||
vfs_b = vfs; | ||
framebuffer_b = framebuffer; | ||
if (vfs != NULL && framebuffer != NULL) { | ||
vfs_b = vfs; | ||
framebuffer_b = framebuffer; | ||
} | ||
} | ||
|
||
|
||
void tty_flush() { | ||
nighterm_flush(cur_tty->context, 0, 0, 0); | ||
nighterm_set_cursor_position(cur_tty->context, 0, 0); | ||
if (cur_tty != NULL && cur_tty->context != NULL) { | ||
nighterm_flush(cur_tty->context, 0, 0, 0); | ||
nighterm_set_cursor_position(cur_tty->context, 0, 0); | ||
} | ||
} | ||
|
||
int tty_spawn(uint8_t id, char* font_path) | ||
{ | ||
if(ttys[id] != NULL) | ||
return 1; | ||
|
||
struct nighterm_ctx *context = malloc(sizeof(struct nighterm_ctx)); | ||
if (context == NULL) | ||
return 4; | ||
|
||
char *font_data; | ||
vfs_op_status status = driver_read(vfs_b, 0x00000000, font_path, &font_data); | ||
|
||
if (status != STATUS_OK) { | ||
free(context); | ||
return 2; | ||
} | ||
|
||
int s = nighterm_initialize(context, | ||
font_data, | ||
framebuffer_b->address, | ||
framebuffer_b->width, | ||
framebuffer_b->height, | ||
framebuffer_b->pitch, | ||
framebuffer_b->bpp, | ||
malloc, free); | ||
|
||
free(font_data); | ||
|
||
if(s != NIGHTERM_SUCCESS) { | ||
free(context); | ||
return 3; | ||
} | ||
|
||
tty* temp = malloc(sizeof(tty)); | ||
if (temp == NULL) { | ||
free(context); | ||
return 4; | ||
} | ||
|
||
temp->id = id; | ||
temp->context = context; | ||
ttys[id] = temp; | ||
tty_switch(id); | ||
return 0; | ||
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) { | ||
return -2; | ||
} | ||
|
||
struct nighterm_ctx *context = malloc(sizeof(struct nighterm_ctx)); | ||
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) { | ||
free(temp); | ||
free(context); | ||
return -3; | ||
} | ||
|
||
int s = nighterm_initialize(context, | ||
font_data, | ||
framebuffer_b->address, | ||
framebuffer_b->width, | ||
framebuffer_b->height, | ||
framebuffer_b->pitch, | ||
framebuffer_b->bpp, | ||
malloc, free); | ||
|
||
free(font_data); | ||
|
||
if (s != NIGHTERM_SUCCESS) { | ||
free(temp); | ||
free(context); | ||
return -4; | ||
} | ||
|
||
temp->id = id; | ||
temp->context = context; | ||
ttys[id] = temp; | ||
tty_switch(id); | ||
|
||
return 0; | ||
} | ||
|
||
int tty_destroy(uint8_t id) { | ||
if(ttys[id] == NULL) | ||
return 1; | ||
if (id >= MAX_TTYS || ttys[id] == NULL) { | ||
return -1; | ||
} | ||
|
||
free(ttys[id]->context); | ||
free(ttys[id]); | ||
ttys[id] = NULL; | ||
free(ttys[id]->context); | ||
free(ttys[id]); | ||
ttys[id] = NULL; | ||
|
||
if (cur_tty_id == id) { | ||
cur_tty_id = 0; | ||
cur_tty = NULL; | ||
} | ||
if (cur_tty_id == id) { | ||
cur_tty_id = 0; | ||
cur_tty = NULL; | ||
} | ||
|
||
return 0; | ||
return 0; | ||
} | ||
|
||
int tty_get_cur() { | ||
return cur_tty_id; | ||
} | ||
|
||
void tty_switch(uint8_t id) { | ||
cur_tty = ttys[id]; | ||
cur_tty_id = id; | ||
tty_flush(); | ||
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) { | ||
struct nighterm_ctx *context = cur_tty->context; | ||
nighterm_write(context, ch); | ||
if (cur_tty != NULL && cur_tty->context != NULL) { | ||
nighterm_write(cur_tty->context, ch); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters