SHOW:
|
|
- or go back to the newest paste.
1 | .macro push stackname, value, sp ; stackname, valuetoassign, stackpointer | |
2 | ||
3 | .ident( .sprintf("%s%04X",stackname,sp)) .set value | |
4 | sp .set sp + 1 | |
5 | ||
6 | .endmacro | |
7 | ||
8 | .macro pop stackname, var, sp | |
9 | ||
10 | sp .set sp - 1 | |
11 | var .set .ident( .sprintf("%s%04X",stackname,sp)) | |
12 | ||
13 | .endmacro | |
14 | ||
15 | ||
16 | ||
17 | .macro if flagtest | |
18 | ||
19 | ; first time this macro is used: | |
20 | .ifndef _endif_flagtest_IF_label | |
21 | _endif_flagtest_IF_label .set -1 ; total number of IFs used, first time will be incremented = 0 | |
22 | _endif_flagtest_SP .set 0 ; Stack Pointer | |
23 | _endif_flagtest_END_label .set 0 | |
24 | .endif | |
25 | ||
26 | _endif_flagtest_IF_label .set _endif_flagtest_IF_label + 1 | |
27 | ||
28 | push "IF_ENDIF_STACK",_endif_flagtest_IF_label, _endif_flagtest_SP | |
29 | ||
30 | ||
31 | ; Carry flag: | |
32 | ; carry set | |
33 | ; carry clear | |
34 | ; no carry | |
35 | ; not carry | |
36 | ; C set | |
37 | ; C clear | |
38 | ; less | |
39 | ; not less | |
40 | ; greater_equal | |
41 | ; not greater_equal | |
42 | ||
43 | ||
44 | ; carry clear | |
45 | .if (.xmatch(.left(1, {flagtest}) , less)) .or (.xmatch(.mid(1,1, {flagtest}) , less)) | |
46 | .if (.xmatch(.left (1,{flagtest}), not)) | |
47 | - | bcc .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) ; not less |
47 | + | bcc .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) ; branch away if less |
48 | .else | |
49 | .if (.xmatch(.left(1, {flagtest}) , less)) | |
50 | - | bcs .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) ; less |
50 | + | bcs .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) ; branch away if greater or equal |
51 | .else | |
52 | .error "Unknown condition in IF (C flag - carry clear)" | |
53 | .fatal "" | |
54 | .endif | |
55 | .endif | |
56 | .else | |
57 | ||
58 | ; Carry set | |
59 | .if (.xmatch(.left(1, {flagtest}) , greater_equal)) .or (.xmatch(.mid(1,1, {flagtest}) , greater_equal)) .or (.xmatch(.left(1, {flagtest}) , carry)) .or (.xmatch(.mid(1,1, {flagtest}) , carry)) .or (.xmatch(.left(1, {flagtest}) , C)) | |
60 | .if (.xmatch(.mid (1, 1,{flagtest}), clear)) .or (.xmatch(.left (1,{flagtest}), no)) .or (.xmatch(.left (1,{flagtest}), not)) | |
61 | - | bcs .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) |
61 | + | bcs .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) ; branch away if carryset OR greaterORequal |
62 | .else | |
63 | - | .if (.xmatch(.mid (1, 1, {flagtest}), set)) .or (.xmatch(.left(1, {flagtest}) , greater_equal)) |
63 | + | .if (.xmatch(.mid (1, 1, {flagtest}), set)) .or (.xmatch(.left(1, {flagtest}) , greater_equal)) ; ; branch away if carryclear OR less |
64 | bcc .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) | |
65 | .else | |
66 | .error "Unknown condition in IF (C flag - carry set)" | |
67 | .endif | |
68 | .endif | |
69 | .else ; end "carry" | |
70 | ||
71 | ; Special case for greater than check ; | |
72 | - | .if (.xmatch(.left(1, {flagtest}) , greater)) .or (.xmatch(.mid(1,1, {flagtest}) , greater)) |
72 | + | .if (.xmatch(.left(1, {flagtest}) , greater)) .or (.xmatch(.mid(1,1, {flagtest}) , greater)) .or (.xmatch(.left(1,{flagtest}) , less_equal)) |
73 | - | .if (.xmatch(.left (1,{flagtest}), not)) ; Enter block on EQUAL or LESS - branch away on greater(BCS), stay if equal |
73 | + | .if (.xmatch(.left (1,{flagtest}), not)) .or (.xmatch(.left(1,{flagtest}) , less_equal)) ; Enter block on EQUAL or LESS - branch away on greater(BCS), stay if equal |
74 | beq :+ | |
75 | bcs .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) | |
76 | : | |
77 | .else | |
78 | .if (.xmatch(.left(1, {flagtest}) , greater)) ; enter block on greater - branch away on less or equal | |
79 | beq .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) | |
80 | bcc .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) | |
81 | .else | |
82 | .error "Unknown condition in IF (C flag - greater)" | |
83 | .endif | |
84 | .endif | |
85 | .else ; end "greater" | |
86 | ||
87 | ||
88 | ; Zero flag: - set when equal | |
89 | ; zero | |
90 | ; zero clear | |
91 | ; zero set | |
92 | ; not zero | |
93 | ; equal | |
94 | ; not equal | |
95 | ; Z set | |
96 | ; Z clear | |
97 | ; | |
98 | ||
99 | .if (.xmatch(.mid(1,1, {flagtest}) , zero)) .or (.xmatch(.left(1, {flagtest}) , zero)) .or (.xmatch(.mid(1,1, {flagtest}) , equal)) .or (.xmatch(.left(1,{flagtest}) , equal)) .or (.xmatch(.left(1, {flagtest}) , Z)) | |
100 | .if (.xmatch(.mid (1, 1, {flagtest}), clear)) .or (.xmatch(.left(1, {flagtest}), not)) | |
101 | beq .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) | |
102 | .else | |
103 | .if (.xmatch(.mid (1, 1,{flagtest}), set)) .or (.xmatch(.left(1,{flagtest}) , equal)) .or (.xmatch(.left(1, {flagtest}) , zero)) | |
104 | bne .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) | |
105 | .else | |
106 | .error "Unknown condition in IF (Z flag)" | |
107 | .fatal "" | |
108 | .endif | |
109 | .endif | |
110 | .else ; end "zero" | |
111 | ||
112 | ; Negative flag: set indicates negative | |
113 | ||
114 | ; plus | |
115 | ; not plus | |
116 | ; positive | |
117 | ; not positive | |
118 | ; minus | |
119 | ; negative | |
120 | ; not minus | |
121 | ; not negative | |
122 | ; N set | |
123 | ; N clear | |
124 | ; bit7 set | |
125 | ; bit7 clear | |
126 | ||
127 | .if (.xmatch(.mid(1,1, {flagtest}) , plus)) .or (.xmatch(.mid(1,1, {flagtest}) , positive)) .or (.xmatch(.left(1, {flagtest}) , plus)) .or (.xmatch(.left(1, {flagtest}) , positive)) | |
128 | .if (.xmatch(.left(1, {flagtest}), not)) | |
129 | bpl .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) | |
130 | .else | |
131 | .if (.xmatch(.left(1, {flagtest}) , plus)) .or (.xmatch(.left(1, {flagtest}) , positive)) | |
132 | bmi .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) | |
133 | .else | |
134 | .error "Unknown condition in IF (N flag)" | |
135 | .fatal "" | |
136 | .endif | |
137 | .endif | |
138 | .else ; end "plus" | |
139 | ||
140 | .if (.xmatch(.left(1, {flagtest}) , minus)) .or (.xmatch(.left(1, {flagtest}) , negative)) .or (.xmatch(.mid(1,1, {flagtest}) , minus)) .or (.xmatch(.mid(1,1, {flagtest}) , negative)) .or (.xmatch(.left(1, {flagtest}) , N)) .or (.xmatch(.left(1, {flagtest}) , bit7)) | |
141 | .if (.xmatch(.left(1, {flagtest}), not)) .or (.xmatch(.mid(1,1, {flagtest}), clear)) | |
142 | bmi .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) | |
143 | .else | |
144 | .if (.xmatch(.left(1, {flagtest}) , minus)) .or (.xmatch(.left(1, {flagtest}) , negative)) .or (.xmatch(.mid(1,1, {flagtest}), set)) | |
145 | bpl .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) | |
146 | .else | |
147 | .error "Unknown condition in IF (N flag)" | |
148 | - | .fatal |
148 | + | .fatal "" |
149 | .endif | |
150 | .endif | |
151 | .else ; end "minus" | |
152 | ||
153 | ; V: | |
154 | ; overflow | |
155 | ; overflow set | |
156 | ; overflow clear | |
157 | ; not overflow | |
158 | ; V set | |
159 | ; V clear | |
160 | ; bit6 clear | |
161 | ; bit6 set | |
162 | ||
163 | .if (.xmatch(.mid(1,1, {flagtest}) , overflow)) .or (.xmatch(.left(1, {flagtest}) , overflow)) .or (.xmatch(.left(1,{flagtest}) , V)) .or (.xmatch(.left(1, {flagtest}) , bit6)) | |
164 | .if (.xmatch(.mid (1, 1, {flagtest}), clear)) .or (.xmatch(.left(1, {flagtest}), not)) | |
165 | bvs .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) | |
166 | .else | |
167 | .if (.xmatch(.mid (1, 1,{flagtest}), set)) .or (.xmatch(.left(1,{flagtest}) , overflow)) | |
168 | bvc .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) | |
169 | .else | |
170 | .error "Unknown condition in IF (V Flag)" | |
171 | - | .fatal |
171 | + | .fatal "" |
172 | .endif | |
173 | .endif | |
174 | .else ; end "zero" | |
175 | .if (.xmatch(.left(1,{flagtest}) , TRUE)) ; always true for ELSE macro | |
176 | ; do nothing (no branch) | |
177 | .else | |
178 | .error "Unrecognized IF test condition." | |
179 | .fatal "" | |
180 | .endif | |
181 | .endif | |
182 | .endif | |
183 | .endif | |
184 | .endif | |
185 | .endif | |
186 | .endif | |
187 | .endif | |
188 | ||
189 | ||
190 | ||
191 | .endmacro | |
192 | ||
193 | ; Create a label that will point to the next ENDIF and create an ENDIF/IF for the ELSE - the IF creates no code | |
194 | ||
195 | .macro else | |
196 | jmp .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label + 1)) ; one more than the last label, same lablel as the "if TRUE" | |
197 | endif | |
198 | if TRUE | |
199 | .endmacro | |
200 | ||
201 | ||
202 | ; Pop if address from the IF stack and make a label | |
203 | .macro endif | |
204 | ||
205 | .if (_endif_flagtest_SP - 1) < 0 ; if accessing the stack will result in a negative value, there are too many ENDIFs | |
206 | .error "ENDIF without IF" | |
207 | .fatal "" | |
208 | .endif | |
209 | ||
210 | pop "IF_ENDIF_STACK",_endif_flagtest_END_label, _endif_flagtest_SP | |
211 | ||
212 | .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_END_label)): | |
213 | ||
214 | .endmacro |