summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu/m6502/m6502make.py
diff options
context:
space:
mode:
author Olivier Galibert <galibert@pobox.com>2017-07-05 11:44:49 +0200
committer Olivier Galibert <galibert@pobox.com>2017-11-26 17:41:27 +0100
commit6caef2579a1490f05d28bcede731cbdd45fc5c65 (patch)
tree8055384e183be3cb27e7d0894ac53dc96c09e6fa /src/devices/cpu/m6502/m6502make.py
parent34b222062c89adbeed822f56be6130421777e11f (diff)
dvdisasm: Overhaul [O. Galibert]
Disassemblers are now independant classes. Not only the code is cleaner, but unidasm has access to all the cpu cores again. The interface to the disassembly method has changed from byte buffers to objects that give a result to read methods. This also adds support for lfsr and/or paged PCs.
Diffstat (limited to 'src/devices/cpu/m6502/m6502make.py')
-rwxr-xr-xsrc/devices/cpu/m6502/m6502make.py66
1 files changed, 44 insertions, 22 deletions
diff --git a/src/devices/cpu/m6502/m6502make.py b/src/devices/cpu/m6502/m6502make.py
index 8bcd85f8e21..b874b7c5ba9 100755
--- a/src/devices/cpu/m6502/m6502make.py
+++ b/src/devices/cpu/m6502/m6502make.py
@@ -6,7 +6,7 @@ from __future__ import print_function
USAGE = """
Usage:
-%s device_name {opc.lst|-} disp.lst device.inc
+%s prefix {opc.lst|-} disp.lst device.inc deviced.inc
"""
import sys
import logging
@@ -59,7 +59,7 @@ def emit(f, text):
print(text, file=f)
FULL_PROLOG="""\
-void %(device)s::%(opcode)s_full()
+void %(device)s_device::%(opcode)s_full()
{
"""
@@ -82,7 +82,7 @@ FULL_NONE="""\
"""
PARTIAL_PROLOG="""\
-void %(device)s::%(opcode)s_partial()
+void %(device)s_device::%(opcode)s_partial()
{
switch(inst_substate) {
case 0:
@@ -158,7 +158,7 @@ def save_opcodes(f, device, opcodes):
DO_EXEC_FULL_PROLOG="""\
-void %(device)s::do_exec_full()
+void %(device)s_device::do_exec_full()
{
\tswitch(inst_state) {
"""
@@ -169,7 +169,7 @@ DO_EXEC_FULL_EPILOG="""\
"""
DO_EXEC_PARTIAL_PROLOG="""\
-void %(device)s::do_exec_partial()
+void %(device)s_device::do_exec_partial()
{
\tswitch(inst_state) {
"""
@@ -180,7 +180,7 @@ DO_EXEC_PARTIAL_EPILOG="""\
"""
DISASM_PROLOG="""\
-const %(device)s::disasm_entry %(device)s::disasm_entries[0x%(disasm_count)x] = {
+const %(device)s_disassembler::disasm_entry %(device)s_disassembler::disasm_entries[0x%(disasm_count)x] = {
"""
DISASM_EPILOG="""\
@@ -194,25 +194,31 @@ def save_tables(f, device, states):
"disasm_count": total_states-1
}
-
emit(f, DO_EXEC_FULL_PROLOG % d)
for n, state in enumerate(states):
if state == ".": continue
if n < total_states - 1:
- emit(f, "\tcase 0x%02x: %s_full(); break;\n" % (n, state))
+ emit(f, "\tcase 0x%02x: %s_full(); break;" % (n, state))
else:
- emit(f, "\tcase %s: %s_full(); break;\n" % ("STATE_RESET", state))
+ emit(f, "\tcase %s: %s_full(); break;" % ("STATE_RESET", state))
emit(f, DO_EXEC_FULL_EPILOG % d)
emit(f, DO_EXEC_PARTIAL_PROLOG % d)
for n, state in enumerate(states):
if state == ".": continue
if n < total_states - 1:
- emit(f, "\tcase 0x%02x: %s_partial(); break;\n" % (n, state))
+ emit(f, "\tcase 0x%02x: %s_partial(); break;" % (n, state))
else:
- emit(f, "\tcase %s: %s_partial(); break;\n" % ("STATE_RESET", state))
+ emit(f, "\tcase %s: %s_partial(); break;" % ("STATE_RESET", state))
emit(f, DO_EXEC_PARTIAL_EPILOG % d)
+def save_dasm(f, device, states):
+ total_states = len(states)
+
+ d = { "device": device,
+ "disasm_count": total_states-1
+ }
+
emit(f, DISASM_PROLOG % d )
for n, state in enumerate(states):
if state == ".": continue
@@ -222,13 +228,13 @@ def save_tables(f, device, states):
mode = tokens[-1]
extra = "0"
if opc in ["jsr", "bsr"]:
- extra = "DASMFLAG_STEP_OVER"
+ extra = "STEP_OVER"
elif opc in ["rts", "rti", "rtn"]:
- extra = "DASMFLAG_STEP_OUT"
- emit(f, '\t{ "%s", DASM_%s, %s },\n' % (opc, mode, extra))
+ extra = "STEP_OUT"
+ emit(f, '\t{ "%s", DASM_%s, %s },' % (opc, mode, extra))
emit(f, DISASM_EPILOG % d)
-def save(fname, device, opcodes, states):
+def saves(fname, device, opcodes, states):
logging.info("saving: %s", fname)
try:
f = open(fname, "w")
@@ -236,12 +242,24 @@ def save(fname, device, opcodes, states):
err = sys.exc_info()[1]
logging.error("cannot write file %s [%s]", fname, err)
sys.exit(1)
- save_opcodes(f,device, opcodes)
+ save_opcodes(f, device, opcodes)
emit(f, "\n")
save_tables(f, device, states)
f.close()
+def saved(fname, device, opcodes, states):
+ logging.info("saving: %s", fname)
+ try:
+ f = open(fname, "w")
+ except Exception:
+ err = sys.exc_info()[1]
+ logging.error("cannot write file %s [%s]", fname, err)
+ sys.exit(1)
+ save_dasm(f, device, states)
+ f.close()
+
+
def main(argv):
debug = False
logformat=("%(levelname)s:"
@@ -255,25 +273,29 @@ def main(argv):
logging.basicConfig(level=logging.WARNING, format=logformat)
- if len(argv) != 5:
+ if len(argv) != 6:
print(USAGE % argv[0])
return 1
- device_name = argv[1]
+ mode = argv[1]
+ device_name = argv[2]
opcodes = []
- if argv[2] != "-":
- opcodes = load_opcodes(argv[2])
+ if argv[3] != "-":
+ opcodes = load_opcodes(argv[3])
logging.info("found %d opcodes", len(opcodes))
else:
logging.info("skipping opcode reading")
- states = load_disp(argv[3])
+ states = load_disp(argv[4])
logging.info("loaded %s states", len(states))
assert (len(states) & 0xff) == 1
- save(argv[4], device_name, opcodes, states)
+ if mode == 's':
+ saves(argv[5], device_name, opcodes, states)
+ else:
+ saved(argv[5], device_name, opcodes, states)
# ======================================================================