mirror of
https://github.com/jtauber/applepy.git
synced 2024-11-29 20:49:21 +00:00
refactor control command processing
This commit is contained in:
parent
19693bc905
commit
8b62860152
56
cpu6502.py
56
cpu6502.py
@ -335,30 +335,20 @@ class ControlHandler:
|
|||||||
self.sock.send("ApplePy 6502 core\n")
|
self.sock.send("ApplePy 6502 core\n")
|
||||||
self.buffer = ""
|
self.buffer = ""
|
||||||
|
|
||||||
def handle_read(self):
|
def cmd_help(self, args):
|
||||||
buf = self.sock.recv(1024)
|
self.sock.send("commands: %s\n" % ", ".join(sorted(x[4:] for x in dir(self) if x.startswith("cmd_"))))
|
||||||
if not buf:
|
|
||||||
self.cpu.control.remove(self)
|
def cmd_peek(self, args):
|
||||||
return
|
addr = int(args[1])
|
||||||
self.buffer += buf
|
|
||||||
while True:
|
|
||||||
i = self.buffer.find("\n")
|
|
||||||
if i < 0:
|
|
||||||
break
|
|
||||||
s = self.buffer[:i].strip()
|
|
||||||
self.buffer = self.buffer[i+1:]
|
|
||||||
a = s.split()
|
|
||||||
if a[0] == "help":
|
|
||||||
self.sock.send("commands: help, peek, poke, status, quit, reset\n")
|
|
||||||
elif a[0] == "peek":
|
|
||||||
addr = int(a[1])
|
|
||||||
self.sock.send("%02X\n" % self.cpu.memory.read_byte(self.cpu.cycles, addr))
|
self.sock.send("%02X\n" % self.cpu.memory.read_byte(self.cpu.cycles, addr))
|
||||||
elif a[0] == "poke":
|
|
||||||
addr = int(a[1])
|
def cmd_poke(self, args):
|
||||||
val = int(a[2])
|
addr = int(args[1])
|
||||||
|
val = int(args[2])
|
||||||
self.cpu.memory.write_byte(self.cpu.cycles, addr, val)
|
self.cpu.memory.write_byte(self.cpu.cycles, addr, val)
|
||||||
self.sock.send("poked\n")
|
self.sock.send("poked\n")
|
||||||
elif a[0] == "status":
|
|
||||||
|
def cmd_status(self, args):
|
||||||
self.sock.send("A=%02X X=%02X Y=%02X S=%02X PC=%04X F=%c%c0%c%c%c%c%c\n" % (
|
self.sock.send("A=%02X X=%02X Y=%02X S=%02X PC=%04X F=%c%c0%c%c%c%c%c\n" % (
|
||||||
self.cpu.accumulator,
|
self.cpu.accumulator,
|
||||||
self.cpu.x_index,
|
self.cpu.x_index,
|
||||||
@ -373,14 +363,32 @@ class ControlHandler:
|
|||||||
"Z" if self.cpu.zero_flag else "z",
|
"Z" if self.cpu.zero_flag else "z",
|
||||||
"C" if self.cpu.carry_flag else "c",
|
"C" if self.cpu.carry_flag else "c",
|
||||||
))
|
))
|
||||||
elif a[0] == "quit":
|
|
||||||
|
def cmd_quit(self, args):
|
||||||
self.cpu.quit = True
|
self.cpu.quit = True
|
||||||
self.sock.send("quitting\n")
|
self.sock.send("quitting\n")
|
||||||
elif a[0] == "reset":
|
|
||||||
|
def cmd_reset(self, args):
|
||||||
self.cpu.reset()
|
self.cpu.reset()
|
||||||
self.cpu.running = True
|
self.cpu.running = True
|
||||||
self.sock.send("resetting\n")
|
self.sock.send("resetting\n")
|
||||||
else:
|
|
||||||
|
def handle_read(self):
|
||||||
|
buf = self.sock.recv(1024)
|
||||||
|
if not buf:
|
||||||
|
self.cpu.control.remove(self)
|
||||||
|
return
|
||||||
|
self.buffer += buf
|
||||||
|
while True:
|
||||||
|
i = self.buffer.find("\n")
|
||||||
|
if i < 0:
|
||||||
|
break
|
||||||
|
s = self.buffer[:i].strip()
|
||||||
|
self.buffer = self.buffer[i+1:]
|
||||||
|
a = s.split()
|
||||||
|
try:
|
||||||
|
getattr(self, "cmd_" + a[0])(a)
|
||||||
|
except AttributeError:
|
||||||
self.sock.send("unknown command\n")
|
self.sock.send("unknown command\n")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user