term stuff

This commit is contained in:
~d6 2023-02-04 16:02:21 -05:00
parent 3d81b6eeca
commit b0e380caaa
2 changed files with 15 additions and 11 deletions

24
term.c
View File

@ -1,7 +1,6 @@
#include <pty.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
int main(int argc, char **argv) {
@ -10,20 +9,25 @@ int main(int argc, char **argv) {
return 1;
}
char *rom = argv[1];
int fd = -1;
int fdm = -1;
setenv("TERM", "ansi", 1);
pid_t pid = forkpty(&fdm, NULL, NULL, NULL);
pid_t pid = forkpty(&fd, NULL, NULL, NULL);
if (pid == 0) {
if (pid < 0) {
// failure
printf("fork failed");
return 1;
} else if (pid == 0) {
// child
setenv("TERM", "ansi", 1);
setsid();
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);
// 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);
}
}

View File

@ -32,7 +32,7 @@ def main():
# set the terminal size
###cols, rows = 79, 40
cols, rows = 80, 24
size = struct.pack("HHHH", rows, cols, 8, 8)
size = struct.pack("HHHH", rows, cols, 8, 12)
fcntl.ioctl(fd, termios.TIOCSWINSZ, size)
# use fd for the terminals stdin/stdout