Use print() function in both Python 2 and Python 3

__print()__ is a function in Python 3.
This commit is contained in:
cclauss 2018-10-28 22:52:39 +01:00
parent 934bf1a495
commit e5eb3b308c
2 changed files with 31 additions and 29 deletions

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import json
import sys
import urllib
@ -45,7 +46,7 @@ def cmd_disassemble(a):
addr = status["program_counter"]
disasm = get("/disassemble/%d" % addr)
for d in disasm:
print format_disassemble(d)
print(format_disassemble(d))
def cmd_dump(a):
@ -80,7 +81,7 @@ def cmd_dump(a):
s += "."
else:
s += " "
print s
print(s)
addr += 16
@ -89,20 +90,20 @@ def cmd_help(a):
if len(a) > 1:
f = Commands.get(a[1])
if f is not None:
print f.__doc__
print(f.__doc__)
else:
print "Unknown command:", a[1]
print("Unknown command:", a[1])
else:
print "Commands:"
print("Commands:")
for c in sorted(Commands):
print " ", c
print(" ", c)
def cmd_peek(a):
"""Peek memory location"""
addr = value(a[1])
dump = get("/memory/%d" % addr)
print "%04X: %02X" % (addr, dump[0])
print("%04X: %02X" % (addr, dump[0]))
def cmd_poke(a):
@ -115,7 +116,7 @@ def cmd_poke(a):
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" % (
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"],
@ -128,9 +129,9 @@ def cmd_status(a):
"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])
print(format_disassemble(disasm[0]))
def cmd_quit(a):
@ -155,7 +156,7 @@ Commands = {
def main():
print "ApplePy control console"
print("ApplePy control console")
while True:
s = raw_input("6502> ")
a = s.strip().split()
@ -163,7 +164,7 @@ def main():
if f is not None:
f(a)
else:
print "Unknown command:", s
print("Unknown command:", s)
if __name__ == "__main__":
main()

View File

@ -1,3 +1,4 @@
from __future__ import print_function
# ApplePy - an Apple ][ emulator in Python
# James Tauber / http://jtauber.com/
# originally written 2001, updated 2011
@ -718,9 +719,9 @@ class CPU:
op = self.read_pc_byte()
func = self.ops[op]
if func is None:
print "UNKNOWN OP"
print hex(self.program_counter - 1)
print hex(op)
print("UNKNOWN OP")
print(hex(self.program_counter - 1))
print(hex(op))
break
else:
self.ops[op]()
@ -735,9 +736,9 @@ class CPU:
op = self.read_pc_byte()
func = self.ops[op]
if func is None:
print "UNKNOWN OP"
print hex(self.program_counter - 1)
print hex(op)
print("UNKNOWN OP")
print(hex(self.program_counter - 1))
print(hex(op))
break
else:
self.ops[op]()
@ -1171,15 +1172,15 @@ class CPU:
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: cpu6502.py [options]"
print >>sys.stderr
print >>sys.stderr, " -b, --bus Bus port number"
print >>sys.stderr, " -p, --pc Initial PC value"
print >>sys.stderr, " -R, --rom ROM file to use (default A2ROM.BIN)"
print >>sys.stderr, " -r, --ram RAM file to load (default none)"
print("ApplePy - an Apple ][ emulator in Python", file=sys.stderr)
print("James Tauber / http://jtauber.com/", file=sys.stderr)
print(file=sys.stderr)
print("Usage: cpu6502.py [options]", file=sys.stderr)
print(file=sys.stderr)
print(" -b, --bus Bus port number", file=sys.stderr)
print(" -p, --pc Initial PC value", file=sys.stderr)
print(" -R, --rom ROM file to use (default A2ROM.BIN)", file=sys.stderr)
print(" -r, --ram RAM file to load (default none)", file=sys.stderr)
sys.exit(1)
@ -1219,8 +1220,8 @@ def get_options():
if __name__ == "__main__":
options = get_options()
if options.bus is None:
print "ApplePy cpu core"
print "Run applepy.py instead"
print("ApplePy cpu core")
print("Run applepy.py instead")
sys.exit(0)
mem = Memory(options)