Files
RockOS/programs/vga_text_term/main.c

69 lines
1.1 KiB
C
Raw Normal View History

#include <unistd.h>
2026-07-12 04:37:46 -05:00
#define VGA_TEXT_W 80
#define VGA_TEXT_H 25
void term();
int ptys;
int ptym;
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
ptym = pty(&ptys);
if (fork() == 0) {
close(ptym);
dup2(ptys, 0);
dup2(0, 1);
dup2(0, 2);
exec("/bin/rocksh.elf");
}
close(ptys);
dup2(ptym, 0);
dup2(0, 1);
dup2(0, 2);
term();
return 0;
}
2026-07-12 04:37:46 -05:00
void clear(int fd) {
lseek(fd, 0, 0);
size_t bytes = VGA_TEXT_W * VGA_TEXT_H;
char c = ' ';
for (size_t i = 0; i < bytes; i++) {
write(fd, &c, 1);
}
lseek(fd, 0, 0);
}
void term() {
int vga_fd = open("/dev/tvga");
if (vga_fd == -1) return;
2026-07-12 04:37:46 -05:00
int kbd_fd = open("/dev/kbd");
if (kbd_fd == -1) return;
clear(vga_fd);
char c;
while (1) {
2026-07-12 04:37:46 -05:00
// first, get shell output
int rd = read(0, &c, 1);
if (rd > 0) {
write(vga_fd, &c, 1);
}
2026-07-12 04:37:46 -05:00
// then read a byte from the kbd. If we got one, pass it to the shell
rd = read(kbd_fd, &c, 1);
if (rd > 0) {
write(1, &c, 1);
}
}
}