trunk/src/emu/cpu/arcompact/arcompact_make.py
| r244767 | r244768 | |
| 114 | 114 | |
| 115 | 115 | def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler): |
| 116 | 116 | # 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 |
| 118 | 118 | print >>f, "{" |
| 119 | 119 | print >>f, " int size = 4;" |
| 120 | 120 | |
| r244767 | r244768 | |
| 170 | 170 | print >>f, " }" |
| 171 | 171 | print >>f, " /* todo: is the limm, limm syntax valid? (it's pointless.) */" |
| 172 | 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) |
| 173 | print >>f, " %s" % opexecute |
| 174 | print >>f, " %s" % opwrite |
| 175 | 175 | print >>f, " " |
| 176 | 176 | EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) |
| 177 | 177 | print >>f, " return m_pc + (size >> 0);" |
| r244767 | r244768 | |
| 179 | 179 | print >>f, "" |
| 180 | 180 | print >>f, "" |
| 181 | 181 | # 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 |
| 183 | 183 | print >>f, "{" |
| 184 | 184 | 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 |
| 187 | 187 | print >>f, " " |
| 188 | 188 | EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) |
| 189 | 189 | print >>f, " return m_pc + (size >> 0);" |
| r244767 | r244768 | |
| 191 | 191 | print >>f, "" |
| 192 | 192 | print >>f, "" |
| 193 | 193 | # 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 |
| 195 | 195 | if ignore_a == 2: |
| 196 | 196 | print >>f, "{" |
| 197 | 197 | print >>f, " int size = 4;" |
| r244767 | r244768 | |
| 237 | 237 | print >>f, " c = (UINT32)S;" |
| 238 | 238 | print >>f, " " |
| 239 | 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) |
| 240 | print >>f, " %s" % opexecute |
| 241 | print >>f, " %s" % opwrite_alt |
| 242 | 242 | print >>f, " " |
| 243 | 243 | EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) |
| 244 | 244 | print >>f, " return m_pc + (size >> 0);" |
| r244767 | r244768 | |
| 246 | 246 | print >>f, "" |
| 247 | 247 | print >>f, "" |
| 248 | 248 | # 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 |
| 250 | 250 | if ignore_a == 2: |
| 251 | 251 | print >>f, "{" |
| 252 | 252 | print >>f, " int size = 4;" |
| r244767 | r244768 | |
| 262 | 262 | print >>f, "" |
| 263 | 263 | print >>f, "" |
| 264 | 264 | # 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 |
| 266 | 266 | if ignore_a == 2: |
| 267 | 267 | print >>f, "{" |
| 268 | 268 | print >>f, " int size = 4;" |
| r244767 | r244768 | |
| 276 | 276 | print >>f, " if (!check_condition(condition))" |
| 277 | 277 | print >>f, " return m_pc + (size>>0);" |
| 278 | 278 | print >>f, "" |
| 279 | | print >>f, " %s" % (opexecute) |
| 280 | | print >>f, " %s" % (opwrite_alt) |
| 279 | print >>f, " %s" % opexecute |
| 280 | print >>f, " %s" % opwrite_alt |
| 281 | 281 | print >>f, " " |
| 282 | 282 | EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) |
| 283 | 283 | print >>f, " return m_pc + (size >> 0);" |
| r244767 | r244768 | |
| 288 | 288 | |
| 289 | 289 | # xxx_S c, b, u3 format opcodes (note c is destination) |
| 290 | 290 | def 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 |
| 292 | 292 | print >>f, "{" |
| 293 | 293 | print >>f, " int u, breg, creg;" |
| 294 | 294 | print >>f, "" |
| r244767 | r244768 | |
| 299 | 299 | print >>f, " REG_16BIT_RANGE(breg);" |
| 300 | 300 | print >>f, " REG_16BIT_RANGE(creg);" |
| 301 | 301 | print >>f, "" |
| 302 | | print >>f, " %s" % (opexecute) |
| 303 | | print >>f, " %s" % (opwrite) |
| 302 | print >>f, " %s" % opexecute |
| 303 | print >>f, " %s" % opwrite |
| 304 | 304 | print >>f, "" |
| 305 | 305 | print >>f, " return m_pc + (2 >> 0);" |
| 306 | 306 | print >>f, "}" |
| r244767 | r244768 | |
| 310 | 310 | |
| 311 | 311 | # xxx_S b <- b,c format opcodes |
| 312 | 312 | def 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 |
| 314 | 314 | print >>f, "{" |
| 315 | 315 | print >>f, " int breg, creg;" |
| 316 | 316 | print >>f, "" |
| r244767 | r244768 | |
| 320 | 320 | print >>f, " REG_16BIT_RANGE(breg);" |
| 321 | 321 | print >>f, " REG_16BIT_RANGE(creg);" |
| 322 | 322 | print >>f, "" |
| 323 | | print >>f, " %s" % (opexecute) |
| 324 | | print >>f, " %s" % (opwrite) |
| 323 | print >>f, " %s" % opexecute |
| 324 | print >>f, " %s" % opwrite |
| 325 | 325 | print >>f, "" |
| 326 | 326 | print >>f, " return m_pc + (2 >> 0);" |
| 327 | 327 | print >>f, "}" |
| r244767 | r244768 | |
| 331 | 331 | |
| 332 | 332 | # xxx_S b, b, u5 format opcodes |
| 333 | 333 | def 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 |
| 335 | 335 | print >>f, "{" |
| 336 | 336 | print >>f, " int breg, u;" |
| 337 | 337 | print >>f, " " |
| r244767 | r244768 | |
| 340 | 340 | print >>f, " " |
| 341 | 341 | print >>f, " REG_16BIT_RANGE(breg);" |
| 342 | 342 | print >>f, " " |
| 343 | | print >>f, " %s" % (opexecute) |
| 343 | print >>f, " %s" % opexecute |
| 344 | 344 | print >>f, " " |
| 345 | 345 | print >>f, " return m_pc + (2 >> 0);" |
| 346 | 346 | print >>f, "}" |
trunk/src/emu/cpu/h8/h8make.py
| r244767 | r244768 | |
| 7 | 7 | import sys |
| 8 | 8 | |
| 9 | 9 | def name_to_type(name): |
| 10 | | if(name == "o"): |
| 10 | if name == "o": |
| 11 | 11 | return 0 |
| 12 | | if(name == "h"): |
| 12 | if name == "h": |
| 13 | 13 | return 1 |
| 14 | | if(name == "s20"): |
| 14 | if name == "s20": |
| 15 | 15 | return 2 |
| 16 | | if(name == "s26"): |
| 16 | if name == "s26": |
| 17 | 17 | return 3 |
| 18 | 18 | print "Unknown chip type name %s" % name |
| 19 | 19 | sys.exit(1) |
| 20 | 20 | |
| 21 | 21 | def type_to_device(dtype): |
| 22 | | if(dtype == 0): |
| 22 | if dtype == 0: |
| 23 | 23 | return "h8_device" |
| 24 | | if(dtype == 1): |
| 24 | if dtype == 1: |
| 25 | 25 | return "h8h_device" |
| 26 | | if(dtype == 2): |
| 26 | if dtype == 2: |
| 27 | 27 | return "h8s2000_device" |
| 28 | 28 | return "h8s2600_device" |
| 29 | 29 | |
| r244767 | r244768 | |
| 52 | 52 | if has_memory(line): |
| 53 | 53 | print >>f, "\tif(icount <= bcount) { inst_substate = %d; return; }" % substate |
| 54 | 54 | print >>f, line |
| 55 | | substate = substate + 1 |
| 55 | substate += 1 |
| 56 | 56 | elif has_eat(line): |
| 57 | 57 | print >>f, "\tif(icount) icount = bcount; inst_substate = %d; return;" % substate |
| 58 | | substate = substate + 1 |
| 58 | substate += 1 |
| 59 | 59 | else: |
| 60 | 60 | print >>f, line |
| 61 | 61 | print >>f, "}" |
| r244767 | r244768 | |
| 72 | 72 | print >>f, "\tif(icount <= bcount) { inst_substate = %d; return; }" % substate |
| 73 | 73 | print >>f, "case %d:;" % substate |
| 74 | 74 | print >>f, line |
| 75 | | substate = substate + 1 |
| 75 | substate += 1 |
| 76 | 76 | elif has_eat(line): |
| 77 | 77 | print >>f, "\tif(icount) icount = bcount; inst_substate = %d; return;" % substate |
| 78 | 78 | print >>f, "case %d:;" % substate |
| 79 | | substate = substate + 1 |
| 79 | substate += 1 |
| 80 | 80 | else: |
| 81 | 81 | print >>f, line |
| 82 | 82 | print >>f, "\tbreak;" |
| r244767 | r244768 | |
| 122 | 122 | self.enabled = otype == -1 or (otype == 0 and dtype == 0) or (otype != 0 and dtype >= otype) |
| 123 | 123 | self.needed = self.enabled and (otype == dtype or (otype == -1 and dtype == 0)) |
| 124 | 124 | 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 |
| 126 | 126 | 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 |
| 128 | 128 | extra_words = 0 |
| 129 | 129 | 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 |
| 131 | 131 | if (am1 == "abs32" or am2 == "abs32") and self.skip == 0: |
| 132 | | extra_words = extra_words + 2 |
| 132 | extra_words += 2 |
| 133 | 133 | 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 |
| 135 | 135 | if am1 == "imm32" or am1 == "r32d32hh" or am2 == "r32d32hh": |
| 136 | | extra_words = extra_words + 2 |
| 136 | extra_words += 2 |
| 137 | 137 | self.extra_words = extra_words |
| 138 | 138 | base_offset = len(self.val)/2 + self.skip |
| 139 | 139 | 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)) |
| 141 | 141 | |
| 142 | 142 | def description(self): |
| 143 | 143 | return "%s %s %s" % (self.name, self.am1, self.am2) |
| r244767 | r244768 | |
| 217 | 217 | lval = "" |
| 218 | 218 | for i in range(len(self.params)-1, len(tokens)-1): |
| 219 | 219 | if lval != "": |
| 220 | | lval = lval + " " |
| 220 | lval += " " |
| 221 | 221 | lval = lval + tokens[i+1] |
| 222 | 222 | values.append(lval) |
| 223 | 223 | for i in range(0, len(self.source)): |
| r244767 | r244768 | |
| 234 | 234 | self.enabled = False |
| 235 | 235 | self.mask = opc.mask[pos-1] |
| 236 | 236 | for i in range(0, pos): |
| 237 | | self.name = self.name + ("%02x" % opc.val[i]) |
| 237 | self.name += "%02x" % opc.val[i] |
| 238 | 238 | if pos == 2: |
| 239 | 239 | self.skip = opc.skip |
| 240 | 240 | else: |
| r244767 | r244768 | |
| 250 | 250 | for i in range(start, end+1): |
| 251 | 251 | s.append("\tIR[%d] = fetch();" % i) |
| 252 | 252 | s.append("\tinst_state = 0x%x0000 | IR[%d];" % (self.id, end)) |
| 253 | | return s; |
| 253 | return s |
| 254 | 254 | |
| 255 | |
| 255 | 256 | class OpcodeList: |
| 256 | 257 | def __init__(self, fname, dtype): |
| 257 | 258 | self.opcode_info = [] |
| r244767 | r244768 | |
| 392 | 393 | fmask = h2.premask | (h.mask ^ 0xff) |
| 393 | 394 | c = "" |
| 394 | 395 | 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 |
| 400 | 401 | print >>f, "\t\t%s{" % c |
| 401 | 402 | if h2.mask == 0x00: |
| 402 | 403 | n = h2.d[0] |
| r244767 | r244768 | |
| 420 | 421 | fmask = fmask | n.mask[mpos] |
| 421 | 422 | c = "" |
| 422 | 423 | 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 |
| 428 | 429 | if n.is_dispatch(): |
| 429 | 430 | print >>f, "\t\t\t%sdispatch_%s_%s(); break;" % (c, n.name, v) |
| 430 | 431 | else: |
trunk/src/emu/cpu/m6809/m6809make.py
| r244767 | r244768 | |
| 12 | 12 | def load_file(fname, lines): |
| 13 | 13 | path = fname.rpartition('/')[0] |
| 14 | 14 | if path != "": |
| 15 | | path = path + '/' |
| 15 | path += '/' |
| 16 | 16 | try: |
| 17 | 17 | f = open(fname, "rU") |
| 18 | 18 | except Exception: |
| r244767 | r244768 | |
| 28 | 28 | load_file(path + line.split('"')[1], lines) |
| 29 | 29 | else: |
| 30 | 30 | lines.append(line) |
| 31 | | count = count + 2 |
| 31 | count += 2 |
| 32 | 32 | |
| 33 | 33 | f.close() |
| 34 | 34 | |
| r244767 | r244768 | |
| 57 | 57 | |
| 58 | 58 | # Do we have a label? |
| 59 | 59 | label = line[:percent_pos].strip() |
| 60 | | if (label != ""): |
| 60 | if label != "": |
| 61 | 61 | text += whitespace + label + "\n" |
| 62 | | whitespace = whitespace + "\t" |
| 62 | whitespace += "\t" |
| 63 | 63 | |
| 64 | 64 | # Create the goto command |
| 65 | | if (dispatch[-1:] == "*"): |
| 65 | if dispatch[-1:] == "*": |
| 66 | 66 | goto_command = "if (is_register_register_op_16_bit()) goto %s16; else goto %s8;\n" %(dispatch[:-1], dispatch[:-1]) |
| 67 | 67 | else: |
| 68 | 68 | goto_command = "goto %s;\n" % dispatch |
| r244767 | r244768 | |
| 70 | 70 | # Are we right before a 'return'? |
| 71 | 71 | if next_line_is_return: |
| 72 | 72 | text += whitespace + goto_command |
| 73 | | count = count + 1 # Skip the return |
| 73 | count += 1 # Skip the return |
| 74 | 74 | elif next_line_is_dispatch_and_return: |
| 75 | 75 | # We are followed by a dispatch/return combo; identify the next dispatch |
| 76 | 76 | percent_pos = lines[count+1].find("%") |
| r244767 | r244768 | |
| 80 | 80 | if next_dispatch not in dispatch_to_states: |
| 81 | 81 | dispatch_to_states[next_dispatch] = state |
| 82 | 82 | states_to_dispatch[state] = next_dispatch |
| 83 | | state = state + 1 |
| 83 | state += 1 |
| 84 | 84 | |
| 85 | 85 | text += whitespace + "push_state(%s);\t// %s\n" % (dispatch_to_states[next_dispatch], next_dispatch) |
| 86 | 86 | text += whitespace + goto_command |
| 87 | | count = count + 2 # Skip the dispatch/return |
| 88 | | |
| 87 | count += 2 # Skip the dispatch/return |
| 88 | |
| 89 | 89 | else: |
| 90 | 90 | # Normal dispatch |
| 91 | | text += whitespace + "push_state(%s);\n" % (state) |
| 91 | text += whitespace + "push_state(%s);\n" % state |
| 92 | 92 | text += whitespace + goto_command |
| 93 | | text += "state_%s:\n" % (state) |
| 94 | | state = state + 1 |
| 93 | text += "state_%s:\n" % state |
| 94 | state += 1 |
| 95 | 95 | else: |
| 96 | 96 | # "Normal" code |
| 97 | 97 | # Is there an '@' here? |
| r244767 | r244768 | |
| 104 | 104 | |
| 105 | 105 | # If we have to decrement the icount, output more info |
| 106 | 106 | 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 |
| 110 | 110 | |
| 111 | 111 | # Advance to next line |
| 112 | | count = count + 1 |
| 112 | count += 1 |
| 113 | 113 | |
| 114 | 114 | # Output the case labels |
| 115 | 115 | for i in range(0, state): |