nxu/term.c

30 lines
669 B
C
Raw Normal View History

2023-01-25 23:37:56 -05:00
#include <pty.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
int main(int argc, char **argv) {
if (argc < 2) {
printf("usage: %s ROM\n", argv[0]);
return 1;
}
char *rom = argv[1];
int fd = -1;
pid_t pid = forkpty(&fd, NULL, NULL, NULL);
if (pid == 0) {
// child
setenv("TERM", "ansi", 1);
execlp("bash", "bash");
} else {
// parent
char *argp = {0, 40, 0, 79, 0, 8, 0, 8}; // HHHH: height, width, 8, 8
ioctl(fd, TIOCSWINSZ, argp);
dup2(fd, STDIN);
dup2(dup(fd), STDOUT);
execlp("uxnemu", "uxnemu", rom);
}
}