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

View File

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