Permalink
Browse files

Merge branch 'master' into disk

  • Loading branch information...
jtauber committed Apr 18, 2012
2 parents 9aea463 + bdbc60e commit 81cc4f546b8e9fae8ad62410b9b7753063b9b0ec
Showing with 567 additions and 193 deletions.
  1. +13 −0 applepy.py
  2. +157 −0 control.py
  3. +397 −193 cpu6502.py
View
@@ -109,6 +109,10 @@ def __init__(self):
self.flash_time = time.time()
self.flash_on = False
self.flash_chars = [[0] * 0x400] * 2
+
+ self.page = 1
+ self.text = True
+ self.colour = False
self.chargen = []
for c in self.characters:
@@ -488,6 +492,10 @@ def __init__(self, options, display, speaker, cassette):
args.extend([
"--ram", options.ram,
])
+ if options.pc is not None:
+ args.extend([
+ "--pc", str(options.pc),
+ ])
self.core = subprocess.Popen(args)
rs, _, _ = select.select([listener], [], [], 2)
@@ -544,6 +552,7 @@ def usage():
print >>sys.stderr, " -c, --cassette Cassette wav file to load"
print >>sys.stderr, " -R, --rom ROM file to use (default A2ROM.BIN)"
print >>sys.stderr, " -r, --ram RAM file to load (default none)"
+ print >>sys.stderr, " -p, --pc Initial PC value"
print >>sys.stderr, " -q, --quiet Quiet mode, no sounds (default sounds)"
sys.exit(1)
@@ -554,6 +563,7 @@ def __init__(self):
self.cassette = None
self.rom = "A2ROM.BIN"
self.ram = None
+ self.pc = None
self.quiet = False
options = Options()
@@ -569,6 +579,9 @@ def __init__(self):
elif sys.argv[a] in ("-r", "--ram"):
a += 1
options.ram = sys.argv[a]
+ elif sys.argv[a] in ("-p", "--pc"):
+ a += 1
+ options.pc = int(sys.argv[a])
elif sys.argv[a] in ("-q", "--quiet"):
options.quiet = True
else:
View
@@ -0,0 +1,157 @@
+import json
+import readline
+import sys
+import urllib
+
+URL_PREFIX = "http://localhost:6502"
+
+def get(url):
+ return json.loads(urllib.urlopen(URL_PREFIX + url).read())
+
+def post(url, data=None):
+ return urllib.urlopen(URL_PREFIX + url, json.dumps(data) if data is not None else "")
+
+def value(s):
+ if s.startswith("$"):
+ return int(s[1:], 16)
+ if s.startswith("0x"):
+ return int(s[2:], 16)
+ return int(s)
+
+def format_disassemble(dis):
+ r = "%04X- " % dis["address"]
+ for i in range(3):
+ if i < len(dis["bytes"]):
+ r += "%02X " % dis["bytes"][i]
+ else:
+ r += " "
+ r += " %s" % dis["mnemonic"]
+ if "operand" in dis:
+ r += " %-10s" % dis["operand"]
+ if "memory" in dis:
+ r += "[%04X] = %0*X" % tuple(dis["memory"])
+ return r
+
+def cmd_disassemble(a):
+ """Disassemble"""
+ if len(a) > 1:
+ addr = value(a[1])
+ else:
+ status = get("/status")
+ addr = status["program_counter"]
+ disasm = get("/disassemble/%d" % addr)
+ for d in disasm:
+ print format_disassemble(d)
+
+def cmd_dump(a):
+ """Dump memory"""
+ start = value(a[1])
+ if len(a) > 2:
+ end = value(a[2])
+ else:
+ end = start + 15
+ data = get("/memory/%d-%d" % (start, end))
+ addr = start & ~0xF
+ while addr <= end:
+ s = "%04X-" % addr
+ for i in range(16):
+ if start <= addr + i <= end:
+ s += " %02X" % data[addr + i - start]
+ else:
+ s += " "
+ s += " "
+ for i in range(16):
+ if start <= addr + i <= end:
+ c = data[addr + i - start]
+
+ # adjust for apple character set
+ c &= 0x3f
+ if c < 0x20:
+ c += 0x40
+
+ if 0x20 <= c < 0x7f:
+ s += chr(c)
+ else:
+ s += "."
+ else:
+ s += " "
+ print s
+ addr += 16
+
+def cmd_help(a):
+ """Help commands"""
+ if len(a) > 1:
+ f = Commands.get(a[1])
+ if f is not None:
+ print f.__doc__
+ else:
+ print "Unknown command:", a[1]
+ else:
+ print "Commands:"
+ for c in sorted(Commands):
+ print " ", c
+
+def cmd_peek(a):
+ """Peek memory location"""
+ addr = value(a[1])
+ dump = get("/memory/%d" % addr)
+ print "%04X: %02X" % (addr, dump[0])
+
+def cmd_poke(a):
+ """Poke memory location"""
+ addr = value(a[1])
+ val = value(a[2])
+ post("/memory/%d" % addr, [val])
+
+def cmd_status(a):
+ """CPU status"""
+ status = get("/status")
+ print "A=%02X X=%02X Y=%02X S=%02X PC=%04X F=%c%c0%c%c%c%c%c" % (
+ status["accumulator"],
+ status["x_index"],
+ status["y_index"],
+ status["stack_pointer"],
+ status["program_counter"],
+ "N" if status["sign_flag"] else "n",
+ "V" if status["overflow_flag"] else "v",
+ "B" if status["break_flag"] else "b",
+ "D" if status["decimal_mode_flag"] else "d",
+ "I" if status["interrupt_disable_flag"] else "i",
+ "Z" if status["zero_flag"] else "z",
+ "C" if status["carry_flag"] else "c",
+ )
+ disasm = get("/disassemble/%d" % status["program_counter"])
+ print format_disassemble(disasm[0])
+
+def cmd_quit(a):
+ """Quit"""
+ sys.exit(0)
+
+def cmd_reset(a):
+ """Reset"""
+ post("/reset")
+
+Commands = {
+ "disassemble": cmd_disassemble,
+ "dump": cmd_dump,
+ "help": cmd_help,
+ "peek": cmd_peek,
+ "poke": cmd_poke,
+ "status": cmd_status,
+ "quit": cmd_quit,
+ "reset": cmd_reset,
+}
+
+def main():
+ print "ApplePy control console"
+ while True:
+ s = raw_input("6502> ")
+ a = s.strip().split()
+ f = Commands.get(a[0])
+ if f is not None:
+ f(a)
+ else:
+ print "Unknown command:", s
+
+if __name__ == "__main__":
+ main()
Oops, something went wrong.

0 comments on commit 81cc4f5

Please sign in to comment.