Previous 199869 Revisions Next

r36256 Thursday 5th March, 2015 at 15:38:07 UTC by Oliver Stöneberg
more Python script cleanups based on PyCharm inspection (nw)
[src/build]file2str.py verinfo.py
[src/emu/cpu/arcompact]arcompact_make.py
[src/emu/cpu/h8]h8make.py
[src/emu/cpu/m6809]m6809make.py
[src/emu/cpu/mcs96]mcs96make.py
[src/emu/cpu/tms57002]tmsmake.py

trunk/src/build/file2str.py
r244767r244768
55import sys
66import os
77
8if (len(sys.argv) < 4) :
8if len(sys.argv) < 4:
99    print('Usage:')
1010    print('  file2str <source.lay> <output.h> <varname> [<type>]')
1111    print('')
r244767r244768
1717dstfile = sys.argv[2]
1818varname = sys.argv[3]
1919
20if (len(sys.argv) >= 5) :
20if len(sys.argv) >= 5:
2121    type = sys.argv[4]
2222    terminate = 0
2323else:
r244767r244768
3232byteCount = os.path.getsize(srcfile)
3333try:
3434    dst = open(dstfile,'w')
35    dst.write('extern const %s %s[];\n' % ( type, varname ));
36    dst.write('const %s %s[] =\n{\n\t' % ( type, varname));
35    dst.write('extern const %s %s[];\n' % ( type, varname ))
36    dst.write('const %s %s[] =\n{\n\t' % ( type, varname))
3737    offs = 0
3838    with open(srcfile, "rb") as src:
3939        while True:
r244767r244768
4444                    if isinstance(b, str):
4545                        b = ord(b)
4646                    dst.write('0x%02x' % b)
47                    offs = offs + 1
47                    offs += 1
4848                    if offs != byteCount:
4949                        dst.write(',')
5050            else:
trunk/src/build/verinfo.py
r244767r244768
120120    fp.write('\tFILEVERSION %s,%s,%s,%s\n' % (version_major, version_minor, version_build, version_subbuild))
121121    fp.write('\tPRODUCTVERSION %s,%s,%s,%s\n' % (version_major, version_minor, version_build, version_subbuild))
122122    fp.write('\tFILEFLAGSMASK 0x3fL\n')
123    if (version_build == 0):
123    if version_build == 0:
124124        fp.write('\tFILEFLAGS 0x0L\n')
125125    else:
126126        fp.write('\tFILEFLAGS VS_FF_PRERELEASE\n')
trunk/src/emu/cpu/arcompact/arcompact_make.py
r244767r244768
114114
115115def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler):
116116    # the mode 0x00 handler 
117    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p00(OPS_32)" % (funcname)
117    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p00(OPS_32)" % funcname
118118    print >>f, "{"
119119    print >>f, "   int size = 4;"
120120   
r244767r244768
170170    print >>f, "   }"
171171    print >>f, "   /* todo: is the limm, limm syntax valid? (it's pointless.) */"
172172    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)   
173    print >>f, "   %s" % opexecute
174    print >>f, "   %s" % opwrite
175175    print >>f, "   "
176176    EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
177177    print >>f, "   return m_pc + (size >> 0);"
r244767r244768
179179    print >>f, ""
180180    print >>f, ""
181181    # the mode 0x01 handler   
182    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p01(OPS_32)" % (funcname)
182    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p01(OPS_32)" % funcname
183183    print >>f, "{"
184184    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)   
185    print >>f, "   %s" % opexecute
186    print >>f, "   %s" % opwrite
187187    print >>f, "   "
188188    EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
189189    print >>f, "   return m_pc + (size >> 0);"
r244767r244768
191191    print >>f, ""
192192    print >>f, ""
193193    # the mode 0x10 handler
194    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p10(OPS_32)" % (funcname)
194    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p10(OPS_32)" % funcname
195195    if ignore_a == 2:
196196        print >>f, "{"
197197        print >>f, "   int size = 4;"
r244767r244768
237237        print >>f, "    c = (UINT32)S;"
238238        print >>f, "   "
239239        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)   
240        print >>f, "   %s" % opexecute
241        print >>f, "   %s" % opwrite_alt
242242        print >>f, "   "
243243        EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
244244        print >>f, "   return m_pc + (size >> 0);"
r244767r244768
246246    print >>f, ""
247247    print >>f, ""
248248    # the mode 0x11 m0 handler   
249    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m0(OPS_32)" % (funcname)
249    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m0(OPS_32)" % funcname
250250    if ignore_a == 2:
251251        print >>f, "{"
252252        print >>f, "   int size = 4;"
r244767r244768
262262        print >>f, ""
263263        print >>f, ""   
264264    # the mode 0x11 m1 handler   
265    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m1(OPS_32)" % (funcname)
265    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m1(OPS_32)" % funcname
266266    if ignore_a == 2:
267267        print >>f, "{"
268268        print >>f, "   int size = 4;"
r244767r244768
276276        print >>f, "   if (!check_condition(condition))"
277277        print >>f, "      return m_pc + (size>>0);"
278278        print >>f, ""     
279        print >>f, "   %s" % (opexecute)
280        print >>f, "   %s" % (opwrite_alt)   
279        print >>f, "   %s" % opexecute
280        print >>f, "   %s" % opwrite_alt
281281        print >>f, "   "
282282        EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
283283        print >>f, "   return m_pc + (size >> 0);"
r244767r244768
288288
289289# xxx_S  c, b, u3  format opcodes (note c is destination)
290290def EmitGroup0d(f,funcname, opname, opexecute, opwrite):
291    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"  % (funcname)
291    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"  % funcname
292292    print >>f, "{"
293293    print >>f, "   int u, breg, creg;"
294294    print >>f, ""
r244767r244768
299299    print >>f, "   REG_16BIT_RANGE(breg);"
300300    print >>f, "   REG_16BIT_RANGE(creg);"
301301    print >>f, ""
302    print >>f, "   %s" % (opexecute)
303    print >>f, "   %s" % (opwrite)
302    print >>f, "   %s" % opexecute
303    print >>f, "   %s" % opwrite
304304    print >>f, ""
305305    print >>f, "   return m_pc + (2 >> 0);"
306306    print >>f, "}"
r244767r244768
310310
311311# xxx_S b <- b,c format opcodes
312312def EmitGroup0f(f,funcname, opname, opexecute, opwrite):
313    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"% (funcname)
313    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"% funcname
314314    print >>f, "{"
315315    print >>f, "   int breg, creg;"
316316    print >>f, ""
r244767r244768
320320    print >>f, "   REG_16BIT_RANGE(breg);"
321321    print >>f, "   REG_16BIT_RANGE(creg);"
322322    print >>f, ""
323    print >>f, "   %s" % (opexecute)
324    print >>f, "   %s" % (opwrite)   
323    print >>f, "   %s" % opexecute
324    print >>f, "   %s" % opwrite
325325    print >>f, ""
326326    print >>f, "   return m_pc + (2 >> 0);"
327327    print >>f, "}"
r244767r244768
331331
332332#  xxx_S b, b, u5 format opcodes
333333def EmitGroup17(f,funcname, opname, opexecute):
334    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % (funcname)
334    print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname
335335    print >>f, "{"
336336    print >>f, "   int breg, u;"
337337    print >>f, "   "
r244767r244768
340340    print >>f, "   "
341341    print >>f, "   REG_16BIT_RANGE(breg);"
342342    print >>f, "   "
343    print >>f, "   %s" % (opexecute)
343    print >>f, "   %s" % opexecute
344344    print >>f, "   "
345345    print >>f, "   return m_pc + (2 >> 0);"
346346    print >>f, "}"
trunk/src/emu/cpu/h8/h8make.py
r244767r244768
77import sys
88
99def name_to_type(name):
10    if(name == "o"):
10    if name == "o":
1111        return 0
12    if(name == "h"):
12    if name == "h":
1313        return 1
14    if(name == "s20"):
14    if name == "s20":
1515        return 2
16    if(name == "s26"):
16    if name == "s26":
1717        return 3
1818    print "Unknown chip type name %s" % name
1919    sys.exit(1)
2020
2121def type_to_device(dtype):
22    if(dtype == 0):
22    if dtype == 0:
2323        return "h8_device"
24    if(dtype == 1):
24    if dtype == 1:
2525        return "h8h_device"
26    if(dtype == 2):
26    if dtype == 2:
2727        return "h8s2000_device"
2828    return "h8s2600_device"
2929
r244767r244768
5252        if has_memory(line):
5353            print >>f, "\tif(icount <= bcount) { inst_substate = %d; return; }" % substate
5454            print >>f, line
55            substate = substate + 1
55            substate += 1
5656        elif has_eat(line):
5757            print >>f, "\tif(icount) icount = bcount; inst_substate = %d; return;" % substate
58            substate = substate + 1
58            substate += 1
5959        else:
6060            print >>f, line
6161    print >>f, "}"
r244767r244768
7272            print >>f, "\tif(icount <= bcount) { inst_substate = %d; return; }" % substate
7373            print >>f, "case %d:;" % substate
7474            print >>f, line
75            substate = substate + 1
75            substate += 1
7676        elif has_eat(line):
7777            print >>f, "\tif(icount) icount = bcount; inst_substate = %d; return;" % substate
7878            print >>f, "case %d:;" % substate
79            substate = substate + 1
79            substate += 1
8080        else:
8181            print >>f, line
8282    print >>f, "\tbreak;"
r244767r244768
122122        self.enabled = otype == -1 or (otype == 0 and dtype == 0) or (otype != 0 and dtype >= otype)
123123        self.needed = self.enabled and (otype == dtype or (otype == -1 and dtype == 0))
124124        if dtype == 0 and (am1 == "r16l" or am2 == "r16l"):
125            self.mask[len(self.mask)-1] = self.mask[len(self.mask)-1] | 0x08
125            self.mask[len(self.mask) - 1] |= 0x08
126126        if dtype == 0 and (am1 == "r16h" or am2 == "r16h"):
127            self.mask[len(self.mask)-1] = self.mask[len(self.mask)-1] | 0x80
127            self.mask[len(self.mask) - 1] |= 0x80
128128        extra_words = 0
129129        if (am1 == "abs16" or am2 == "abs16" or am1 == "abs16e" or am1 == "abs24e") and self.skip == 0:
130            extra_words = extra_words + 1
130            extra_words += 1
131131        if (am1 == "abs32" or am2 == "abs32") and self.skip == 0:
132            extra_words = extra_words + 2
132            extra_words += 2
133133        if am1 == "imm16" or am1 == "rel16" or am1 == "r16d16h" or am2 == "r16d16h" or am1 == "r32d16h" or am2 == "r32d16h":
134            extra_words = extra_words + 1
134            extra_words += 1
135135        if am1 == "imm32" or am1 == "r32d32hh" or am2 == "r32d32hh":
136            extra_words = extra_words + 2
136            extra_words += 2
137137        self.extra_words = extra_words
138138        base_offset = len(self.val)/2 + self.skip
139139        for i in range(0, extra_words):
140            self.source.append("\tfetch(%d);\n" % (i+base_offset));
140            self.source.append("\tfetch(%d);\n" % (i+base_offset))
141141
142142    def description(self):
143143        return "%s %s %s" % (self.name, self.am1, self.am2)
r244767r244768
217217        lval = ""
218218        for i in range(len(self.params)-1, len(tokens)-1):
219219            if lval != "":
220                lval = lval + " "
220                lval += " "
221221            lval = lval + tokens[i+1]
222222        values.append(lval)
223223        for i in range(0, len(self.source)):
r244767r244768
234234        self.enabled = False
235235        self.mask = opc.mask[pos-1]
236236        for i in range(0, pos):
237            self.name = self.name + ("%02x" % opc.val[i])
237            self.name += "%02x" % opc.val[i]
238238        if pos == 2:
239239            self.skip = opc.skip
240240        else:
r244767r244768
250250        for i in range(start, end+1):
251251            s.append("\tIR[%d] = fetch();" % i)
252252        s.append("\tinst_state = 0x%x0000 | IR[%d];" % (self.id, end))
253        return s;
253        return s
254254
255
255256class OpcodeList:
256257    def __init__(self, fname, dtype):
257258        self.opcode_info = []
r244767r244768
392393                            fmask = h2.premask | (h.mask ^ 0xff)
393394                            c = ""
394395                            s = 0
395                            while(s < 0x100):
396                                c = c + "case 0x%02x: " % (val | s)
397                                s = s + 1
398                                while(s & fmask):
399                                    s = s + (s & fmask)                   
396                            while s < 0x100:
397                                c += "case 0x%02x: " % (val | s)
398                                s += 1
399                                while s & fmask:
400                                    s += s & fmask
400401                            print >>f, "\t\t%s{" % c
401402                            if h2.mask == 0x00:
402403                                n = h2.d[0]
r244767r244768
420421                                            fmask = fmask | n.mask[mpos]
421422                                        c = ""
422423                                        s = 0
423                                        while(s < 0x100):
424                                            c = c + "case 0x%02x: " % (val2 | s)
425                                            s = s + 1
426                                            while(s & fmask):
427                                                s = s + (s & fmask)
424                                        while s < 0x100:
425                                            c += "case 0x%02x: " % (val2 | s)
426                                            s += 1
427                                            while s & fmask:
428                                                s += s & fmask
428429                                        if n.is_dispatch():
429430                                            print >>f, "\t\t\t%sdispatch_%s_%s(); break;" % (c, n.name, v)
430431                                        else:
trunk/src/emu/cpu/m6809/m6809make.py
r244767r244768
1212def load_file(fname, lines):
1313   path = fname.rpartition('/')[0]
1414   if path != "":
15      path = path + '/'
15      path += '/'
1616   try:
1717      f = open(fname, "rU")
1818   except Exception:
r244767r244768
2828         load_file(path + line.split('"')[1], lines)
2929      else:
3030         lines.append(line)
31      count = count + 2
31      count += 2
3232   
3333   f.close()
3434
r244767r244768
5757
5858      # Do we have a label?
5959      label = line[:percent_pos].strip()
60      if (label != ""):
60      if label != "":
6161         text += whitespace + label + "\n"
62         whitespace = whitespace + "\t"
62         whitespace += "\t"
6363     
6464      # Create the goto command
65      if (dispatch[-1:] == "*"):
65      if dispatch[-1:] == "*":
6666         goto_command = "if (is_register_register_op_16_bit()) goto %s16; else goto %s8;\n" %(dispatch[:-1], dispatch[:-1])
6767      else:
6868         goto_command = "goto %s;\n" % dispatch
r244767r244768
7070      # Are we right before a 'return'?
7171      if next_line_is_return:
7272         text += whitespace + goto_command
73         count = count + 1   # Skip the return
73         count += 1  # Skip the return
7474      elif next_line_is_dispatch_and_return:
7575         # We are followed by a dispatch/return combo; identify the next dispatch
7676         percent_pos = lines[count+1].find("%")
r244767r244768
8080         if next_dispatch not in dispatch_to_states:
8181            dispatch_to_states[next_dispatch] = state
8282            states_to_dispatch[state] = next_dispatch
83            state = state + 1
83            state += 1
8484
8585         text += whitespace + "push_state(%s);\t// %s\n" % (dispatch_to_states[next_dispatch], next_dispatch)
8686         text += whitespace + goto_command
87         count = count + 2   # Skip the dispatch/return
88                     
87         count += 2  # Skip the dispatch/return
88
8989      else:
9090         # Normal dispatch
91         text += whitespace + "push_state(%s);\n" % (state)
91         text += whitespace + "push_state(%s);\n" % state
9292         text += whitespace + goto_command
93         text += "state_%s:\n" % (state)
94         state = state + 1
93         text += "state_%s:\n" % state
94         state += 1
9595   else:
9696      # "Normal" code
9797      # Is there an '@' here?
r244767r244768
104104
105105      # If we have to decrement the icount, output more info
106106      if check_icount and not next_line_is_return:
107         text += whitespace + "if (UNEXPECTED(m_icount <= 0)) { push_state(%s); return; }\n" % (state)
108         text += "state_%s:\n" % (state)
109         state = state + 1
107         text += whitespace + "if (UNEXPECTED(m_icount <= 0)) { push_state(%s); return; }\n" % state
108         text += "state_%s:\n" % state
109         state += 1
110110
111111   # Advance to next line
112   count = count + 1
112   count += 1
113113
114114# Output the case labels
115115for i in range(0, state):
trunk/src/emu/cpu/mcs96/mcs96make.py
r244767r244768
158158            if opc != None:
159159                nm = opc.name + "_" + opc.amode
160160                if opc.is_196:
161                    nm = nm + "_196"
161                   nm += "_196"
162162                print >>f, "\tcase 0x%03x: %s_full(); break;" % (i, nm)
163163        print >>f, "\tcase 0x200: fetch_full(); break;"
164164        print >>f, "\tcase 0x201: fetch_noirq_full(); break;"
trunk/src/emu/cpu/tms57002/tmsmake.py
r244767r244768
269269                if v in flags_fixed:
270270                    #print "@@@@", f
271271                    vals.append("%s=%d" % (v, flags_fixed[v]))
272            out = []
273            out.append("case %d: // %s %s" % (no, self._name, " ".join(vals)))
272            out = ["case %d: // %s %s" % (no, self._name, " ".join(vals))]
274273            for line in self.PreprocessRunString():
275274                out.append(self.ExpandCintrp(line, flags_fixed))
276275            out.append("  break;")


Previous 199869 Revisions Next


© 1997-2024 The MAME Team