diff options
Diffstat (limited to 'src/devices/cpu/m6502/m6502make.py')
-rwxr-xr-x | src/devices/cpu/m6502/m6502make.py | 157 |
1 files changed, 74 insertions, 83 deletions
diff --git a/src/devices/cpu/m6502/m6502make.py b/src/devices/cpu/m6502/m6502make.py index ea51fe43350..99b4320cc11 100755 --- a/src/devices/cpu/m6502/m6502make.py +++ b/src/devices/cpu/m6502/m6502make.py @@ -4,13 +4,14 @@ from __future__ import print_function +import io +import logging +import sys + USAGE = """ Usage: %s prefix {opc.lst|-} disp.lst device.inc deviced.inc """ -import sys -import logging - MAX_STATES = 0 def load_opcodes(fname): @@ -18,7 +19,7 @@ def load_opcodes(fname): opcodes = [] logging.info("load_opcodes: %s", fname) try: - f = open(fname, "rU") + f = io.open(fname, "r") except Exception: err = sys.exc_info()[1] logging.error("cannot read opcodes file %s [%s]", fname, err) @@ -30,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, [])) @@ -41,7 +51,7 @@ def load_disp(fname): logging.info("load_disp: %s", fname) states = [] try: - f = open(fname, "rU") + f = io.open(fname, "r") except Exception: err = sys.exc_info()[1] logging.error("cannot read display file %s [%s]", fname, err) @@ -58,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" @@ -120,41 +79,71 @@ 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, "\tdebugger_wait_hook();") + 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, "\tdebugger_wait_hook();") + 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="""\ @@ -193,7 +182,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 @@ -218,7 +207,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 @@ -227,10 +216,12 @@ def save_dasm(f, device, states): opc = tokens[0] mode = tokens[-1] extra = "0" - if opc in ["jsr", "bsr", "callf"]: + if opc in ["jsr", "bsr", "callf", "jpi", "jsb"]: extra = "STEP_OVER" - elif opc in ["rts", "rti", "rtn", "retf"]: + 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) |