diff options
author | 2015-07-30 11:44:44 +0200 | |
---|---|---|
committer | 2015-07-30 11:44:43 +0200 | |
commit | 4b1e08c1bb282af1f3b09d992bf006a58908eee6 (patch) | |
tree | 4e38421b8aa166abc1d2f674743af7874ff238b7 | |
parent | 93bd0f0daf4bce350dc66071799edb38812a8d2f (diff) |
python: Make all scripts python 2/3 compatible
-rw-r--r-- | src/build/makelist.py | 2 | ||||
-rw-r--r-- | src/build/png.py | 27 | ||||
-rw-r--r-- | src/build/png2bdc.py | 48 | ||||
-rw-r--r-- | src/emu/cpu/arcompact/arcompact_make.py | 513 | ||||
-rw-r--r-- | src/emu/cpu/h8/h8make.py | 118 | ||||
-rwxr-xr-x | src/emu/cpu/m6502/m6502make.py | 6 | ||||
-rw-r--r-- | src/emu/cpu/mcs96/mcs96make.py | 40 |
7 files changed, 384 insertions, 370 deletions
diff --git a/src/build/makelist.py b/src/build/makelist.py index 1f94814bf88..144dc636c8d 100644 --- a/src/build/makelist.py +++ b/src/build/makelist.py @@ -11,7 +11,7 @@ drivlist = [] def parse_file(srcfile): try: - fp = open(srcfile, 'rb') + fp = open(srcfile, 'rt') except IOError: sys.stderr.write("Unable to open source file '%s'\n" % srcfile) return 1 diff --git a/src/build/png.py b/src/build/png.py index f096a1dbdf5..8d504ec8ea0 100644 --- a/src/build/png.py +++ b/src/build/png.py @@ -143,15 +143,16 @@ And now, my famous members """ # http://www.python.org/doc/2.2.3/whatsnew/node5.html -from __future__ import generators +from __future__ import generators,print_function __version__ = "0.0.17" from array import array -try: # See :pyver:old - import itertools +try: + from itertools import imap except ImportError: - pass + imap = map +from itertools import starmap import math # http://www.python.org/doc/2.4.4/lib/module-operator.html import operator @@ -1650,11 +1651,10 @@ class Reader: spb = 8//self.bitdepth out = array('B') mask = 2**self.bitdepth - 1 - shifts = map(self.bitdepth.__mul__, reversed(range(spb))) + shifts = list(map(self.bitdepth.__mul__, reversed(range(spb)))) for o in raw: - out.extend(map(lambda i: mask&(o>>i), shifts)) + out.extend(list(map(lambda i: mask&(o>>i), shifts))) return out[:width] - return itertools.imap(asvalues, rows) def serialtoflat(self, bytes, width=None): @@ -1915,8 +1915,8 @@ class Reader: while True: try: type, data = self.chunk(lenient=lenient) - except ValueError, e: - raise ChunkError(e.args[0]) + except ValueError: + raise ChunkError(sys.exc_info()[1].args[0]) if type == 'IEND': # http://www.w3.org/TR/PNG/#11IEND break @@ -1947,7 +1947,6 @@ class Reader: self.preamble(lenient=lenient) raw = iterdecomp(iteridat()) - if self.interlace: raw = array('B', itertools.chain(*raw)) arraycode = 'BH'[self.bitdepth>8] @@ -2062,10 +2061,10 @@ class Reader: meta['alpha'] = bool(self.trns) meta['bitdepth'] = 8 meta['planes'] = 3 + bool(self.trns) - plte = self.palette() + plte = list(self.palette()) def iterpal(pixels): for row in pixels: - row = map(plte.__getitem__, row) + row = list(map(plte.__getitem__, row)) yield array('B', itertools.chain(*row)) pixels = iterpal(pixels) elif self.trns: @@ -2779,5 +2778,5 @@ def _main(argv): if __name__ == '__main__': try: _main(sys.argv) - except Error, e: - print >>sys.stderr, e + except Error: + print (sys.exc_info()[1], file=e) diff --git a/src/build/png2bdc.py b/src/build/png2bdc.py index 58a5983ce97..4ffeb4c01ab 100644 --- a/src/build/png2bdc.py +++ b/src/build/png2bdc.py @@ -59,6 +59,13 @@ import os import png import sys +if sys.version_info >= (3,): + def b2p(v): + return bytes([v]) +else: + def b2p(v): + return chr(v) + ######################################## ## Helper classes @@ -117,27 +124,27 @@ def renderFontSaveCached(font, filename, hash32): CACHED_HEADER_SIZE = 16 try: - fp.write('f') - fp.write('o') - fp.write('n') - fp.write('t') - fp.write(chr(hash32 >> 24 & 0xff)) - fp.write(chr(hash32 >> 16 & 0xff)) - fp.write(chr(hash32 >> 8 & 0xff)) - fp.write(chr(hash32 >> 0 & 0xff)) - fp.write(chr(font.height >> 8 & 0xff)) - fp.write(chr(font.height >> 0 & 0xff)) - fp.write(chr(font.yOffs >> 8 & 0xff)) - fp.write(chr(font.yOffs >> 0 & 0xff)) - fp.write(chr(numChars >> 24 & 0xff)) - fp.write(chr(numChars >> 16 & 0xff)) - fp.write(chr(numChars >> 8 & 0xff)) - fp.write(chr(numChars >> 0 & 0xff)) + fp.write(b'f') + fp.write(b'o') + fp.write(b'n') + fp.write(b't') + fp.write(b2p(hash32 >> 24 & 0xff)) + fp.write(b2p(hash32 >> 16 & 0xff)) + fp.write(b2p(hash32 >> 8 & 0xff)) + fp.write(b2p(hash32 >> 0 & 0xff)) + fp.write(b2p(font.height >> 8 & 0xff)) + fp.write(b2p(font.height >> 0 & 0xff)) + fp.write(b2p(font.yOffs >> 8 & 0xff)) + fp.write(b2p(font.yOffs >> 0 & 0xff)) + fp.write(b2p(numChars >> 24 & 0xff)) + fp.write(b2p(numChars >> 16 & 0xff)) + fp.write(b2p(numChars >> 8 & 0xff)) + fp.write(b2p(numChars >> 0 & 0xff)) # Write a blank table at first (?) charTable = [0]*(numChars * CACHED_CHAR_SIZE) for i in range(numChars * CACHED_CHAR_SIZE): - fp.write(chr(charTable[i])) + fp.write(b2p(charTable[i])) # Loop over all characters tableIndex = 0 @@ -173,7 +180,7 @@ def renderFontSaveCached(font, filename, hash32): # Write the data for j in range(len(dBuffer)): - fp.write(chr(dBuffer[j])) + fp.write(b2p(dBuffer[j])) destIndex = tableIndex * CACHED_CHAR_SIZE charTable[destIndex + 0] = i >> 8 & 0xff @@ -193,12 +200,13 @@ def renderFontSaveCached(font, filename, hash32): # Seek back to the beginning and rewrite the table fp.seek(CACHED_HEADER_SIZE, 0) for i in range(numChars * CACHED_CHAR_SIZE): - fp.write(chr(charTable[i])) + fp.write(b2p(charTable[i])) fp.close() return 0 except: + print(sys.exc_info[1]) return 1 @@ -347,7 +355,7 @@ def main(): except: sys.stderr.write("Error reading PNG file.\n") return 1 - + error = bitmapToChars(pngObject, font) if error: return 1 diff --git a/src/emu/cpu/arcompact/arcompact_make.py b/src/emu/cpu/arcompact/arcompact_make.py index dba815b9f70..080fd72b426 100644 --- a/src/emu/cpu/arcompact/arcompact_make.py +++ b/src/emu/cpu/arcompact/arcompact_make.py @@ -1,351 +1,352 @@ #!/usr/bin/python +from __future__ import print_function import sys def EmitGroup04_Handle_NZ_Flags(f, funcname, opname): - print >>f, " if (result & 0x80000000) { STATUS32_SET_N; }" - print >>f, " else { STATUS32_CLEAR_N; }" - print >>f, " if (result == 0x00000000) { STATUS32_SET_Z; }" - print >>f, " else { STATUS32_CLEAR_Z; }" + print(" if (result & 0x80000000) { STATUS32_SET_N; }", file=f) + print(" else { STATUS32_CLEAR_N; }", file=f) + print(" if (result == 0x00000000) { STATUS32_SET_Z; }", file=f) + print(" else { STATUS32_CLEAR_Z; }", file=f) def EmitGroup04_Handle_NZC_LSR1_Flags(f, funcname, opname): - print >>f, " if (result & 0x80000000) { STATUS32_SET_N; }" - print >>f, " else { STATUS32_CLEAR_N; }" - print >>f, " if (result == 0x00000000) { STATUS32_SET_Z; }" - print >>f, " else { STATUS32_CLEAR_Z; }" - print >>f, " if (c == 0x00000001) { STATUS32_SET_C; }" - print >>f, " else { STATUS32_CLEAR_C; }" + print(" if (result & 0x80000000) { STATUS32_SET_N; }", file=f) + print(" else { STATUS32_CLEAR_N; }", file=f) + print(" if (result == 0x00000000) { STATUS32_SET_Z; }", file=f) + print(" else { STATUS32_CLEAR_Z; }", file=f) + print(" if (c == 0x00000001) { STATUS32_SET_C; }", file=f) + print(" else { STATUS32_CLEAR_C; }", file=f) def EmitGroup04_Handle_NZCV_ADD_Flags(f, funcname, opname): - print >>f, " if (result & 0x80000000) { STATUS32_SET_N; }" - print >>f, " else { STATUS32_CLEAR_N; }" - print >>f, " if (result == 0x00000000) { STATUS32_SET_Z; }" - print >>f, " else { STATUS32_CLEAR_Z; }" - print >>f, " if ((b & 0x80000000) == (c & 0x80000000))" - print >>f, " {" - print >>f, " if ((result & 0x80000000) != (b & 0x80000000))" - print >>f, " {" - print >>f, " STATUS32_SET_V;" - print >>f, " }" - print >>f, " else" - print >>f, " {" - print >>f, " STATUS32_CLEAR_V;" - print >>f, " }" - print >>f, " }" - print >>f, " if (b < c)" - print >>f, " {" - print >>f, " STATUS32_SET_C;" - print >>f, " }" - print >>f, " else" - print >>f, " {" - print >>f, " STATUS32_CLEAR_C;" - print >>f, " }" + print(" if (result & 0x80000000) { STATUS32_SET_N; }", file=f) + print(" else { STATUS32_CLEAR_N; }", file=f) + print(" if (result == 0x00000000) { STATUS32_SET_Z; }", file=f) + print(" else { STATUS32_CLEAR_Z; }", file=f) + print(" if ((b & 0x80000000) == (c & 0x80000000))", file=f) + print(" {", file=f) + print(" if ((result & 0x80000000) != (b & 0x80000000))", file=f) + print(" {", file=f) + print(" STATUS32_SET_V;", file=f) + print(" }", file=f) + print(" else", file=f) + print(" {", file=f) + print(" STATUS32_CLEAR_V;", file=f) + print(" }", file=f) + print(" }", file=f) + print(" if (b < c)", file=f) + print(" {", file=f) + print(" STATUS32_SET_C;", file=f) + print(" }", file=f) + print(" else", file=f) + print(" {", file=f) + print(" STATUS32_CLEAR_C;", file=f) + print(" }", file=f) def EmitGroup04_no_Flags(f, funcname, opname): - print >>f, " // no flag changes" + print(" // no flag changes", file=f) def EmitGroup04_unsupported_Flags(f, funcname, opname): - print >>f, " arcompact_fatal(\"arcompact_handle%s (%s) (F set)\\n\"); // not yet supported" % (funcname, opname) + print(" arcompact_fatal(\"arcompact_handle%s (%s) (F set)\\n\"); // not yet supported" % (funcname, opname), file=f) def EmitGroup04_Flaghandler(f,funcname, opname, flagcondition, flaghandler): if flagcondition == -1: - print >>f, " if (F)" - print >>f, " {" + print(" if (F)", file=f) + print(" {", file=f) flaghandler(f, funcname, opname) - print >>f, " }" + print(" }", file=f) elif flagcondition == 0: - print >>f, " if (0)" - print >>f, " {" + print(" if (0)", file=f) + print(" {", file=f) flaghandler(f, funcname, opname) - print >>f, " }" + print(" }", file=f) elif flagcondition == 1: - print >>f, " if (1)" - print >>f, " {" + print(" if (1)", file=f) + print(" {", file=f) flaghandler(f, funcname, opname) - print >>f, " }" + print(" }", file=f) def EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler): - print >>f, " int size = 4;" + print(" int size = 4;", file=f) if breg_is_dst_only == 0: - print >>f, " UINT32 limm = 0;" + print(" UINT32 limm = 0;", file=f) - print >>f, "/* int got_limm = 0; */" - print >>f, " " - print >>f, " COMMON32_GET_breg;" + print("/* int got_limm = 0; */", file=f) + print(" ", file=f) + print(" COMMON32_GET_breg;", file=f) if flagcondition == -1: - print >>f, " COMMON32_GET_F;" + print(" COMMON32_GET_F;", file=f) - print >>f, " COMMON32_GET_u6;" + print(" COMMON32_GET_u6;", file=f) if ignore_a == 0: - print >>f, " COMMON32_GET_areg;" + print(" COMMON32_GET_areg;", file=f) elif ignore_a == 1: - print >>f, " //COMMON32_GET_areg; // areg is reserved / not used" + print(" //COMMON32_GET_areg; // areg is reserved / not used", file=f) elif ignore_a == 2: - print >>f, " //COMMON32_GET_areg; // areg bits already used as opcode select" + print(" //COMMON32_GET_areg; // areg bits already used as opcode select", file=f) elif ignore_a == 3: - print >>f, " //COMMON32_GET_areg; // areg bits already used as condition code select" - print >>f, " " + print(" //COMMON32_GET_areg; // areg bits already used as condition code select", file=f) + print(" ", file=f) - print >>f, " UINT32 c;" + print(" UINT32 c;", file=f) if breg_is_dst_only == 0: - print >>f, " UINT32 b;" - print >>f, " " - print >>f, " /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */" - print >>f, " if (breg == LIMM_REG)" - print >>f, " {" - print >>f, " GET_LIMM_32;" - print >>f, " size = 8;" - print >>f, "/* got_limm = 1; */" - print >>f, " b = limm;" - print >>f, " }" - print >>f, " else" - print >>f, " {" - print >>f, " b = m_regs[breg];" - print >>f, " }" + print(" UINT32 b;", file=f) + print(" ", file=f) + print(" /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */", file=f) + print(" if (breg == LIMM_REG)", file=f) + print(" {", file=f) + print(" GET_LIMM_32;", file=f) + print(" size = 8;", file=f) + print("/* got_limm = 1; */", file=f) + print(" b = limm;", file=f) + print(" }", file=f) + print(" else", file=f) + print(" {", file=f) + print(" b = m_regs[breg];", file=f) + print(" }", file=f) - print >>f, " " - print >>f, " c = u;" - print >>f, " " - print >>f, " /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */" + print(" ", file=f) + print(" c = u;", file=f) + print(" ", file=f) + print(" /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */", file=f) def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler): # the mode 0x00 handler - print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p00(OPS_32)" % funcname - print >>f, "{" - print >>f, " int size = 4;" + print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p00(OPS_32)" % funcname, file=f) + print("{", file=f) + print(" int size = 4;", file=f) - print >>f, " UINT32 limm = 0;" + print(" UINT32 limm = 0;", file=f) - print >>f, " int got_limm = 0;" - print >>f, " " - print >>f, " COMMON32_GET_breg;" + print(" int got_limm = 0;", file=f) + print(" ", file=f) + print(" COMMON32_GET_breg;", file=f) if flagcondition == -1: - print >>f, " COMMON32_GET_F;" + print(" COMMON32_GET_F;", file=f) - print >>f, " COMMON32_GET_creg;" + print(" COMMON32_GET_creg;", file=f) if ignore_a == 0: - print >>f, " COMMON32_GET_areg;" + print(" COMMON32_GET_areg;", file=f) elif ignore_a == 1: - print >>f, " //COMMON32_GET_areg; // areg is reserved / not used" + print(" //COMMON32_GET_areg; // areg is reserved / not used", file=f) elif ignore_a == 2: - print >>f, " //COMMON32_GET_areg; // areg bits already used as opcode select" + print(" //COMMON32_GET_areg; // areg bits already used as opcode select", file=f) - print >>f, " " + print(" ", file=f) - print >>f, " UINT32 c;" + print(" UINT32 c;", file=f) if breg_is_dst_only == 0: - print >>f, " UINT32 b;" - print >>f, " " - print >>f, " if (breg == LIMM_REG)" - print >>f, " {" - print >>f, " GET_LIMM_32;" - print >>f, " size = 8;" - print >>f, " got_limm = 1;" - print >>f, " b = limm;" - print >>f, " }" - print >>f, " else" - print >>f, " {" - print >>f, " b = m_regs[breg];" - print >>f, " }" + print(" UINT32 b;", file=f) + print(" ", file=f) + print(" if (breg == LIMM_REG)", file=f) + print(" {", file=f) + print(" GET_LIMM_32;", file=f) + print(" size = 8;", file=f) + print(" got_limm = 1;", file=f) + print(" b = limm;", file=f) + print(" }", file=f) + print(" else", file=f) + print(" {", file=f) + print(" b = m_regs[breg];", file=f) + print(" }", file=f) - print >>f, " " - print >>f, " if (creg == LIMM_REG)" - print >>f, " {" - print >>f, " if (!got_limm)" - print >>f, " {" - print >>f, " GET_LIMM_32;" - print >>f, " size = 8;" - print >>f, " }" - print >>f, " c = limm;" - print >>f, " }" - print >>f, " else" - print >>f, " {" - print >>f, " c = m_regs[creg];" - print >>f, " }" - print >>f, " /* todo: is the limm, limm syntax valid? (it's pointless.) */" - print >>f, " /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */" - print >>f, " %s" % opexecute - print >>f, " %s" % opwrite - print >>f, " " + print(" ", file=f) + print(" if (creg == LIMM_REG)", file=f) + print(" {", file=f) + print(" if (!got_limm)", file=f) + print(" {", file=f) + print(" GET_LIMM_32;", file=f) + print(" size = 8;", file=f) + print(" }", file=f) + print(" c = limm;", file=f) + print(" }", file=f) + print(" else", file=f) + print(" {", file=f) + print(" c = m_regs[creg];", file=f) + print(" }", file=f) + print(" /* todo: is the limm, limm syntax valid? (it's pointless.) */", file=f) + print(" /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */", file=f) + print(" %s" % opexecute, file=f) + print(" %s" % opwrite, file=f) + print(" ", file=f) EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) - print >>f, " return m_pc + (size >> 0);" - print >>f, "}" - print >>f, "" - print >>f, "" + print(" return m_pc + (size >> 0);", file=f) + print("}", file=f) + print("", file=f) + print("", file=f) # the mode 0x01 handler - print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p01(OPS_32)" % funcname - print >>f, "{" + print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p01(OPS_32)" % funcname, file=f) + print("{", file=f) EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler) - print >>f, " %s" % opexecute - print >>f, " %s" % opwrite - print >>f, " " + print(" %s" % opexecute, file=f) + print(" %s" % opwrite, file=f) + print(" ", file=f) EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) - print >>f, " return m_pc + (size >> 0);" - print >>f, "}" - print >>f, "" - print >>f, "" + print(" return m_pc + (size >> 0);", file=f) + print("}", file=f) + print("", file=f) + print("", file=f) # the mode 0x10 handler - print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p10(OPS_32)" % funcname + print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p10(OPS_32)" % funcname, file=f) if ignore_a == 2: - print >>f, "{" - print >>f, " int size = 4;" - print >>f, " arcompact_fatal(\"illegal arcompact_handle%s_p10 (ares bits already used as opcode select, can't be used as s12) (%s)\\n\");" % (funcname, opname) - print >>f, " return m_pc + (size >> 0);" - print >>f, "}" + print("{", file=f) + print(" int size = 4;", file=f) + print(" arcompact_fatal(\"illegal arcompact_handle%s_p10 (ares bits already used as opcode select, can't be used as s12) (%s)\\n\");" % (funcname, opname), file=f) + print(" return m_pc + (size >> 0);", file=f) + print("}", file=f) else: - print >>f, "{" - print >>f, " int size = 4;" + print("{", file=f) + print(" int size = 4;", file=f) if breg_is_dst_only == 0: - print >>f, " UINT32 limm = 0;" + print(" UINT32 limm = 0;", file=f) - print >>f, "/* int got_limm = 0; */" - print >>f, " " - print >>f, " COMMON32_GET_breg;" + print("/* int got_limm = 0; */", file=f) + print(" ", file=f) + print(" COMMON32_GET_breg;", file=f) if flagcondition == -1: - print >>f, " COMMON32_GET_F;" + print(" COMMON32_GET_F;", file=f) - print >>f, " COMMON32_GET_s12;" + print(" COMMON32_GET_s12;", file=f) # areg can't be used here, it's used for s12 bits - print >>f, " " - print >>f, " UINT32 c;" + print(" ", file=f) + print(" UINT32 c;", file=f) if breg_is_dst_only == 0: - print >>f, " UINT32 b;" - print >>f, " " - print >>f, " /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */" - print >>f, " if (breg == LIMM_REG)" - print >>f, " {" - print >>f, " GET_LIMM_32;" - print >>f, " size = 8;" - print >>f, "/* got_limm = 1; */" - print >>f, " b = limm;" - print >>f, " }" - print >>f, " else" - print >>f, " {" - print >>f, " b = m_regs[breg];" - print >>f, " }" + print(" UINT32 b;", file=f) + print(" ", file=f) + print(" /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */", file=f) + print(" if (breg == LIMM_REG)", file=f) + print(" {", file=f) + print(" GET_LIMM_32;", file=f) + print(" size = 8;", file=f) + print("/* got_limm = 1; */", file=f) + print(" b = limm;", file=f) + print(" }", file=f) + print(" else", file=f) + print(" {", file=f) + print(" b = m_regs[breg];", file=f) + print(" }", file=f) - print >>f, " " - print >>f, " c = (UINT32)S;" - print >>f, " " - print >>f, " /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */" - print >>f, " %s" % opexecute - print >>f, " %s" % opwrite_alt - print >>f, " " + print(" ", file=f) + print(" c = (UINT32)S;", file=f) + print(" ", file=f) + print(" /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */", file=f) + print(" %s" % opexecute, file=f) + print(" %s" % opwrite_alt, file=f) + print(" ", file=f) EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) - print >>f, " return m_pc + (size >> 0);" - print >>f, "}" - print >>f, "" - print >>f, "" + print(" return m_pc + (size >> 0);", file=f) + print("}", file=f) + print("", file=f) + print("", file=f) # the mode 0x11 m0 handler - print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m0(OPS_32)" % funcname + print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m0(OPS_32)" % funcname, file=f) if ignore_a == 2: - print >>f, "{" - print >>f, " int size = 4;" - print >>f, " arcompact_fatal(\"illegal arcompact_handle%s_p11_m0 (ares bits already used as opcode select, can't be used as Q condition) (%s)\\n\");" % (funcname, opname) - print >>f, " return m_pc + (size >> 0);" - print >>f, "}" + print("{", file=f) + print(" int size = 4;", file=f) + print(" arcompact_fatal(\"illegal arcompact_handle%s_p11_m0 (ares bits already used as opcode select, can't be used as Q condition) (%s)\\n\");" % (funcname, opname), file=f) + print(" return m_pc + (size >> 0);", file=f) + print("}", file=f) else: - print >>f, "{" - print >>f, " int size = 4;" - print >>f, " arcompact_fatal(\"arcompact_handle%s_p11_m0 (%s)\\n\");" % (funcname, opname) - print >>f, " return m_pc + (size >> 0);" - print >>f, "}" - print >>f, "" - print >>f, "" + print("{", file=f) + print(" int size = 4;", file=f) + print(" arcompact_fatal(\"arcompact_handle%s_p11_m0 (%s)\\n\");" % (funcname, opname), file=f) + print(" return m_pc + (size >> 0);", file=f) + print("}", file=f) + print("", file=f) + print("", file=f) # the mode 0x11 m1 handler - print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m1(OPS_32)" % funcname + print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m1(OPS_32)" % funcname, file=f) if ignore_a == 2: - print >>f, "{" - print >>f, " int size = 4;" - print >>f, " arcompact_fatal(\"illegal arcompact_handle%s_p11_m1 (ares bits already used as opcode select, can't be used as Q condition) (%s)\\n\");" % (funcname, opname) - print >>f, " return m_pc + (size >> 0);" - print >>f, "}" + print("{", file=f) + print(" int size = 4;", file=f) + print(" arcompact_fatal(\"illegal arcompact_handle%s_p11_m1 (ares bits already used as opcode select, can't be used as Q condition) (%s)\\n\");" % (funcname, opname), file=f) + print(" return m_pc + (size >> 0);", file=f) + print("}", file=f) else: - print >>f, "{" + print("{", file=f) EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, 3, breg_is_dst_only, flagcondition, flaghandler) - print >>f, " COMMON32_GET_CONDITION;" - print >>f, " if (!check_condition(condition))" - print >>f, " return m_pc + (size>>0);" - print >>f, "" - print >>f, " %s" % opexecute - print >>f, " %s" % opwrite_alt - print >>f, " " + print(" COMMON32_GET_CONDITION;", file=f) + print(" if (!check_condition(condition))", file=f) + print(" return m_pc + (size>>0);", file=f) + print("", file=f) + print(" %s" % opexecute, file=f) + print(" %s" % opwrite_alt, file=f) + print(" ", file=f) EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) - print >>f, " return m_pc + (size >> 0);" - print >>f, "}" - print >>f, "" - print >>f, "" + print(" return m_pc + (size >> 0);", file=f) + print("}", file=f) + print("", file=f) + print("", file=f) # xxx_S c, b, u3 format opcodes (note c is destination) def EmitGroup0d(f,funcname, opname, opexecute, opwrite): - print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname - print >>f, "{" - print >>f, " int u, breg, creg;" - print >>f, "" - print >>f, " COMMON16_GET_u3;" - print >>f, " COMMON16_GET_breg;" - print >>f, " COMMON16_GET_creg;" - print >>f, "" - print >>f, " REG_16BIT_RANGE(breg);" - print >>f, " REG_16BIT_RANGE(creg);" - print >>f, "" - print >>f, " %s" % opexecute - print >>f, " %s" % opwrite - print >>f, "" - print >>f, " return m_pc + (2 >> 0);" - print >>f, "}" - print >>f, "" - print >>f, "" + print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname, file=f) + print("{", file=f) + print(" int u, breg, creg;", file=f) + print("", file=f) + print(" COMMON16_GET_u3;", file=f) + print(" COMMON16_GET_breg;", file=f) + print(" COMMON16_GET_creg;", file=f) + print("", file=f) + print(" REG_16BIT_RANGE(breg);", file=f) + print(" REG_16BIT_RANGE(creg);", file=f) + print("", file=f) + print(" %s" % opexecute, file=f) + print(" %s" % opwrite, file=f) + print("", file=f) + print(" return m_pc + (2 >> 0);", file=f) + print("}", file=f) + print("", file=f) + print("", file=f) # xxx_S b <- b,c format opcodes def EmitGroup0f(f,funcname, opname, opexecute, opwrite): - print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"% funcname - print >>f, "{" - print >>f, " int breg, creg;" - print >>f, "" - print >>f, " COMMON16_GET_breg;" - print >>f, " COMMON16_GET_creg;" - print >>f, "" - print >>f, " REG_16BIT_RANGE(breg);" - print >>f, " REG_16BIT_RANGE(creg);" - print >>f, "" - print >>f, " %s" % opexecute - print >>f, " %s" % opwrite - print >>f, "" - print >>f, " return m_pc + (2 >> 0);" - print >>f, "}" - print >>f, "" - print >>f, "" + print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"% funcname, file=f) + print("{", file=f) + print(" int breg, creg;", file=f) + print("", file=f) + print(" COMMON16_GET_breg;", file=f) + print(" COMMON16_GET_creg;", file=f) + print("", file=f) + print(" REG_16BIT_RANGE(breg);", file=f) + print(" REG_16BIT_RANGE(creg);", file=f) + print("", file=f) + print(" %s" % opexecute, file=f) + print(" %s" % opwrite, file=f) + print("", file=f) + print(" return m_pc + (2 >> 0);", file=f) + print("}", file=f) + print("", file=f) + print("", file=f) # xxx_S b, b, u5 format opcodes def EmitGroup17(f,funcname, opname, opexecute): - print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname - print >>f, "{" - print >>f, " int breg, u;" - print >>f, " " - print >>f, " COMMON16_GET_breg;" - print >>f, " COMMON16_GET_u5;" - print >>f, " " - print >>f, " REG_16BIT_RANGE(breg);" - print >>f, " " - print >>f, " %s" % opexecute - print >>f, " " - print >>f, " return m_pc + (2 >> 0);" - print >>f, "}" - print >>f, "" - print >>f, "" + print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname, file=f) + print("{", file=f) + print(" int breg, u;", file=f) + print(" ", file=f) + print(" COMMON16_GET_breg;", file=f) + print(" COMMON16_GET_u5;", file=f) + print(" ", file=f) + print(" REG_16BIT_RANGE(breg);", file=f) + print(" ", file=f) + print(" %s" % opexecute, file=f) + print(" ", file=f) + print(" return m_pc + (2 >> 0);", file=f) + print("}", file=f) + print("", file=f) + print("", file=f) diff --git a/src/emu/cpu/h8/h8make.py b/src/emu/cpu/h8/h8make.py index 4cd435df373..929b5d14c4e 100644 --- a/src/emu/cpu/h8/h8make.py +++ b/src/emu/cpu/h8/h8make.py @@ -1,5 +1,7 @@ #!/usr/bin/python +from __future__ import print_function + USAGE = """ Usage: %s h8.lst <type> h8.inc (type = o/h/s20/s26) @@ -45,45 +47,45 @@ def has_eat(ins): return False def save_full_one(f, t, name, source): - print >>f, "void %s::%s_full()" % (t, name) - print >>f, "{" + print("void %s::%s_full()" % (t, name), file=f) + print("{", file=f) substate = 1 for line in source: if has_memory(line): - print >>f, "\tif(icount <= bcount) { inst_substate = %d; return; }" % substate - print >>f, line + print("\tif(icount <= bcount) { inst_substate = %d; return; }" % substate, file=f) + print(line, file=f) substate += 1 elif has_eat(line): - print >>f, "\tif(icount) icount = bcount; inst_substate = %d; return;" % substate + print("\tif(icount) icount = bcount; inst_substate = %d; return;" % substate, file=f) substate += 1 else: - print >>f, line - print >>f, "}" - print >>f + print(line, file=f) + print("}", file=f) + print("", file=f) def save_partial_one(f, t, name, source): - print >>f, "void %s::%s_partial()" % (t, name) - print >>f, "{" - print >>f, "switch(inst_substate) {" - print >>f, "case 0:" + print("void %s::%s_partial()" % (t, name), file=f) + print("{", file=f) + print("switch(inst_substate) {", file=f) + print("case 0:", file=f) substate = 1 for line in source: if has_memory(line): - print >>f, "\tif(icount <= bcount) { inst_substate = %d; return; }" % substate - print >>f, "case %d:;" % substate - print >>f, line + print("\tif(icount <= bcount) { inst_substate = %d; return; }" % substate, file=f) + print("case %d:;" % substate, file=f) + print(line, file=f) substate += 1 elif has_eat(line): - print >>f, "\tif(icount) icount = bcount; inst_substate = %d; return;" % substate - print >>f, "case %d:;" % substate + print("\tif(icount) icount = bcount; inst_substate = %d; return;" % substate, file=f) + print("case %d:;" % substate, file=f) substate += 1 else: - print >>f, line - print >>f, "\tbreak;" - print >>f, "}" - print >>f, "\tinst_substate = 0;" - print >>f, "}" - print >>f + print(line, file=f) + print("\tbreak;", file=f) + print("}", file=f) + print("\tinst_substate = 0;", file=f) + print("}", file=f) + print("", file=f) class Hash: def __init__(self, premask): @@ -185,7 +187,7 @@ class Opcode: else: flags = "%d" % size - print >>f, "\t{ %d, 0x%08x, 0x%08x, 0x%04x, 0x%04x, \"%s\", DASM_%s, DASM_%s, %s }, // %s" % ( slot, val, mask, val2, mask2, self.name, self.am1 if self.am1 != "-" else "none", self.am2 if self.am2 != "-" else "none", flags, "needed" if self.needed else "inherited") + print("\t{ %d, 0x%08x, 0x%08x, 0x%04x, 0x%04x, \"%s\", DASM_%s, DASM_%s, %s }, // %s" % ( slot, val, mask, val2, mask2, self.name, self.am1 if self.am1 != "-" else "none", self.am2 if self.am2 != "-" else "none", flags, "needed" if self.needed else "inherited"), file=f) class Special: def __init__(self, val, name, otype, dtype): @@ -244,7 +246,7 @@ class DispatchStep: return True def source(self): - start = self.pos / 2 + start = self.pos // 2 end = start + self.skip s = [] for i in range(start, end+1): @@ -345,13 +347,13 @@ class OpcodeList: h = self.get(d.id) def save_dasm(self, f, dname): - print >>f, "const %s::disasm_entry %s::disasm_entries[] = {" % (dname, dname) + print("const %s::disasm_entry %s::disasm_entries[] = {" % (dname, dname), file=f) for opc in self.opcode_info: if opc.enabled: opc.save_dasm(f) - print >>f, "\t{ 0, 0, 0, 0, 0, \"illegal\", 0, 0, 2 }," - print >>f, "};" - print >>f + print("\t{ 0, 0, 0, 0, 0, \"illegal\", 0, 0, 2 },", file=f) + print("};", file=f) + print("", file=f) def save_opcodes(self, f, t): for opc in self.opcode_info: @@ -370,24 +372,24 @@ class OpcodeList: save_partial_one(f, t, "dispatch_" + dsp.name, dsp.source()) def save_exec(self, f, t, dtype, v): - print >>f, "void %s::do_exec_%s()" % (t, v) - print >>f, "{" - print >>f, "\tswitch(inst_state >> 16) {" + print("void %s::do_exec_%s()" % (t, v), file=f) + print("{", file=f) + print("\tswitch(inst_state >> 16) {", file=f) for i in range(0, len(self.dispatch_info)+2): if i == 1: - print >>f, "\tcase 0x01: {" - print >>f, "\t\tswitch(inst_state & 0xffff) {" + print("\tcase 0x01: {", file=f) + print("\t\tswitch(inst_state & 0xffff) {", file=f) for sta in self.states_info: if sta.enabled: - print >>f, "\t\tcase 0x%02x: state_%s_%s(); break;" % (sta.val & 0xffff, sta.name, v) - print >>f, "\t\t}" - print >>f, "\t\tbreak;" - print >>f, "\t}" + print("\t\tcase 0x%02x: state_%s_%s(); break;" % (sta.val & 0xffff, sta.name, v), file=f) + print("\t\t}", file=f) + print("\t\tbreak;", file=f) + print("\t}", file=f) else: if i == 0 or self.dispatch_info[i-2].enabled: - print >>f, "\tcase 0x%02x: {" % i + print("\tcase 0x%02x: {" % i, file=f) h = self.get(i) - print >>f, "\t\tswitch((inst_state >> 8) & 0x%02x) {" % h.mask + print("\t\tswitch((inst_state >> 8) & 0x%02x) {" % h.mask, file=f) for val, h2 in sorted(h.d.items()): if h2.enabled: fmask = h2.premask | (h.mask ^ 0xff) @@ -398,16 +400,16 @@ class OpcodeList: s += 1 while s & fmask: s += s & fmask - print >>f, "\t\t%s{" % c + print("\t\t%s{" % c, file=f) if h2.mask == 0x00: n = h2.d[0] if n.is_dispatch(): - print >>f, "\t\t\tdispatch_%s_%s();" % (n.name, v) + print("\t\t\tdispatch_%s_%s();" % (n.name, v), file=f) else: - print >>f, "\t\t\t%s_%s();" % (n.function_name(), v) - print >>f, "\t\t\tbreak;" + print("\t\t\t%s_%s();" % (n.function_name(), v), file=f) + print("\t\t\tbreak;", file=f) else: - print >>f, "\t\t\tswitch(inst_state & 0x%02x) {" % h2.mask + print("\t\t\tswitch(inst_state & 0x%02x) {" % h2.mask, file=f) if i == 0: mpos = 1 else: @@ -427,23 +429,23 @@ class OpcodeList: while s & fmask: s += s & fmask if n.is_dispatch(): - print >>f, "\t\t\t%sdispatch_%s_%s(); break;" % (c, n.name, v) + print("\t\t\t%sdispatch_%s_%s(); break;" % (c, n.name, v), file=f) else: - print >>f, "\t\t\t%s%s_%s(); break;" % (c, n.function_name(), v) - print >>f, "\t\t\tdefault: illegal(); break;" - print >>f, "\t\t\t}" - print >>f, "\t\t\tbreak;" - print >>f, "\t\t}" - print >>f, "\t\tdefault: illegal(); break;" - print >>f, "\t\t}" - print >>f, "\t\tbreak;" - print >>f, "\t}" - print >>f, "\t}" - print >>f, "}" + print("\t\t\t%s%s_%s(); break;" % (c, n.function_name(), v), file=f) + print("\t\t\tdefault: illegal(); break;", file=f) + print("\t\t\t}", file=f) + print("\t\t\tbreak;", file=f) + print("\t\t}", file=f) + print("\t\tdefault: illegal(); break;", file=f) + print("\t\t}", file=f) + print("\t\tbreak;", file=f) + print("\t}", file=f) + print("\t}", file=f) + print("}", file=f) def main(argv): if len(argv) != 4: - print USAGE % argv[0] + print(USAGE % argv[0]) return 1 dtype = name_to_type(argv[2]) diff --git a/src/emu/cpu/m6502/m6502make.py b/src/emu/cpu/m6502/m6502make.py index 591d01268ca..4ac62e90ce9 100755 --- a/src/emu/cpu/m6502/m6502make.py +++ b/src/emu/cpu/m6502/m6502make.py @@ -1,5 +1,7 @@ #!/usr/bin/python +from __future__ import print_function + USAGE = """ Usage: %s device_name {opc.lst|-} disp.lst device.inc @@ -52,7 +54,7 @@ def load_disp(fname): def emit(f, text): """write string to file""" - print >>f, text, + print(text, file=f) FULL_PROLOG="""\ void %(device)s::%(opcode)s_full() @@ -252,7 +254,7 @@ def main(argv): if len(argv) != 5: - print USAGE % argv[0] + print(USAGE % argv[0]) return 1 device_name = argv[1] diff --git a/src/emu/cpu/mcs96/mcs96make.py b/src/emu/cpu/mcs96/mcs96make.py index 8381e63dc2f..72d8f36cfa6 100644 --- a/src/emu/cpu/mcs96/mcs96make.py +++ b/src/emu/cpu/mcs96/mcs96make.py @@ -1,5 +1,7 @@ #!/usr/bin/python +from __future__ import print_function + USAGE = """ Usage: %s mcs96ops.lst mcs96.inc @@ -7,12 +9,12 @@ Usage: import sys def save_full_one(f, t, name, source): - print >>f, "void %s_device::%s_full()" % (t, name) - print >>f, "{" + print("void %s_device::%s_full()" % (t, name), file=f) + print("{", file=f) for line in source: - print >>f, line - print >>f, "}" - print >>f + print(line, file=f) + print("}", file=f) + print("", file=f) class Opcode: def __init__(self, rng, name, amode, is_196, ea): @@ -113,7 +115,7 @@ class OpcodeList: self.opcode_per_id[i] = inf def save_dasm(self, f, t): - print >>f, "const %s_device::disasm_entry %s_device::disasm_entries[0x100] = {" % (t, t) + print("const %s_device::disasm_entry %s_device::disasm_entries[0x100] = {" % (t, t), file=f) for i in range(0, 0x100): if i in self.opcode_per_id: opc = self.opcode_per_id[i] @@ -126,11 +128,11 @@ class OpcodeList: flags = "DASMFLAG_STEP_OUT" else: flags = "0" - print >>f, "\t{ \"%s\", %s, DASM_%s, %s }," % (opc.name, alt, opc.amode, flags) + print("\t{ \"%s\", %s, DASM_%s, %s }," % (opc.name, alt, opc.amode, flags), file=f) else: - print >>f, "\t{ \"???\", NULL, DASM_none, 0 }," - print >>f, "};" - print >>f + print("\t{ \"???\", NULL, DASM_none, 0 },", file=f) + print("};", file=f) + print("", file=f) def save_opcodes(self, f, t): pf = "" @@ -146,9 +148,9 @@ class OpcodeList: save_full_one(f, t, "fetch_noirq", self.fetch_noirq.source) def save_exec(self, f, t): - print >>f, "void %s_device::do_exec_full()" % t - print >>f, "{" - print >>f, "\tswitch(inst_state) {" + print("void %s_device::do_exec_full()" % t, file=f) + print("{", file=f) + print("\tswitch(inst_state) {", file=f) for i in range(0x000, 0x200): opc = None if i >= 0x100 and i-0x100+0xfe00 in self.opcode_per_id: @@ -159,15 +161,15 @@ class OpcodeList: nm = opc.name + "_" + opc.amode if opc.is_196: nm += "_196" - print >>f, "\tcase 0x%03x: %s_full(); break;" % (i, nm) - print >>f, "\tcase 0x200: fetch_full(); break;" - print >>f, "\tcase 0x201: fetch_noirq_full(); break;" - print >>f, "\t}" - print >>f, "}" + print("\tcase 0x%03x: %s_full(); break;" % (i, nm), file=f) + print("\tcase 0x200: fetch_full(); break;", file=f) + print("\tcase 0x201: fetch_noirq_full(); break;", file=f) + print("\t}", file=f) + print("}", file=f) def main(argv): if len(argv) != 4: - print USAGE % argv[0] + print(USAGE % argv[0]) return 1 t = argv[1] |