mirror of
https://github.com/jtauber/applepy.git
synced 2025-01-14 01:29:48 +00:00
update curses UI for socket comms
This commit is contained in:
parent
cd692af6f3
commit
dcc8e9d8ce
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import curses
|
import curses
|
||||||
|
import socket
|
||||||
import struct
|
import struct
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@ -55,20 +56,29 @@ def write(win, addr, val):
|
|||||||
|
|
||||||
def run(win):
|
def run(win):
|
||||||
global kbd
|
global kbd
|
||||||
p = subprocess.Popen(
|
|
||||||
args=[sys.executable, "cpu6502.py"],
|
listener = socket.socket()
|
||||||
stdin=subprocess.PIPE,
|
listener.bind(("127.0.0.1", 0))
|
||||||
stdout=subprocess.PIPE,
|
listener.listen(0)
|
||||||
)
|
|
||||||
|
args = [
|
||||||
|
sys.executable,
|
||||||
|
"cpu6502.py",
|
||||||
|
"--ui", str(listener.getsockname()[1]),
|
||||||
|
"--rom", options.rom,
|
||||||
|
]
|
||||||
|
|
||||||
|
p = subprocess.Popen(args)
|
||||||
|
cpu, _ = listener.accept()
|
||||||
|
|
||||||
win.clear()
|
win.clear()
|
||||||
curses.noecho()
|
curses.noecho()
|
||||||
win.nodelay(True)
|
win.nodelay(True)
|
||||||
while True:
|
while True:
|
||||||
op = p.stdout.read(8)
|
op = cpu.recv(8)
|
||||||
cycle, rw, addr, val = struct.unpack("<IBHB", op)
|
cycle, rw, addr, val = struct.unpack("<IBHB", op)
|
||||||
if rw == 0:
|
if rw == 0:
|
||||||
p.stdin.write(chr(read(addr, val)))
|
cpu.send(chr(read(addr, val)))
|
||||||
p.stdin.flush()
|
|
||||||
elif rw == 1:
|
elif rw == 1:
|
||||||
write(win, addr, val)
|
write(win, addr, val)
|
||||||
else:
|
else:
|
||||||
@ -85,7 +95,39 @@ def run(win):
|
|||||||
pass
|
pass
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def usage():
|
||||||
|
print >>sys.stderr, "ApplePy - an Apple ][ emulator in Python"
|
||||||
|
print >>sys.stderr, "James Tauber / http://jtauber.com/"
|
||||||
|
print >>sys.stderr
|
||||||
|
print >>sys.stderr, "Usage: applepy_curses.py [options]"
|
||||||
|
print >>sys.stderr
|
||||||
|
print >>sys.stderr, " -R, --rom ROM file to use (default A2ROM.BIN)"
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def get_options():
|
||||||
|
class Options:
|
||||||
|
def __init__(self):
|
||||||
|
self.rom = "A2ROM.BIN"
|
||||||
|
|
||||||
|
options = Options()
|
||||||
|
a = 1
|
||||||
|
while a < len(sys.argv):
|
||||||
|
if sys.argv[a].startswith("-"):
|
||||||
|
if sys.argv[a] in ("-R", "--rom"):
|
||||||
|
a += 1
|
||||||
|
options.rom = sys.argv[a]
|
||||||
|
else:
|
||||||
|
usage()
|
||||||
|
else:
|
||||||
|
usage()
|
||||||
|
a += 1
|
||||||
|
|
||||||
|
return options
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
options = get_options()
|
||||||
curses.wrapper(run)
|
curses.wrapper(run)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user