2023-01-25 23:37:56 -05:00
|
|
|
#include <pty.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.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];
|
2023-02-04 16:02:21 -05:00
|
|
|
int fdm = -1;
|
|
|
|
setenv("TERM", "ansi", 1);
|
|
|
|
pid_t pid = forkpty(&fdm, NULL, NULL, NULL);
|
2023-01-25 23:37:56 -05:00
|
|
|
|
2023-02-04 16:02:21 -05:00
|
|
|
if (pid < 0) {
|
|
|
|
// failure
|
|
|
|
printf("fork failed");
|
|
|
|
return 1;
|
|
|
|
} else if (pid == 0) {
|
2023-01-25 23:37:56 -05:00
|
|
|
// child
|
2023-02-04 16:02:21 -05:00
|
|
|
setsid();
|
2023-01-25 23:37:56 -05:00
|
|
|
execlp("bash", "bash");
|
|
|
|
} else {
|
|
|
|
// parent
|
2023-02-04 16:02:21 -05:00
|
|
|
// rows, cols, xpixels, ypixels (little endian)
|
|
|
|
char argp[] = {23, 0, 80, 0, 8, 0, 12, 0};
|
|
|
|
ioctl(fdm, TIOCSWINSZ, argp);
|
|
|
|
dup2(fdm, 0);
|
|
|
|
dup2(fdm, 1);
|
2023-01-25 23:37:56 -05:00
|
|
|
execlp("uxnemu", "uxnemu", rom);
|
|
|
|
}
|
|
|
|
}
|