asar coverage - build #238


src/asar/
File: src/asar/arch-65816.cpp
Date: 2025-02-21 02:52:03
Lines:
277/312
88.8%
Functions:
140/141
99.3%
Branches:
381/576
66.1%

Line Branch Exec Source
1 #include "asar.h"
2 #include "assembleblock.h"
3 #include "asar_math.h"
4
5 #define write1 write1_pick
6
7 2247 void asinit_65816()
8 {
9 2247 }
10
11 2109 void asend_65816()
12 {
13 2109 }
14
15 // like an address mode, but without a specific width
16 enum class addr_kind {
17 abs, // $00
18 x, // $00,x
19 y, // $00,y
20 ind, // ($00)
21 lind, // [$00]
22 xind, // ($00,x)
23 indy, // ($00),y
24 lindy, // [$00],y
25 s, // $00,s
26 sy, // ($00,s),y
27 imp, // implied (no argument)
28 a, // 'A' as argument
29 imm, // #$00
30 };
31
32 struct insn_context {
33 string arg;
34 char orig_insn[3]; // oops i didn't end up using this... could be useful in some error messages maybe
35 char modifier;
36 // right now these 2 are only used for autoclean, so not set for some weird opcodes
37 string parsed_arg;
38 int written_len;
39 uint8_t written_opcode;
40 };
41
42 6705 struct parse_result {
43 addr_kind kind;
44 string arg;
45 };
46
47 // checks for matching characters at the start of haystack, ignoring spaces.
48 // returns index into haystack right after the match
49 template<char... chars>
50 60906 int64_t startmatch(const string& haystack) {
51 static const char needle[] = {chars...};
52 30486 size_t haystack_i = 0;
53
2/2
✓ Branch 0 taken 30453 times.
✓ Branch 1 taken 2418 times.
65742 for(size_t i = 0; i < sizeof...(chars); i++) {
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30453 times.
60906 while(haystack[haystack_i] == ' ') haystack_i++;
55
2/2
✓ Branch 0 taken 15237 times.
✓ Branch 1 taken 15216 times.
60906 if(needle[i] != to_lower(haystack[haystack_i++])) return -1;
56 }
57 4836 return haystack_i;
58 }
59
60 // checks for matching characters at the end of haystack, ignoring spaces.
61 // returns index into haystack right before the match
62 template<char... chars>
63 51138 int64_t endmatch(const string& haystack) {
64 static const char needle[] = {chars...};
65 51138 int64_t haystack_i = haystack.length()-1;
66
2/2
✓ Branch 0 taken 29673 times.
✓ Branch 1 taken 2934 times.
65214 for(int64_t i = sizeof...(chars)-1; i >= 0; i--) {
67
4/6
✓ Branch 0 taken 20781 times.
✓ Branch 1 taken 8892 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 20781 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 14850 times.
59346 while(haystack_i >= 0 && haystack[haystack_i] == ' ') haystack_i--;
68
6/6
✓ Branch 0 taken 20781 times.
✓ Branch 1 taken 8892 times.
✓ Branch 2 taken 10404 times.
✓ Branch 3 taken 10377 times.
✓ Branch 4 taken 11331 times.
✓ Branch 5 taken 3519 times.
59346 if(haystack_i < 0 || needle[i] != to_lower(haystack[haystack_i--])) return -1;
69 }
70 5868 return haystack_i+1;
71 }
72
73 /*
74 * Parses the address kind from an argument, given a list of allowed address kinds.
75 * Throws "invalid address mode" if the argument does not match any kinds.
76 */
77 // i still don't like this function...
78 template<addr_kind... allowed_kinds>
79
2/2
✓ Branch 0 taken 711 times.
✓ Branch 1 taken 4221 times.
22638 parse_result parse_addr_kind(insn_context& ctx) {
80 11334 int64_t start_i = 0, end_i = ctx.arg.length();
81 // If this addressing kind is allowed, return it, along with a trimmed version of the string.
82 #define RETURN_IF_ALLOWED(kind) \
83 if constexpr(((allowed_kinds == addr_kind::kind) || ...)) { \
84 string out(ctx.arg.data() + start_i, end_i - start_i); \
85 ctx.parsed_arg = out; \
86 return parse_result{addr_kind::kind, out}; \
87 }
88
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 9891 times.
22638 if((start_i = startmatch<'#'>(ctx.arg)) >= 0) {
89
2/4
✓ Branch 0 taken 1428 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 717 times.
✗ Branch 3 not taken.
5748 RETURN_IF_ALLOWED(imm);
90 asar_throw_error(1, error_type_block, error_id_bad_addr_mode);
91 }
92
2/2
✓ Branch 0 taken 648 times.
✓ Branch 1 taken 9243 times.
19782 if((start_i = startmatch<'('>(ctx.arg)) >= 0) {
93
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 504 times.
1296 if((end_i = endmatch<',', 's', ')', ',', 'y'>(ctx.arg)) >= 0) {
94
2/4
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 144 times.
✗ Branch 3 not taken.
576 RETURN_IF_ALLOWED(sy);
95 asar_throw_error(1, error_type_block, error_id_bad_addr_mode);
96 }
97
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 360 times.
1008 if((end_i = endmatch<')', ',', 'y'>(ctx.arg)) >= 0) {
98
2/4
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
576 RETURN_IF_ALLOWED(indy);
99 asar_throw_error(1, error_type_block, error_id_bad_addr_mode);
100 }
101
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 180 times.
720 if((end_i = endmatch<',', 'x', ')'>(ctx.arg)) >= 0) {
102
2/4
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
✗ Branch 3 not taken.
720 RETURN_IF_ALLOWED(xind);
103 asar_throw_error(1, error_type_block, error_id_bad_addr_mode);
104 }
105
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
360 if((end_i = endmatch<')'>(ctx.arg)) >= 0) {
106
2/4
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
✗ Branch 3 not taken.
738 RETURN_IF_ALLOWED(ind);
107 asar_throw_warning(1, warning_id_assuming_address_mode, "($00)", "$00", " (if this was intentional, add a +0 after the parentheses.)");
108 }
109 }
110
2/2
✓ Branch 0 taken 342 times.
✓ Branch 1 taken 8901 times.
18486 if((start_i = startmatch<'['>(ctx.arg)) >= 0) {
111
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 198 times.
684 if((end_i = endmatch<']', ',', 'y'>(ctx.arg)) >= 0) {
112
2/4
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
576 RETURN_IF_ALLOWED(lindy);
113 asar_throw_error(1, error_type_block, error_id_bad_addr_mode);
114 }
115
1/2
✓ Branch 0 taken 198 times.
✗ Branch 1 not taken.
396 if((end_i = endmatch<']'>(ctx.arg)) >= 0) {
116
2/4
✓ Branch 0 taken 198 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 99 times.
✗ Branch 3 not taken.
792 RETURN_IF_ALLOWED(lind);
117 asar_throw_error(1, error_type_block, error_id_bad_addr_mode);
118 }
119 }
120 8910 start_i = 0;
121
2/2
✓ Branch 0 taken 1566 times.
✓ Branch 1 taken 7335 times.
17802 if((end_i = endmatch<',', 'x'>(ctx.arg)) >= 0) {
122
2/4
✓ Branch 0 taken 1566 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 783 times.
✗ Branch 3 not taken.
6264 RETURN_IF_ALLOWED(x);
123 asar_throw_error(1, error_type_block, error_id_bad_addr_mode);
124 }
125
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 7101 times.
14670 if((end_i = endmatch<',', 'y'>(ctx.arg)) >= 0) {
126
2/4
✓ Branch 0 taken 234 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 117 times.
✗ Branch 3 not taken.
936 RETURN_IF_ALLOWED(y);
127 asar_throw_error(1, error_type_block, error_id_bad_addr_mode);
128 }
129
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 6957 times.
14202 if((end_i = endmatch<',', 's'>(ctx.arg)) >= 0) {
130
2/4
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
576 RETURN_IF_ALLOWED(s);
131 asar_throw_error(1, error_type_block, error_id_bad_addr_mode);
132 }
133 6966 end_i = ctx.arg.length();
134 // hoping that by now, something would have stripped whitespace lol
135
2/2
✓ Branch 0 taken 2952 times.
✓ Branch 1 taken 4005 times.
13914 if(ctx.arg.length() == 0) {
136
2/4
✓ Branch 0 taken 2952 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1476 times.
✗ Branch 3 not taken.
11808 RETURN_IF_ALLOWED(imp);
137 asar_throw_error(1, error_type_block, error_id_bad_addr_mode);
138 }
139
6/6
✓ Branch 0 taken 3987 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 108 times.
✓ Branch 3 taken 3879 times.
✓ Branch 4 taken 63 times.
✓ Branch 5 taken 1944 times.
8010 if(ctx.arg == "a" || ctx.arg == "A") {
140
2/4
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
✗ Branch 3 not taken.
432 RETURN_IF_ALLOWED(a);
141 // todo: some hint for "don't name your label "a" "?
142 36 asar_throw_error(1, error_type_block, error_id_bad_addr_mode);
143 }
144
2/4
✓ Branch 0 taken 3879 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1944 times.
✗ Branch 3 not taken.
16326 RETURN_IF_ALLOWED(abs);
145 asar_throw_error(1, error_type_block, error_id_bad_addr_mode);
146 #undef RETURN_IF_ALLOWED
147
11/22
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4374 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 396 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 276 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 576 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 144 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 144 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 900 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 144 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 144 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 1785 times.
✗ Branch 21 not taken.
22602 }
148
149 const char* format_valid_widths(int min, int max) {
150 if(min == 1) {
151 if(max == 1) return "only 8-bit";
152 if(max == 2) return "only 8-bit or 16-bit";
153 if(max == 3) return "any width"; // shouldn't actually happen lol
154 } else if(min == 2) {
155 if(max == 2) return "only 16-bit";
156 if(max == 3) return "only 16-bit or 24-bit";
157 } else if(min == 3) {
158 return "only 24-bit";
159 }
160 return "???";
161 }
162
163 7758 int get_real_len(int min_len, int max_len, insn_context& ctx, const parse_result& parsed) {
164 // we can theoretically give min_len to getlen now :o
165
1/2
✓ Branch 0 taken 3885 times.
✗ Branch 1 not taken.
7758 int arg_min_len = getlen(parsed.arg, parsed.kind == addr_kind::imm);
166 int out_len;
167
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 5418 times.
7758 if(ctx.modifier != 0) {
168
2/2
✓ Branch 0 taken 1161 times.
✓ Branch 1 taken 9 times.
2340 out_len = getlenfromchar(ctx.modifier);
169
2/4
✓ Branch 0 taken 2322 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2322 times.
2322 if(out_len < min_len || out_len > max_len)
170 asar_throw_error(2, error_type_block, error_id_bad_access_width, format_valid_widths(min_len, max_len), out_len*8);
171 } else {
172
2/2
✓ Branch 0 taken 609 times.
✓ Branch 1 taken 4809 times.
5418 if(parsed.kind == addr_kind::imm) {
173
4/4
✓ Branch 0 taken 348 times.
✓ Branch 1 taken 261 times.
✓ Branch 2 taken 45 times.
✓ Branch 3 taken 261 times.
609 if(!is_hex_constant(parsed.arg.data()))
174
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
87 asar_throw_warning(2, warning_id_implicitly_sized_immediate);
175
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 609 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
609 if(arg_min_len == 3 && max_len == 2) {
176 // lda #label
177 // todo: throw pedantic warning
178 ctx.written_len = max_len;
179 return max_len;
180 }
181 }
182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5418 times.
5418 if(arg_min_len > max_len) {
183 // we might get here on pass 0 if getlen is wrong about the width,
184 // which can happen with forward labels and namespaces.
185 // in that case return some valid width to silence the error.
186 if(pass == 0) return max_len;
187
188 asar_throw_error(2, error_type_block, error_id_bad_access_width, format_valid_widths(min_len, max_len), arg_min_len*8);
189 }
190 // todo warn about widening when dpbase != 0
191 5418 out_len = std::max(arg_min_len, min_len);
192 }
193 7740 ctx.written_len = out_len;
194 7740 return out_len;
195 }
196
197 219 void handle_implicit_rep(string& arg, int opcode) {
198 219 int64_t rep_count = getnum(arg);
199
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 111 times.
219 if(foundlabel) asar_throw_error(0, error_type_block, error_id_no_labels_here);
200
2/2
✓ Branch 0 taken 510 times.
✓ Branch 1 taken 219 times.
729 for (int64_t i=0;i<rep_count;i++) { write1(opcode); }
201 219 }
202
203 5937 void opcode0(insn_context& ctx, uint8_t opcode) {
204 11862 ctx.written_opcode = opcode;
205
13/26
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1413 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 9 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 9 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 9 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 9 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 9 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 9 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 9 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 9 times.
✗ Branch 25 not taken.
7845 write1(opcode);
206 7458 }
207 3441 void opcode1(insn_context& ctx, uint8_t opcode, int num) {
208 1722 opcode0(ctx, opcode);
209 3441 write1(num);
210 3441 }
211 3075 void opcode2(insn_context& ctx, uint8_t opcode, int num) {
212 1542 opcode0(ctx, opcode);
213 3075 write2(num);
214 3075 }
215 1530 void opcode3(insn_context& ctx, uint8_t opcode, int num) {
216 765 opcode0(ctx, opcode);
217 1530 write3(num);
218 1530 }
219
220 template<int base, bool allow_imm = true>
221 9192 void the8(insn_context& ctx) {
222 using K = addr_kind;
223
1/2
✓ Branch 0 taken 2301 times.
✗ Branch 1 not taken.
9192 auto parsed = parse_addr_kind<K::xind, K::s, K::abs, K::lind, K::imm, K::indy, K::ind, K::sy, K::x, K::y, K::lindy>(ctx);
224 9192 addr_kind kind = parsed.kind;
225 4602 int min_len = 0, max_len = 4;
226
14/14
✓ Branch 0 taken 4380 times.
✓ Branch 1 taken 216 times.
✓ Branch 2 taken 2157 times.
✓ Branch 3 taken 2223 times.
✓ Branch 4 taken 2085 times.
✓ Branch 5 taken 72 times.
✓ Branch 6 taken 2013 times.
✓ Branch 7 taken 72 times.
✓ Branch 8 taken 1941 times.
✓ Branch 9 taken 72 times.
✓ Branch 10 taken 1869 times.
✓ Branch 11 taken 72 times.
✓ Branch 12 taken 72 times.
✓ Branch 13 taken 1797 times.
9192 if(kind == K::xind || kind == K::s || kind == K::sy || kind == K::indy || kind == K::ind || kind == K::lind || kind == K::lindy) min_len = max_len = 1;
227
2/2
✓ Branch 0 taken 894 times.
✓ Branch 1 taken 903 times.
3594 else if(kind == K::abs) min_len = 1, max_len = 3;
228
2/2
✓ Branch 0 taken 450 times.
✓ Branch 1 taken 453 times.
1806 else if(kind == K::x) min_len = 1, max_len = 3;
229
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 381 times.
906 else if(kind == K::y) min_len = max_len = 2;
230
1/2
✓ Branch 0 taken 381 times.
✗ Branch 1 not taken.
762 else if(kind == K::imm) min_len = 1, max_len = 2;
231
4/4
✓ Branch 0 taken 1532 times.
✓ Branch 1 taken 3064 times.
✓ Branch 2 taken 1520 times.
✓ Branch 3 taken 12 times.
9192 int64_t the_num = pass == 2 ? getnum(parsed.arg) : 0;
232
2/2
✓ Branch 0 taken 4566 times.
✓ Branch 1 taken 18 times.
9168 int real_len = get_real_len(min_len, max_len, ctx, parsed);
233 4572 int opcode_offset = 0;
234
2/2
✓ Branch 0 taken 1965 times.
✓ Branch 1 taken 2601 times.
9132 if(real_len == 1) {
235
2/2
✓ Branch 0 taken 981 times.
✓ Branch 1 taken 984 times.
3930 if(kind == K::xind) opcode_offset = 0x1;
236
2/2
✓ Branch 0 taken 909 times.
✓ Branch 1 taken 984 times.
3786 if(kind == K::s) opcode_offset = 0x3;
237
2/2
✓ Branch 0 taken 909 times.
✓ Branch 1 taken 984 times.
3786 if(kind == K::abs) opcode_offset = 0x5;
238
2/2
✓ Branch 0 taken 801 times.
✓ Branch 1 taken 984 times.
3570 if(kind == K::lind) opcode_offset = 0x7;
239
2/2
✓ Branch 0 taken 912 times.
✓ Branch 1 taken 981 times.
3786 if(kind == K::imm) opcode_offset = 0x9;
240
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 984 times.
3624 if(kind == K::indy) opcode_offset = 0x11;
241
2/2
✓ Branch 0 taken 909 times.
✓ Branch 1 taken 984 times.
3786 if(kind == K::ind) opcode_offset = 0x12;
242
2/2
✓ Branch 0 taken 909 times.
✓ Branch 1 taken 984 times.
3786 if(kind == K::sy) opcode_offset = 0x13;
243
2/2
✓ Branch 0 taken 909 times.
✓ Branch 1 taken 984 times.
3786 if(kind == K::x) opcode_offset = 0x15;
244
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 1677 times.
3642 if(kind == K::lindy) opcode_offset = 0x17;
245
1/2
✓ Branch 0 taken 1965 times.
✗ Branch 1 not taken.
3930 opcode1(ctx, base + opcode_offset, the_num);
246
2/2
✓ Branch 0 taken 1647 times.
✓ Branch 1 taken 954 times.
5202 } else if(real_len == 2) {
247
2/2
✓ Branch 0 taken 822 times.
✓ Branch 1 taken 825 times.
3294 if(kind == K::imm) opcode_offset = 0x9;
248
2/2
✓ Branch 0 taken 612 times.
✓ Branch 1 taken 822 times.
2868 if(kind == K::abs) opcode_offset = 0xd;
249
2/2
✓ Branch 0 taken 435 times.
✓ Branch 1 taken 825 times.
2520 if(kind == K::y) opcode_offset = 0x19;
250
2/2
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 1275 times.
3150 if(kind == K::x) opcode_offset = 0x1d;
251
1/2
✓ Branch 0 taken 1647 times.
✗ Branch 1 not taken.
3294 opcode2(ctx, base + opcode_offset, the_num);
252
1/2
✓ Branch 0 taken 954 times.
✗ Branch 1 not taken.
1908 } else if(real_len == 3) {
253
2/2
✓ Branch 0 taken 477 times.
✓ Branch 1 taken 477 times.
1908 if(kind == K::abs) opcode_offset = 0xf;
254
2/2
✓ Branch 0 taken 312 times.
✓ Branch 1 taken 321 times.
1266 if(kind == K::x) opcode_offset = 0x1f;
255
1/2
✓ Branch 0 taken 954 times.
✗ Branch 1 not taken.
1908 opcode3(ctx, base + opcode_offset, the_num);
256 }
257 9162 }
258
259 template<int base, int accum_opc, bool is_bit = false>
260
1/2
✓ Branch 0 taken 612 times.
✗ Branch 1 not taken.
2448 void thenext8(insn_context& ctx) {
261 using K = addr_kind;
262 1224 parse_result parsed;
263 if constexpr(is_bit) {
264
1/2
✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
432 parsed = parse_addr_kind<K::x, K::abs, K::imm>(ctx);
265 } else {
266
1/2
✓ Branch 0 taken 1008 times.
✗ Branch 1 not taken.
2016 parsed = parse_addr_kind<K::x, K::abs, K::imm, K::a, K::imp>(ctx);
267 // todo: some checks on ctx.modifier here
268
3/4
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 972 times.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
2016 if(parsed.kind == K::imm) return handle_implicit_rep(parsed.arg, accum_opc);
269
3/4
✓ Branch 0 taken 486 times.
✓ Branch 1 taken 486 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 432 times.
1944 if(parsed.kind == K::a || parsed.kind == K::imp) {
270
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
108 opcode0(ctx, accum_opc);
271 108 return;
272 }
273 }
274
3/4
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 720 times.
✓ Branch 2 taken 360 times.
✗ Branch 3 not taken.
2160 int64_t the_num = pass == 2 ? getnum(parsed.arg) : 0;
275
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
2160 int real_len = get_real_len(1, 2, ctx, parsed);
276 1080 int opcode = 0;
277
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 1008 times.
2160 if(parsed.kind == K::imm) {
278 72 opcode = accum_opc;
279 }
280
2/2
✓ Branch 0 taken 540 times.
✓ Branch 1 taken 540 times.
2160 if(real_len == 1) {
281
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 288 times.
1080 if(parsed.kind == K::abs) opcode = base+0x6;
282
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 288 times.
1080 if(parsed.kind == K::x) opcode = base+0x16;
283
1/2
✓ Branch 0 taken 540 times.
✗ Branch 1 not taken.
1080 opcode1(ctx, opcode, the_num);
284
1/2
✓ Branch 0 taken 540 times.
✗ Branch 1 not taken.
1080 } else if(real_len == 2) {
285
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 288 times.
1080 if(parsed.kind == K::abs) opcode = base+0xe;
286
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 288 times.
1080 if(parsed.kind == K::x) opcode = base+0x1e;
287
1/2
✓ Branch 0 taken 540 times.
✗ Branch 1 not taken.
1080 opcode2(ctx, opcode, the_num);
288 }
289
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 72 times.
1440 }
290
291 template<int base>
292 288 void tsb_trb(insn_context& ctx) {
293 using K = addr_kind;
294
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
288 auto parsed = parse_addr_kind<K::abs>(ctx);
295
3/4
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
288 int64_t the_num = pass == 2 ? getnum(parsed.arg) : 0;
296
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
288 int real_len = get_real_len(1, 2, ctx, parsed);
297
3/4
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
288 if(real_len == 1) opcode1(ctx, base + 0x04, the_num);
298
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
144 else opcode2(ctx, base + 0x0c, the_num);
299 288 }
300
301 template<int opc, int width = 1>
302 432 void branch(insn_context& ctx) {
303 using K = addr_kind;
304
2/2
✓ Branch 0 taken 99 times.
✓ Branch 1 taken 9 times.
432 auto parsed = parse_addr_kind<K::abs>(ctx);
305 198 int64_t num = 0;
306
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 132 times.
396 if(pass == 2) {
307
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
132 num = getnum(parsed.arg);
308 132 bool target_is_abs = foundlabel;
309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
132 if(ctx.modifier != 0) {
310 if(to_lower(ctx.modifier) == 'a') target_is_abs = true;
311 else if(to_lower(ctx.modifier) == 'r') target_is_abs = false;
312 // TODO: better error message
313 else asar_throw_error(2, error_type_block, error_id_invalid_opcode_length);
314 }
315
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 6 times.
132 if(target_is_abs) {
316 // cast delta to signed 16-bit, this makes it possible to handle bank-border-wrapping automatically
317 120 int16_t delta = num - (snespos + width + 1);
318
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
120 if((num & ~0xffff) != (snespos & ~0xffff)) {
319 // todo: should throw error "can't branch to different bank"
320 asar_throw_error(2, error_type_block, error_id_relative_branch_out_of_bounds, dec(delta).data());
321 }
322
3/4
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 27 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
108 if(width==1 && (delta < -128 || delta > 127)) {
323 asar_throw_error(2, error_type_block, error_id_relative_branch_out_of_bounds, dec(delta).data());
324 }
325 120 num = delta;
326 } else {
327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
12 if(num & ~(width==2 ? 0xffff : 0xff)) {
328 asar_throw_error(2, error_type_block, error_id_relative_branch_out_of_bounds, dec(num).data());
329 }
330 12 num = (int16_t)(width==2 ? num : (int8_t)num);
331 }
332 }
333
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
324 if(width == 1) opcode1(ctx, opc, num);
334
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
72 else if(width == 2) opcode2(ctx, opc, num);
335 396 }
336
337 template<int opc>
338 1548 void implied(insn_context& ctx) {
339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 774 times.
1548 if(ctx.arg != "") {
340 // todo: some kind of "this instruction doesn't take an argument" message?
341 asar_throw_error(0, error_type_block, error_id_bad_addr_mode);
342 }
343 774 opcode0(ctx, opc);
344 1548 }
345
346 template<int opc>
347 6162 void implied_rep(insn_context& ctx) {
348 using K = addr_kind;
349
1/2
✓ Branch 0 taken 1542 times.
✗ Branch 1 not taken.
6162 auto parsed = parse_addr_kind<K::imm, K::imp>(ctx);
350
2/2
✓ Branch 0 taken 2898 times.
✓ Branch 1 taken 183 times.
6162 if(parsed.kind == K::imp) {
351
1/2
✓ Branch 0 taken 1449 times.
✗ Branch 1 not taken.
2898 opcode0(ctx, opc);
352 } else {
353
1/2
✓ Branch 0 taken 183 times.
✗ Branch 1 not taken.
366 handle_implicit_rep(parsed.arg, opc);
354 }
355 6162 }
356
357 template<int base, char op, char xy>
358
1/2
✓ Branch 0 taken 450 times.
✗ Branch 1 not taken.
1800 void xy_ops(insn_context& ctx) {
359 using K = addr_kind;
360 900 parse_result parsed;
361 if(op == 'S') { // stx
362
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
360 parsed = parse_addr_kind<K::abs, (xy == 'X' ? K::y : K::x)>(ctx);
363 } else if(op == 'L') { // ldx
364
1/2
✓ Branch 0 taken 432 times.
✗ Branch 1 not taken.
864 parsed = parse_addr_kind<K::abs, K::imm, (xy == 'X' ? K::y : K::x)>(ctx);
365 } else { // cpx
366
1/2
✓ Branch 0 taken 288 times.
✗ Branch 1 not taken.
576 parsed = parse_addr_kind<K::abs, K::imm>(ctx);
367 }
368
3/4
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 600 times.
✓ Branch 2 taken 300 times.
✗ Branch 3 not taken.
1800 int64_t the_num = pass == 2 ? getnum(parsed.arg) : 0;
369
1/2
✓ Branch 0 taken 900 times.
✗ Branch 1 not taken.
1800 int real_len = get_real_len(1, 2, ctx, parsed);
370 900 int opcode = 0;
371
2/2
✓ Branch 0 taken 450 times.
✓ Branch 1 taken 450 times.
1800 if(parsed.kind == K::imm) {
372 288 opcode = base;
373
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 180 times.
1224 } else if(parsed.kind == K::abs) {
374
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 216 times.
864 if(real_len == 1) opcode = base + 0x4;
375 216 else opcode = base + 0xc;
376 } else { // ,x or ,y
377
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 72 times.
360 if(real_len == 1) opcode = base + 0x14;
378 72 else opcode = base + 0x1c;
379 }
380
3/4
✓ Branch 0 taken 306 times.
✓ Branch 1 taken 288 times.
✓ Branch 2 taken 468 times.
✗ Branch 3 not taken.
1512 if(real_len == 1) opcode1(ctx, opcode, the_num);
381
2/4
✓ Branch 0 taken 432 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 432 times.
✗ Branch 3 not taken.
864 else if(real_len == 2) opcode2(ctx, opcode, the_num);
382 1800 }
383
384 template<int opc>
385 216 void interrupt(insn_context& ctx) {
386 using K = addr_kind;
387
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
216 auto parsed = parse_addr_kind<K::imm, K::imp>(ctx);
388
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 54 times.
216 if(parsed.kind == K::imp) {
389
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
108 opcode1(ctx, opc, 0);
390 } else {
391
3/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
108 int64_t num = pass == 2 ? getnum(parsed.arg) : 0;
392 // this is kinda hacky
393
3/8
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
72 if(num < 0 || num > 255) asar_throw_error(2, error_type_block, error_id_bad_access_width, format_valid_widths(1, 1), num > 65535 ? 24 : 16);
394
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
108 opcode1(ctx, opc, num);
395 }
396 216 }
397
398 template<int opc, addr_kind k, int width>
399 1044 void oneoff(insn_context& ctx) {
400
1/2
✓ Branch 0 taken 261 times.
✗ Branch 1 not taken.
1044 auto parsed = parse_addr_kind<k>(ctx);
401
3/4
✓ Branch 0 taken 174 times.
✓ Branch 1 taken 348 times.
✓ Branch 2 taken 174 times.
✗ Branch 3 not taken.
1044 int64_t the_num = pass == 2 ? getnum(parsed.arg) : 0;
402 // only for error checking, we know the answer anyways
403
1/2
✓ Branch 0 taken 522 times.
✗ Branch 1 not taken.
1044 get_real_len(width, width, ctx, parsed);
404
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
108 if(width == 1) opcode1(ctx, opc, the_num);
405
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
36 else if(width == 2) opcode2(ctx, opc, the_num);
406
1/2
✓ Branch 0 taken 450 times.
✗ Branch 1 not taken.
900 else if(width == 3) opcode3(ctx, opc, the_num);
407 1044 }
408
409 144 void stz(insn_context& ctx) {
410 using K = addr_kind;
411
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
144 auto parsed = parse_addr_kind<K::abs, K::x>(ctx);
412
3/4
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
144 int64_t the_num = pass == 2 ? getnum(parsed.arg) : 0;
413
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 int real_len = get_real_len(1, 2, ctx, parsed);
414
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 72 times.
144 if(real_len == 1) {
415
3/4
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
72 if(parsed.kind == K::abs) opcode1(ctx, 0x64, the_num);
416
2/4
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
36 else if(parsed.kind == K::x) opcode1(ctx, 0x74, the_num);
417 } else {
418
3/4
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
72 if(parsed.kind == K::abs) opcode2(ctx, 0x9c, the_num);
419
2/4
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
36 else if(parsed.kind == K::x) opcode2(ctx, 0x9e, the_num);
420 }
421 144 }
422
423 template<char which>
424 768 void jmp_jsr_jml(insn_context& ctx) {
425 using K = addr_kind;
426
1/2
✓ Branch 0 taken 195 times.
✗ Branch 1 not taken.
768 auto parsed = which == 'R' ? parse_addr_kind<K::abs, K::xind>(ctx)
427 : which == 'P' ? parse_addr_kind<K::abs, K::xind, K::ind, K::lind>(ctx)
428 : /* 'L' */ parse_addr_kind<K::abs, K::lind>(ctx);
429
3/4
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 256 times.
✓ Branch 2 taken 128 times.
✗ Branch 3 not taken.
768 int64_t the_num = pass == 2 ? getnum(parsed.arg) : 0;
430 // set optimizeforbank to -1 (i.e. auto, assume DBR = current bank)
431 // because jmp and jsr's arguments are relative to the program bank anyways
432 768 int old_optimize = optimizeforbank;
433
4/4
✓ Branch 0 taken 204 times.
✓ Branch 1 taken 180 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 159 times.
768 if(parsed.kind == K::lind || parsed.kind == K::ind) {
434 // these ones for Some Reason always read the pointer from bank 0 lol
435 144 optimizeforbank = 0;
436 } else {
437 // the rest use bank K
438 624 optimizeforbank = -1;
439 }
440 390 int the_width = 2;
441
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 18 times.
288 if(which == 'L' && parsed.kind == K::abs) the_width = 3;
442
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
768 get_real_len(the_width, the_width, ctx, parsed);
443 768 optimizeforbank = old_optimize;
444 if(which == 'R') {
445
3/4
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 126 times.
✗ Branch 3 not taken.
288 if(parsed.kind == K::abs) opcode2(ctx, 0x20, the_num);
446
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
36 else if(parsed.kind == K::xind) opcode2(ctx, 0xfc, the_num);
447 } else if(which == 'L') {
448
3/4
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 126 times.
✗ Branch 3 not taken.
288 if(parsed.kind == K::abs) opcode3(ctx, 0x5c, the_num);
449
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
36 else if(parsed.kind == K::lind) opcode2(ctx, 0xdc, the_num);
450 } else {
451
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
192 if(parsed.kind == K::abs) opcode2(ctx, 0x4c, the_num);
452
3/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
144 else if(parsed.kind == K::ind) opcode2(ctx, 0x6c, the_num);
453
3/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
108 else if(parsed.kind == K::xind) opcode2(ctx, 0x7c, the_num);
454
2/4
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
72 else if(parsed.kind == K::lind) opcode2(ctx, 0xdc, the_num);
455 }
456 768 }
457
458 template<int opc>
459 72 void mvn_mvp(insn_context& ctx) {
460 72 int count = 0;
461
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
72 autoptr<char**> parts = qpsplit(ctx.arg.raw(), ',', &count);
462
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
72 if(count != 2) asar_throw_error(2, error_type_block, error_id_bad_addr_mode);
463 // todo length checks ???
464
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
36 opcode0(ctx, opc);
465
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 24 times.
72 if(pass == 2) {
466
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
24 write1(getnum(parts[0]));
467
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
24 write1(getnum(parts[1]));
468 } else {
469
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
48 write2(0);
470 }
471 72 }
472
473 assocarr<void(*)(insn_context&)> mnemonics = {
474 { "ora", the8<0x00> },
475 { "and", the8<0x20> },
476 { "eor", the8<0x40> },
477 { "adc", the8<0x60> },
478 { "sta", the8<0x80, false> },
479 { "lda", the8<0xa0> },
480 { "cmp", the8<0xc0> },
481 { "sbc", the8<0xe0> },
482 { "asl", thenext8<0x00, 0x0a> },
483 { "bit", thenext8<0x1e, 0x89, true> },
484 { "rol", thenext8<0x20, 0x2a> },
485 { "lsr", thenext8<0x40, 0x4a> },
486 { "ror", thenext8<0x60, 0x6a> },
487 { "dec", thenext8<0xc0, 0x3a> },
488 { "inc", thenext8<0xe0, 0x1a> },
489 { "bcc", branch<0x90> },
490 { "bcs", branch<0xb0> },
491 { "beq", branch<0xf0> },
492 { "bmi", branch<0x30> },
493 { "bne", branch<0xd0> },
494 { "bpl", branch<0x10> },
495 { "bra", branch<0x80> },
496 { "bvc", branch<0x50> },
497 { "bvs", branch<0x70> },
498 { "brl", branch<0x82, 2> },
499 { "clc", implied<0x18> },
500 { "cld", implied<0xd8> },
501 { "cli", implied<0x58> },
502 { "clv", implied<0xb8> },
503 { "dex", implied_rep<0xca> },
504 { "dey", implied_rep<0x88> },
505 { "inx", implied_rep<0xe8> },
506 { "iny", implied_rep<0xc8> },
507 { "nop", implied_rep<0xea> },
508 { "pha", implied<0x48> },
509 { "phb", implied<0x8b> },
510 { "phd", implied<0x0b> },
511 { "phk", implied<0x4b> },
512 { "php", implied<0x08> },
513 { "phx", implied<0xda> },
514 { "phy", implied<0x5a> },
515 { "pla", implied<0x68> },
516 { "plb", implied<0xab> },
517 { "pld", implied<0x2b> },
518 { "plp", implied<0x28> },
519 { "plx", implied<0xfa> },
520 { "ply", implied<0x7a> },
521 { "rti", implied<0x40> },
522 { "rtl", implied<0x6b> },
523 { "rts", implied<0x60> },
524 { "sec", implied<0x38> },
525 { "sed", implied<0xf8> },
526 { "sei", implied<0x78> },
527 { "stp", implied<0xdb> },
528 { "tax", implied<0xaa> },
529 { "tay", implied<0xa8> },
530 { "tcd", implied<0x5b> },
531 { "tcs", implied<0x1b> },
532 { "tdc", implied<0x7b> },
533 { "tsc", implied<0x3b> },
534 { "tsx", implied<0xba> },
535 { "txa", implied<0x8a> },
536 { "txs", implied<0x9a> },
537 { "txy", implied<0x9b> },
538 { "tya", implied<0x98> },
539 { "tyx", implied<0xbb> },
540 { "wai", implied<0xcb> },
541 { "xba", implied<0xeb> },
542 { "xce", implied<0xfb> },
543 { "ldy", xy_ops<0xa0, 'L', 'Y'> },
544 { "ldx", xy_ops<0xa2, 'L', 'X'> },
545 { "cpy", xy_ops<0xc0, 'C', 'Y'> },
546 { "cpx", xy_ops<0xe0, 'C', 'X'> },
547 { "stx", xy_ops<0x82, 'S', 'X'> },
548 { "sty", xy_ops<0x80, 'S', 'Y'> },
549 { "cop", interrupt<0x02> },
550 { "wdm", interrupt<0x42> },
551 { "brk", interrupt<0x00> },
552 { "tsb", tsb_trb<0x00> },
553 { "trb", tsb_trb<0x10> },
554 { "rep", oneoff<0xc2, addr_kind::imm, 1> },
555 { "sep", oneoff<0xe2, addr_kind::imm, 1> },
556 { "pei", oneoff<0xd4, addr_kind::ind, 1> },
557 { "pea", oneoff<0xf4, addr_kind::abs, 2> },
558 { "mvn", mvn_mvp<0x54> },
559 { "mvp", mvn_mvp<0x44> },
560 { "jsl", oneoff<0x22, addr_kind::abs, 3> },
561 { "per", branch<0x62, 2> },
562 { "stz", stz },
563 { "jmp", jmp_jsr_jml<'P'> },
564 { "jsr", jmp_jsr_jml<'R'> },
565 { "jml", jmp_jsr_jml<'L'> },
566 };
567
568
569 70545 bool asblock_65816(char** word, int numwords)
570 {
571
2/2
✓ Branch 0 taken 37719 times.
✓ Branch 1 taken 32826 times.
70545 if(word[0][0] == '\'') return false;
572 32223 int word_i = 0;
573 32223 bool autoclean = false;
574
2/2
✓ Branch 0 taken 486 times.
✓ Branch 1 taken 68853 times.
69339 if(!stricmpwithlower(word[0], "autoclean")) {
575 243 word_i++;
576 243 autoclean = true;
577 }
578
1/2
✓ Branch 0 taken 32223 times.
✗ Branch 1 not taken.
69339 string opc = word[word_i++];
579 32223 string par;
580
2/2
✓ Branch 0 taken 63981 times.
✓ Branch 1 taken 69339 times.
133320 for(int i = word_i; i < numwords; i++){
581
3/4
✓ Branch 0 taken 2031 times.
✓ Branch 1 taken 61950 times.
✓ Branch 2 taken 2031 times.
✗ Branch 3 not taken.
63981 if(i > word_i) par += " ";
582
1/2
✓ Branch 0 taken 63981 times.
✗ Branch 1 not taken.
63981 par += word[i];
583 }
584
2/2
✓ Branch 0 taken 353826 times.
✓ Branch 1 taken 69339 times.
423165 for(int i = 0; i < opc.length(); i++) opc.raw()[i] = to_lower(opc[i]);
585 32223 char mod = 0;
586
6/6
✓ Branch 0 taken 69051 times.
✓ Branch 1 taken 288 times.
✓ Branch 2 taken 2340 times.
✓ Branch 3 taken 66711 times.
✓ Branch 4 taken 1170 times.
✓ Branch 5 taken 31053 times.
69339 if(opc.length() >= 2 && opc[opc.length()-2] == '.') {
587 2340 mod = opc[opc.length()-1];
588
1/2
✓ Branch 0 taken 2340 times.
✗ Branch 1 not taken.
2340 opc.truncate(opc.length()-2);
589 }
590
3/4
✓ Branch 0 taken 69339 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32208 times.
✓ Branch 3 taken 37131 times.
69339 if(!mnemonics.exists(opc.data())) return false;
591
2/6
✓ Branch 0 taken 12129 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12129 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
12129 insn_context ctx{par, {}, mod, 0};
592 12129 ctx.orig_insn[0] = opc[0];
593 12129 ctx.orig_insn[1] = opc[1];
594 12129 ctx.orig_insn[2] = opc[2];
595
3/4
✓ Branch 0 taken 12129 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12081 times.
✓ Branch 3 taken 48 times.
12129 mnemonics.find(opc.data())(ctx);
596
4/4
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 11649 times.
✓ Branch 2 taken 288 times.
✓ Branch 3 taken 144 times.
12081 if(autoclean && pass > 0) {
597 // should be changed to "can't use autoclean on this instruction"?
598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 288 times.
288 if(ctx.written_len != 3) asar_throw_error(2, error_type_block, error_id_broken_autoclean);
599
1/2
✓ Branch 0 taken 288 times.
✗ Branch 1 not taken.
288 handle_autoclean(ctx.parsed_arg, ctx.written_opcode, snespos - 4);
600 }
601 6048 return true;
602 69435 }
603