-
Notifications
You must be signed in to change notification settings - Fork 0
/
printing.py
187 lines (148 loc) · 4.94 KB
/
printing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import opcodes
from util import dw_to_uint, tc_to_int
def format_absolute(instruction, symbols=None):
format_string = "{ins} ${address:04X}"
address = dw_to_uint(instruction.operands)
label = None
if symbols:
label = symbols.get_label(address)
if label:
format_string = "{ins} {label}"
return format_string.format(
ins=instruction.mnemonic,
address=address,
label=label)
def format_absolute_x(instruction, symbols=None):
format_string = "{ins} ${address:04X},X"
address = dw_to_uint(instruction.operands)
label = None
if symbols:
label = symbols.get_label(address)
if label:
format_string = "{ins} {label},X"
return format_string.format(
ins=instruction.mnemonic,
address=address,
label=label)
def format_absolute_y(instruction, symbols=None):
format_string = "{ins} ${address:04X},Y"
address = dw_to_uint(instruction.operands)
label = None
if symbols:
label = symbols.get_label(address)
if label:
format_string = "{ins} {label},Y"
return format_string.format(
ins=instruction.mnemonic,
address=address,
label=label)
def format_accumulator(instruction, symbols=None):
return "{ins} A".format(ins=instruction.mnemonic)
def format_zero_page(instruction, symbols=None):
format_string = "{ins} ${address:02X}"
address = instruction.operands[0]
label = None
if symbols:
label = symbols.get_label(address)
if label:
format_string = "{ins} {label}"
return format_string.format(
ins=instruction.mnemonic,
address=address,
label=label)
def format_zero_page_indirect_y(instruction, symbols=None):
format_string = "{ins} (${address:02X}),Y"
address = instruction.operands[0]
label = None
if symbols:
label = symbols.get_label(address)
if label:
format_string = "{ins} ({label}),Y"
return format_string.format(
ins=instruction.mnemonic,
address=address,
label=label)
def format_zero_page_x(instruction, symbols=None):
format_string = "{ins} ${address:02X},X"
address = instruction.operands[0]
label = None
if symbols:
label = symbols.get_label(address)
if label:
format_string = "{ins} {label},X"
return format_string.format(
ins=instruction.mnemonic,
address=address,
label=label)
def format_zero_page_x_indirect(instruction, symbols=None):
format_string = "{ins} (${address:02X},X)"
address = instruction.operands[0]
label = None
if symbols:
label = symbols.get_label(address)
if label:
format_string = "{ins} ({label},X)"
return format_string.format(
ins=instruction.mnemonic,
address=address,
label=label)
def format_zero_page_y(instruction, symbols=None):
format_string = "{ins} ${address:02X},Y"
address = instruction.operands[0]
label = None
if symbols:
label = symbols.get_label(address)
if label:
format_string = "{ins} {label},Y"
return format_string.format(
ins=instruction.mnemonic,
address=address,
label=label)
def format_illegal(instruction, symbols=None):
return "??? ???"
def format_immediate(instruction, symbols=None):
return "{ins} #${ops:02X}".format(
ins=instruction.mnemonic,
ops=instruction.operands[0])
def format_implicit(instruction, symbols=None):
return "{ins}".format(ins=instruction.mnemonic)
def format_jmp_absolute(instruction, symbols=None):
format_string = "{ins} ${address:04X}"
jmp_target = dw_to_uint(instruction.operands)
label = None
if symbols:
label = symbols.get_label(jmp_target)
if label:
format_string = "{ins} {label}"
return format_string.format(
ins=instruction.mnemonic,
address=jmp_target,
label=label)
def format_jmp_absolute_indirect(instruction, symbols=None):
format_string = "{ins} (${address:04X})"
ind_target = dw_to_uint(instruction.operands)
label = None
if symbols:
label = symbols.get_label(ind_target)
if label:
format_string = "{ins} ({label})"
return format_string.format(
ins=instruction.mnemonic,
address=ind_target,
label=label)
def format_relative(instruction, symbols=None):
format_string = "{ins} ${offset:+02X}"
offset = tc_to_int(instruction.operands[0])
label = None
if symbols:
relative_base = instruction.address + instruction.size
target = relative_base + offset
label = symbols.get_label(target)
if label:
format_string = "{ins} {label}"
return format_string.format(
ins=instruction.mnemonic,
offset=offset,
label=label)
def format_ret(instruction, symbols=None):
return "{ins}".format(ins=instruction.mnemonic)