2023-01-21 22:54:20 -05:00
|
|
|
#/usr/bin/env python
|
2023-01-21 15:41:27 -05:00
|
|
|
|
2023-01-21 22:54:20 -05:00
|
|
|
import fcntl
|
|
|
|
import os
|
|
|
|
import pty
|
2023-01-21 15:41:27 -05:00
|
|
|
import sys
|
2023-01-21 22:54:20 -05:00
|
|
|
import struct
|
|
|
|
import termios
|
2023-01-21 15:41:27 -05:00
|
|
|
|
|
|
|
def main():
|
2023-01-21 22:54:20 -05:00
|
|
|
|
|
|
|
# check usage
|
2023-01-21 15:41:27 -05:00
|
|
|
args = sys.argv[1:]
|
2023-01-21 22:54:20 -05:00
|
|
|
if len(args) < 1:
|
|
|
|
print('usage: %s ROM')
|
2023-01-21 15:58:02 -05:00
|
|
|
print('')
|
2023-01-21 22:54:20 -05:00
|
|
|
print(' ROM: the rom file to launch')
|
2023-01-21 15:41:27 -05:00
|
|
|
sys.exit(1)
|
|
|
|
|
2023-01-21 22:54:20 -05:00
|
|
|
# path to rom to run
|
|
|
|
rom = args[0]
|
2023-01-21 15:41:27 -05:00
|
|
|
|
2023-01-21 22:54:20 -05:00
|
|
|
# fork with a new pty
|
|
|
|
pid, fd = pty.fork()
|
2023-01-21 15:58:02 -05:00
|
|
|
|
2023-01-21 22:54:20 -05:00
|
|
|
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)
|
|
|
|
|
2023-01-23 12:25:59 -05:00
|
|
|
## disable terminal echo
|
|
|
|
#attr = termios.tcgetattr(fd)
|
|
|
|
#attr[3] = attr[3] & ~termios.ECHO
|
|
|
|
#termios.tcsetattr(fd, termios.TCSADRAIN, attr)
|
2023-01-21 15:41:27 -05:00
|
|
|
|
2023-01-21 22:54:20 -05:00
|
|
|
# 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])
|
|
|
|
|
2023-01-21 15:41:27 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|