nxu/term.py

50 lines
1.1 KiB
Python
Executable File

#/usr/bin/env python
import fcntl
import os
import pty
import sys
import struct
import termios
def main():
# check usage
args = sys.argv[1:]
if len(args) < 1:
print('usage: %s ROM')
print('')
print(' ROM: the rom file to launch')
sys.exit(1)
# path to rom to run
rom = args[0]
# fork with a new pty
pid, fd = pty.fork()
if pid == 0:
# set TERM to something we can handle
env = dict(os.environ)
env['TERM'] = 'dumb'
os.execvpe('bash', ['bash', '--noediting', '-i'], env)
else:
# set the terminal size
#cols, rows = 63, 32
cols, rows = 79, 40
size = struct.pack("HHHH", rows, cols, 8, 8)
fcntl.ioctl(fd, termios.TIOCSWINSZ, size)
## disable terminal echo
#attr = termios.tcgetattr(fd)
#attr[3] = attr[3] & ~termios.ECHO
#termios.tcsetattr(fd, termios.TCSADRAIN, attr)
# use fd for the terminals stdin/stdout
os.dup2(fd, sys.stdin.fileno())
os.dup2(os.dup(fd), sys.stdout.fileno())
os.execvp('uxnemu', ['uxnemu', rom])
if __name__ == "__main__":
main()