Coverage for MC6809/components/MC6809data/CPU6809_HTML_export.py: 97%
67 statements
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-06 19:50 +0100
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-06 19:50 +0100
1"""
2 6809 instruction set data
3 ~~~~~~~~~~~~~~~~~~~~~~~~~
5 data from:
6 * http://www.maddes.net/m6809pm/sections.htm#sec4_4
7 * http://www.burgins.com/m6809.html
8 * http://www.maddes.net/m6809pm/appendix_a.htm#appA
10 :copyleft: 2013-2014 by Jens Diemer
11 :license: GNU GPL v3 or above, see LICENSE for more details.
12"""
15import os
17from MC6809.components.MC6809data.MC6809_op_data import BYTE, OP_DATA, WORD
18from MC6809.components.MC6809data.MC6809_op_docs import OP_DOC
21OUTFILENAME = "CPU6809_opcodes.html"
23WIDTH_DICT = {
24 None: "no",
25 BYTE: "byte",
26 WORD: "word",
27}
30class Cell:
31 def __init__(self, txt):
32 self.txt = txt
33 self.rowspan = 0
34 self.headline = None
36 def html(self):
37 if self.rowspan is None: 37 ↛ 38line 37 didn't jump to line 38, because the condition on line 37 was never true
38 return ""
39 elif self.rowspan == 1:
40 return f"<td>{self.txt}</td>"
41 return f'<td rowspan="{self.rowspan:d}" title="{self.headline}: {self.txt}">{self.txt}</td>'
43 def __str__(self):
44 return f"<'{self.txt}' rowspan={self.rowspan}>"
45 __repr__ = __str__
48headlines = (
49 "instruction",
50 "mnemonic",
51 "CC flags",
52 "example",
53 "op code",
54 "bytes",
55 "cycles",
56 "address mode",
57 "needs ea",
58 "read from memory",
59 "write to memory",
60 "register",
61)
64# Collect the data for the table from MC6809_data_raw2
65data = []
66for instruction, instr_data in sorted(OP_DATA.items()):
67 for mnemonic, memoric_data in sorted(instr_data["mnemonic"].items()):
68 instruction_doc = OP_DOC[instruction]
69 mnemonic_doc = instruction_doc["mnemonic"][mnemonic]
71 for op_code, op_data in sorted(memoric_data["ops"].items()):
73 addr_mode = op_data["addr_mode"]
74 if addr_mode:
75 addr_mode = addr_mode.replace("_", " ").lower()
77 if op_code > 0xff:
78 op_code = f"${op_code:04x}"
79 else:
80 op_code = f"${op_code:02x}"
82 data.append([
83 instruction,
84 mnemonic,
85 mnemonic_doc["HNZVC"] or "",
86 mnemonic_doc["desc"] or "",
87 op_code,
88 op_data["bytes"],
89 op_data["cycles"],
90 addr_mode,
92 "yes" if memoric_data["needs_ea"] else "no",
93 WIDTH_DICT[memoric_data["read_from_memory"]],
94 WIDTH_DICT[memoric_data["write_to_memory"]],
95 memoric_data["register"] or "-",
97 ])
100# add rowspan information
101for colum_no in range(len(data[0])):
102 old_cell = None
103 same_count = 0
104 for row in reversed(data):
105 cell = row[colum_no] = Cell(row[colum_no])
106 if old_cell is None:
107 same_count = 1
108 elif cell.txt == old_cell.txt:
109 old_cell.rowspan = None
110 same_count += 1
111 else:
112 old_cell.rowspan = same_count
113 same_count = 1
114 old_cell = cell
115 old_cell.rowspan = same_count
118# add headline to cells (used for td title="")
119for row in data:
120 for cell, headline in zip(row, headlines):
121 if cell.rowspan is not None:
122 cell.headline = headline
125# generate html file
126with open(OUTFILENAME, 'w') as htmlfile:
127 htmlfile.write("""<!DOCTYPE html>
128<html>
129<head>
130<style>
131table, th, td{border-collapse:collapse;border:1px solid black;}
132th, td {padding:5px;}
133</style>
134</head>
135<body>
136<h1>6809 opcodes:</h1>
137<table>
138<tr>
139""")
140 for headline in headlines:
141 htmlfile.write(f"\t<th>{headline}</th>\n")
142 htmlfile.write("</tr>\n")
144 for row in data:
145 htmlfile.write("\t<tr>\n")
146 for cell in row:
147 if cell.rowspan is not None:
148 htmlfile.write(f"\t\t{cell.html()}\n")
149 htmlfile.write("\t</tr>\n")
150 htmlfile.write("</table>")
151 htmlfile.write(
152 f"<addr>This file was generated by {os.path.split(__file__)[1]}</addr>"
153 )
154 htmlfile.write("</body></html>")
157print(f"file {OUTFILENAME!r} written")
158print(" -- END -- ")