Previous 199869 Revisions Next

r40070 Thursday 30th July, 2015 at 09:44:43 UTC by Olivier Galibert
python: Make all scripts python 2/3 compatible
[src/build]makelist.py png.py png2bdc.py
[src/emu/cpu/arcompact]arcompact_make.py
[src/emu/cpu/h8]h8make.py
[src/emu/cpu/m6502]m6502make.py
[src/emu/cpu/mcs96]mcs96make.py

trunk/src/build/makelist.py
r248581r248582
1111
1212def parse_file(srcfile):
1313    try:
14        fp = open(srcfile, 'rb')
14        fp = open(srcfile, 'rt')
1515    except IOError:
1616        sys.stderr.write("Unable to open source file '%s'\n" % srcfile)
1717        return 1
trunk/src/build/png.py
r248581r248582
143143"""
144144
145145# http://www.python.org/doc/2.2.3/whatsnew/node5.html
146from __future__ import generators
146from __future__ import generators,print_function
147147
148148__version__ = "0.0.17"
149149
150150from array import array
151try: # See :pyver:old
152    import itertools
151try:
152    from itertools import imap
153153except ImportError:
154    pass
154    imap = map
155from itertools import starmap
155156import math
156157# http://www.python.org/doc/2.4.4/lib/module-operator.html
157158import operator
r248581r248582
16501651            spb = 8//self.bitdepth
16511652            out = array('B')
16521653            mask = 2**self.bitdepth - 1
1653            shifts = map(self.bitdepth.__mul__, reversed(range(spb)))
1654            shifts = list(map(self.bitdepth.__mul__, reversed(range(spb))))
16541655            for o in raw:
1655                out.extend(map(lambda i: mask&(o>>i), shifts))
1656                out.extend(list(map(lambda i: mask&(o>>i), shifts)))
16561657            return out[:width]
1657
16581658        return itertools.imap(asvalues, rows)
16591659
16601660    def serialtoflat(self, bytes, width=None):
r248581r248582
19151915            while True:
19161916                try:
19171917                    type, data = self.chunk(lenient=lenient)
1918                except ValueError, e:
1919                    raise ChunkError(e.args[0])
1918                except ValueError:
1919                    raise ChunkError(sys.exc_info()[1].args[0])
19201920                if type == 'IEND':
19211921                    # http://www.w3.org/TR/PNG/#11IEND
19221922                    break
r248581r248582
19471947
19481948        self.preamble(lenient=lenient)
19491949        raw = iterdecomp(iteridat())
1950
19511950        if self.interlace:
19521951            raw = array('B', itertools.chain(*raw))
19531952            arraycode = 'BH'[self.bitdepth>8]
r248581r248582
20622061            meta['alpha'] = bool(self.trns)
20632062            meta['bitdepth'] = 8
20642063            meta['planes'] = 3 + bool(self.trns)
2065            plte = self.palette()
2064            plte = list(self.palette())
20662065            def iterpal(pixels):
20672066                for row in pixels:
2068                    row = map(plte.__getitem__, row)
2067                    row = list(map(plte.__getitem__, row))
20692068                    yield array('B', itertools.chain(*row))
20702069            pixels = iterpal(pixels)
20712070        elif self.trns:
r248581r248582
27792778if __name__ == '__main__':
27802779    try:
27812780        _main(sys.argv)
2782    except Error, e:
2783        print >>sys.stderr, e
2781    except Error:
2782        print (sys.exc_info()[1], file=e)
trunk/src/build/png2bdc.py
r248581r248582
5959import png
6060import sys
6161
62if sys.version_info >= (3,):
63    def b2p(v):
64        return bytes([v])
65else:
66    def b2p(v):
67        return chr(v)
6268
69
6370########################################
6471## Helper classes
6572########################################
r248581r248582
117124    CACHED_HEADER_SIZE = 16
118125   
119126    try:
120        fp.write('f')
121        fp.write('o')
122        fp.write('n')
123        fp.write('t')
124        fp.write(chr(hash32 >> 24 & 0xff))
125        fp.write(chr(hash32 >> 16 & 0xff))
126        fp.write(chr(hash32 >> 8 & 0xff))
127        fp.write(chr(hash32 >> 0 & 0xff))
128        fp.write(chr(font.height >> 8 & 0xff))
129        fp.write(chr(font.height >> 0 & 0xff))
130        fp.write(chr(font.yOffs >> 8 & 0xff))
131        fp.write(chr(font.yOffs >> 0 & 0xff))
132        fp.write(chr(numChars >> 24 & 0xff))
133        fp.write(chr(numChars >> 16 & 0xff))
134        fp.write(chr(numChars >> 8 & 0xff))
135        fp.write(chr(numChars >> 0 & 0xff))
127        fp.write(b'f')
128        fp.write(b'o')
129        fp.write(b'n')
130        fp.write(b't')
131        fp.write(b2p(hash32 >> 24 & 0xff))
132        fp.write(b2p(hash32 >> 16 & 0xff))
133        fp.write(b2p(hash32 >> 8 & 0xff))
134        fp.write(b2p(hash32 >> 0 & 0xff))
135        fp.write(b2p(font.height >> 8 & 0xff))
136        fp.write(b2p(font.height >> 0 & 0xff))
137        fp.write(b2p(font.yOffs >> 8 & 0xff))
138        fp.write(b2p(font.yOffs >> 0 & 0xff))
139        fp.write(b2p(numChars >> 24 & 0xff))
140        fp.write(b2p(numChars >> 16 & 0xff))
141        fp.write(b2p(numChars >> 8 & 0xff))
142        fp.write(b2p(numChars >> 0 & 0xff))
136143       
137144        # Write a blank table at first (?)
138145        charTable = [0]*(numChars * CACHED_CHAR_SIZE)
139146        for i in range(numChars * CACHED_CHAR_SIZE):
140            fp.write(chr(charTable[i]))
147            fp.write(b2p(charTable[i]))
141148       
142149        # Loop over all characters
143150        tableIndex = 0
r248581r248582
173180               
174181                # Write the data
175182                for j in range(len(dBuffer)):
176                    fp.write(chr(dBuffer[j]))
183                    fp.write(b2p(dBuffer[j]))
177184           
178185            destIndex = tableIndex * CACHED_CHAR_SIZE
179186            charTable[destIndex +  0] = i >> 8 & 0xff
r248581r248582
193200        # Seek back to the beginning and rewrite the table
194201        fp.seek(CACHED_HEADER_SIZE, 0)
195202        for i in range(numChars * CACHED_CHAR_SIZE):
196            fp.write(chr(charTable[i]))
203            fp.write(b2p(charTable[i]))
197204   
198205        fp.close()
199206        return 0
200207
201208    except:
209        print(sys.exc_info[1])
202210        return 1
203211   
204212
r248581r248582
347355    except:
348356        sys.stderr.write("Error reading PNG file.\n")
349357        return 1
350           
358
351359    error = bitmapToChars(pngObject, font)
352360    if error:
353361        return 1
trunk/src/emu/cpu/arcompact/arcompact_make.py
r248581r248582
11#!/usr/bin/python
22
3from __future__ import print_function
34import sys
45
56def EmitGroup04_Handle_NZ_Flags(f, funcname, opname):
6        print >>f, "      if (result & 0x80000000) { STATUS32_SET_N; }"
7        print >>f, "      else { STATUS32_CLEAR_N; }"
8        print >>f, "      if (result == 0x00000000) { STATUS32_SET_Z; }"
9        print >>f, "      else { STATUS32_CLEAR_Z; }"
7        print("      if (result & 0x80000000) { STATUS32_SET_N; }", file=f)
8        print("      else { STATUS32_CLEAR_N; }", file=f)
9        print("      if (result == 0x00000000) { STATUS32_SET_Z; }", file=f)
10        print("      else { STATUS32_CLEAR_Z; }", file=f)
1011
1112def EmitGroup04_Handle_NZC_LSR1_Flags(f, funcname, opname):
12        print >>f, "      if (result & 0x80000000) { STATUS32_SET_N; }"
13        print >>f, "      else { STATUS32_CLEAR_N; }"
14        print >>f, "      if (result == 0x00000000) { STATUS32_SET_Z; }"
15        print >>f, "      else { STATUS32_CLEAR_Z; }"
16        print >>f, "      if (c == 0x00000001) { STATUS32_SET_C; }"
17        print >>f, "      else { STATUS32_CLEAR_C; }"
13        print("      if (result & 0x80000000) { STATUS32_SET_N; }", file=f)
14        print("      else { STATUS32_CLEAR_N; }", file=f)
15        print("      if (result == 0x00000000) { STATUS32_SET_Z; }", file=f)
16        print("      else { STATUS32_CLEAR_Z; }", file=f)
17        print("      if (c == 0x00000001) { STATUS32_SET_C; }", file=f)
18        print("      else { STATUS32_CLEAR_C; }", file=f)
1819
1920def EmitGroup04_Handle_NZCV_ADD_Flags(f, funcname, opname):
20        print >>f, "      if (result & 0x80000000) { STATUS32_SET_N; }"
21        print >>f, "      else { STATUS32_CLEAR_N; }"
22        print >>f, "      if (result == 0x00000000) { STATUS32_SET_Z; }"
23        print >>f, "      else { STATUS32_CLEAR_Z; }"
24        print >>f, "      if ((b & 0x80000000) == (c & 0x80000000))"
25        print >>f, "      {"
26        print >>f, "         if ((result & 0x80000000) != (b & 0x80000000))"
27        print >>f, "         {"
28        print >>f, "            STATUS32_SET_V;"
29        print >>f, "         }"
30        print >>f, "         else"
31        print >>f, "         {"
32        print >>f, "            STATUS32_CLEAR_V;"
33        print >>f, "         }"
34        print >>f, "      }"
35        print >>f, "      if (b < c)"
36        print >>f, "      {"
37        print >>f, "         STATUS32_SET_C;"
38        print >>f, "      }"
39        print >>f, "      else"
40        print >>f, "      {"
41        print >>f, "         STATUS32_CLEAR_C;"
42        print >>f, "      }"
21        print("      if (result & 0x80000000) { STATUS32_SET_N; }", file=f)
22        print("      else { STATUS32_CLEAR_N; }", file=f)
23        print("      if (result == 0x00000000) { STATUS32_SET_Z; }", file=f)
24        print("      else { STATUS32_CLEAR_Z; }", file=f)
25        print("      if ((b & 0x80000000) == (c & 0x80000000))", file=f)
26        print("      {", file=f)
27        print("         if ((result & 0x80000000) != (b & 0x80000000))", file=f)
28        print("         {", file=f)
29        print("            STATUS32_SET_V;", file=f)
30        print("         }", file=f)
31        print("         else", file=f)
32        print("         {", file=f)
33        print("            STATUS32_CLEAR_V;", file=f)
34        print("         }", file=f)
35        print("      }", file=f)
36        print("      if (b < c)", file=f)
37        print("      {", file=f)
38        print("         STATUS32_SET_C;", file=f)
39        print("      }", file=f)
40        print("      else", file=f)
41        print("      {", file=f)
42        print("         STATUS32_CLEAR_C;", file=f)
43        print("      }", file=f)
4344
4445
4546def EmitGroup04_no_Flags(f, funcname, opname):
46       print >>f, "      // no flag changes"
47       print("      // no flag changes", file=f)
4748
4849def EmitGroup04_unsupported_Flags(f, funcname, opname):
49        print >>f, "      arcompact_fatal(\"arcompact_handle%s (%s) (F set)\\n\"); // not yet supported" % (funcname, opname)
50        print("      arcompact_fatal(\"arcompact_handle%s (%s) (F set)\\n\"); // not yet supported" % (funcname, opname), file=f)
5051
5152def EmitGroup04_Flaghandler(f,funcname, opname, flagcondition, flaghandler):
5253    if flagcondition == -1:
53        print >>f, "   if (F)"
54        print >>f, "   {"
54        print("   if (F)", file=f)
55        print("   {", file=f)
5556        flaghandler(f, funcname, opname)
56        print >>f, "   }"
57        print("   }", file=f)
5758    elif flagcondition == 0:
58        print >>f, "   if (0)"
59        print >>f, "   {"
59        print("   if (0)", file=f)
60        print("   {", file=f)
6061        flaghandler(f, funcname, opname)
61        print >>f, "   }"
62        print("   }", file=f)
6263    elif flagcondition == 1:
63        print >>f, "   if (1)"
64        print >>f, "   {"
64        print("   if (1)", file=f)
65        print("   {", file=f)
6566        flaghandler(f, funcname, opname)
66        print >>f, "   }"
67        print("   }", file=f)
6768
6869def EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler):
69    print >>f, "   int size = 4;"
70    print("   int size = 4;", file=f)
7071   
7172    if breg_is_dst_only == 0:   
72        print >>f, "   UINT32 limm = 0;"
73        print("   UINT32 limm = 0;", file=f)
7374   
74    print >>f, "/*   int got_limm = 0; */"
75    print >>f, "   "
76    print >>f, "   COMMON32_GET_breg;"
75    print("/*   int got_limm = 0; */", file=f)
76    print("   ", file=f)
77    print("   COMMON32_GET_breg;", file=f)
7778   
7879    if flagcondition == -1:
79        print >>f, "   COMMON32_GET_F;"
80        print("   COMMON32_GET_F;", file=f)
8081   
81    print >>f, "   COMMON32_GET_u6;"
82    print("   COMMON32_GET_u6;", file=f)
8283   
8384    if ignore_a == 0:
84        print >>f, "   COMMON32_GET_areg;"
85        print("   COMMON32_GET_areg;", file=f)
8586    elif ignore_a == 1:
86        print >>f, "     //COMMON32_GET_areg; // areg is reserved / not used"
87        print("     //COMMON32_GET_areg; // areg is reserved / not used", file=f)
8788    elif ignore_a == 2:
88        print >>f, "     //COMMON32_GET_areg; // areg bits already used as opcode select"
89        print("     //COMMON32_GET_areg; // areg bits already used as opcode select", file=f)
8990    elif ignore_a == 3:
90        print >>f, "     //COMMON32_GET_areg; // areg bits already used as condition code select"
91    print >>f, "   "
91        print("     //COMMON32_GET_areg; // areg bits already used as condition code select", file=f)
92    print("   ", file=f)
9293   
93    print >>f, "   UINT32 c;"
94    print("   UINT32 c;", file=f)
9495    if breg_is_dst_only == 0:
95        print >>f, "   UINT32 b;"
96        print >>f, "   "
97        print >>f, "   /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */"
98        print >>f, "   if (breg == LIMM_REG)"
99        print >>f, "   {"
100        print >>f, "      GET_LIMM_32;"
101        print >>f, "      size = 8;"
102        print >>f, "/*      got_limm = 1; */"
103        print >>f, "      b = limm;"
104        print >>f, "   }"
105        print >>f, "   else"
106        print >>f, "   {"
107        print >>f, "      b = m_regs[breg];"
108        print >>f, "   }"
96        print("   UINT32 b;", file=f)
97        print("   ", file=f)
98        print("   /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */", file=f)
99        print("   if (breg == LIMM_REG)", file=f)
100        print("   {", file=f)
101        print("      GET_LIMM_32;", file=f)
102        print("      size = 8;", file=f)
103        print("/*      got_limm = 1; */", file=f)
104        print("      b = limm;", file=f)
105        print("   }", file=f)
106        print("   else", file=f)
107        print("   {", file=f)
108        print("      b = m_regs[breg];", file=f)
109        print("   }", file=f)
109110   
110    print >>f, "    "
111    print >>f, "    c = u;"
112    print >>f, "   "
113    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?) */"
111    print("    ", file=f)
112    print("    c = u;", file=f)
113    print("   ", file=f)
114    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)
114115
115116def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler):
116117    # the mode 0x00 handler 
117    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p00(OPS_32)" % funcname
118    print >>f, "{"
119    print >>f, "   int size = 4;"
118    print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p00(OPS_32)" % funcname, file=f)
119    print("{", file=f)
120    print("   int size = 4;", file=f)
120121   
121    print >>f, "   UINT32 limm = 0;"
122    print("   UINT32 limm = 0;", file=f)
122123   
123    print >>f, "   int got_limm = 0;"
124    print >>f, "   "
125    print >>f, "   COMMON32_GET_breg;"
124    print("   int got_limm = 0;", file=f)
125    print("   ", file=f)
126    print("   COMMON32_GET_breg;", file=f)
126127
127128    if flagcondition == -1:
128        print >>f, "   COMMON32_GET_F;"
129        print("   COMMON32_GET_F;", file=f)
129130       
130    print >>f, "   COMMON32_GET_creg;"
131    print("   COMMON32_GET_creg;", file=f)
131132
132133    if ignore_a == 0:
133        print >>f, "   COMMON32_GET_areg;"
134        print("   COMMON32_GET_areg;", file=f)
134135    elif ignore_a == 1:
135        print >>f, "     //COMMON32_GET_areg; // areg is reserved / not used"
136        print("     //COMMON32_GET_areg; // areg is reserved / not used", file=f)
136137    elif ignore_a == 2:
137        print >>f, "     //COMMON32_GET_areg; // areg bits already used as opcode select"
138        print("     //COMMON32_GET_areg; // areg bits already used as opcode select", file=f)
138139 
139    print >>f, "   "
140    print("   ", file=f)
140141   
141    print >>f, "   UINT32 c;"
142    print("   UINT32 c;", file=f)
142143    if breg_is_dst_only == 0:
143        print >>f, "   UINT32 b;"
144        print >>f, "   "
145        print >>f, "   if (breg == LIMM_REG)"
146        print >>f, "   {"
147        print >>f, "      GET_LIMM_32;"
148        print >>f, "      size = 8;"
149        print >>f, "      got_limm = 1;"
150        print >>f, "      b = limm;"
151        print >>f, "   }"
152        print >>f, "   else"
153        print >>f, "   {"
154        print >>f, "      b = m_regs[breg];"
155        print >>f, "   }"
144        print("   UINT32 b;", file=f)
145        print("   ", file=f)
146        print("   if (breg == LIMM_REG)", file=f)
147        print("   {", file=f)
148        print("      GET_LIMM_32;", file=f)
149        print("      size = 8;", file=f)
150        print("      got_limm = 1;", file=f)
151        print("      b = limm;", file=f)
152        print("   }", file=f)
153        print("   else", file=f)
154        print("   {", file=f)
155        print("      b = m_regs[breg];", file=f)
156        print("   }", file=f)
156157   
157    print >>f, "   "
158    print >>f, "   if (creg == LIMM_REG)"
159    print >>f, "   {"
160    print >>f, "      if (!got_limm)"
161    print >>f, "      {"
162    print >>f, "         GET_LIMM_32;"
163    print >>f, "         size = 8;"
164    print >>f, "      }"
165    print >>f, "      c = limm;"
166    print >>f, "   }"
167    print >>f, "   else"
168    print >>f, "   {"
169    print >>f, "      c = m_regs[creg];"
170    print >>f, "   }"
171    print >>f, "   /* todo: is the limm, limm syntax valid? (it's pointless.) */"
172    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?) */"
173    print >>f, "   %s" % opexecute
174    print >>f, "   %s" % opwrite
175    print >>f, "   "
158    print("   ", file=f)
159    print("   if (creg == LIMM_REG)", file=f)
160    print("   {", file=f)
161    print("      if (!got_limm)", file=f)
162    print("      {", file=f)
163    print("         GET_LIMM_32;", file=f)
164    print("         size = 8;", file=f)
165    print("      }", file=f)
166    print("      c = limm;", file=f)
167    print("   }", file=f)
168    print("   else", file=f)
169    print("   {", file=f)
170    print("      c = m_regs[creg];", file=f)
171    print("   }", file=f)
172    print("   /* todo: is the limm, limm syntax valid? (it's pointless.) */", file=f)
173    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)
174    print("   %s" % opexecute, file=f)
175    print("   %s" % opwrite, file=f)
176    print("   ", file=f)
176177    EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
177    print >>f, "   return m_pc + (size >> 0);"
178    print >>f, "}"
179    print >>f, ""
180    print >>f, ""
178    print("   return m_pc + (size >> 0);", file=f)
179    print("}", file=f)
180    print("", file=f)
181    print("", file=f)
181182    # the mode 0x01 handler   
182    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p01(OPS_32)" % funcname
183    print >>f, "{"
183    print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p01(OPS_32)" % funcname, file=f)
184    print("{", file=f)
184185    EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler)
185    print >>f, "   %s" % opexecute
186    print >>f, "   %s" % opwrite
187    print >>f, "   "
186    print("   %s" % opexecute, file=f)
187    print("   %s" % opwrite, file=f)
188    print("   ", file=f)
188189    EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
189    print >>f, "   return m_pc + (size >> 0);"
190    print >>f, "}"
191    print >>f, ""
192    print >>f, ""
190    print("   return m_pc + (size >> 0);", file=f)
191    print("}", file=f)
192    print("", file=f)
193    print("", file=f)
193194    # the mode 0x10 handler
194    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p10(OPS_32)" % funcname
195    print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p10(OPS_32)" % funcname, file=f)
195196    if ignore_a == 2:
196        print >>f, "{"
197        print >>f, "   int size = 4;"
198        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)
199        print >>f, "   return m_pc + (size >> 0);"
200        print >>f, "}"
197        print("{", file=f)
198        print("   int size = 4;", file=f)
199        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)
200        print("   return m_pc + (size >> 0);", file=f)
201        print("}", file=f)
201202    else:
202        print >>f, "{"
203        print >>f, "   int size = 4;"
203        print("{", file=f)
204        print("   int size = 4;", file=f)
204205        if breg_is_dst_only == 0:
205            print >>f, "   UINT32 limm = 0;"
206            print("   UINT32 limm = 0;", file=f)
206207       
207        print >>f, "/*   int got_limm = 0; */"
208        print >>f, "   "
209        print >>f, "   COMMON32_GET_breg;"
208        print("/*   int got_limm = 0; */", file=f)
209        print("   ", file=f)
210        print("   COMMON32_GET_breg;", file=f)
210211   
211212        if flagcondition == -1:   
212            print >>f, "   COMMON32_GET_F;"
213            print("   COMMON32_GET_F;", file=f)
213214       
214        print >>f, "   COMMON32_GET_s12;"
215        print("   COMMON32_GET_s12;", file=f)
215216       
216217        # areg can't be used here, it's used for s12 bits
217218       
218        print >>f, "   "
219        print >>f, "   UINT32 c;"
219        print("   ", file=f)
220        print("   UINT32 c;", file=f)
220221        if breg_is_dst_only == 0:
221            print >>f, "   UINT32 b;"
222            print >>f, "   "
223            print >>f, "   /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */"
224            print >>f, "   if (breg == LIMM_REG)"
225            print >>f, "   {"
226            print >>f, "      GET_LIMM_32;"
227            print >>f, "      size = 8;"
228            print >>f, "/*      got_limm = 1; */"
229            print >>f, "      b = limm;"
230            print >>f, "   }"
231            print >>f, "   else"
232            print >>f, "   {"
233            print >>f, "      b = m_regs[breg];"
234            print >>f, "   }"
222            print("   UINT32 b;", file=f)
223            print("   ", file=f)
224            print("   /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */", file=f)
225            print("   if (breg == LIMM_REG)", file=f)
226            print("   {", file=f)
227            print("      GET_LIMM_32;", file=f)
228            print("      size = 8;", file=f)
229            print("/*      got_limm = 1; */", file=f)
230            print("      b = limm;", file=f)
231            print("   }", file=f)
232            print("   else", file=f)
233            print("   {", file=f)
234            print("      b = m_regs[breg];", file=f)
235            print("   }", file=f)
235236       
236        print >>f, "    "
237        print >>f, "    c = (UINT32)S;"
238        print >>f, "   "
239        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?) */"
240        print >>f, "   %s" % opexecute
241        print >>f, "   %s" % opwrite_alt
242        print >>f, "   "
237        print("    ", file=f)
238        print("    c = (UINT32)S;", file=f)
239        print("   ", file=f)
240        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)
241        print("   %s" % opexecute, file=f)
242        print("   %s" % opwrite_alt, file=f)
243        print("   ", file=f)
243244        EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
244        print >>f, "   return m_pc + (size >> 0);"
245        print >>f, "}"
246    print >>f, ""
247    print >>f, ""
245        print("   return m_pc + (size >> 0);", file=f)
246        print("}", file=f)
247    print("", file=f)
248    print("", file=f)
248249    # the mode 0x11 m0 handler   
249    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m0(OPS_32)" % funcname
250    print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m0(OPS_32)" % funcname, file=f)
250251    if ignore_a == 2:
251        print >>f, "{"
252        print >>f, "   int size = 4;"
253        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)
254        print >>f, "   return m_pc + (size >> 0);"
255        print >>f, "}"
252        print("{", file=f)
253        print("   int size = 4;", file=f)
254        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)
255        print("   return m_pc + (size >> 0);", file=f)
256        print("}", file=f)
256257    else:
257        print >>f, "{"
258        print >>f, "   int size = 4;"
259        print >>f, "   arcompact_fatal(\"arcompact_handle%s_p11_m0 (%s)\\n\");"  % (funcname, opname)
260        print >>f, "   return m_pc + (size >> 0);"
261        print >>f, "}"
262        print >>f, ""
263        print >>f, ""   
258        print("{", file=f)
259        print("   int size = 4;", file=f)
260        print("   arcompact_fatal(\"arcompact_handle%s_p11_m0 (%s)\\n\");"  % (funcname, opname), file=f)
261        print("   return m_pc + (size >> 0);", file=f)
262        print("}", file=f)
263        print("", file=f)
264        print("", file=f)
264265    # the mode 0x11 m1 handler   
265    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m1(OPS_32)" % funcname
266    print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m1(OPS_32)" % funcname, file=f)
266267    if ignore_a == 2:
267        print >>f, "{"
268        print >>f, "   int size = 4;"
269        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)
270        print >>f, "   return m_pc + (size >> 0);"
271        print >>f, "}"
268        print("{", file=f)
269        print("   int size = 4;", file=f)
270        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)
271        print("   return m_pc + (size >> 0);", file=f)
272        print("}", file=f)
272273    else:
273        print >>f, "{"
274        print("{", file=f)
274275        EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, 3, breg_is_dst_only, flagcondition, flaghandler)
275        print >>f, "   COMMON32_GET_CONDITION;"
276        print >>f, "   if (!check_condition(condition))"
277        print >>f, "      return m_pc + (size>>0);"
278        print >>f, ""     
279        print >>f, "   %s" % opexecute
280        print >>f, "   %s" % opwrite_alt
281        print >>f, "   "
276        print("   COMMON32_GET_CONDITION;", file=f)
277        print("   if (!check_condition(condition))", file=f)
278        print("      return m_pc + (size>>0);", file=f)
279        print("", file=f)
280        print("   %s" % opexecute, file=f)
281        print("   %s" % opwrite_alt, file=f)
282        print("   ", file=f)
282283        EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
283        print >>f, "   return m_pc + (size >> 0);"
284        print >>f, "}"
285    print >>f, ""
286    print >>f, ""
284        print("   return m_pc + (size >> 0);", file=f)
285        print("}", file=f)
286    print("", file=f)
287    print("", file=f)
287288
288289
289290# xxx_S  c, b, u3  format opcodes (note c is destination)
290291def EmitGroup0d(f,funcname, opname, opexecute, opwrite):
291    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"  % funcname
292    print >>f, "{"
293    print >>f, "   int u, breg, creg;"
294    print >>f, ""
295    print >>f, "   COMMON16_GET_u3;"
296    print >>f, "   COMMON16_GET_breg;"
297    print >>f, "   COMMON16_GET_creg;"
298    print >>f, ""
299    print >>f, "   REG_16BIT_RANGE(breg);"
300    print >>f, "   REG_16BIT_RANGE(creg);"
301    print >>f, ""
302    print >>f, "   %s" % opexecute
303    print >>f, "   %s" % opwrite
304    print >>f, ""
305    print >>f, "   return m_pc + (2 >> 0);"
306    print >>f, "}"
307    print >>f, ""
308    print >>f, ""
292    print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"  % funcname, file=f)
293    print("{", file=f)
294    print("   int u, breg, creg;", file=f)
295    print("", file=f)
296    print("   COMMON16_GET_u3;", file=f)
297    print("   COMMON16_GET_breg;", file=f)
298    print("   COMMON16_GET_creg;", file=f)
299    print("", file=f)
300    print("   REG_16BIT_RANGE(breg);", file=f)
301    print("   REG_16BIT_RANGE(creg);", file=f)
302    print("", file=f)
303    print("   %s" % opexecute, file=f)
304    print("   %s" % opwrite, file=f)
305    print("", file=f)
306    print("   return m_pc + (2 >> 0);", file=f)
307    print("}", file=f)
308    print("", file=f)
309    print("", file=f)
309310
310311
311312# xxx_S b <- b,c format opcodes
312313def EmitGroup0f(f,funcname, opname, opexecute, opwrite):
313    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"% funcname
314    print >>f, "{"
315    print >>f, "   int breg, creg;"
316    print >>f, ""
317    print >>f, "   COMMON16_GET_breg;"
318    print >>f, "   COMMON16_GET_creg;"
319    print >>f, ""
320    print >>f, "   REG_16BIT_RANGE(breg);"
321    print >>f, "   REG_16BIT_RANGE(creg);"
322    print >>f, ""
323    print >>f, "   %s" % opexecute
324    print >>f, "   %s" % opwrite
325    print >>f, ""
326    print >>f, "   return m_pc + (2 >> 0);"
327    print >>f, "}"
328    print >>f, ""
329    print >>f, ""
314    print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"% funcname, file=f)
315    print("{", file=f)
316    print("   int breg, creg;", file=f)
317    print("", file=f)
318    print("   COMMON16_GET_breg;", file=f)
319    print("   COMMON16_GET_creg;", file=f)
320    print("", file=f)
321    print("   REG_16BIT_RANGE(breg);", file=f)
322    print("   REG_16BIT_RANGE(creg);", file=f)
323    print("", file=f)
324    print("   %s" % opexecute, file=f)
325    print("   %s" % opwrite, file=f)
326    print("", file=f)
327    print("   return m_pc + (2 >> 0);", file=f)
328    print("}", file=f)
329    print("", file=f)
330    print("", file=f)
330331
331332
332333#  xxx_S b, b, u5 format opcodes
333334def EmitGroup17(f,funcname, opname, opexecute):
334    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname
335    print >>f, "{"
336    print >>f, "   int breg, u;"
337    print >>f, "   "
338    print >>f, "   COMMON16_GET_breg;"
339    print >>f, "   COMMON16_GET_u5;"
340    print >>f, "   "
341    print >>f, "   REG_16BIT_RANGE(breg);"
342    print >>f, "   "
343    print >>f, "   %s" % opexecute
344    print >>f, "   "
345    print >>f, "   return m_pc + (2 >> 0);"
346    print >>f, "}"
347    print >>f, ""
348    print >>f, ""
335    print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname, file=f)
336    print("{", file=f)
337    print("   int breg, u;", file=f)
338    print("   ", file=f)
339    print("   COMMON16_GET_breg;", file=f)
340    print("   COMMON16_GET_u5;", file=f)
341    print("   ", file=f)
342    print("   REG_16BIT_RANGE(breg);", file=f)
343    print("   ", file=f)
344    print("   %s" % opexecute, file=f)
345    print("   ", file=f)
346    print("   return m_pc + (2 >> 0);", file=f)
347    print("}", file=f)
348    print("", file=f)
349    print("", file=f)
349350
350351
351352
trunk/src/emu/cpu/h8/h8make.py
r248581r248582
11#!/usr/bin/python
22
3from __future__ import print_function
4
35USAGE = """
46Usage:
57%s h8.lst <type> h8.inc (type = o/h/s20/s26)
r248581r248582
4547    return False
4648
4749def save_full_one(f, t, name, source):
48    print >>f, "void %s::%s_full()" % (t, name)
49    print >>f, "{"
50    print("void %s::%s_full()" % (t, name), file=f)
51    print("{", file=f)
5052    substate = 1
5153    for line in source:
5254        if has_memory(line):
53            print >>f, "\tif(icount <= bcount) { inst_substate = %d; return; }" % substate
54            print >>f, line
55            print("\tif(icount <= bcount) { inst_substate = %d; return; }" % substate, file=f)
56            print(line, file=f)
5557            substate += 1
5658        elif has_eat(line):
57            print >>f, "\tif(icount) icount = bcount; inst_substate = %d; return;" % substate
59            print("\tif(icount) icount = bcount; inst_substate = %d; return;" % substate, file=f)
5860            substate += 1
5961        else:
60            print >>f, line
61    print >>f, "}"
62    print >>f
62            print(line, file=f)
63    print("}", file=f)
64    print("", file=f)
6365
6466def save_partial_one(f, t, name, source):
65    print >>f, "void %s::%s_partial()" % (t, name)
66    print >>f, "{"
67    print >>f, "switch(inst_substate) {"
68    print >>f, "case 0:"
67    print("void %s::%s_partial()" % (t, name), file=f)
68    print("{", file=f)
69    print("switch(inst_substate) {", file=f)
70    print("case 0:", file=f)
6971    substate = 1
7072    for line in source:
7173        if has_memory(line):
72            print >>f, "\tif(icount <= bcount) { inst_substate = %d; return; }" % substate
73            print >>f, "case %d:;" % substate
74            print >>f, line
74            print("\tif(icount <= bcount) { inst_substate = %d; return; }" % substate, file=f)
75            print("case %d:;" % substate, file=f)
76            print(line, file=f)
7577            substate += 1
7678        elif has_eat(line):
77            print >>f, "\tif(icount) icount = bcount; inst_substate = %d; return;" % substate
78            print >>f, "case %d:;" % substate
79            print("\tif(icount) icount = bcount; inst_substate = %d; return;" % substate, file=f)
80            print("case %d:;" % substate, file=f)
7981            substate += 1
8082        else:
81            print >>f, line
82    print >>f, "\tbreak;"
83    print >>f, "}"
84    print >>f, "\tinst_substate = 0;"
85    print >>f, "}"
86    print >>f
83            print(line, file=f)
84    print("\tbreak;", file=f)
85    print("}", file=f)
86    print("\tinst_substate = 0;", file=f)
87    print("}", file=f)
88    print("", file=f)
8789
8890class Hash:
8991    def __init__(self, premask):
r248581r248582
185187        else:
186188            flags = "%d" % size
187189       
188        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")
190        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)
189191
190192class Special:
191193    def __init__(self, val, name, otype, dtype):
r248581r248582
244246        return True
245247
246248    def source(self):
247        start = self.pos / 2
249        start = self.pos // 2
248250        end = start + self.skip
249251        s = []
250252        for i in range(start, end+1):
r248581r248582
345347                        h = self.get(d.id)
346348   
347349    def save_dasm(self, f, dname):
348        print >>f, "const %s::disasm_entry %s::disasm_entries[] = {" % (dname, dname)
350        print("const %s::disasm_entry %s::disasm_entries[] = {" % (dname, dname), file=f)
349351        for opc in self.opcode_info:
350352            if opc.enabled:
351353                opc.save_dasm(f)
352        print >>f, "\t{ 0, 0, 0, 0, 0, \"illegal\", 0, 0, 2 },"
353        print >>f, "};"
354        print >>f
354        print("\t{ 0, 0, 0, 0, 0, \"illegal\", 0, 0, 2 },", file=f)
355        print("};", file=f)
356        print("", file=f)
355357   
356358    def save_opcodes(self, f, t):
357359        for opc in self.opcode_info:
r248581r248582
370372            save_partial_one(f, t, "dispatch_" + dsp.name, dsp.source())
371373   
372374    def save_exec(self, f, t, dtype, v):
373        print >>f, "void %s::do_exec_%s()" % (t, v)
374        print >>f, "{"
375        print >>f, "\tswitch(inst_state >> 16) {"
375        print("void %s::do_exec_%s()" % (t, v), file=f)
376        print("{", file=f)
377        print("\tswitch(inst_state >> 16) {", file=f)
376378        for i in range(0, len(self.dispatch_info)+2):
377379            if i == 1:
378                print >>f, "\tcase 0x01: {"
379                print >>f, "\t\tswitch(inst_state & 0xffff) {"
380                print("\tcase 0x01: {", file=f)
381                print("\t\tswitch(inst_state & 0xffff) {", file=f)
380382                for sta in self.states_info:
381383                    if sta.enabled:
382                        print >>f, "\t\tcase 0x%02x: state_%s_%s(); break;" % (sta.val & 0xffff, sta.name, v)
383                print >>f, "\t\t}"
384                print >>f, "\t\tbreak;"
385                print >>f, "\t}"
384                        print("\t\tcase 0x%02x: state_%s_%s(); break;" % (sta.val & 0xffff, sta.name, v), file=f)
385                print("\t\t}", file=f)
386                print("\t\tbreak;", file=f)
387                print("\t}", file=f)
386388            else:
387389                if i == 0 or self.dispatch_info[i-2].enabled:
388                    print >>f, "\tcase 0x%02x: {" % i
390                    print("\tcase 0x%02x: {" % i, file=f)
389391                    h = self.get(i)
390                    print >>f, "\t\tswitch((inst_state >> 8) & 0x%02x) {" % h.mask
392                    print("\t\tswitch((inst_state >> 8) & 0x%02x) {" % h.mask, file=f)
391393                    for val, h2 in sorted(h.d.items()):
392394                        if h2.enabled:
393395                            fmask = h2.premask | (h.mask ^ 0xff)
r248581r248582
398400                                s += 1
399401                                while s & fmask:
400402                                    s += s & fmask
401                            print >>f, "\t\t%s{" % c
403                            print("\t\t%s{" % c, file=f)
402404                            if h2.mask == 0x00:
403405                                n = h2.d[0]
404406                                if n.is_dispatch():
405                                    print >>f, "\t\t\tdispatch_%s_%s();" % (n.name, v)
407                                    print("\t\t\tdispatch_%s_%s();" % (n.name, v), file=f)
406408                                else:
407                                    print >>f, "\t\t\t%s_%s();" % (n.function_name(), v)
408                                print >>f, "\t\t\tbreak;"
409                                    print("\t\t\t%s_%s();" % (n.function_name(), v), file=f)
410                                print("\t\t\tbreak;", file=f)
409411                            else:
410                                print >>f, "\t\t\tswitch(inst_state & 0x%02x) {" % h2.mask
412                                print("\t\t\tswitch(inst_state & 0x%02x) {" % h2.mask, file=f)
411413                                if i == 0:
412414                                    mpos = 1
413415                                else:
r248581r248582
427429                                            while s & fmask:
428430                                                s += s & fmask
429431                                        if n.is_dispatch():
430                                            print >>f, "\t\t\t%sdispatch_%s_%s(); break;" % (c, n.name, v)
432                                            print("\t\t\t%sdispatch_%s_%s(); break;" % (c, n.name, v), file=f)
431433                                        else:
432                                            print >>f, "\t\t\t%s%s_%s(); break;" % (c, n.function_name(), v)
433                                print >>f, "\t\t\tdefault: illegal(); break;"
434                                print >>f, "\t\t\t}"
435                                print >>f, "\t\t\tbreak;"
436                            print >>f, "\t\t}"
437                    print >>f, "\t\tdefault: illegal(); break;"
438                    print >>f, "\t\t}"
439                    print >>f, "\t\tbreak;"
440                    print >>f, "\t}"
441        print >>f, "\t}"
442        print >>f, "}"
434                                            print("\t\t\t%s%s_%s(); break;" % (c, n.function_name(), v), file=f)
435                                print("\t\t\tdefault: illegal(); break;", file=f)
436                                print("\t\t\t}", file=f)
437                                print("\t\t\tbreak;", file=f)
438                            print("\t\t}", file=f)
439                    print("\t\tdefault: illegal(); break;", file=f)
440                    print("\t\t}", file=f)
441                    print("\t\tbreak;", file=f)
442                    print("\t}", file=f)
443        print("\t}", file=f)
444        print("}", file=f)
443445
444446def main(argv):
445447    if len(argv) != 4:
446        print USAGE % argv[0]
448        print(USAGE % argv[0])
447449        return 1
448450
449451    dtype = name_to_type(argv[2])
trunk/src/emu/cpu/m6502/m6502make.py
r248581r248582
11#!/usr/bin/python
22
3from __future__ import print_function
4
35USAGE = """
46Usage:
57%s device_name {opc.lst|-} disp.lst device.inc
r248581r248582
5254
5355def emit(f, text):
5456    """write string to file"""
55    print >>f, text,
57    print(text, file=f)
5658
5759FULL_PROLOG="""\
5860void %(device)s::%(opcode)s_full()
r248581r248582
252254
253255
254256    if len(argv) != 5:
255        print USAGE % argv[0]
257        print(USAGE % argv[0])
256258        return 1
257259
258260    device_name = argv[1]
trunk/src/emu/cpu/mcs96/mcs96make.py
r248581r248582
11#!/usr/bin/python
22
3from __future__ import print_function
4
35USAGE = """
46Usage:
57%s mcs96ops.lst mcs96.inc
r248581r248582
79import sys
810
911def save_full_one(f, t, name, source):
10    print >>f, "void %s_device::%s_full()" % (t, name)
11    print >>f, "{"
12    print("void %s_device::%s_full()" % (t, name), file=f)
13    print("{", file=f)
1214    for line in source:
13        print >>f, line
14    print >>f, "}"
15    print >>f
15        print(line, file=f)
16    print("}", file=f)
17    print("", file=f)
1618
1719class Opcode:
1820    def __init__(self, rng, name, amode, is_196, ea):
r248581r248582
113115                            self.opcode_per_id[i] = inf
114116
115117    def save_dasm(self, f, t):
116        print >>f, "const %s_device::disasm_entry %s_device::disasm_entries[0x100] = {" % (t, t)
118        print("const %s_device::disasm_entry %s_device::disasm_entries[0x100] = {" % (t, t), file=f)
117119        for i in range(0, 0x100):
118120            if i in self.opcode_per_id:
119121                opc = self.opcode_per_id[i]
r248581r248582
126128                    flags = "DASMFLAG_STEP_OUT"
127129                else:
128130                    flags = "0"
129                print >>f, "\t{ \"%s\", %s, DASM_%s, %s }," % (opc.name, alt, opc.amode, flags)
131                print("\t{ \"%s\", %s, DASM_%s, %s }," % (opc.name, alt, opc.amode, flags), file=f)
130132            else:
131                print >>f, "\t{ \"???\", NULL, DASM_none, 0 },"
132        print >>f, "};"
133        print >>f
133                print("\t{ \"???\", NULL, DASM_none, 0 },", file=f)
134        print("};", file=f)
135        print("", file=f)
134136   
135137    def save_opcodes(self, f, t):
136138        pf = ""
r248581r248582
146148            save_full_one(f, t, "fetch_noirq", self.fetch_noirq.source)
147149   
148150    def save_exec(self, f, t):
149        print >>f, "void %s_device::do_exec_full()" % t
150        print >>f, "{"
151        print >>f, "\tswitch(inst_state) {"
151        print("void %s_device::do_exec_full()" % t, file=f)
152        print("{", file=f)
153        print("\tswitch(inst_state) {", file=f)
152154        for i in range(0x000, 0x200):
153155            opc = None
154156            if i >= 0x100 and i-0x100+0xfe00 in self.opcode_per_id:
r248581r248582
159161                nm = opc.name + "_" + opc.amode
160162                if opc.is_196:
161163                    nm += "_196"
162                print >>f, "\tcase 0x%03x: %s_full(); break;" % (i, nm)
163        print >>f, "\tcase 0x200: fetch_full(); break;"
164        print >>f, "\tcase 0x201: fetch_noirq_full(); break;"
165        print >>f, "\t}"
166        print >>f, "}"
164                print("\tcase 0x%03x: %s_full(); break;" % (i, nm), file=f)
165        print("\tcase 0x200: fetch_full(); break;", file=f)
166        print("\tcase 0x201: fetch_noirq_full(); break;", file=f)
167        print("\t}", file=f)
168        print("}", file=f)
167169
168170def main(argv):
169171    if len(argv) != 4:
170        print USAGE % argv[0]
172        print(USAGE % argv[0])
171173        return 1
172174   
173175    t = argv[1]


Previous 199869 Revisions Next


© 1997-2024 The MAME Team