summaryrefslogtreecommitdiff
path: root/userland
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-03-14 13:09:59 +0100
committerAnton Kling <anton@kling.gg>2024-03-14 13:09:59 +0100
commit2e8b474d4219e7faaac3823e73c8d528c2698a37 (patch)
tree7d93b5fd220e8b703ba69f9b55122d15c9d619fb /userland
parent051ac9f1941e8bc6ad87beccb61a2d53111ba8ea (diff)
random changes made
Diffstat (limited to 'userland')
-rw-r--r--userland/libc/include/syscall.h8
-rw-r--r--userland/terminal/term.c130
2 files changed, 128 insertions, 10 deletions
diff --git a/userland/libc/include/syscall.h b/userland/libc/include/syscall.h
index 72f781d..5e0e567 100644
--- a/userland/libc/include/syscall.h
+++ b/userland/libc/include/syscall.h
@@ -53,6 +53,14 @@
#define SYS_INSTALL_IRQ 44
#define SYS_TMP_KERNEL_HANDLE_PACKET 45
+#define SYS_TCP_CONNECT 46
+#define SYS_TCP_WRITE 47
+#define SYS_TCP_READ 48
+
+#define SYS_QUEUE_CREATE 49
+#define SYS_QUEUE_ADD 50
+#define SYS_QUEUE_WAIT 51
+
int syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx,
uint32_t esi, uint32_t edi);
int s_syscall(int sys);
diff --git a/userland/terminal/term.c b/userland/terminal/term.c
index 2bc4a02..62aaa55 100644
--- a/userland/terminal/term.c
+++ b/userland/terminal/term.c
@@ -19,6 +19,8 @@ uint32_t screen_pos_x = 0;
uint32_t screen_pos_y = 0;
int serial_fd;
+int raw_mode = 0;
+
void execsh(void) {
char *argv[] = {NULL};
execv("/sh", argv);
@@ -27,7 +29,7 @@ void execsh(void) {
uint32_t cursor_pos_x = 0;
uint32_t cursor_pos_y = 0;
-void screen_remove_old_cursor() {
+void screen_remove_old_cursor(void) {
GUI_OverwriteFont(global_w, cursor_pos_x, cursor_pos_y, TERM_BACKGROUND);
}
@@ -38,6 +40,11 @@ void screen_update_cursor() {
}
void screen_putchar(uint32_t c) {
+ if (raw_mode) {
+ GUI_DrawFont(global_w, screen_pos_x, screen_pos_y, c);
+ screen_remove_old_cursor();
+ return;
+ }
if (c == '\n') {
screen_pos_x = 0;
screen_pos_y += 8;
@@ -77,9 +84,11 @@ void screen_delete_char(void) {
void screen_print(const unsigned char *s, int l) {
for (; l; l--, s++) {
- if ('\b' == *s) {
- screen_delete_char();
- continue;
+ if (!raw_mode) {
+ if ('\b' == *s) {
+ screen_delete_char();
+ continue;
+ }
}
screen_putchar((uint32_t)*s);
}
@@ -112,6 +121,103 @@ void writetty(const char *b, size_t len) {
}
}
+// VT100 escape codes
+void handle_escape_codes_or_print(char *buffer, int len) {
+ static int inside_escape_code = 0;
+ static int second_stage = 0;
+
+ if (!inside_escape_code) {
+ for (; len > 0; len--, buffer++) {
+ if ('\033' == *buffer) {
+ inside_escape_code = 1;
+ buffer++;
+ len--;
+ break;
+ }
+ screen_print(buffer, 1);
+ }
+ if (0 == len) {
+ return;
+ }
+ }
+ assert(inside_escape_code);
+ if (!second_stage) {
+ if ('[' == *buffer) {
+ second_stage = 1;
+ buffer++;
+ len--;
+ } else {
+ // TODO: Implement the rest.
+ inside_escape_code = 0;
+ buffer++;
+ len--;
+ handle_escape_codes_or_print(buffer, len);
+ }
+ }
+
+ static int in_second_argument = 0;
+ static int first_argument = 0;
+ if (!in_second_argument) {
+ // Parse the first argument(number)
+ for (; len > 0; len--, buffer++) {
+ if (!isdigit(*buffer)) {
+ break;
+ }
+ first_argument *= 10;
+ first_argument += *buffer - '0';
+ }
+ if (0 == len) {
+ return;
+ }
+ }
+ if (';' == *buffer) {
+ in_second_argument = 1;
+ buffer++;
+ len--;
+ }
+ static int second_argument = 0;
+ if (in_second_argument) {
+ for (; len > 0; len--, buffer++) {
+ if (!isdigit(*buffer)) {
+ break;
+ }
+ second_argument *= 10;
+ second_argument += *buffer - '0';
+ }
+ if (0 == len) {
+ return;
+ }
+ }
+
+ if ('H' == *buffer) {
+ assert(in_second_argument);
+ screen_pos_x = first_argument * 8;
+ screen_pos_y = second_argument * 8;
+ screen_remove_old_cursor();
+ buffer++;
+ len--;
+ } else if ('J' == *buffer) {
+ // clearscreen ED2 Clear entire screen ^[[2J
+ if (!in_second_argument && 2 == first_argument) {
+ for (int i = 0; i < 250 * 150 * 4 * 4; i++) {
+ global_w->bitmap_ptr[i] = TERM_BACKGROUND;
+ }
+ buffer++;
+ len--;
+ }
+ } else if ('X' == *buffer) {
+ raw_mode = 1;
+ buffer++;
+ len--;
+ }
+ inside_escape_code = 0;
+ second_stage = 0;
+ in_second_argument = 0;
+ first_argument = 0;
+ second_argument = 0;
+ handle_escape_codes_or_print(buffer, len);
+}
+
void run() {
char buffer[4096];
struct pollfd fds[2];
@@ -126,19 +232,22 @@ void run() {
if (fds[0].revents & POLLIN) {
int rc;
if ((rc = read(cmdfd, buffer, 4096))) {
- screen_print(buffer, rc);
+ handle_escape_codes_or_print(buffer, rc);
GUI_UpdateWindow(global_w);
}
}
if (fds[1].revents & POLLIN) {
WS_EVENT e;
int rc;
- if (0 >= (rc = read(global_w->ws_socket, &e, sizeof(e))))
+ if (0 >= (rc = read(global_w->ws_socket, &e, sizeof(e)))) {
+ continue;
+ }
+ if (1 == e.ev.release) {
continue;
- if (1 == e.ev.release)
- continue;
- if (0 == e.ev.c)
+ }
+ if (0 == e.ev.c) {
continue;
+ }
write(cmdfd, &e.ev.c, 1);
}
}
@@ -150,8 +259,9 @@ int main(void) {
global_w = GUI_CreateWindow(20, 20, 250 * 4, 150 * 4);
assert(global_w);
- for (int i = 0; i < 250 * 150 * 4 * 4; i++)
+ for (int i = 0; i < 250 * 150 * 4 * 4; i++) {
global_w->bitmap_ptr[i] = TERM_BACKGROUND;
+ }
// memset(global_w->bitmap_ptr, 0x0, 50 * 50);
GUI_UpdateWindow(global_w);
newtty();