diff options
Diffstat (limited to 'src/devices/cpu/m6502/m6502make.py')
-rwxr-xr-x | src/devices/cpu/m6502/m6502make.py | 140 |
1 files changed, 64 insertions, 76 deletions
diff --git a/src/devices/cpu/m6502/m6502make.py b/src/devices/cpu/m6502/m6502make.py index 422b5a8ab74..3be6a3f6f3c 100755 --- a/src/devices/cpu/m6502/m6502make.py +++ b/src/devices/cpu/m6502/m6502make.py @@ -31,7 +31,16 @@ def load_opcodes(fname): if not line: continue if line.startswith(" ") or line.startswith("\t"): # append instruction to last opcode - opcodes[-1][1].append(line) + if line == '\tprefetch();': + opcodes[-1][1].append("\tprefetch_start();") + opcodes[-1][1].append("\tIR = mintf->read_sync(PC);") + opcodes[-1][1].append("\tprefetch_end();") + elif line == '\tprefetch_noirq();': + opcodes[-1][1].append("\tprefetch_start();") + opcodes[-1][1].append("\tIR = mintf->read_sync(PC);") + opcodes[-1][1].append("\tprefetch_end_noirq();") + else: + opcodes[-1][1].append(line) else: # add new opcode opcodes.append((line, [])) @@ -59,61 +68,10 @@ def emit(f, text): """write string to file""" print(text, file=f) -FULL_PROLOG="""\ -void %(device)s_device::%(opcode)s_full() -{ -""" - -FULL_EPILOG="""\ -} -""" - -FULL_EAT_ALL="""\ -\ticount=0; inst_substate = %(substate)s; return; -""" - -FULL_MEMORY="""\ -\tif(icount == 0) { inst_substate = %(substate)s; return; } -%(ins)s -\ticount--; -""" - -FULL_NONE="""\ -%(ins)s -""" - -PARTIAL_PROLOG="""\ -void %(device)s_device::%(opcode)s_partial() -{ -switch(inst_substate) { -case 0: -""" -PARTIAL_EPILOG="""\ -} -\tinst_substate = 0; -} - -""" - -PARTIAL_EAT_ALL="""\ -\ticount=0; inst_substate = %(substate)s; return; -case %(substate)s:; -""" - -PARTIAL_MEMORY="""\ -\tif(icount == 0) { inst_substate = %(substate)s; return; } -case %(substate)s: -%(ins)s -\ticount--; -""" - -PARTIAL_NONE="""\ -%(ins)s -""" def identify_line_type(ins): if "eat-all-cycles" in ins: return "EAT" - for s in ["read", "write", "prefetch(", "prefetch_noirq("]: + for s in ["read", "write"]: if s in ins: return "MEMORY" return "NONE" @@ -121,41 +79,69 @@ def identify_line_type(ins): def save_opcodes(f, device, opcodes): for name, instructions in opcodes: - d = { "device": device, - "opcode": name, - } - - emit(f, FULL_PROLOG % d) + emit(f, "void %s_device::%s_full()" % (device, name)) + emit(f, "{") substate = 1 for ins in instructions: - d["substate"] = str(substate) - d["ins"] = ins line_type = identify_line_type(ins) if line_type == "EAT": - emit(f, FULL_EAT_ALL % d) + emit(f, "\ticount = 0;") + emit(f, "\tinst_substate = %d;" % substate) + emit(f, "\treturn;") substate += 1 elif line_type == "MEMORY": - emit(f, FULL_MEMORY % d) - substate += 1 + emit(f, ins) + emit(f, "\ticount--;") + emit(f, "\tif(icount <= 0) {") + emit(f, "\t\tif(access_to_be_redone()) {") + emit(f, "\t\t\ticount++;") + emit(f, "\t\t\tinst_substate = %d;" % substate) + emit(f, "\t\t} else") + emit(f, "\t\t\tinst_substate = %d;" % (substate+1)) + emit(f, "\t\treturn;") + emit(f, "\t}") + substate += 2 else: - emit(f, FULL_NONE %d) - emit(f, FULL_EPILOG % d) - - emit(f, PARTIAL_PROLOG % d) + emit(f, ins) + emit(f, "}") + emit(f, "") + + emit(f, "void %s_device::%s_partial()" % (device, name)) + emit(f, "{") + emit(f, "\tswitch(inst_substate) {") + emit(f, "case 0:") substate = 1 for ins in instructions: - d["substate"] = str(substate) - d["ins"] = ins line_type = identify_line_type(ins) if line_type == "EAT": - emit(f, PARTIAL_EAT_ALL % d) + emit(f, "\ticount = 0;") + emit(f, "\tinst_substate = %d;" % substate) + emit(f, "\treturn;") + emit(f, "\tcase %d:;" % substate) substate += 1 elif line_type == "MEMORY": - emit(f, PARTIAL_MEMORY % d) - substate += 1 + emit(f, "\t[[fallthrough]];") + emit(f, "case %d:" % substate) + emit(f, ins) + emit(f, "\ticount--;") + emit(f, "\tif(icount <= 0) {") + emit(f, "\t\tif(access_to_be_redone()) {") + emit(f, "\t\t\ticount++;") + emit(f, "\t\t\tinst_substate = %d;" % substate) + emit(f, "\t\t} else") + emit(f, "\t\t\tinst_substate = %d;" % (substate+1)) + emit(f, "\t\treturn;") + emit(f, "\t}") + emit(f, "\t[[fallthrough]];") + emit(f, "case %d:;" % (substate+1)) + substate += 2 else: - emit(f, PARTIAL_NONE %d) - emit(f, PARTIAL_EPILOG % d) + emit(f, ins) + emit(f, "\tbreak;") + emit(f, "}") + emit(f, "\tinst_substate = 0;") + emit(f, "}") + emit(f, "") DO_EXEC_FULL_PROLOG="""\ @@ -194,7 +180,7 @@ def save_tables(f, device, states): d = { "device": device, "disasm_count": total_states-1 } - + emit(f, DO_EXEC_FULL_PROLOG % d) for n, state in enumerate(states): if state == ".": continue @@ -219,7 +205,7 @@ def save_dasm(f, device, states): d = { "device": device, "disasm_count": total_states-1 } - + emit(f, DISASM_PROLOG % d ) for n, state in enumerate(states): if state == ".": continue @@ -232,6 +218,8 @@ def save_dasm(f, device, states): extra = "STEP_OVER" elif opc in ["rts", "rti", "rtn", "retf", "tpi"]: extra = "STEP_OUT" + elif opc in ["bcc", "bcs", "beq", "bmi", "bne", "bpl", "bvc", "bvs", "bbr", "bbs", "bbc", "bar", "bas"]: + extra = "STEP_COND" emit(f, '\t{ "%s", DASM_%s, %s },' % (opc, mode, extra)) emit(f, DISASM_EPILOG % d) |