34 lines
773 B
C
34 lines
773 B
C
#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];
|
|
int fdm = -1;
|
|
setenv("TERM", "ansi", 1);
|
|
pid_t pid = forkpty(&fdm, NULL, NULL, NULL);
|
|
|
|
if (pid < 0) {
|
|
// failure
|
|
printf("fork failed");
|
|
return 1;
|
|
} else if (pid == 0) {
|
|
// child
|
|
setsid();
|
|
execlp("bash", "bash");
|
|
} else {
|
|
// parent
|
|
// 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);
|
|
execlp("uxnemu", "uxnemu", rom);
|
|
}
|
|
}
|