asar coverage - build #167


src/asar/
File: src/asar/assembleblock.cpp
Date: 2024-01-27 14:19:37
Lines:
1361/1627
83.7%
Functions:
38/41
92.7%
Branches:
2048/3780
54.2%

Line Branch Exec Source
1 #include "addr2line.h"
2 #include "asar.h"
3 #include "libstr.h"
4 #include "libsmw.h"
5 #include "assocarr.h"
6 #include "autoarray.h"
7 #include "warnings.h"
8 #include "assembleblock.h"
9 #include "asar_math.h"
10 #include "macro.h"
11 #include "platform/file-helpers.h"
12 #include <cinttypes>
13
14 #include "interface-shared.h"
15 #include "arch-shared.h"
16
17 int arch=arch_65816;
18
19 int snespos;
20 int realsnespos;
21 int startpos;
22 int realstartpos;
23
24 bool emulatexkas;
25 bool mapper_set = false;
26 bool warn_endwhile = true;
27 static bool specifiedasarver = false;
28
29 static int old_snespos;
30 static int old_startpos;
31 static int old_optimizeforbank;
32 static int struct_base;
33 static string struct_name;
34 static string struct_parent;
35 static bool in_struct = false;
36 static bool in_sub_struct = false;
37 static bool static_struct = false;
38 static bool in_spcblock = false;
39
40 assocarr<snes_struct> structs;
41
42 static bool movinglabelspossible = false;
43
44 static bool disable_bank_cross_errors = false;
45 static bool check_half_banks_crossed = false;
46
47 int bytes;
48
49 static enum {
50 ratsmeta_ban,
51 ratsmeta_allow,
52 ratsmeta_used,
53 } ratsmetastate=ratsmeta_ban;
54
55 enum spcblock_type{
56 spcblock_nspc,
57 spcblock_custom
58 };
59
60 struct spcblock_data{
61 unsigned int destination;
62 spcblock_type type;
63 string macro_name;
64
65 unsigned int execute_address; // Can be removed in Asar 2.0
66 unsigned int size_address;
67 mapper_t old_mapper;
68 }spcblock;
69
70 282 int snestopc_pick(int addr)
71 {
72 492 return snestopc(addr);
73 }
74
75 239012 inline void verifysnespos()
76 {
77
3/4
✓ Branch 0 taken 238988 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 238988 times.
239012 if (snespos<0 || realsnespos<0)
78 {
79 24 asar_throw_warning(0, warning_id_missing_org);
80 24 snespos=0x008000;
81 24 realsnespos=0x008000;
82 24 startpos=0x008000;
83 24 realstartpos=0x008000;
84 }
85 239012 }
86
87 960 static int fixsnespos(int inaddr, int step)
88 {
89 // randomdude999: turns out it wasn't very reliable at all.
90 /* // RPG Hacker: No idea how reliable this is.
91 // Might not work with some of the more exotic mappers.
92 return pctosnes(snestopc(inaddr) + step); */
93
2/2
✓ Branch 0 taken 372 times.
✓ Branch 1 taken 588 times.
960 if (mapper == lorom) {
94
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 348 times.
372 if ((inaddr&0xFFFF)+step > 0xFFFF) {
95 // bank crossed
96 24 return inaddr+step+0x8000;
97 }
98 348 return inaddr+step;
99
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 294 times.
294 } else if (mapper == hirom) {
100 if ((inaddr&0x400000) == 0) {
101 // system pages, need to account for low pages and stuff
102 if ((inaddr&0xFFFF)+step > 0xFFFF) {
103 return inaddr+step+0x8000;
104 }
105 }
106 return inaddr+step;
107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 294 times.
294 } else if (mapper == exlorom) {
108 // exlorom has no mirroring so this should work fine
109 return pctosnes(snestopc(inaddr)+step);
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 294 times.
294 } else if (mapper == exhirom) {
111 // apparently exhirom is pretty similar to hirom after all
112 if ((inaddr&0x400000) == 0) {
113 // system pages, need to account for low pages and stuff
114 if ((inaddr&0xFFFF)+step > 0xFFFF) {
115 return inaddr+step+0x8000;
116 }
117 }
118 return inaddr+step;
119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 294 times.
294 } else if (mapper == sa1rom) {
120 if((inaddr&0x400000) == 0) {
121 // lorom area
122 if ((inaddr&0xFFFF)+step > 0xFFFF) {
123 return inaddr+step+0x8000;
124 }
125 return inaddr+step;
126 } else {
127 // hirom area
128 return inaddr+step;
129 }
130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 294 times.
294 } else if (mapper == sfxrom) {
131 if ((inaddr&0x400000) == 0) {
132 // lorom area
133 if ((inaddr&0xFFFF)+step > 0xFFFF) {
134 return inaddr+step+0x8000;
135 }
136 } else {
137 // hirom area
138 return inaddr+step;
139 }
140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 294 times.
294 } else if (mapper == bigsa1rom) {
141 // no mirrors here, so this should work
142 return pctosnes(snestopc(inaddr)+step);
143
1/2
✓ Branch 0 taken 294 times.
✗ Branch 1 not taken.
294 } else if (mapper == norom) {
144 588 return inaddr+step;
145 }
146 return -1;
147 }
148
149 238304 inline void step(int num)
150 {
151
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 237824 times.
238304 if (disable_bank_cross_errors)
152 {
153 480 snespos = fixsnespos(snespos, num);
154 480 realsnespos = fixsnespos(realsnespos, num);
155
156 // RPG Hacker: Not adjusting startpos here will eventually throw
157 // an error in checkbankcross() if we set warn bankcross on again.
158 // As far as I can tell, those are pretty much just used for
159 // checking bank crossing, anyways, so it's hopefully save to just
160 // adjust them here.
161 480 startpos = snespos;
162 480 realstartpos = realsnespos;
163 }
164 else
165 {
166 237824 snespos += num;
167 237824 realsnespos += num;
168 }
169 238304 bytes+=num;
170 238304 }
171
172 238100 inline void write1_65816(unsigned int num)
173 {
174 238100 verifysnespos();
175
2/2
✓ Branch 0 taken 79356 times.
✓ Branch 1 taken 158744 times.
238100 if (pass==2)
176 {
177 79356 int pcpos=snestopc(realsnespos&0xFFFFFF);
178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79356 times.
79356 if (pcpos<0)
179 {
180 movinglabelspossible=true;
181 asar_throw_error(2, error_type_block, error_id_snes_address_doesnt_map_to_rom, hex6((unsigned int)realsnespos).data());
182 }
183 79356 writeromdata_byte(pcpos, (unsigned char)num);
184
2/2
✓ Branch 0 taken 8246 times.
✓ Branch 1 taken 71110 times.
79356 if (pcpos>=romlen) {
185
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 8172 times.
8246 if(pcpos - romlen > 0) writeromdata_bytes(romlen, default_freespacebyte, pcpos - romlen, false);
186 8246 romlen=pcpos+1;
187 }
188 }
189 238100 step(1);
190 238100 ratsmetastate=ratsmeta_ban;
191 238100 }
192
193 int recent_opcode_num = 0;
194
195 126747 void write1_pick(unsigned int num)
196 {
197
10/20
✓ Branch 0 taken 106876 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 27 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 27 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 27 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 27 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 27 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 27 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 27 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 27 times.
✗ Branch 19 not taken.
233866 write1_65816(num);
198 226718 }
199
200 228050 static bool asblock_pick(char** word, int numwords)
201 {
202 228050 recent_opcode_num = 1;
203
204
4/4
✓ Branch 0 taken 225716 times.
✓ Branch 1 taken 2334 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 225686 times.
228050 if (arch==arch_spc700 || in_spcblock) return asblock_spc700(word, numwords);
205
2/2
✓ Branch 0 taken 222020 times.
✓ Branch 1 taken 3666 times.
225686 if (arch==arch_65816) return asblock_65816(word, numwords);
206
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 3654 times.
3666 if (arch==arch_spc700_inline) return asblock_spc700(word, numwords);
207
1/2
✓ Branch 0 taken 3654 times.
✗ Branch 1 not taken.
3654 if (arch==arch_superfx) return asblock_superfx(word, numwords);
208 return true;
209 }
210
211 #define write1 write1_pick
212 #define snestopc snestopc_pick
213
214 1368 const char * safedequote(char * str)
215 {
216 1368 const char * tmp=dequote(str);
217
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1368 times.
1368 if (!tmp) asar_throw_error(0, error_type_block, error_id_garbage_near_quoted_string);
218 1368 return tmp;
219 }
220
221 extern char romtitle[30];
222 extern bool stdlib;
223
224 1774 void write2(unsigned int num)
225 {
226 887 write1(num);
227 1774 write1(num/256);
228 1774 }
229
230 1154 void write3(unsigned int num)
231 {
232 577 write1(num);
233 1154 write1(num/256);
234 1154 write1(num/65536);
235 1154 }
236
237 90 void write4(unsigned int num)
238 {
239 45 write1(num);
240 90 write1(num/256);
241 90 write1(num/65536);
242 90 write1(num/16777216);
243 90 }
244
245 //these are NOT used by the math parser - see math.cpp for that
246 int read1(int insnespos)
247 {
248 int addr=snestopc(insnespos);
249 if (addr<0 || addr+1>romlen_r) return -1;
250 return
251 romdata_r[addr ] ;
252 }
253
254 48 int read2(int insnespos)
255 {
256 24 int addr=snestopc(insnespos);
257
4/4
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 23 times.
✓ Branch 3 taken 23 times.
48 if (addr<0 || addr+2>romlen_r) return -1;
258 return
259 46 romdata_r[addr ] |
260 46 (romdata_r[addr+1]<< 8);
261 }
262
263 114 int read3(int insnespos)
264 {
265 57 int addr=snestopc(insnespos);
266
3/4
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✓ Branch 3 taken 57 times.
114 if (addr<0 || addr+3>romlen_r) return -1;
267 return
268 114 romdata_r[addr ] |
269 114 (romdata_r[addr+1]<< 8)|
270 114 (romdata_r[addr+2]<<16);
271 }
272
273 1416 int getlenfromchar(char c)
274 {
275 1416 c=(char)to_lower(c);
276
2/2
✓ Branch 0 taken 708 times.
✓ Branch 1 taken 708 times.
1416 if (c=='b') return 1;
277
2/2
✓ Branch 0 taken 378 times.
✓ Branch 1 taken 378 times.
756 if (c=='w') return 2;
278
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if (c=='l') return 3;
279 if (c=='d')
280 {
281 asar_throw_warning(1, warning_id_feature_deprecated, ".d opcode suffix", "this doesn't even make sense");
282 return 4;
283 }
284 asar_throw_error(0, error_type_block, error_id_invalid_opcode_length);
285 return -1;
286 }
287
288 assocarr<snes_label> labels;
289 static autoarray<int> poslabels;
290 static autoarray<int> neglabels;
291
292 autoarray<int>* macroposlabels;
293 autoarray<int>* macroneglabels;
294
295 autoarray<string> sublabels;
296 autoarray<string>* macrosublabels;
297
298 // randomdude999: ns is still the string to prefix to all labels, it's calculated whenever namespace_list is changed
299 string ns;
300 string ns_backup;
301 autoarray<string> namespace_list;
302
303 //bool fastrom=false;
304
305 autoarray<string> includeonce;
306
307 896 bool confirmname(const char * name)
308 {
309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 896 times.
896 if (!name[0]) return false;
310
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 764 times.
896 if (is_digit(name[0])) return false;
311
2/2
✓ Branch 0 taken 5472 times.
✓ Branch 1 taken 758 times.
6230 for (int i=0;name[i];i++)
312 {
313
6/6
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 5196 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 270 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 2733 times.
5472 if (!is_alnum(name[i]) && name[i]!='_') return false;
314 }
315 379 return true;
316 }
317
318 2282656 string posneglabelname(const char ** input, bool define)
319 {
320 2282656 const char* label = *input;
321
322 1141328 string output;
323
324 1141328 int depth = 0;
325 1141328 bool ismacro = false;
326
327
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 2282606 times.
2282656 if (label[0] == '?')
328 {
329 25 ismacro = true;
330 50 label++;
331 }
332
4/4
✓ Branch 0 taken 1141328 times.
✓ Branch 1 taken 1141328 times.
✓ Branch 2 taken 216 times.
✓ Branch 3 taken 2282366 times.
2282656 if (label[0] == '-' || label[0] == '+')
333 {
334 145 char first = label[0];
335
4/4
✓ Branch 0 taken 368 times.
✓ Branch 1 taken 212 times.
✓ Branch 2 taken 290 times.
✓ Branch 3 taken 78 times.
580 for (depth = 0; label[0] && label[0] == first; depth++) label++;
336
337
2/2
✓ Branch 0 taken 270 times.
✓ Branch 1 taken 20 times.
290 if (!ismacro)
338 {
339
2/2
✓ Branch 0 taken 206 times.
✓ Branch 1 taken 64 times.
270 if (first == '+')
340 {
341 206 *input = label;
342
8/16
✓ Branch 0 taken 103 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 103 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 103 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 103 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 103 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 103 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 103 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 103 times.
✗ Branch 15 not taken.
309 output = STR":pos_" + dec(depth) + "_" + dec(poslabels[depth]);
343
3/4
✓ Branch 0 taken 102 times.
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
257 if (define) poslabels[depth]++;
344 }
345 else
346 {
347 64 *input = label;
348
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
67 if (define) neglabels[depth]++;
349
8/16
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 32 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 32 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 32 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 32 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 32 times.
✗ Branch 15 not taken.
96 output = STR":neg_" + dec(depth) + "_" + dec(neglabels[depth]);
350 }
351 }
352 else
353 {
354
3/6
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 20 times.
20 if (macrorecursion == 0 || macroposlabels == nullptr || macroneglabels == nullptr)
355 {
356 if (!macrorecursion) asar_throw_error(0, error_type_block, error_id_macro_label_outside_of_macro);
357 }
358 else
359 {
360
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if (first == '+')
361 {
362 10 *input = label;
363
12/24
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 5 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 5 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 5 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 5 times.
✗ Branch 23 not taken.
20 output = STR":macro_" + dec(calledmacros) + STR"_pos_" + dec(depth) + "_" + dec((*macroposlabels)[depth]);
364
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
10 if (define) (*macroposlabels)[depth]++;
365 }
366 else
367 {
368 10 *input = label;
369
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
13 if (define) (*macroneglabels)[depth]++;
370
12/24
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 5 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 5 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 5 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 5 times.
✗ Branch 23 not taken.
20 output = STR":macro_" + dec(calledmacros) + STR"_neg_" + dec(depth) + "_" + dec((*macroneglabels)[depth]);
371 }
372 }
373 }
374 }
375
376 2282656 return output;
377 }
378
379 2662 static string labelname(const char ** rawname, bool define=false)
380 {
381 #define deref_rawname (*rawname)
382 2662 bool ismacro = (deref_rawname[0] == '?');
383
384
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 2638 times.
2662 if (ismacro)
385 {
386 24 deref_rawname++;
387 }
388
389 1331 bool issublabel = false;
390
391 1331 string name;
392 1331 int i=-1;
393
394 1331 autoarray<string>* sublabellist = &sublabels;
395
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 2638 times.
2662 if (ismacro)
396 {
397 24 sublabellist = macrosublabels;
398 }
399
400
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2662 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2662 if (is_digit(*deref_rawname)) asar_throw_error(1, error_type_block, error_id_invalid_label_name);
401
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 2566 times.
2662 if (*deref_rawname ==':')
402 {
403 96 deref_rawname++;
404
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 name=":";
405 }
406
4/4
✓ Branch 0 taken 1283 times.
✓ Branch 1 taken 1283 times.
✓ Branch 2 taken 1193 times.
✓ Branch 3 taken 1193 times.
2566 else if (!in_struct && !in_sub_struct)
407 {
408
2/2
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 2362 times.
2430 for (i=0;(*deref_rawname =='.');i++) deref_rawname++;
409
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2362 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2362 if (!is_ualnum(*deref_rawname)) asar_throw_error(1, error_type_block, error_id_invalid_label_name);
410
3/6
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2346 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2362 if (emulatexkas && i>1) asar_throw_warning(1, warning_id_convert_to_asar);
411
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 2300 times.
2362 if (i)
412 {
413
6/12
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✓ Branch 3 taken 31 times.
✓ Branch 4 taken 31 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 31 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 31 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
62 if (!sublabellist || !(*sublabellist)[i - 1]) asar_throw_error(1, error_type_block, error_id_label_missing_parent);
414
4/8
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 31 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 31 times.
✗ Branch 7 not taken.
93 name+=STR(*sublabellist)[i-1]+"_";
415 31 issublabel = true;
416 }
417 }
418
419
4/4
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 2643 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 5 times.
2662 if (ismacro && !issublabel)
420 {
421 // RPG Hacker: Don't add the prefix for sublabels, because they already inherit it from
422 // their parents' names.
423
2/6
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
14 if (!macrorecursion || macrosublabels == nullptr) asar_throw_error(1, error_type_block, error_id_macro_label_outside_of_macro);
424
6/12
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
21 name = STR":macro_" + dec(calledmacros) + "_" + name;
425 }
426
427
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 2638 times.
2662 if(in_sub_struct)
428 {
429
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
24 name += struct_parent + ".";
430 }
431
432
4/4
✓ Branch 0 taken 2482 times.
✓ Branch 1 taken 180 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 2458 times.
2662 if (in_struct || in_sub_struct)
433 {
434
1/2
✓ Branch 0 taken 102 times.
✗ Branch 1 not taken.
204 name += struct_name;
435
1/2
✓ Branch 0 taken 102 times.
✗ Branch 1 not taken.
204 name += '.';
436
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 204 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
204 if(*deref_rawname != '.') asar_throw_error(1, error_type_block, error_id_invalid_label_name); //probably should be a better error. TODO!!!
437 204 deref_rawname++;
438 }
439
440
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2662 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2662 if (!is_ualnum(*deref_rawname)) asar_throw_error(1, error_type_block, error_id_invalid_label_name);
441
442
8/8
✓ Branch 0 taken 11945 times.
✓ Branch 1 taken 11945 times.
✓ Branch 2 taken 1530 times.
✓ Branch 3 taken 1530 times.
✓ Branch 4 taken 78 times.
✓ Branch 5 taken 2662 times.
✓ Branch 6 taken 10614 times.
✓ Branch 7 taken 1331 times.
23890 while (is_ualnum(*deref_rawname) || *deref_rawname == '.' || *deref_rawname == '[')
443 {
444
6/6
✓ Branch 0 taken 20022 times.
✓ Branch 1 taken 1206 times.
✓ Branch 2 taken 19950 times.
✓ Branch 3 taken 72 times.
✓ Branch 4 taken 78 times.
✓ Branch 5 taken 19872 times.
21228 if(!in_struct && !in_sub_struct && *deref_rawname == '[')
445 {
446 39 bool invalid = true;
447
1/2
✓ Branch 0 taken 234 times.
✗ Branch 1 not taken.
234 while (isprint(*deref_rawname))
448 {
449
2/2
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 117 times.
234 if (*(deref_rawname++) == ']')
450 {
451 39 invalid = false;
452 39 break;
453 }
454 }
455
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
78 if (invalid)
456 {
457 asar_throw_error(1, error_type_block, error_id_invalid_label_missing_closer);
458 }
459 39 }
460
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21150 times.
21150 else if (*deref_rawname == '{')
461 {
462 asar_throw_error(1, error_type_block, error_id_array_invalid_inside_structs);
463 }
464
465
1/2
✓ Branch 0 taken 10614 times.
✗ Branch 1 not taken.
21228 name+=*(deref_rawname++);
466 }
467
4/4
✓ Branch 0 taken 672 times.
✓ Branch 1 taken 1990 times.
✓ Branch 2 taken 285 times.
✓ Branch 3 taken 102 times.
2662 if (define && i>=0)
468 {
469
1/2
✓ Branch 0 taken 285 times.
✗ Branch 1 not taken.
570 (*sublabellist).reset(i);
470
2/4
✓ Branch 0 taken 285 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 285 times.
✗ Branch 3 not taken.
285 (*sublabellist)[i]=name;
471 }
472 2662 return name;
473 #undef deref_rawname
474 }
475
476 1864 inline bool labelvalcore(const char ** rawname, snes_label * rval, bool define, bool shouldthrow)
477 {
478
1/2
✓ Branch 0 taken 932 times.
✗ Branch 1 not taken.
1864 string name=labelname(rawname, define);
479 932 snes_label rval_;
480
24/36
✓ Branch 0 taken 977 times.
✓ Branch 1 taken 887 times.
✓ Branch 2 taken 90 times.
✓ Branch 3 taken 1774 times.
✓ Branch 4 taken 90 times.
✓ Branch 5 taken 887 times.
✓ Branch 6 taken 74 times.
✓ Branch 7 taken 903 times.
✓ Branch 8 taken 45 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 29 times.
✓ Branch 11 taken 16 times.
✓ Branch 12 taken 45 times.
✓ Branch 13 taken 887 times.
✓ Branch 14 taken 45 times.
✓ Branch 15 taken 887 times.
✓ Branch 16 taken 45 times.
✓ Branch 17 taken 887 times.
✓ Branch 18 taken 45 times.
✓ Branch 19 taken 887 times.
✓ Branch 20 taken 29 times.
✓ Branch 21 taken 903 times.
✓ Branch 22 taken 29 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 29 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 29 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
1938 if (ns && labels.exists(STR ns+name)) {rval_ = labels.find(STR ns+name);}
481
5/6
✓ Branch 0 taken 1736 times.
✓ Branch 1 taken 70 times.
✓ Branch 2 taken 833 times.
✓ Branch 3 taken 70 times.
✓ Branch 4 taken 833 times.
✗ Branch 5 not taken.
1806 else if (labels.exists(name)) {rval_ = labels.find(name);}
482 else
483 {
484
3/4
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 86 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 54 times.
140 if (shouldthrow && pass)
485 {
486 asar_throw_error(2, error_type_block, error_id_label_not_found, name.data());
487 }
488
1/2
✓ Branch 0 taken 140 times.
✗ Branch 1 not taken.
140 if (rval) { rval->pos = (unsigned int)-1; rval->is_static = false; }
489 140 return false;
490 }
491
1/2
✓ Branch 0 taken 1724 times.
✗ Branch 1 not taken.
1724 if (rval)
492 {
493 1724 *rval=rval_;
494 //if (fastrom && (rval_&0x700000)!=0x700000) *rval|=0x800000;
495 }
496 862 return true;
497 1864 }
498
499 1160 snes_label labelval(const char ** rawname, bool define)
500 {
501 580 snes_label rval;
502
1/2
✓ Branch 0 taken 580 times.
✗ Branch 1 not taken.
1160 labelvalcore(rawname, &rval, define, true);
503 1160 return rval;
504 }
505
506 snes_label labelval(char ** rawname, bool define)
507 {
508 snes_label rval;
509 labelvalcore(const_cast<const char**>(rawname), &rval, define, true);
510 return rval;
511 }
512
513 56 snes_label labelval(string name, bool define)
514 {
515 56 const char * rawname=name;
516 28 snes_label rval;
517
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
56 labelvalcore(&rawname, &rval, define, true);
518 84 return rval;
519 }
520
521 592 bool labelval(const char ** rawname, snes_label * rval, bool define)
522 {
523 592 return labelvalcore(rawname, rval, define, false);
524 }
525
526 bool labelval(char ** rawname, snes_label * rval, bool define)
527 {
528 return labelvalcore(const_cast<const char**>(rawname), rval, define, false);
529 }
530
531 56 bool labelval(string name, snes_label * rval, bool define)
532 {
533 56 const char * str=name;
534
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
84 return labelvalcore(&str, rval, define, false);
535 }
536
537 1082 static void setlabel(string name, int loc=-1, bool is_static=false)
538 {
539
2/2
✓ Branch 0 taken 912 times.
✓ Branch 1 taken 170 times.
1082 if (loc==-1)
540 {
541
1/2
✓ Branch 0 taken 456 times.
✗ Branch 1 not taken.
912 verifysnespos();
542 912 loc=snespos;
543 }
544
545 541 snes_label label_data;
546 1082 label_data.pos = (unsigned int)loc;
547 1082 label_data.is_static = is_static;
548
549 unsigned int labelpos;
550
2/2
✓ Branch 0 taken 362 times.
✓ Branch 1 taken 720 times.
1082 if (pass==0)
551 {
552
4/4
✓ Branch 0 taken 182 times.
✓ Branch 1 taken 180 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 180 times.
362 if (labels.exists(name))
553 {
554 2 movinglabelspossible=true;
555
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
2 asar_throw_error(0, error_type_block, error_id_label_redefined, name.data());
556 }
557
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
360 labels.create(name) = label_data;
558 }
559
2/2
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 360 times.
720 else if (pass==1)
560 {
561
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
360 labels.create(name) = label_data;
562 }
563
1/2
✓ Branch 0 taken 360 times.
✗ Branch 1 not taken.
360 else if (pass==2)
564 {
565 //all label locations are known at this point, add a sanity check
566
3/6
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 180 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 180 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
360 if (!labels.exists(name)) asar_throw_error(2, error_type_block, error_id_label_on_third_pass);
567
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
360 labelpos = labels.find(name).pos;
568
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 360 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
360 if ((int)labelpos != loc && !movinglabelspossible)
569 {
570 if((unsigned int)loc < labelpos && (unsigned int)loc>>16 != labelpos>>16) asar_throw_error(2, error_type_block, error_id_label_ambiguous, name.raw());
571 else if((unsigned int)loc < labelpos && labelpos == (dp_base + 0xFFu)) asar_throw_error(2, error_type_block, error_id_label_ambiguous, name.raw());
572 else if(errored) return;
573 else asar_throw_error(2, error_type_block, error_id_label_moving);
574 }
575 }
576 }
577
578
579 chartabledata table;
580 static autoarray<chartabledata> tablestack;
581
582 static int freespacepos[256];
583 static int freespacelen[256];
584 static int freespaceidnext;
585 static int freespaceid;
586 static int freespacestart;
587 int freespaceextra;
588 bool freespace_is_freecode;
589
590 static bool freespaceleak[256];
591 static string freespacefile[256];
592
593 static int freespaceorgpos[256];
594 static int freespaceorglen[256];
595 static bool freespacestatic[256];
596 static unsigned char freespacebyte[256];
597
598 586 static void cleartable()
599 {
600
2/2
✓ Branch 0 taken 150016 times.
✓ Branch 1 taken 586 times.
150602 for (unsigned int i=0;i<256;i++) table.table[i]=i;
601 586 }
602
603 struct pushable {
604 int arch;
605 int snespos;
606 int snesstart;
607 int snesposreal;
608 int snesstartreal;
609 int freeid;
610 int freeex;
611 int freest;
612 int arch1;
613 int arch2;
614 int arch3;
615 int arch4;
616 };
617 static autoarray<pushable> pushpc;
618 static int pushpcnum;
619
620 static autoarray<int> basestack;
621 static int basestacknum;
622
623 102 struct ns_pushable {
624 string ns;
625 autoarray<string> namespace_list;
626 bool nested_namespaces;
627 };
628
629 static autoarray<ns_pushable> pushns;
630 static int pushnsnum;
631
632
633 static unsigned char fillbyte[12];
634 static unsigned char padbyte[12];
635
636 static bool nested_namespaces = false;
637
638 936 static int getfreespaceid()
639 {
640 static const int max_num_freespaces = 125;
641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 936 times.
936 if (freespaceidnext > max_num_freespaces) asar_throw_error(pass, error_type_fatal, error_id_freespace_limit_reached, max_num_freespaces);
642 936 return freespaceidnext++;
643 }
644
645 874716 void checkbankcross()
646 {
647
6/8
✓ Branch 0 taken 7092 times.
✓ Branch 1 taken 867624 times.
✓ Branch 2 taken 7092 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7092 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3546 times.
✓ Branch 7 taken 3546 times.
874716 if (snespos<0 && realsnespos<0 && startpos<0 && realstartpos<0) return;
648
2/2
✓ Branch 0 taken 433812 times.
✓ Branch 1 taken 433812 times.
867624 if (disable_bank_cross_errors) return;
649
2/2
✓ Branch 0 taken 433479 times.
✓ Branch 1 taken 433479 times.
866958 unsigned int mask = 0x7FFF0000 | (check_half_banks_crossed ? 0x8000 : 0);
650
4/4
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 866920 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 36 times.
866958 if (((snespos^ startpos) & mask) && (((snespos - 1) ^ startpos) & mask))
651 {
652 2 asar_throw_error(pass, error_type_fatal, error_id_bank_border_crossed, snespos);
653 }
654
3/4
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 866920 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 36 times.
866956 else if (((realsnespos^realstartpos) & mask) && (((realsnespos - 1) ^ realstartpos) & mask))
655 {
656 asar_throw_error(pass, error_type_fatal, error_id_bank_border_crossed, realsnespos);
657 }
658 }
659
660 2258 static void freespaceend()
661 {
662
4/4
✓ Branch 0 taken 1496 times.
✓ Branch 1 taken 762 times.
✓ Branch 2 taken 930 times.
✓ Branch 3 taken 566 times.
2258 if ((snespos&0x7F000000) && ((unsigned int)snespos&0x80000000)==0)
663 {
664 930 freespacelen[freespaceid]=snespos-freespacestart+freespaceextra;
665 930 snespos=(int)0xFFFFFFFF;
666 }
667 2258 freespaceextra=0;
668 2258 }
669
670 int numopcodes;
671
672 bool warnxkas;
673
674
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
5860 static void adddefine(const string & key, string & value)
675 {
676
1/2
✓ Branch 0 taken 5860 times.
✗ Branch 1 not taken.
5860 if (!defines.exists(key)) defines.create(key) = value;
677 5860 }
678
679 586 void initstuff()
680 {
681
2/2
✓ Branch 0 taken 198 times.
✓ Branch 1 taken 388 times.
586 if (pass==0)
682 {
683
2/2
✓ Branch 0 taken 50688 times.
✓ Branch 1 taken 198 times.
50886 for (int i=0;i<256;i++)
684 {
685 50688 freespacepos[i]=-1;
686 50688 freespaceleak[i]=true;
687 50688 freespaceorgpos[i]=-2;
688 50688 freespaceorglen[i]=-1;
689 50688 freespacebyte[i] = 0x00;
690 }
691 }
692 586 arch=arch_65816;
693 586 mapper=lorom;
694 586 mapper_set = false;
695 586 reallycalledmacros=0;
696 586 calledmacros=0;
697 586 macrorecursion=0;
698 586 repeatnext=1;
699 586 defines.reset();
700 586 builtindefines.each(adddefine);
701 586 clidefines.each(adddefine);
702 293 ns="";
703 586 namespace_list.reset();
704 586 sublabels.reset();
705 586 poslabels.reset();
706 586 neglabels.reset();
707 586 macroposlabels = nullptr;
708 586 macroneglabels = nullptr;
709 586 macrosublabels = nullptr;
710 586 cleartable();
711 586 pushpc.reset();
712 586 pushpcnum=0;
713 586 pushns.reset();
714 586 pushnsnum = 0;
715 586 bytes=0;
716 586 memset(fillbyte, 0, sizeof(fillbyte));
717 586 memset(padbyte, 0, sizeof(padbyte));
718 586 snespos=(int)0xFFFFFFFF;
719 586 realsnespos= (int)0xFFFFFFFF;
720 586 startpos= (int)0xFFFFFFFF;
721 586 realstartpos= (int)0xFFFFFFFF;
722 //fastrom=false;
723 586 freespaceidnext=1;
724 586 freespaceid=1;
725 586 freespaceextra=0;
726 586 default_freespacebyte=0x00;
727 586 numopcodes=0;
728 586 specifiedasarver = false;
729 586 incsrcdepth = 0;
730
731 586 optimizeforbank = -1;
732 586 optimize_dp = optimize_dp_flag::NONE;
733 586 dp_base = 0;
734 586 optimize_address = optimize_address_flag::DEFAULT;
735
736 586 in_struct = false;
737 586 in_sub_struct = false;
738 586 in_spcblock = false;
739
740 586 math_pri=false;
741 586 math_round=true;
742
743
1/2
✓ Branch 0 taken 586 times.
✗ Branch 1 not taken.
586 if (arch==arch_65816) asinit_65816();
744
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if (arch==arch_spc700) asinit_spc700();
745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if (arch==arch_spc700_inline) asinit_spc700();
746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if (arch==arch_superfx) asinit_superfx();
747
748 586 warnxkas=false;
749 586 emulatexkas=false;
750 586 disable_bank_cross_errors = false;
751 586 check_half_banks_crossed = false;
752 586 nested_namespaces = false;
753
754 293 thisfilename = "";
755
756 586 includeonce.reset();
757
758 extern AddressToLineMapping addressToLineMapping;
759 586 addressToLineMapping.reset();
760
761 586 push_warnings(false);
762
763 586 initmathcore();
764 586 }
765
766
767 //void nerf(const string& left, string& right){puts(S left+" = "+right);}
768
769 582 void finishpass()
770 {
771 582 verify_warnings();
772 582 pull_warnings(false);
773
774 //defines.traverse(nerf);
775
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 582 times.
582 if(in_spcblock) asar_throw_error(0, error_type_block, error_id_missing_endspcblock);
776
2/4
✓ Branch 0 taken 582 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 582 times.
582 if (in_struct || in_sub_struct) asar_throw_error(pass, error_type_null, error_id_struct_without_endstruct);
777
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 582 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
582 else if (pushpcnum && pass == 0) asar_throw_error(pass, error_type_null, error_id_pushpc_without_pullpc);
778
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 582 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
582 else if (pushnsnum && pass == 0) asar_throw_error(pass, error_type_null, error_id_pushns_without_pullns);
779 582 freespaceend();
780
2/2
✓ Branch 0 taken 540 times.
✓ Branch 1 taken 42 times.
582 if (arch==arch_65816) asend_65816();
781
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 558 times.
582 if (arch==arch_spc700) asend_spc700();
782
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 576 times.
582 if (arch==arch_spc700_inline) asend_spc700();
783
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 570 times.
582 if (arch==arch_superfx) asend_superfx();
784
785 582 deinitmathcore();
786 582 }
787
788 873642 static bool addlabel(const char * label, int pos=-1, bool global_label = false)
789 {
790
4/4
✓ Branch 0 taken 651998 times.
✓ Branch 1 taken 221644 times.
✓ Branch 2 taken 325999 times.
✓ Branch 3 taken 325999 times.
873642 if (!label[0] || label[0]==':') return false;//colons are reserved for special labels
791
792 651998 const char* posneglabel = label;
793
1/2
✓ Branch 0 taken 325999 times.
✗ Branch 1 not taken.
651998 string posnegname = posneglabelname(&posneglabel, true);
794
795
4/4
✓ Branch 0 taken 326059 times.
✓ Branch 1 taken 325939 times.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 325939 times.
651998 if (posnegname.length() > 0)
796 {
797
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 60 times.
120 if (global_label) return false;
798
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
120 if (*posneglabel != '\0' && *posneglabel != ':') asar_throw_error(0, error_type_block, error_id_broken_label_definition);
799
2/4
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
✗ Branch 3 not taken.
120 setlabel(posnegname, pos);
800 120 return true;
801 }
802
7/8
✓ Branch 0 taken 651122 times.
✓ Branch 1 taken 756 times.
✓ Branch 2 taken 651068 times.
✓ Branch 3 taken 54 times.
✓ Branch 4 taken 651062 times.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 651062 times.
651878 if (label[strlen(label)-1]==':' || label[0]=='.' || label[0]=='?' || label[0] == '#')
803 {
804
2/2
✓ Branch 0 taken 408 times.
✓ Branch 1 taken 408 times.
816 if (!label[1]) return false;
805
6/8
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 762 times.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 21 times.
✓ Branch 7 taken 21 times.
804 if(global_label && (in_struct || in_sub_struct || label[0]=='?')) return false;
806
807 399 bool define = true;
808
809
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 774 times.
798 if (label[0] == '#')
810 {
811 12 define = false;
812 24 label++;
813 }
814
815 // RPG Hacker: Also checking label[1] now, since it might be a macro sublabel.
816 // Also, apparently this here doesn't account for main labels. I guess because
817 // we don't even get here in the first place if they don't include a colon?
818
6/8
✓ Branch 0 taken 546 times.
✓ Branch 1 taken 252 times.
✓ Branch 2 taken 540 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 540 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 270 times.
798 bool requirecolon = (label[0] != '.' && label[1] != '.') && (in_struct || in_sub_struct);
819
1/2
✓ Branch 0 taken 798 times.
✗ Branch 1 not taken.
798 string name=labelname(&label, define);
820
2/2
✓ Branch 0 taken 756 times.
✓ Branch 1 taken 42 times.
798 if (label[0]==':') label++;
821
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
42 else if (requirecolon) asar_throw_error(0, error_type_block, error_id_broken_label_definition);
822
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 21 times.
42 else if (global_label) return false;
823
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 792 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
792 if (label[0]) asar_throw_error(0, error_type_block, error_id_broken_label_definition);
824
11/14
✓ Branch 0 taken 450 times.
✓ Branch 1 taken 342 times.
✓ Branch 2 taken 102 times.
✓ Branch 3 taken 348 times.
✓ Branch 4 taken 48 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 48 times.
✓ Branch 7 taken 348 times.
✓ Branch 8 taken 48 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 48 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 48 times.
✗ Branch 13 not taken.
840 if (ns && !global_label) name=STR ns+name;
825
9/10
✓ Branch 0 taken 612 times.
✓ Branch 1 taken 180 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 588 times.
✓ Branch 4 taken 470 times.
✓ Branch 5 taken 28 times.
✓ Branch 6 taken 396 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 395 times.
✓ Branch 9 taken 1 times.
793 setlabel(name, pos, ((in_struct || in_sub_struct) && static_struct));
826 790 return true;
827 798 }
828 325531 return false;
829 651998 }
830
831 224104 static void add_addr_to_line(int pos)
832 {
833
2/2
✓ Branch 0 taken 74926 times.
✓ Branch 1 taken 149178 times.
224104 if (pass == 2)
834 74926 addressToLineMapping.includeMapping(thisfilename.data(), thisline + 1, pos);
835 224104 }
836
837 static autoarray<bool> elsestatus;
838 int numtrue=0;//if 1 -> increase both
839 int numif = 0; //if 0 or inside if 0 -> increase only numif
840
841 autoarray<whiletracker> whilestatus;
842 int single_line_for_tracker;
843
844 static int freespaceuse=0;
845
846
847 78 static void push_pc()
848 {
849 78 pushpc[pushpcnum].arch=arch;
850 78 pushpc[pushpcnum].snespos=snespos;
851 78 pushpc[pushpcnum].snesstart=startpos;
852 78 pushpc[pushpcnum].snesposreal=realsnespos;
853 78 pushpc[pushpcnum].snesstartreal=realstartpos;
854 78 pushpc[pushpcnum].freeid=freespaceid;
855 78 pushpc[pushpcnum].freeex=freespaceextra;
856 78 pushpc[pushpcnum].freest=freespacestart;
857 78 pushpcnum++;
858 78 }
859
860 78 static void pop_pc()
861 {
862 78 pushpcnum--;
863 78 snespos=pushpc[pushpcnum].snespos;
864 78 startpos=pushpc[pushpcnum].snesstart;
865 78 realsnespos=pushpc[pushpcnum].snesposreal;
866 78 realstartpos=pushpc[pushpcnum].snesstartreal;
867 78 freespaceid=pushpc[pushpcnum].freeid;
868 78 freespaceextra=pushpc[pushpcnum].freeex;
869 78 freespacestart=pushpc[pushpcnum].freest;
870 78 }
871
872
873 132 string handle_print(char* input)
874 {
875 // evaluating this math can be unsafe in pass 0
876
3/4
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 44 times.
✗ Branch 3 not taken.
132 if(pass != 2) return "";
877
3/6
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
44 if (!confirmqpar(input)) asar_throw_error(2, error_type_block, error_id_mismatched_parentheses);
878 22 string out;
879
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 autoptr<char**> pars = qpsplit(input, ",");
880
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 44 times.
152 for (int i = 0; pars[i]; i++)
881 {
882 if (0);
883
4/6
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 38 times.
✓ Branch 2 taken 70 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 35 times.
✗ Branch 5 not taken.
108 else if (pars[i][0] == '"') out += safedequote(pars[i]);
884
3/6
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
38 else if (!stricmp(pars[i], "bytes")) out += dec(bytes);
885
3/6
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
38 else if (!stricmp(pars[i], "freespaceuse")) out += dec(freespaceuse);
886
3/6
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
38 else if (!stricmp(pars[i], "pc")) out += hex6((unsigned int)(snespos & 0xFFFFFF));
887
3/4
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 4 times.
53 else if (!strncasecmp(pars[i], "bin(", strlen("bin(")) ||
888
4/4
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 4 times.
41 !strncasecmp(pars[i], "dec(", strlen("dec(")) ||
889
5/6
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
78 !strncasecmp(pars[i], "hex(", strlen("hex(")) ||
890
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 !strncasecmp(pars[i], "double(", strlen("double(")))
891 {
892 38 char * arg1pos = strchr(pars[i], '(') + 1;
893 38 char * endpos = strchr(arg1pos, '\0');
894
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
✓ Branch 2 taken 38 times.
✓ Branch 3 taken 38 times.
76 while (*endpos == ' ' || *endpos == '\0') endpos--;
895
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
38 if (*endpos != ')') asar_throw_error(2, error_type_block, error_id_invalid_print_function_syntax);
896
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
38 string paramstr = string(arg1pos, (int)(endpos - arg1pos));
897
898 19 int numargs;
899
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 autoptr<char**> params = qpsplit(paramstr.temp_raw(), ",", &numargs);
900
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
38 if (numargs > 2) asar_throw_error(2, error_type_block, error_id_wrong_num_parameters);
901 19 int precision = 0;
902 38 bool hasprec = numargs == 2;
903
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 19 times.
38 if (hasprec)
904 {
905
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 precision = getnum64(params[1]);
906
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (precision < 0) precision = 0;
907
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
26 if (precision > 64) precision = 64;
908 }
909 38 *(arg1pos - 1) = '\0'; // allows more convenient comparsion functions
910
4/4
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 15 times.
38 if (!stricmp(pars[i], "bin"))
911 {
912 // sadly printf doesn't have binary, so let's roll our own
913
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 int64_t value = getnum64(params[0]);
914 4 char buffer[65];
915
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (value < 0) {
916 out += '-';
917 value = -value;
918 // decrement precision because we've output one char already
919 precision -= 1;
920 if (precision<0) precision = 0;
921 }
922
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 8 times.
520 for (int j = 0; j < 64; j++) {
923 512 buffer[63 - j] = '0' + ((value & (1ull << j)) >> j);
924 }
925 8 buffer[64] = 0;
926 4 int startidx = 0;
927
3/4
✓ Branch 0 taken 448 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 448 times.
✗ Branch 3 not taken.
456 while (startidx < 64 - precision && buffer[startidx] == '0') startidx++;
928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (startidx == 64) startidx--; // always want to print at least one digit
929
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
8 out += buffer + startidx;
930 }
931
4/4
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 11 times.
30 else if (!stricmp(pars[i], "dec"))
932 {
933
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 int64_t value = getnum64(params[0]);
934 4 char buffer[65];
935
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
8 snprintf(buffer, 65, "%0*" PRId64, precision, value);
936
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
8 out += buffer;
937 }
938
4/4
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 7 times.
22 else if (!stricmp(pars[i], "hex"))
939 {
940
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 int64_t value = getnum64(params[0]);
941 4 char buffer[65];
942
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
8 snprintf(buffer, 65, "%0*" PRIX64, precision, value);
943
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
8 out += buffer;
944 }
945
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
14 else if (!stricmp(pars[i], "double"))
946 {
947
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
14 if (!hasprec) precision = 5;
948
3/6
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
14 out += ftostrvar(getnumdouble(params[0]), precision);
949 }
950 38 }
951 else asar_throw_error(2, error_type_block, error_id_unknown_variable);
952 }
953
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 return out;
954 44 }
955
956
957 875376 void assembleblock(const char * block, bool isspecialline)
958 {
959
1/2
✓ Branch 0 taken 437688 times.
✗ Branch 1 not taken.
437688 string tmp=block;
960 437688 int numwords;
961
1/2
✓ Branch 0 taken 875376 times.
✗ Branch 1 not taken.
875376 char ** word = qsplit(tmp.temp_raw(), " ", &numwords);
962 437688 string resolved;
963 // when writing out the data for the addrToLine mapping,
964 // we want to write out the snespos we had before writing opcodes
965 875376 int addrToLinePos = realsnespos & 0xFFFFFF;
966
967 #define is(test) (!stricmpwithlower(word[0], test))
968 #define is0(test) (numwords==1 && !stricmpwithlower(word[0], test))
969 #define is1(test) (numwords==2 && !stricmpwithlower(word[0], test))
970 #define is2(test) (numwords==3 && !stricmpwithlower(word[0], test))
971 #define is3(test) (numwords==4 && !stricmpwithlower(word[0], test))
972 #define par word[1]
973
974
2/8
✗ Branch 0 not taken.
✓ Branch 1 taken 875376 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 437688 times.
875376 if(!moreonlinecond && !(is("elseif") || is("else"))){
975 return;
976 }
977
978 // RPG Hacker: Hack to fix the bug where defines in elseifs would never get resolved
979 // This really seems like the only possible place for the fix
980
6/6
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 875238 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 66 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 437652 times.
875376 if (is("elseif") && numtrue+1==numif)
981 {
982
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 resolvedefines(resolved, block);
983
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
72 free(word);
984
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 word = qsplit(resolved.temp_raw(), " ", &numwords);
985 }
986
987 437688 autoptr<char**> wordcopy=word;
988
8/8
✓ Branch 0 taken 873678 times.
✓ Branch 1 taken 1698 times.
✓ Branch 2 taken 436839 times.
✓ Branch 3 taken 436839 times.
✓ Branch 4 taken 112715 times.
✓ Branch 5 taken 112715 times.
✓ Branch 6 taken 21 times.
✓ Branch 7 taken 437667 times.
875376 if (numif==numtrue && is1("global")) {
989
3/4
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 30 times.
42 if (!addlabel(word[1], -1, true)) {
990
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 asar_throw_error(1, error_type_block, error_id_invalid_global_label, word[1]);
991 }
992 30 return;
993 }
994
14/14
✓ Branch 0 taken 874516 times.
✓ Branch 1 taken 1698 times.
✓ Branch 2 taken 873846 times.
✓ Branch 3 taken 670 times.
✓ Branch 4 taken 437970 times.
✓ Branch 5 taken 435876 times.
✓ Branch 6 taken 437724 times.
✓ Branch 7 taken 246 times.
✓ Branch 8 taken 873598 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 436799 times.
✓ Branch 11 taken 436799 times.
✓ Branch 12 taken 440 times.
✓ Branch 13 taken 437666 times.
876214 while (numif==numtrue && word[0] && (!word[1] || strcmp(word[1], "=")) && addlabel(word[0]))
995 {
996 880 word++;
997 880 numwords--;
998 }
999
4/4
✓ Branch 0 taken 874662 times.
✓ Branch 1 taken 670 times.
✓ Branch 2 taken 437331 times.
✓ Branch 3 taken 437331 times.
875332 if (!word[0] || !word[0][0]) return;
1000
4/4
✓ Branch 0 taken 651320 times.
✓ Branch 1 taken 1584 times.
✓ Branch 2 taken 216 times.
✓ Branch 3 taken 651104 times.
652904 if (numif==numtrue && word[0][0]=='%')
1001 {
1002
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 6 times.
216 if (!macrorecursion)
1003 {
1004
1/2
✓ Branch 0 taken 105 times.
✗ Branch 1 not taken.
105 callerfilename=thisfilename;
1005 210 callerline=thisline;
1006 }
1007 216 int fakeendif_prev = fakeendif;
1008 216 int moreonlinecond_prev = moreonlinecond;
1009 216 int calledmacros_prev = calledmacros;
1010 216 int single_line_for_tracker_prev = single_line_for_tracker;
1011
2/2
✓ Branch 0 taken 204 times.
✓ Branch 1 taken 12 times.
216 callmacro(strchr(block, '%')+1);
1012 204 fakeendif = fakeendif_prev;
1013 204 moreonlinecond = moreonlinecond_prev;
1014 204 calledmacros = calledmacros_prev;
1015 204 single_line_for_tracker = single_line_for_tracker_prev;
1016
2/2
✓ Branch 0 taken 198 times.
✓ Branch 1 taken 6 times.
204 if (!macrorecursion)
1017 {
1018
1/2
✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
99 callerfilename="";
1019 198 callerline=-1;
1020 }
1021 204 return;
1022 }
1023
12/12
✓ Branch 0 taken 652352 times.
✓ Branch 1 taken 336 times.
✓ Branch 2 taken 652214 times.
✓ Branch 3 taken 138 times.
✓ Branch 4 taken 652172 times.
✓ Branch 5 taken 42 times.
✓ Branch 6 taken 441188 times.
✓ Branch 7 taken 210984 times.
✓ Branch 8 taken 220594 times.
✓ Branch 9 taken 220594 times.
✓ Branch 10 taken 105924 times.
✓ Branch 11 taken 220420 times.
652688 if (is("if") || is("elseif") || is("assert") || is("while") || is("for"))
1024 {
1025
6/6
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 211512 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 330 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 105921 times.
211848 if(is("if") && moreonline) fakeendif++;
1026
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 211848 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
211848 if (emulatexkas) asar_throw_warning(0, warning_id_convert_to_asar);
1027 105924 string errmsg;
1028 105924 whiletracker wstatus;
1029 211848 wstatus.startline = thisline;
1030 211848 wstatus.iswhile = false;
1031 211848 wstatus.cond = false;
1032 211848 wstatus.is_for = false;
1033 211848 wstatus.for_start = wstatus.for_end = wstatus.for_cur = 0;
1034 211848 wstatus.for_has_var_backup = false;
1035
2/2
✓ Branch 0 taken 210984 times.
✓ Branch 1 taken 864 times.
211848 if (is("while")) wstatus.iswhile = true;
1036
2/2
✓ Branch 0 taken 348 times.
✓ Branch 1 taken 211500 times.
211848 if (is("for")) wstatus.is_for = true;
1037 // if we are a for loop and:
1038 // 1) whilestatus has an entry at this level already
1039 // 2) said entry represents an incomplete for loop
1040 // then this loop must be meant "for us".
1041 // check number 2 is necessary because otherwise, 2 for loops back-to-back (not nested) would try to use the same whilestatus entry
1042 105924 bool is_for_cont = false;
1043
14/16
✓ Branch 0 taken 348 times.
✓ Branch 1 taken 211500 times.
✓ Branch 2 taken 346 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 339 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 209 times.
✓ Branch 7 taken 130 times.
✓ Branch 8 taken 166 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 166 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 123 times.
✓ Branch 13 taken 43 times.
✓ Branch 14 taken 123 times.
✓ Branch 15 taken 105801 times.
212021 if (is("for") && whilestatus.count > numif && whilestatus[numif].is_for && whilestatus[numif].for_cur < whilestatus[numif].for_end)
1044 {
1045 // continuation of a for loop
1046 123 is_for_cont = true;
1047 }
1048
5/8
✓ Branch 0 taken 123 times.
✓ Branch 1 taken 105801 times.
✓ Branch 2 taken 123 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 105801 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 105801 times.
✗ Branch 7 not taken.
211848 whiletracker& addedwstatus = is_for_cont ? whilestatus[numif] : (whilestatus[numif] = wstatus);
1049
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 211806 times.
211848 if (is("assert"))
1050 {
1051
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 autoptr<char**> tokens = qpsplit(word[numwords - 1], ",");
1052
5/6
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 15 times.
42 if (tokens[0] != NULL && tokens[1] != NULL)
1053 {
1054 6 string rawerrmsg;
1055 6 size_t pos = 1;
1056
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 12 times.
54 while (tokens[pos])
1057 {
1058
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
42 rawerrmsg += tokens[pos];
1059
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 12 times.
42 if (tokens[pos + 1] != NULL)
1060 {
1061
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
30 rawerrmsg += ",";
1062 }
1063 21 pos++;
1064 }
1065
1066
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 errmsg = handle_print(rawerrmsg.raw());
1067 12 }
1068 42 }
1069
8/8
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 211740 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 36 times.
✓ Branch 6 taken 18 times.
✓ Branch 7 taken 105906 times.
211848 if (numtrue!=numif && !(is("elseif") && numtrue+1==numif))
1070 {
1071
5/8
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 18 times.
✗ Branch 7 not taken.
36 if ((is("if") || is("while") || is("for"))) numif++;
1072 18 return;
1073 }
1074
8/8
✓ Branch 0 taken 211476 times.
✓ Branch 1 taken 336 times.
✓ Branch 2 taken 510 times.
✓ Branch 3 taken 210966 times.
✓ Branch 4 taken 330 times.
✓ Branch 5 taken 180 times.
✓ Branch 6 taken 105816 times.
✓ Branch 7 taken 90 times.
211812 if ((is("if") || is("while") || is("for"))) numif++;
1075 bool cond;
1076
1077 211812 bool isassert = is("assert");
1078
1079 211812 char ** nextword=word+1;
1080 105906 char * condstr= nullptr;
1081
2/2
✓ Branch 0 taken 211482 times.
✓ Branch 1 taken 330 times.
211812 if(!is("for")) {
1082 while (true)
1083 {
1084
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 211488 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
211488 if (!nextword[0]) asar_throw_error(0, error_type_block, error_id_broken_conditional, word[0]);
1085 105744 bool thiscond = false;
1086
4/6
✓ Branch 0 taken 211134 times.
✓ Branch 1 taken 354 times.
✓ Branch 2 taken 211134 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 211134 times.
211488 if (!nextword[1] || !strcmp(nextword[1], "&&") || !strcmp(nextword[1], "||"))
1087 {
1088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 354 times.
354 if (nextword[0][0] == '!')
1089 {
1090 asar_throw_warning(0, warning_id_feature_deprecated, "old style conditional negation (if !condition) ", "the not function");
1091 double val = getnumdouble(nextword[0]+1);
1092 if (foundlabel && !foundlabel_static && !isassert) asar_throw_error(0, error_type_block, error_id_label_in_conditional, word[0]);
1093 thiscond = !(val > 0);
1094 }
1095 else
1096 {
1097
1/2
✓ Branch 0 taken 354 times.
✗ Branch 1 not taken.
354 double val = getnumdouble(nextword[0]);
1098
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 354 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
354 if (foundlabel && !foundlabel_static && !isassert) asar_throw_error(0, error_type_block, error_id_label_in_conditional, word[0]);
1099 354 thiscond = (val > 0);
1100 }
1101
1102
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 354 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
354 if (condstr && nextword[1])
1103 {
1104 if (strcmp(condstr, nextword[1])) asar_throw_error(1, error_type_block, error_id_invalid_condition);
1105 }
1106 354 else condstr=nextword[1];
1107 354 nextword+=2;
1108 354 }
1109 else
1110 {
1111
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 211134 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
211134 if (!nextword[2]) asar_throw_error(0, error_type_block, error_id_broken_conditional, word[0]);
1112
1/2
✓ Branch 0 taken 211134 times.
✗ Branch 1 not taken.
211134 double par1=getnumdouble(nextword[0]);
1113
6/8
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 211074 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 30 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 30 times.
211134 if (foundlabel && !foundlabel_static && !isassert) asar_throw_error(0, error_type_block, error_id_label_in_conditional, word[0]);
1114
1/2
✓ Branch 0 taken 211104 times.
✗ Branch 1 not taken.
211104 double par2=getnumdouble(nextword[2]);
1115
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 211104 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
211104 if (foundlabel && !foundlabel_static && !isassert) asar_throw_error(0, error_type_block, error_id_label_in_conditional, word[0]);
1116 if(0);
1117
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 210984 times.
211104 else if (!strcmp(nextword[1], ">")) thiscond=(par1>par2);
1118
2/2
✓ Branch 0 taken 210870 times.
✓ Branch 1 taken 114 times.
210984 else if (!strcmp(nextword[1], "<")) thiscond=(par1<par2);
1119
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 108 times.
114 else if (!strcmp(nextword[1], ">=")) thiscond=(par1>=par2);
1120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 else if (!strcmp(nextword[1], "<=")) thiscond=(par1<=par2);
1121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 else if (!strcmp(nextword[1], "="))
1122 {
1123 asar_throw_warning(0, warning_id_feature_deprecated, "if a = b", "use \"if a == b\" instead");
1124 thiscond=(par1==par2);
1125 }
1126
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 else if (!strcmp(nextword[1], "==")) thiscond=(par1==par2);
1127
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 else if (!strcmp(nextword[1], "!=")) thiscond=(par1!=par2);
1128 //else if (!strcmp(nextword[1], "<>")) thiscond=(par1!=par2);
1129 else asar_throw_error(0, error_type_block, error_id_broken_conditional, word[0]);
1130
1131
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 211098 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
211104 if (condstr && nextword[3])
1132 {
1133 if (strcmp(condstr, nextword[3])) asar_throw_error(1, error_type_block, error_id_invalid_condition);
1134 }
1135 211104 else condstr=nextword[3];
1136 211104 nextword+=4;
1137 }
1138
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 211440 times.
211458 if (condstr)
1139 {
1140
3/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 12 times.
18 if (!strcmp(condstr, "&&")) { if(thiscond) continue; }
1141 else if (!strcmp(condstr, "||")) { if(!thiscond) continue; }
1142 else asar_throw_error(0, error_type_block, error_id_broken_conditional, word[0]);
1143 }
1144 105726 cond=thiscond;
1145 105726 break;
1146 3 }
1147 }
1148
1149
2/2
✓ Branch 0 taken 330 times.
✓ Branch 1 taken 211452 times.
211782 if (is("for"))
1150 {
1151 // for loops as anything except the first block cause weirdness
1152 // (while loops do too, but let's not talk about it)
1153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 330 times.
330 if(single_line_for_tracker != 1) {
1154 numif--;
1155 asar_throw_error(0, error_type_line, error_id_bad_single_line_for);
1156 }
1157 // TODO: these errors could probably be a bit more descriptive
1158
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 246 times.
330 if(!is_for_cont)
1159 {
1160 // "for i = 0..16"
1161
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
84 if(numwords != 4) asar_throw_error(0, error_type_block, error_id_broken_for_loop);
1162
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
84 if(strcmp(word[2], "=") != 0) asar_throw_error(0, error_type_block, error_id_broken_for_loop);
1163
1164
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 char* range_sep = strqpstr(word[3], "..");
1165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 if(!range_sep)
1166 asar_throw_error(0, error_type_block, error_id_broken_for_loop, "invalid loop range");
1167
1168
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
84 string for_start(word[3], range_sep - word[3]);
1169
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
84 string for_end(range_sep+2);
1170
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 addedwstatus.for_start = getnum(for_start);
1171
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
84 if(foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_label_in_conditional, "for");
1172
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 addedwstatus.for_end = getnum(for_end);
1173
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
84 if(foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_label_in_conditional, "for");
1174
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
84 string varname = word[1];
1175
2/6
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 84 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
84 if(!validatedefinename(varname)) asar_throw_error(0, error_type_block, error_id_broken_for_loop);
1176
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
84 addedwstatus.for_variable = varname;
1177 84 addedwstatus.for_cur = addedwstatus.for_start;
1178 84 }
1179 else
1180 {
1181 246 addedwstatus.for_cur++;
1182 }
1183 // this cond is actually also used to tell assemblefile whether to jump back to the beginning of the loop, so keep it updated
1184 330 addedwstatus.cond = addedwstatus.for_cur < addedwstatus.for_end;
1185 330 single_line_for_tracker = 2;
1186
2/2
✓ Branch 0 taken 246 times.
✓ Branch 1 taken 84 times.
330 if(addedwstatus.cond)
1187 {
1188
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 27 times.
246 numtrue++;
1189
4/4
✓ Branch 0 taken 219 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 96 times.
✓ Branch 3 taken 27 times.
246 if(defines.exists(addedwstatus.for_variable)) {
1190 192 addedwstatus.for_has_var_backup = true;
1191
2/4
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
192 addedwstatus.for_var_backup = defines.find(addedwstatus.for_variable);
1192 }
1193
3/6
✓ Branch 0 taken 246 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 123 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 123 times.
✗ Branch 5 not taken.
246 defines.create(addedwstatus.for_variable) = ftostr(addedwstatus.for_cur);
1194 }
1195 }
1196
6/6
✓ Branch 0 taken 211146 times.
✓ Branch 1 taken 306 times.
✓ Branch 2 taken 105573 times.
✓ Branch 3 taken 105573 times.
✓ Branch 4 taken 105636 times.
✓ Branch 5 taken 90 times.
211452 else if (is("if") || is("while"))
1197 {
1198 if(0);
1199
2/2
✓ Branch 0 taken 211050 times.
✓ Branch 1 taken 222 times.
211272 else if (cond)
1200 {
1201 211050 numtrue++;
1202
1/2
✓ Branch 0 taken 105525 times.
✗ Branch 1 not taken.
211050 elsestatus[numif]=true;
1203 }
1204
1/2
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
111 else if (!cond)
1205 {
1206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 222 times.
222 if(moreonline) moreonlinecond=false;
1207
1/2
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
222 elsestatus[numif]=false;
1208 }
1209 211272 addedwstatus.cond = cond;
1210 }
1211
2/2
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 42 times.
180 else if (is("elseif"))
1212 {
1213
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
138 if (!numif) asar_throw_error(1, error_type_block, error_id_misplaced_elseif);
1214
3/6
✓ Branch 0 taken 69 times.
✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 69 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
138 if (whilestatus[numif - 1].iswhile) asar_throw_error(1, error_type_block, error_id_elseif_in_while);
1215
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 72 times.
138 if (numif==numtrue) numtrue--;
1216
8/8
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 51 times.
✓ Branch 3 taken 15 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 15 times.
✓ Branch 6 taken 18 times.
✓ Branch 7 taken 51 times.
171 if (cond && !elsestatus[numif])
1217 {
1218
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if(moreonline) moreonlinecond = true;
1219 36 numtrue++;
1220
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
36 elsestatus[numif]=true;
1221 }
1222 }
1223 // otherwise, must be assert command
1224
4/4
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 4 times.
42 else if (pass == 2 && !cond)
1225 {
1226
7/10
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
20 if (errmsg) asar_throw_error(2, error_type_block, error_id_assertion_failed, (string(": ") + errmsg).data());
1227
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 else asar_throw_error(2, error_type_block, error_id_assertion_failed, ".");
1228 }
1229
4/4
✓ Branch 0 taken 105886 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 105886 times.
✓ Branch 3 taken 18 times.
211906 }
1230
8/8
✓ Branch 0 taken 439658 times.
✓ Branch 1 taken 1182 times.
✓ Branch 2 taken 229520 times.
✓ Branch 3 taken 210138 times.
✓ Branch 4 taken 114760 times.
✓ Branch 5 taken 114760 times.
✓ Branch 6 taken 105834 times.
✓ Branch 7 taken 114586 times.
440840 else if (is("endif") || is("endwhile") || is("endfor"))
1231 {
1232
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 211662 times.
211668 if(fakeendif) fakeendif--;
1233
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 211668 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
211668 if (numwords != 1) asar_throw_error(1, error_type_block, error_id_unknown_command);
1234
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 211668 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
211668 if (!numif) asar_throw_error(1, error_type_block, error_id_misplaced_endif);
1235
2/2
✓ Branch 0 taken 211200 times.
✓ Branch 1 taken 468 times.
211668 if (numif==numtrue) numtrue--;
1236 211668 numif--;
1237
4/4
✓ Branch 0 taken 106008 times.
✓ Branch 1 taken 105660 times.
✓ Branch 2 taken 174 times.
✓ Branch 3 taken 105660 times.
211668 if(whilestatus[numif].is_for) {
1238
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 288 times.
348 if(single_line_for_tracker == 2) single_line_for_tracker = 3;
1239
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 348 times.
348 if(moreonline) {
1240 // sabotage the whilestatus to prevent the loop running again
1241 // and spamming more of the same error
1242 whilestatus[numif].for_cur = whilestatus[numif].for_end;
1243 whilestatus[numif].cond = false;
1244 asar_throw_error(0, error_type_block, error_id_bad_single_line_for);
1245 }
1246
4/4
✓ Branch 0 taken 297 times.
✓ Branch 1 taken 51 times.
✓ Branch 2 taken 123 times.
✓ Branch 3 taken 51 times.
348 if(whilestatus[numif].cond) {
1247
4/4
✓ Branch 0 taken 219 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 96 times.
✓ Branch 3 taken 27 times.
246 if(whilestatus[numif].for_has_var_backup)
1248
4/8
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 96 times.
✗ Branch 7 not taken.
192 defines.create(whilestatus[numif].for_variable) = whilestatus[numif].for_var_backup;
1249
2/4
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✗ Branch 3 not taken.
54 else defines.remove(whilestatus[numif].for_variable);
1250 }
1251 }
1252
2/2
✓ Branch 0 taken 210818 times.
✓ Branch 1 taken 850 times.
211668 if(warn_endwhile) {
1253
4/4
✓ Branch 0 taken 210479 times.
✓ Branch 1 taken 339 times.
✓ Branch 2 taken 105070 times.
✓ Branch 3 taken 339 times.
210818 if(whilestatus[numif].iswhile) {
1254
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 210138 times.
210140 if(!is("endwhile")) {
1255 2 warn_endwhile = false;
1256
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 asar_throw_warning(0, warning_id_feature_deprecated, "mismatched terminators", "use endwhile to terminate a while statement");
1257 }
1258 }
1259
4/4
✓ Branch 0 taken 513 times.
✓ Branch 1 taken 165 times.
✓ Branch 2 taken 174 times.
✓ Branch 3 taken 165 times.
678 else if(whilestatus[numif].is_for) {
1260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 348 times.
348 if(!is("endfor")) {
1261 warn_endwhile = false;
1262 asar_throw_warning(0, warning_id_feature_deprecated, "mismatched terminators", "use endfor to terminate a for statement");
1263 }
1264 }
1265
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 330 times.
330 else if(!is("endif")) {
1266 warn_endwhile = false;
1267 asar_throw_warning(0, warning_id_feature_deprecated, "mismatched terminators", "use endif to terminate an if statement");
1268 }
1269 }
1270 }
1271
2/2
✓ Branch 0 taken 228 times.
✓ Branch 1 taken 228944 times.
229172 else if (is("else"))
1272 {
1273
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
228 if(!moreonlinecond) moreonlinecond = true;
1274
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
228 if (numwords != 1) asar_throw_error(1, error_type_block, error_id_unknown_command);
1275
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
228 if (!numif) asar_throw_error(1, error_type_block, error_id_misplaced_else);
1276
5/12
✓ Branch 0 taken 228 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 228 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 114 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 114 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 114 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
228 if (whilestatus[numif - 1].iswhile || whilestatus[numif - 1].is_for) asar_throw_error(1, error_type_block, error_id_else_in_while_loop);
1277
2/2
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 114 times.
228 else if (numif==numtrue) numtrue--;
1278
7/8
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 81 times.
✓ Branch 3 taken 33 times.
✓ Branch 4 taken 24 times.
✓ Branch 5 taken 33 times.
✓ Branch 6 taken 24 times.
✓ Branch 7 taken 33 times.
171 else if (numif==numtrue+1 && !elsestatus[numif])
1279 {
1280 48 numtrue++;
1281
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
48 elsestatus[numif]=true;
1282 }
1283 }
1284
2/2
✓ Branch 0 taken 114472 times.
✓ Branch 1 taken 114472 times.
228944 else if (numif!=numtrue) return;
1285
4/4
✓ Branch 0 taken 228048 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 9712 times.
✓ Branch 3 taken 218336 times.
228050 else if (asblock_pick(word, numwords))
1286 {
1287
1/2
✓ Branch 0 taken 9712 times.
✗ Branch 1 not taken.
9712 add_addr_to_line(addrToLinePos);
1288 9712 numopcodes += recent_opcode_num;
1289 }
1290
6/6
✓ Branch 0 taken 217066 times.
✓ Branch 1 taken 1270 times.
✓ Branch 2 taken 108533 times.
✓ Branch 3 taken 108533 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 109165 times.
218336 else if (is1("undef"))
1291 {
1292 3 string def;
1293 // RPG Hacker: Not sure if we should allow this?
1294 // Currently, the manual states that we should not include the
1295 // exclamation mark, and I believe that this is for the better
1296 // because I can see this leading to ambiguities or causing
1297 // problems. If we add this back in, we should definitely
1298 // also added it to the defined() function for consistency, though.
1299 // Well, actually I just check and we can't support this in
1300 // defined() (the defined is already replaced at that point), so
1301 // I think we should not support it here, either.
1302 /*if (*par == '!') def = S safedequote(par) + 1;
1303
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
9 else*/ def = STR safedequote(par);
1304
1305
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 if (defines.exists(def))
1306 {
1307
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 defines.remove(def);
1308 }
1309 else
1310 {
1311 asar_throw_error(0, error_type_block, error_id_define_not_found, def.data());
1312 }
1313 6 }
1314
6/6
✓ Branch 0 taken 560 times.
✓ Branch 1 taken 217770 times.
✓ Branch 2 taken 280 times.
✓ Branch 3 taken 280 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 109162 times.
218330 else if (is0("error"))
1315 {
1316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 asar_throw_error(0, error_type_block, error_id_error_command, ".");
1317 }
1318
6/6
✓ Branch 0 taken 554 times.
✓ Branch 1 taken 217770 times.
✓ Branch 2 taken 277 times.
✓ Branch 3 taken 277 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 109159 times.
218324 else if (is0("warn"))
1319 {
1320
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 asar_throw_warning(2, warning_id_warn_command, ".");
1321 }
1322
6/6
✓ Branch 0 taken 217060 times.
✓ Branch 1 taken 1258 times.
✓ Branch 2 taken 108530 times.
✓ Branch 3 taken 108530 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 109153 times.
218318 else if (is1("error"))
1323 {
1324
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 string out = handle_print(par);
1325 // RPG Hacker: This used to be on pass 0, which had its merits (you don't want to miss a potentially critical
1326 // user-generated error, just because a bazillion other errors are thrown in passes before it). However, I
1327 // don't see how to support print functions with this without moving it to pass 2. Suggestions are welcome.
1328
4/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
36 asar_throw_error(2, error_type_block, error_id_error_command, (string(": ") + out).data());
1329 12 }
1330
6/6
✓ Branch 0 taken 217048 times.
✓ Branch 1 taken 1258 times.
✓ Branch 2 taken 108524 times.
✓ Branch 3 taken 108524 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 109147 times.
218306 else if (is1("warn"))
1331 {
1332
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 string out = handle_print(par);
1333
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
12 asar_throw_warning(2, warning_id_warn_command, (string(": ") + out).data());
1334 12 }
1335
6/6
✓ Branch 0 taken 217036 times.
✓ Branch 1 taken 1258 times.
✓ Branch 2 taken 108518 times.
✓ Branch 3 taken 108518 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 109129 times.
218294 else if (is1("warnings"))
1336 {
1337
4/4
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 9 times.
36 if (stricmp(word[1], "push") == 0)
1338 {
1339
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 push_warnings();
1340 }
1341
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
18 else if (stricmp(word[1], "pull") == 0)
1342 {
1343
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 pull_warnings();
1344 }
1345 }
1346
6/6
✓ Branch 0 taken 650 times.
✓ Branch 1 taken 217608 times.
✓ Branch 2 taken 325 times.
✓ Branch 3 taken 325 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 109093 times.
218258 else if (is2("warnings"))
1347 {
1348
4/4
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 30 times.
72 if (stricmp(word[1], "enable") == 0)
1349 {
1350
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 asar_warning_id warnid = parse_warning_id_from_string(word[2]);
1351
1352
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (warnid != warning_id_end)
1353 {
1354
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 set_warning_enabled(warnid, true);
1355 }
1356 else
1357 {
1358 asar_throw_error(0, error_type_null, error_id_invalid_warning_id, "warnings enable", (int)(warning_id_start + 1), (int)(warning_id_end - 1));
1359 }
1360 }
1361
2/4
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
60 else if (stricmp(word[1], "disable") == 0)
1362 {
1363
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 asar_warning_id warnid = parse_warning_id_from_string(word[2]);
1364
1365
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if (warnid != warning_id_end)
1366 {
1367
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 set_warning_enabled(warnid, false);
1368 }
1369 else
1370 {
1371 asar_throw_error(0, error_type_null, error_id_invalid_warning_id, "warnings disable", (int)(warning_id_start + 1), (int)(warning_id_end - 1));
1372 }
1373 }
1374 }
1375
6/6
✓ Branch 0 taken 578 times.
✓ Branch 1 taken 217608 times.
✓ Branch 2 taken 289 times.
✓ Branch 3 taken 289 times.
✓ Branch 4 taken 34 times.
✓ Branch 5 taken 109059 times.
218186 else if (is2("check"))
1376 {
1377
4/4
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 31 times.
68 if (stricmp(word[1], "title") == 0)
1378 {
1379 // RPG Hacker: Removed trimming for now - I think requiring an exact match is probably
1380 // better here (not sure, though, it's worth discussing)
1381
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 string expected_title = safedequote(word[2]);
1382 // randomdude999: this also removes leading spaces because itrim gets stuck in an endless
1383 // loop when multi is true and one argument is empty
1384 //expected_title = itrim(expected_title.data(), " ", " ", true); // remove trailing spaces
1385 // in hirom the rom needs to be an entire bank for it to have a title, other modes only need 0x8000 bytes
1386
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
6 if (romlen < ((mapper == hirom || mapper == exhirom) ? 0x10000 : 0x8000)) // too short
1387 {
1388 if (!ignoretitleerrors) // title errors shouldn't be ignored
1389 asar_throw_error(0, error_type_block, error_id_rom_too_short, expected_title.data());
1390 else // title errors should be ignored, throw a warning anyways
1391 asar_throw_warning(0, warning_id_rom_too_short, expected_title.data());
1392 }
1393 else {
1394 3 string actual_title;
1395 3 string actual_display_title;
1396
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 6 times.
132 for (int i = 0;i < 21;i++)
1397 {
1398 126 unsigned char c = romdata[snestopc(0x00FFC0 + i)];
1399
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
126 actual_title += (char)c;
1400 // the replacements are from interface-cli.cpp
1401
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 63 times.
126 if (c == 7) c = 14;
1402
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 63 times.
126 if (c == 8) c = 27;
1403
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 63 times.
126 if (c == 9) c = 26;
1404
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 63 times.
126 if (c == '\r') c = 17;
1405
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 63 times.
126 if (c == '\n') c = 25;
1406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 126 times.
126 if (c == '\0') c = 155;
1407
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
126 actual_display_title += (char)c;
1408 }
1409 //actual_display_title = itrim(actual_display_title.data(), " ", " ", true); // remove trailing spaces
1410 //actual_title = itrim(actual_title.data(), " ", " ", true); // remove trailing spaces
1411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (strncmp(expected_title, actual_title, 21) != 0)
1412 {
1413 if (!ignoretitleerrors) // title errors shouldn't be ignored
1414 asar_throw_error(0, error_type_block, error_id_rom_title_incorrect, expected_title.data(), actual_display_title.data());
1415 else // title errors should be ignored, throw a warning anyways
1416 asar_throw_warning(0, warning_id_rom_title_incorrect, expected_title.data(), actual_display_title.data());
1417 }
1418 6 }
1419 6 }
1420
2/4
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
62 else if (stricmp(word[1], "bankcross") == 0)
1421 {
1422 if (0);
1423
4/4
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 16 times.
62 else if (!stricmp(word[2], "on"))
1424 {
1425
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 asar_throw_warning(0, warning_id_feature_deprecated, "bankcheck on", "bankcheck full or bankcheck half");
1426 }
1427
4/4
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 1 times.
32 else if (!stricmp(word[2], "off"))
1428 {
1429 30 disable_bank_cross_errors = true;
1430 }
1431
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 else if (!stricmp(word[2], "half"))
1432 {
1433 2 disable_bank_cross_errors = false;
1434 2 check_half_banks_crossed = true;
1435 }
1436 else if (!stricmp(word[2], "full"))
1437 {
1438 disable_bank_cross_errors = false;
1439 check_half_banks_crossed = false;
1440 }
1441 else asar_throw_error(0, error_type_block, error_id_invalid_check);
1442
1443 }
1444 else
1445 {
1446 asar_throw_error(0, error_type_block, error_id_invalid_check);
1447 }
1448 }
1449
9/10
✓ Branch 0 taken 548 times.
✓ Branch 1 taken 217570 times.
✓ Branch 2 taken 548 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 217000 times.
✓ Branch 5 taken 1118 times.
✓ Branch 6 taken 30 times.
✓ Branch 7 taken 216970 times.
✓ Branch 8 taken 15 times.
✓ Branch 9 taken 109044 times.
218118 else if (is0("asar") || is1("asar"))
1450 {
1451
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
30 if (!asarverallowed) asar_throw_error(0, error_type_block, error_id_start_of_file);
1452
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 15 times.
30 if (!par) return;
1453
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
30 if (emulatexkas) asar_throw_error(0, error_type_block, error_id_xkas_asar_conflict);
1454 15 int dots=0;
1455 15 int dig=0;
1456
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 30 times.
150 for (int i=0;par[i];i++)
1457 {
1458
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 90 times.
120 if (par[i]=='.')
1459 {
1460
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
30 if (!dig) asar_throw_error(0, error_type_block, error_id_invalid_version_number);
1461 15 dig=0;
1462 30 dots++;
1463 }
1464
1/2
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
90 else if (is_digit(par[i])) dig++;
1465 else asar_throw_error(0, error_type_block, error_id_invalid_version_number);
1466 }
1467
4/8
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 15 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
30 if (!dig || !dots || dots>2) asar_throw_error(0, error_type_block, error_id_invalid_version_number);
1468
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 autoptr<char**> vers=split(par, ".");
1469 30 int vermaj=atoi(vers[0]);
1470
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
30 if (vermaj > asarver_maj) asar_throw_error(pass, error_type_fatal, error_id_asar_too_old);
1471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (vermaj<asarver_maj) return;
1472
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (dots==1)
1473 {
1474
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
30 if (strlen(vers[1])!=2) asar_throw_error(0, error_type_block, error_id_invalid_version_number);
1475 //if (asarver_min<10 && asarver_bug<10 && strlen(vers[1])>2) error(0, "This version of Asar is too old for this patch.");
1476 30 int verminbug=atoi(vers[1]);
1477 30 int tmpver=asarver_bug;
1478
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
30 if (tmpver>9) tmpver=9;
1479
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
30 if (asarver_min*10+tmpver<verminbug) asar_throw_error(pass, error_type_fatal, error_id_asar_too_old);
1480
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 12 times.
30 if(vermaj == 1 && verminbug >= 90) { default_math_pri = true; default_math_round_off = true; }
1481 }
1482 else
1483 {
1484 int vermin=atoi(vers[1]);
1485 if (vermin>asarver_min) asar_throw_error(pass, error_type_fatal, error_id_asar_too_old);
1486 int verbug=atoi(vers[2]);
1487 if (vermin==asarver_min && verbug>asarver_bug) asar_throw_error(pass, error_type_fatal, error_id_asar_too_old);
1488 if(vermaj == 1 && vermin >= 9) { default_math_pri = true; default_math_round_off = true; }
1489 }
1490 30 specifiedasarver = true;
1491
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
30 }
1492
6/6
✓ Branch 0 taken 548 times.
✓ Branch 1 taken 217540 times.
✓ Branch 2 taken 274 times.
✓ Branch 3 taken 274 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 109038 times.
218088 else if (is0("xkas"))
1493 {
1494
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 asar_throw_warning(0, warning_id_feature_deprecated, "xkas compatibility mode", "UPGRADE YOUR PATCH ITS 2021!!!");
1495
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 if (!asarverallowed) asar_throw_error(0, error_type_block, error_id_start_of_file);
1496
4/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
12 if (incsrcdepth != 1 && !emulatexkas) asar_throw_error(0, error_type_block, error_id_command_in_non_root_file);
1497
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (specifiedasarver) asar_throw_error(0, error_type_block, error_id_xkas_asar_conflict);
1498 6 emulatexkas=true;
1499 6 optimizeforbank=0x100;
1500
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!force_checksum_fix)
1501 6 checksum_fix_enabled = false;
1502
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 sublabels[0]=":xkasdefault:";
1503 }
1504
7/10
✓ Branch 0 taken 536 times.
✓ Branch 1 taken 217540 times.
✓ Branch 2 taken 536 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 216970 times.
✓ Branch 5 taken 1106 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 216970 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 109038 times.
218076 else if (is0("include") || is1("includefrom"))
1505 {
1506 if (!asarverallowed) asar_throw_error(0, error_type_block, error_id_start_of_file);
1507 if (istoplevel)
1508 {
1509 if (par) asar_throw_error(pass, error_type_fatal, error_id_cant_be_main_file, (string(" The main file is '") + STR par + STR "'.").data());
1510 else asar_throw_error(pass, error_type_fatal, error_id_cant_be_main_file, "");
1511 }
1512 }
1513
6/6
✓ Branch 0 taken 536 times.
✓ Branch 1 taken 217540 times.
✓ Branch 2 taken 268 times.
✓ Branch 3 taken 268 times.
✓ Branch 4 taken 15 times.
✓ Branch 5 taken 109023 times.
218076 else if (is0("includeonce"))
1514 {
1515
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
30 if (!file_included_once(thisfilename))
1516 {
1517
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
30 includeonce.append(thisfilename);
1518 }
1519 }
1520
18/18
✓ Branch 0 taken 216970 times.
✓ Branch 1 taken 1076 times.
✓ Branch 2 taken 3772 times.
✓ Branch 3 taken 213198 times.
✓ Branch 4 taken 3772 times.
✓ Branch 5 taken 1076 times.
✓ Branch 6 taken 3728 times.
✓ Branch 7 taken 44 times.
✓ Branch 8 taken 3728 times.
✓ Branch 9 taken 1076 times.
✓ Branch 10 taken 3140 times.
✓ Branch 11 taken 588 times.
✓ Branch 12 taken 3140 times.
✓ Branch 13 taken 1076 times.
✓ Branch 14 taken 72 times.
✓ Branch 15 taken 3068 times.
✓ Branch 16 taken 106951 times.
✓ Branch 17 taken 2072 times.
218046 else if (is1("db") || is1("dw") || is1("dl") || is1("dd"))
1521 {
1522 106951 int len = 0;
1523
2/6
✓ Branch 0 taken 213902 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 213902 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
213902 if (!confirmqpar(par)) asar_throw_error(0, error_type_block, error_id_mismatched_parentheses);
1524
5/6
✓ Branch 0 taken 213902 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106951 times.
✓ Branch 3 taken 106951 times.
✓ Branch 4 taken 106599 times.
✓ Branch 5 taken 352 times.
213902 if (is1("db")) len=1;
1525
5/6
✓ Branch 0 taken 213902 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106951 times.
✓ Branch 3 taken 106951 times.
✓ Branch 4 taken 22 times.
✓ Branch 5 taken 106929 times.
213902 if (is1("dw")) len=2;
1526
5/6
✓ Branch 0 taken 213902 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106951 times.
✓ Branch 3 taken 106951 times.
✓ Branch 4 taken 294 times.
✓ Branch 5 taken 106657 times.
213902 if (is1("dl")) len=3;
1527
5/6
✓ Branch 0 taken 213902 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106951 times.
✓ Branch 3 taken 106951 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 106915 times.
213902 if (is1("dd")) len=4;
1528
1/2
✓ Branch 0 taken 213902 times.
✗ Branch 1 not taken.
213902 autoptr<char**> pars=qpsplit(par, ",");
1529
2/2
✓ Branch 0 taken 214616 times.
✓ Branch 1 taken 213892 times.
428508 for (int i=0;pars[i];i++)
1530 {
1531
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 214448 times.
214616 if (pars[i][0]=='"')
1532 {
1533
4/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 162 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 84 times.
168 if (!strcmp(pars[i],"\"STAR\"") && !emulatexkas)
1534 asar_throw_warning(0, warning_id_xkas_patch);
1535
3/4
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 618 times.
✓ Branch 3 taken 168 times.
786 for (char * str=const_cast<char*>(safedequote(pars[i]));*str;str++)
1536 {
1537
3/4
✓ Branch 0 taken 546 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 546 times.
✗ Branch 3 not taken.
618 if (len==1) write1(table.table[(size_t)(unsigned char) *str]);
1538
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 594 times.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
618 if (len==2) write2(table.table[(size_t)(unsigned char) *str]);
1539
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 594 times.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
618 if (len==3) write3(table.table[(size_t)(unsigned char) *str]);
1540
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 594 times.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
618 if (len==4) write4(table.table[(size_t)(unsigned char) *str]);
1541 }
1542 }
1543 else
1544 {
1545 107224 const char * math=pars[i];
1546
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 214448 times.
214448 if (math[0]=='#') math++;
1547
4/4
✓ Branch 0 taken 71482 times.
✓ Branch 1 taken 142966 times.
✓ Branch 2 taken 71472 times.
✓ Branch 3 taken 10 times.
214448 unsigned int num=(pass==2)?getnum(math):0;
1548
3/4
✓ Branch 0 taken 213752 times.
✓ Branch 1 taken 686 times.
✓ Branch 2 taken 106876 times.
✗ Branch 3 not taken.
214438 if (len == 1) write1(num);
1549
3/4
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 214400 times.
✓ Branch 2 taken 38 times.
✗ Branch 3 not taken.
214438 if (len == 2) write2(num);
1550
3/4
✓ Branch 0 taken 582 times.
✓ Branch 1 taken 213856 times.
✓ Branch 2 taken 582 times.
✗ Branch 3 not taken.
214438 if (len == 3) write3(num);
1551
3/4
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 214372 times.
✓ Branch 2 taken 66 times.
✗ Branch 3 not taken.
214438 if (len == 4) write4(num);
1552 }
1553 }
1554
1/2
✓ Branch 0 taken 213892 times.
✗ Branch 1 not taken.
213892 add_addr_to_line(addrToLinePos);
1555 213902 }
1556
6/6
✓ Branch 0 taken 510 times.
✓ Branch 1 taken 3634 times.
✓ Branch 2 taken 378 times.
✓ Branch 3 taken 132 times.
✓ Branch 4 taken 132 times.
✓ Branch 5 taken 123 times.
4144 else if (numwords==3 && !stricmp(word[1], "="))
1557 {
1558
5/8
✓ Branch 0 taken 150 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 150 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 150 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 150 times.
✗ Branch 7 not taken.
246 if (word[0][0]=='\'' && word[0][1] && word[0][2]=='\'' && word[0][3]=='\0')
1559 {
1560
1/2
✓ Branch 0 taken 150 times.
✗ Branch 1 not taken.
150 table.table[(unsigned char)word[0][1]]=getnum(word[2]);
1561
3/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 144 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
150 if (foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
1562 150 return;
1563 }
1564 // randomdude999: int cast b/c i'm too lazy to also mess with making setlabel()
1565 // unsigned, besides it wouldn't matter anyways.
1566
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 int num=(int)getnum(word[2]);
1567
5/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 84 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
96 if (foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_label_cross_assignment);
1568
1569 90 const char* newlabelname = word[0];
1570 45 bool ismacro = false;
1571
1572
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 84 times.
90 if (newlabelname[0] == '?')
1573 {
1574 3 ismacro = true;
1575 6 newlabelname++;
1576 }
1577
1578
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
48 if (ismacro && macrorecursion == 0)
1579 {
1580 asar_throw_error(0, error_type_block, error_id_macro_label_outside_of_macro);
1581 }
1582
1583
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
90 if (!confirmname(newlabelname)) asar_throw_error(0, error_type_block, error_id_invalid_label_name);
1584
1585 45 string completename;
1586
1587
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 84 times.
90 if (ismacro)
1588 {
1589
5/10
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
9 completename += STR":macro_" + dec(calledmacros) + "_";
1590 }
1591
1592
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
90 completename += newlabelname;
1593
1594
2/4
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
✗ Branch 3 not taken.
90 setlabel(ns + completename, num, true);
1595 135 }
1596
3/4
✓ Branch 0 taken 3898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3740 times.
✓ Branch 3 taken 158 times.
3898 else if (assemblemapper(word, numwords)) {}
1597
6/6
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 690 times.
✓ Branch 2 taken 1525 times.
✓ Branch 3 taken 1525 times.
✓ Branch 4 taken 370 times.
✓ Branch 5 taken 1500 times.
3740 else if (is1("org"))
1598 {
1599
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 740 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
740 if(in_spcblock) asar_throw_error(0, error_type_block, error_id_feature_unavaliable_in_spcblock);
1600 740 freespaceend();
1601
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 unsigned int num=getnum(par);
1602
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 740 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
740 if (forwardlabel) asar_throw_error(0, error_type_block, error_id_org_label_forward);
1603
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 740 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
740 if (num&~0xFFFFFF) asar_throw_error(1, error_type_block, error_id_snes_address_out_of_bounds, hex6(num).data());
1604
5/10
✓ Branch 0 taken 266 times.
✓ Branch 1 taken 474 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 260 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 480 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
740 if ((mapper==lorom || mapper==exlorom) && (num&0x408000)==0x400000 && (num&0x700000)!=0x700000) asar_throw_warning(0, warning_id_set_middle_byte);
1605 //if (fastrom) num|=0x800000;
1606 740 snespos=(int)num;
1607 740 realsnespos=(int)num;
1608 740 startpos=(int)num;
1609 740 realstartpos=(int)num;
1610 }
1611 #define ret_error(errid) { asar_throw_error(0, error_type_block, errid); return; }
1612 #define ret_error_params(errid, ...) { asar_throw_error(0, error_type_block, errid, __VA_ARGS__); return; }
1613
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 2922 times.
3000 else if (is("struct"))
1614 {
1615 //verifysnespos();
1616
2/6
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 78 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
78 if (in_struct || in_sub_struct) ret_error(error_id_nested_struct);
1617
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
78 if (numwords < 2) ret_error(error_id_missing_struct_params);
1618
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
78 if (numwords > 4) ret_error(error_id_too_many_struct_params);
1619
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
78 if (!confirmname(word[1])) ret_error(error_id_invalid_struct_name);
1620
1621
6/10
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 39 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
78 if (structs.exists(word[1]) && pass == 0) ret_error_params(error_id_struct_redefined, word[1]);
1622
1623 78 static_struct = false;
1624 78 old_snespos = snespos;
1625 78 old_startpos = startpos;
1626 78 old_optimizeforbank = optimizeforbank;
1627 39 unsigned int base = 0;
1628
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 48 times.
78 if (numwords == 3)
1629 {
1630 30 static_struct = true;
1631
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 base = getnum(word[2]);
1632
1633
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
30 if (foundlabel && !foundlabel_static) static_struct = false;
1634 }
1635
1636 78 bool old_in_struct = in_struct;
1637 78 bool old_in_sub_struct = in_sub_struct;
1638
4/4
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 12 times.
78 in_struct = numwords == 2 || numwords == 3;
1639 78 in_sub_struct = numwords == 4;
1640
1641 #define ret_error_cleanup(errid) { in_struct = old_in_struct; in_sub_struct = old_in_sub_struct; asar_throw_error(0, error_type_block, errid); return; }
1642 #define ret_error_params_cleanup(errid, ...) { in_struct = old_in_struct; in_sub_struct = old_in_sub_struct; asar_throw_error(0, error_type_block, errid, __VA_ARGS__); return; }
1643
1644
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 48 times.
78 if (numwords == 3)
1645 {
1646
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
30 if (base&~0xFFFFFF) ret_error_params_cleanup(error_id_snes_address_out_of_bounds, hex6((unsigned int)base).data());
1647 30 snespos = (int)base;
1648 30 startpos = (int)base;
1649 }
1650
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
48 else if (numwords == 4)
1651 {
1652
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
24 if (strcasecmp(word[2], "extends")) ret_error_cleanup(error_id_missing_extends);
1653
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 if (!confirmname(word[3])) ret_error_cleanup(error_id_struct_invalid_parent_name);
1654
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 string tmp_struct_parent = word[3];
1655
1656
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
24 if (!structs.exists(tmp_struct_parent)) ret_error_params_cleanup(error_id_struct_not_found, tmp_struct_parent.data());
1657
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
24 snes_struct structure = structs.find(tmp_struct_parent);
1658
1659 24 static_struct = structure.is_static;
1660
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 struct_parent = tmp_struct_parent;
1661 24 snespos = structure.base_end;
1662 24 startpos = structure.base_end;
1663
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
24 }
1664
1665
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
78 push_pc();
1666
1667 78 optimizeforbank = -1;
1668
1669
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
78 struct_name = word[1];
1670 78 struct_base = snespos;
1671 78 realsnespos = 0;
1672 78 realstartpos = 0;
1673
1674
2/4
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
78 setlabel(struct_name, snespos, static_struct);
1675
1676 #undef ret_error_cleanup
1677 #undef ret_error_params_cleanup
1678 }
1679
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 2844 times.
2922 else if (is("endstruct"))
1680 {
1681
3/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
78 if (numwords != 1 && numwords != 3) ret_error(error_id_invalid_endstruct_count);
1682
5/8
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
78 if (numwords == 3 && strcasecmp(word[1], "align")) ret_error(error_id_expected_align);
1683
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
78 if (!in_struct && !in_sub_struct) ret_error(error_id_endstruct_without_struct);
1684
1685
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
78 int alignment = numwords == 3 ? (int)getnum(word[2]) : 1;
1686
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
42 if (alignment < 1) ret_error(error_id_alignment_too_small);
1687
1688 39 snes_struct structure;
1689 78 structure.base_end = snespos;
1690 78 structure.struct_size = alignment * ((snespos - struct_base + alignment - 1) / alignment);
1691 78 structure.object_size = structure.struct_size;
1692 78 structure.is_static = static_struct;
1693
1694
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 24 times.
78 if (in_struct)
1695 {
1696
2/4
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✗ Branch 3 not taken.
54 structs.create(struct_name) = structure;
1697 }
1698
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 else if (in_sub_struct)
1699 {
1700 12 snes_struct parent;
1701
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
24 parent = structs.find(struct_parent);
1702
1703
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (parent.object_size < parent.struct_size + structure.struct_size) {
1704 24 parent.object_size = parent.struct_size + structure.struct_size;
1705 }
1706
1707
4/8
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
24 structs.create(struct_parent + "." + struct_name) = structure;
1708
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
24 structs.create(struct_parent) = parent;
1709 12 }
1710
1711
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
78 pop_pc();
1712 78 in_struct = false;
1713 78 in_sub_struct = false;
1714 78 snespos = old_snespos;
1715 78 startpos = old_startpos;
1716 78 optimizeforbank = old_optimizeforbank;
1717 78 static_struct = false;
1718 39 }
1719 #undef ret_error
1720
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2832 times.
2844 else if(is("spcblock"))
1721 {
1722 //banned features when active: org, freespace(and variants), arch, mapper,namespace,pushns
1723
2/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
12 if(in_struct || in_sub_struct) asar_throw_error(0, error_type_block, error_id_spcblock_inside_struct);
1724
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 if(numwords < 2) asar_throw_error(0, error_type_block, error_id_spcblock_too_few_args);
1725
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 if(numwords > 4) asar_throw_error(0, error_type_block, error_id_spcblock_too_many_args);
1726
1727
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 spcblock.destination = getnum(par);
1728 12 spcblock.type = spcblock_nspc;
1729
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 spcblock.macro_name = "";
1730
1731
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
12 if (spcblock.destination&~0xFFFF) asar_throw_error(0, error_type_block, error_id_snes_address_out_of_bounds, hex6(spcblock.destination).data());
1732
1733
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(numwords == 3)
1734 {
1735 if(!stricmp(word[2], "nspc")) spcblock.type = spcblock_nspc;
1736 else if(!stricmp(word[2], "custom")) asar_throw_error(0, error_type_block, error_id_custom_spcblock_missing_macro);
1737 else asar_throw_error(0, error_type_block, error_id_unknown_spcblock_type);
1738 }
1739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 else if(numwords == 4)
1740 {
1741 if(!stricmp(word[2], "custom")) spcblock.type = spcblock_custom;
1742 else asar_throw_error(0, error_type_block, error_id_extra_spcblock_arg_for_type);
1743
1744 if(macros.exists(word[3]))
1745 {
1746 macrodata *macro = macros.find(word[3]);
1747 if(!macro->variadic) asar_throw_error(0, error_type_block, error_id_spcblock_macro_must_be_varadic);
1748 if(macro->numargs != 3) asar_throw_error(0, error_type_block, error_id_spcblock_macro_invalid_static_args);
1749 spcblock.macro_name = word[3];
1750 }
1751 else asar_throw_error(0, error_type_block, error_id_spcblock_macro_doesnt_exist);
1752 }
1753
1754
1/3
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
12 switch(spcblock.type)
1755 {
1756 12 case spcblock_nspc:
1757 12 spcblock.size_address=realsnespos;
1758
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 write2(0x0000);
1759
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 write2(spcblock.destination);
1760 12 snespos=(int)spcblock.destination;
1761 12 startpos=(int)spcblock.destination;
1762 12 spcblock.execute_address = -1u;
1763
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 add_addr_to_line(addrToLinePos);
1764 6 break;
1765 case spcblock_custom:
1766 //this is a todo that probably won't be ready for 1.9
1767 //mostly so we can leverage some cleanups we make in 2.0 for practicality
1768 asar_throw_error(0, error_type_block, error_id_spcblock_custom_types_incomplete);
1769 push_pc();
1770 spcblock.old_mapper = mapper;
1771 mapper = norom;
1772 break;
1773 default:
1774 asar_throw_error(0, error_type_fatal, error_id_internal_error, "invalid spcblock type");
1775 }
1776
1777
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 ns_backup = ns;
1778
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
12 ns = STR":SPCBLOCK:_" + ns_backup;
1779 12 in_spcblock = true;
1780 }
1781
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2820 times.
2832 else if(is("endspcblock"))
1782 {
1783
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 if(!in_spcblock) asar_throw_error(0, error_type_block, error_id_endspcblock_without_spcblock);
1784
1785
1/3
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
12 switch(spcblock.type)
1786 {
1787 12 case spcblock_nspc:
1788
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
12 if (pass==2)
1789 {
1790 4 int pcpos=snestopc(spcblock.size_address&0xFFFFFF);
1791
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
4 if (pcpos<0) asar_throw_error(2, error_type_block, error_id_snes_address_doesnt_map_to_rom, hex6((unsigned int)realsnespos).data());
1792 4 int num=snespos-startpos;
1793
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 writeromdata_byte(pcpos, (unsigned char)num);
1794
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 writeromdata_byte(pcpos+1, (unsigned char)(num >> 8));
1795 }
1796
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (numwords == 3)
1797 {
1798
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (strcmp(par, "execute")) asar_throw_error(0, error_type_null, error_id_invalid_endspcblock_arg, par);
1799 else
1800 {
1801
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 write2(0x0000);
1802
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 write2((unsigned int)getnum64(word[2]));
1803 }
1804 }
1805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 else if (numwords != 1)
1806 {
1807 asar_throw_error(0, error_type_null, error_id_unknown_endspcblock_format);
1808 }
1809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 else if(spcblock.execute_address != -1u)
1810 {
1811 // Legacy case, will be removed with Asar 2.0.
1812 write2(0x0000);
1813 write2((unsigned int)spcblock.execute_address);
1814 }
1815 6 break;
1816 case spcblock_custom:
1817 mapper = spcblock.old_mapper;
1818 pop_pc();
1819 break;
1820 default:
1821 asar_throw_error(0, error_type_fatal, error_id_internal_error, "invalid spcblock type");
1822 }
1823
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 ns = ns_backup;
1824 12 in_spcblock = false;
1825 }
1826 // Remember to also remove execute_address entirely from spcblock once removing this deprecated command.
1827
5/6
✓ Branch 0 taken 2274 times.
✓ Branch 1 taken 546 times.
✓ Branch 2 taken 1137 times.
✓ Branch 3 taken 1137 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1410 times.
2820 else if (is1("startpos"))
1828 {
1829 asar_throw_warning(0, warning_id_feature_deprecated, "startpos", "Use the optional argument to \"endspcblock\"");
1830 if(!in_spcblock) asar_throw_error(0, error_type_block, error_id_startpos_without_spcblock);
1831 spcblock.execute_address=getnum64(par);
1832 }
1833
6/6
✓ Branch 0 taken 2274 times.
✓ Branch 1 taken 546 times.
✓ Branch 2 taken 1137 times.
✓ Branch 3 taken 1137 times.
✓ Branch 4 taken 42 times.
✓ Branch 5 taken 1368 times.
2820 else if (is1("base"))
1834 {
1835
4/4
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 27 times.
84 if (!stricmp(par, "off"))
1836 {
1837 30 snespos=realsnespos;
1838 30 startpos=realstartpos;
1839 30 return;
1840 }
1841
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 unsigned int num=getnum(par);
1842
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
54 if (forwardlabel) asar_throw_error(0, error_type_block, error_id_base_label_invalid);
1843
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
54 if (num&~0xFFFFFF) asar_throw_error(1, error_type_block, error_id_snes_address_out_of_bounds, hex6((unsigned int)num).data());
1844 54 snespos=(int)num;
1845 54 startpos=(int)num;
1846 54 optimizeforbank=-1;
1847 }
1848
6/6
✓ Branch 0 taken 2190 times.
✓ Branch 1 taken 546 times.
✓ Branch 2 taken 1095 times.
✓ Branch 3 taken 1095 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 1362 times.
2736 else if (is1("dpbase"))
1849 {
1850
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 unsigned int num=(int)getnum(par);
1851
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 if (forwardlabel) asar_throw_error(0, error_type_block, error_id_base_label_invalid);
1852
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
12 if (num&~0xFF00) asar_throw_error(1, error_type_block, error_id_bad_dp_base, hex6((unsigned int)num).data());
1853 12 dp_base = (int)num;
1854 }
1855
6/6
✓ Branch 0 taken 222 times.
✓ Branch 1 taken 2502 times.
✓ Branch 2 taken 111 times.
✓ Branch 3 taken 111 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 1326 times.
2724 else if (is2("optimize"))
1856 {
1857
4/4
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 24 times.
72 if (!stricmp(par, "dp"))
1858 {
1859
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 6 times.
24 if (!stricmp(word[2], "none"))
1860 {
1861 12 optimize_dp = optimize_dp_flag::NONE;
1862 12 return;
1863 }
1864
4/4
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
12 if (!stricmp(word[2], "ram"))
1865 {
1866 6 optimize_dp = optimize_dp_flag::RAM;
1867 6 return;
1868 }
1869
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 if (!stricmp(word[2], "always"))
1870 {
1871 6 optimize_dp = optimize_dp_flag::ALWAYS;
1872 6 return;
1873 }
1874 asar_throw_error(1, error_type_block, error_id_bad_dp_optimize, word[2]);
1875 }
1876
2/4
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
48 if (!stricmp(par, "address"))
1877 {
1878
4/4
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 18 times.
48 if (!stricmp(word[2], "default"))
1879 {
1880 12 optimize_address = optimize_address_flag::DEFAULT;
1881 12 return;
1882 }
1883
4/4
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 9 times.
36 if (!stricmp(word[2], "ram"))
1884 {
1885 18 optimize_address = optimize_address_flag::RAM;
1886 18 return;
1887 }
1888
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
18 if (!stricmp(word[2], "mirrors"))
1889 {
1890 18 optimize_address = optimize_address_flag::MIRRORS;
1891 18 return;
1892 }
1893 asar_throw_error(1, error_type_block, error_id_bad_address_optimize, word[2]);
1894 }
1895 asar_throw_error(1, error_type_block, error_id_bad_optimize, par);
1896 }
1897
5/6
✓ Branch 0 taken 2178 times.
✓ Branch 1 taken 474 times.
✓ Branch 2 taken 1089 times.
✓ Branch 3 taken 1089 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1326 times.
2652 else if (is1("bank"))
1898 {
1899 if (!stricmp(par, "auto"))
1900 {
1901 optimizeforbank=-1;
1902 return;
1903 }
1904 if (!stricmp(par, "noassume"))
1905 {
1906 optimizeforbank=0x100;
1907 return;
1908 }
1909 unsigned int num=getnum(par);
1910 //if (forwardlabel) error(0, "bank Label is not valid");
1911 //if (foundlabel) num>>=16;
1912 if (num&~0x0000FF) asar_throw_error(1, error_type_block, error_id_snes_address_out_of_bounds, hex6((unsigned int)num).data());
1913 optimizeforbank=(int)num;
1914 }
1915
7/8
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1806 times.
✓ Branch 3 taken 846 times.
✓ Branch 4 taken 903 times.
✓ Branch 5 taken 903 times.
✓ Branch 6 taken 465 times.
✓ Branch 7 taken 861 times.
2652 else if (is("freespace") || is("freecode") || is("freedata"))
1916 {
1917
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 930 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
930 if(in_spcblock) asar_throw_error(0, error_type_block, error_id_feature_unavaliable_in_spcblock);
1918
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 930 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
930 if (emulatexkas) asar_throw_warning(0, warning_id_convert_to_asar);
1919 465 string parstr;
1920
3/4
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 792 times.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
930 if (numwords==1) parstr="\n";//crappy hack: impossible character to cut out extra commas
1921
2/4
✓ Branch 0 taken 792 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 396 times.
✗ Branch 3 not taken.
792 else if (numwords==2) parstr=word[1];
1922 else asar_throw_error(0, error_type_block, error_id_invalid_freespace_request);
1923
5/8
✓ Branch 0 taken 846 times.
✓ Branch 1 taken 84 times.
✓ Branch 2 taken 423 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 423 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 423 times.
✗ Branch 7 not taken.
1353 if (is("freecode")) parstr=STR"ram,"+parstr;
1924
5/8
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 846 times.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 42 times.
✗ Branch 7 not taken.
972 if (is("freedata")) parstr=STR"noram,"+parstr;
1925
1/2
✓ Branch 0 taken 930 times.
✗ Branch 1 not taken.
930 autoptr<char**> pars=split(parstr.temp_raw(), ",");
1926 930 unsigned char fsbyte = default_freespacebyte;
1927 465 int useram=-1;
1928 465 bool fixedpos=false;
1929 465 bool align=false;
1930 465 bool leakwarn=true;
1931
2/2
✓ Branch 0 taken 1860 times.
✓ Branch 1 taken 930 times.
2790 for (int i=0;pars[i];i++)
1932 {
1933
2/2
✓ Branch 0 taken 1722 times.
✓ Branch 1 taken 138 times.
1860 if (pars[i][0]=='\n') {}
1934
4/4
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 438 times.
✓ Branch 2 taken 423 times.
✓ Branch 3 taken 438 times.
1722 else if (!stricmp(pars[i], "ram"))
1935 {
1936
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 846 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
846 if (useram!=-1) asar_throw_error(0, error_type_block, error_id_invalid_freespace_request);
1937 423 useram=1;
1938 }
1939
4/4
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 396 times.
✓ Branch 2 taken 42 times.
✓ Branch 3 taken 396 times.
876 else if (!stricmp(pars[i], "noram"))
1940 {
1941
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
84 if (useram!=-1) asar_throw_error(0, error_type_block, error_id_invalid_freespace_request);
1942 42 useram=0;
1943 }
1944
6/8
✓ Branch 0 taken 792 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 396 times.
✓ Branch 3 taken 396 times.
✓ Branch 4 taken 396 times.
✓ Branch 5 taken 396 times.
✓ Branch 6 taken 396 times.
✗ Branch 7 not taken.
792 else if (!stricmp(pars[i], "static") || !stricmp(pars[i], "fixed"))
1945 {
1946 if (!stricmp(pars[i], "fixed")) asar_throw_warning(0, warning_id_feature_deprecated, "freespace/code/data fixed", "freespace/code/data static");
1947 if (fixedpos) asar_throw_error(0, error_type_block, error_id_invalid_freespace_request);
1948 fixedpos=true;
1949 }
1950
4/4
✓ Branch 0 taken 399 times.
✓ Branch 1 taken 393 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 393 times.
792 else if (!stricmp(pars[i], "align"))
1951 {
1952
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (align) asar_throw_error(0, error_type_block, error_id_invalid_freespace_request);
1953 3 align=true;
1954 }
1955
2/4
✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 393 times.
✗ Branch 3 not taken.
786 else if (!stricmp(pars[i], "cleaned"))
1956 {
1957
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 786 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
786 if (!leakwarn) asar_throw_error(0, error_type_block, error_id_invalid_freespace_request);
1958 393 leakwarn=false;
1959 }
1960 else
1961 {
1962 asar_throw_warning(0, warning_id_feature_deprecated, "specifying the freespacebyte in the freespace command", "use the separate freespacebyte command");
1963 fsbyte = (unsigned char)getnum(pars[i]);
1964 }
1965 }
1966
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 930 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
930 if (useram==-1) asar_throw_error(0, error_type_block, error_id_invalid_freespace_request);
1967
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 930 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
930 if (mapper == norom) asar_throw_error(0, error_type_block, error_id_no_freespace_norom);
1968 930 freespaceend();
1969
1/2
✓ Branch 0 taken 930 times.
✗ Branch 1 not taken.
930 freespaceid=getfreespaceid();
1970 930 freespacebyte[freespaceid] = fsbyte;
1971 930 freespace_is_freecode = (useram != 0);
1972
2/2
✓ Branch 0 taken 310 times.
✓ Branch 1 taken 620 times.
930 if (pass==0) snespos=(freespaceid<<24)|0x8000;
1973
2/2
✓ Branch 0 taken 310 times.
✓ Branch 1 taken 620 times.
930 if (pass==1)
1974 {
1975
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 310 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
310 if (fixedpos && freespaceorgpos[freespaceid]<0)
1976 {
1977 freespacepos[freespaceid]=0x008000;
1978 freespaceleak[freespaceid]=false;//mute some other errors
1979 asar_throw_error(1, error_type_block, error_id_static_freespace_autoclean);
1980 }
1981
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 155 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
155 if (fixedpos && freespaceorgpos[freespaceid]) freespacepos[freespaceid]=snespos=(freespaceid<<24)|freespaceorgpos[freespaceid];
1982
1/2
✓ Branch 0 taken 310 times.
✗ Branch 1 not taken.
310 else freespacepos[freespaceid]=snespos=(freespaceid<<24)|getsnesfreespace(freespacelen[freespaceid], (useram != 0), true, true, align, freespacebyte[freespaceid]);
1983 }
1984
2/2
✓ Branch 0 taken 310 times.
✓ Branch 1 taken 620 times.
930 if (pass==2)
1985 {
1986
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 310 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
310 if (fixedpos && freespaceorgpos[freespaceid]==-1) return;//to kill some errors
1987 310 snespos=(freespaceid<<24)|freespacepos[freespaceid];
1988
1/2
✓ Branch 0 taken 310 times.
✗ Branch 1 not taken.
310 resizerats(snespos&0xFFFFFF, freespacelen[freespaceid]);
1989
3/6
✓ Branch 0 taken 258 times.
✓ Branch 1 taken 52 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 258 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
310 if (freespaceleak[freespaceid] && leakwarn) asar_throw_warning(2, warning_id_freespace_leaked);
1990
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 310 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
310 if (fixedpos && freespaceorgpos[freespaceid]>0 && freespacelen[freespaceid]>freespaceorglen[freespaceid])
1991 asar_throw_error(2, error_type_block, error_id_static_freespace_growing);
1992 310 freespaceuse+=8+freespacelen[freespaceid];
1993
1994 // add a mapping for the start of the rats tag
1995
1/2
✓ Branch 0 taken 310 times.
✗ Branch 1 not taken.
310 add_addr_to_line(snespos-8);
1996 }
1997 930 freespacestatic[freespaceid]=fixedpos;
1998
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 930 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
930 if (snespos < 0 && mapper == sa1rom) asar_throw_error(pass, error_type_fatal, error_id_no_freespace_in_mapped_banks, dec(freespacelen[freespaceid]).data());
1999
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 930 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
930 if (snespos < 0) asar_throw_error(pass, error_type_fatal, error_id_no_freespace, dec(freespacelen[freespaceid]).data());
2000 930 bytes+=8;
2001 930 freespacestart=snespos;
2002 930 startpos=snespos;
2003 930 realstartpos=snespos;
2004 930 realsnespos=snespos;
2005 930 optimizeforbank=-1;
2006 930 ratsmetastate=ratsmeta_allow;
2007
2/4
✓ Branch 0 taken 465 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 465 times.
✗ Branch 3 not taken.
930 }
2008
6/6
✓ Branch 0 taken 1386 times.
✓ Branch 1 taken 336 times.
✓ Branch 2 taken 693 times.
✓ Branch 3 taken 693 times.
✓ Branch 4 taken 27 times.
✓ Branch 5 taken 834 times.
1722 else if (is1("prot"))
2009 {
2010
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
54 if(in_spcblock) asar_throw_error(0, error_type_block, error_id_feature_unavaliable_in_spcblock);
2011
2/6
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 54 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
54 if (!confirmqpar(par)) asar_throw_error(0, error_type_block, error_id_mismatched_parentheses);
2012
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
54 if (!ratsmetastate) asar_throw_error(2, error_type_block, error_id_prot_not_at_freespace_start);
2013
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 42 times.
54 if (ratsmetastate==ratsmeta_used) step(-5);
2014 27 int num;
2015
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 autoptr<char**> pars=qpsplit(par, ",", &num);
2016
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('P');
2017
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('R');
2018
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('O');
2019
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('T');
2020
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
54 if (num * 3 > 255) asar_throw_error(0, error_type_block, error_id_prot_too_many_entries);
2021
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 write1((unsigned int)(num*3));
2022
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 54 times.
120 for (int i=0;i<num;i++)
2023 {
2024 //int num=getnum(pars[i]);
2025 66 const char * labeltest=pars[i];
2026
1/2
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
33 string testlabel = labeltest;
2027
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 int labelnum=(int)labelval(&labeltest).pos;
2028
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
66 if (*labeltest) asar_throw_error(0, error_type_block, error_id_label_not_found, testlabel.data());
2029
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 write3((unsigned int)labelnum);
2030
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 44 times.
66 if (pass==1) freespaceleak[labelnum >>24]=false;
2031 66 }
2032
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('S');
2033
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('T');
2034
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('O');
2035
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('P');
2036
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1(0);
2037 54 ratsmetastate=ratsmeta_used;
2038
2039
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 add_addr_to_line(addrToLinePos);
2040 54 }
2041
15/18
✓ Branch 0 taken 1332 times.
✓ Branch 1 taken 336 times.
✓ Branch 2 taken 1332 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 150 times.
✓ Branch 5 taken 1518 times.
✓ Branch 6 taken 36 times.
✓ Branch 7 taken 114 times.
✓ Branch 8 taken 1332 times.
✓ Branch 9 taken 222 times.
✓ Branch 10 taken 1332 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 36 times.
✓ Branch 13 taken 1518 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 36 times.
✓ Branch 16 taken 57 times.
✓ Branch 17 taken 777 times.
1668 else if (is1("autoclean") || is2("autoclean") || is1("autoclear") || is2("autoclear"))
2042 {
2043
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
114 if(in_spcblock) asar_throw_error(0, error_type_block, error_id_feature_unavaliable_in_spcblock);
2044
4/12
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 114 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 114 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 57 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
114 if (is1("autoclear") || is2("autoclear")) asar_throw_warning(0, warning_id_autoclear_deprecated);
2045
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 if (numwords==3)
2046 {
2047
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
114 if ((unsigned int)snespos & 0xFF000000) asar_throw_error(0, error_type_block, error_id_autoclean_in_freespace);
2048 114 const char * labeltest = word[2];
2049
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
57 string testlabel = labeltest;
2050
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 int num=(int)labelval(&labeltest).pos;
2051
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
114 if (*labeltest) asar_throw_error(0, error_type_block, error_id_label_not_found, testlabel.data());
2052 57 unsigned char targetid=(unsigned char)(num>>24);
2053
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 76 times.
114 if (pass==1) freespaceleak[targetid]=false;
2054 65 auto is_freespace_reused = [](int ratsloc) -> bool
2055 {
2056
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 14 times.
32 for (int i = 0; i < freespaceidnext; i++)
2057 {
2058
4/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
18 if (freespacepos[i] != -1 && (freespacepos[i] & 0xFFFFFF) == ratsloc) {
2059 1 return true;
2060 }
2061 }
2062 7 return false;
2063 };
2064 114 num&=0xFFFFFF;
2065
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
114 if (strlen(par)>3 && !stricmp(par+3, ".l")) par[3]=0;
2066
6/8
✓ Branch 0 taken 69 times.
✓ Branch 1 taken 45 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 45 times.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 12 times.
114 if (!stricmp(par, "JSL") || !stricmp(par, "JML"))
2067 {
2068 114 int orgpos=read3(snespos+1);
2069 114 int ratsloc=freespaceorgpos[targetid];
2070
4/4
✓ Branch 0 taken 102 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 45 times.
114 int firstbyte = ((!stricmp(par, "JSL")) ? 0x22 : 0x5C);
2071 114 int pcpos=snestopc(snespos);
2072
4/6
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 114 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48 times.
✓ Branch 5 taken 66 times.
114 if (/*pass==1 && */pcpos>=0 && pcpos<romlen_r && romdata_r[pcpos]==firstbyte)
2073 {
2074
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 ratsloc=ratsstart(orgpos)+8;
2075 48 freespaceorglen[targetid]=read2(ratsloc-4)+1;
2076
3/4
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 24 times.
48 if (!freespacestatic[targetid] && pass == 1)
2077 {
2078
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
16 if (!is_freespace_reused(ratsloc)) removerats(orgpos, freespacebyte[targetid]);
2079 }
2080 }
2081
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 15 times.
66 else if (ratsloc<0) ratsloc=0;
2082
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 write1((unsigned int)firstbyte);
2083
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 write3((unsigned int)num);
2084
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 76 times.
114 if (pass==2)
2085 {
2086
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 int start=ratsstart(num);
2087
3/4
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19 times.
38 if (start>=num || start<0)
2088 {
2089 asar_throw_error(2, error_type_block, error_id_autoclean_label_at_freespace_end);
2090 }
2091
2092
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 add_addr_to_line(addrToLinePos);
2093 }
2094 //freespaceorglen[targetid]=read2(ratsloc-4)+1;
2095 114 freespaceorgpos[targetid]=ratsloc;
2096 57 }
2097 else if (!stricmp(par, "dl"))
2098 {
2099 int orgpos=read3(snespos);
2100 int ratsloc=freespaceorgpos[targetid];
2101 int start=ratsstart(num);
2102 if (pass==1 && num>=0)
2103 {
2104 ratsloc=ratsstart(orgpos)+8;
2105 if (!freespacestatic[targetid] && !is_freespace_reused(ratsloc)) removerats(orgpos, freespacebyte[targetid]);
2106 }
2107 else if (!ratsloc) ratsloc=0;
2108 if ((start==num || start<0) && pass==2)
2109 asar_throw_error(2, error_type_block, error_id_autoclean_label_at_freespace_end);
2110 write3((unsigned int)num);
2111 freespaceorgpos[targetid]=ratsloc;
2112 freespaceorglen[targetid]=read2(ratsloc-4)+1;
2113
2114 add_addr_to_line(addrToLinePos);
2115 }
2116 else asar_throw_error(0, error_type_block, error_id_broken_autoclean);
2117 114 }
2118 else if (pass==0) removerats((int)getnum(word[1]), default_freespacebyte);
2119 }
2120
5/6
✓ Branch 0 taken 1332 times.
✓ Branch 1 taken 222 times.
✓ Branch 2 taken 666 times.
✓ Branch 3 taken 666 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 777 times.
1554 else if (is1("freespacebyte"))
2121 {
2122 default_freespacebyte = getnum(word[1]);
2123 if (foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2124 }
2125
6/6
✓ Branch 0 taken 150 times.
✓ Branch 1 taken 1404 times.
✓ Branch 2 taken 75 times.
✓ Branch 3 taken 75 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 774 times.
1554 else if (is0("pushpc"))
2126 {
2127
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (emulatexkas) asar_throw_warning(0, warning_id_convert_to_asar);
2128
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].arch=arch;
2129
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].snespos=snespos;
2130
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].snesstart=startpos;
2131
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].snesposreal=realsnespos;
2132
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].snesstartreal=realstartpos;
2133
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].freeid=freespaceid;
2134
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].freeex=freespaceextra;
2135
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].freest=freespacestart;
2136 6 pushpcnum++;
2137 6 snespos=(int)0xFFFFFFFF;
2138 6 startpos= (int)0xFFFFFFFF;
2139 6 realsnespos= (int)0xFFFFFFFF;
2140 6 realstartpos= (int)0xFFFFFFFF;
2141 }
2142
6/6
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 1404 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 72 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 771 times.
1548 else if (is0("pullpc"))
2143 {
2144
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (!pushpcnum) asar_throw_error(0, error_type_block, error_id_pullpc_without_pushpc);
2145 6 pushpcnum--;
2146 6 freespaceend();
2147
3/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
6 if (arch != pushpc[pushpcnum].arch) asar_throw_error(0, error_type_block, error_id_pullpc_different_arch);
2148
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 snespos=pushpc[pushpcnum].snespos;
2149
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 startpos=pushpc[pushpcnum].snesstart;
2150
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 realsnespos=pushpc[pushpcnum].snesposreal;
2151
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 realstartpos=pushpc[pushpcnum].snesstartreal;
2152
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 freespaceid=pushpc[pushpcnum].freeid;
2153
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 freespaceextra=pushpc[pushpcnum].freeex;
2154
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 freespacestart=pushpc[pushpcnum].freest;
2155 }
2156
6/6
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 1404 times.
✓ Branch 2 taken 69 times.
✓ Branch 3 taken 69 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 768 times.
1542 else if (is0("pushbase"))
2157 {
2158
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (emulatexkas) asar_throw_warning(0, warning_id_convert_to_asar);
2159
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 basestack[basestacknum] = snespos;
2160 6 basestacknum++;
2161 }
2162
6/6
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 1404 times.
✓ Branch 2 taken 66 times.
✓ Branch 3 taken 66 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 765 times.
1536 else if (is0("pullbase"))
2163 {
2164
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (!basestacknum) asar_throw_error(0, error_type_block, error_id_pullbase_without_pushbase);
2165 6 basestacknum--;
2166
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 snespos = basestack[basestacknum];
2167
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 startpos = basestack[basestacknum];
2168
2169
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (snespos != realstartpos)
2170 {
2171 6 optimizeforbank = -1;
2172 }
2173 }
2174
6/6
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 1404 times.
✓ Branch 2 taken 63 times.
✓ Branch 3 taken 63 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 759 times.
1530 else if (is0("pushns"))
2175 {
2176
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 if(in_spcblock) asar_throw_error(0, error_type_block, error_id_feature_unavaliable_in_spcblock);
2177
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 pushns[pushnsnum].ns = ns;
2178
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 for(int i = 0; i < namespace_list.count; i++)
2179 {
2180
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
12 pushns[pushnsnum].namespace_list.append(namespace_list[i]);
2181 }
2182
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 pushns[pushnsnum].nested_namespaces = nested_namespaces;
2183 12 pushnsnum++;
2184
2185
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 namespace_list.reset();
2186
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 ns = "";
2187 12 nested_namespaces = false;
2188 }
2189
6/6
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 1404 times.
✓ Branch 2 taken 57 times.
✓ Branch 3 taken 57 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 753 times.
1518 else if (is0("pullns"))
2190 {
2191
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 if(in_spcblock) asar_throw_error(0, error_type_block, error_id_feature_unavaliable_in_spcblock);
2192
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 if (!pushnsnum) asar_throw_error(0, error_type_block, error_id_pullns_without_pushns);
2193 12 pushnsnum--;
2194
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 ns = pushns[pushnsnum].ns;
2195
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 nested_namespaces = pushns[pushnsnum].nested_namespaces;
2196
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 namespace_list.reset();
2197
4/4
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 6 times.
36 for(int i = 0; i < pushns[pushnsnum].namespace_list.count; i++)
2198 {
2199
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
24 namespace_list.append(pushns[pushnsnum].namespace_list[i]);
2200 }
2201 }
2202
9/10
✓ Branch 0 taken 1332 times.
✓ Branch 1 taken 174 times.
✓ Branch 2 taken 1206 times.
✓ Branch 3 taken 126 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 1344 times.
✓ Branch 6 taken 36 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 81 times.
✓ Branch 9 taken 672 times.
1506 else if (is1("namespace") || is2("namespace"))
2203 {
2204
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 162 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
162 if(in_spcblock) asar_throw_error(0, error_type_block, error_id_feature_unavaliable_in_spcblock);
2205 81 bool leave = false;
2206
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if (par)
2207 {
2208
4/4
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 57 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 57 times.
162 if (!stricmp(par, "off"))
2209 {
2210
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
48 if (word[2]) asar_throw_error(0, error_type_block, error_id_invalid_namespace_use);
2211 24 leave = true;
2212 }
2213
4/4
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 39 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 39 times.
114 else if (!stricmp(par, "nested"))
2214 {
2215
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
36 if (!word[2]) asar_throw_error(0, error_type_block, error_id_invalid_namespace_use);
2216
4/4
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 9 times.
36 else if (!stricmp(word[2], "on")) nested_namespaces = true;
2217
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
18 else if (!stricmp(word[2], "off")) nested_namespaces = false;
2218 }
2219 else
2220 {
2221
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
78 if (word[2]) asar_throw_error(0, error_type_block, error_id_invalid_namespace_use);
2222
1/2
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
78 const char * tmpstr= safedequote(par);
2223
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
78 if (!confirmname(tmpstr)) asar_throw_error(0, error_type_block, error_id_invalid_namespace_name);
2224
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 48 times.
78 if (!nested_namespaces)
2225 {
2226
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
30 namespace_list.reset();
2227 }
2228
2/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
78 namespace_list.append(STR tmpstr);
2229 }
2230 }
2231 else
2232 {
2233 leave = true;
2234 }
2235
2236
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 57 times.
81 if (leave)
2237 {
2238
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 if (nested_namespaces)
2239 {
2240
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
36 namespace_list.remove(namespace_list.count - 1);
2241 }
2242 else
2243 {
2244
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 namespace_list.reset();
2245 }
2246 }
2247
2248 // recompute ns
2249
1/2
✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
81 ns = "";
2250
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 162 times.
354 for (int i = 0; i < namespace_list.count; i++)
2251 {
2252
2/4
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
192 ns += namespace_list[i];
2253
2/4
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
192 ns += STR"_";
2254 }
2255 }
2256
5/6
✓ Branch 0 taken 1206 times.
✓ Branch 1 taken 138 times.
✓ Branch 2 taken 603 times.
✓ Branch 3 taken 603 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 672 times.
1344 else if (is1("warnpc"))
2257 {
2258 asar_throw_warning(0, warning_id_feature_deprecated, "warnpc", "use \"assert pc() <= $xxxxxx\" instead");
2259 unsigned int maxpos=getnum(par);
2260 if ((unsigned int)snespos & 0xFF000000) asar_throw_error(0, error_type_block, error_id_warnpc_in_freespace);
2261 if ((unsigned int)maxpos & 0xFF000000) asar_throw_error(0, error_type_block, error_id_warnpc_broken_param);
2262 if ((unsigned int)snespos > maxpos) asar_throw_error(0, error_type_block, error_id_warnpc_failed, hex6((unsigned int)snespos).data(), hex6((unsigned int)maxpos).data());
2263 if (warnxkas && (unsigned int)snespos == maxpos) asar_throw_warning(0, warning_id_xkas_warnpc_relaxed);
2264 if (emulatexkas && (unsigned int)snespos==maxpos) asar_throw_error(0, error_type_block, error_id_warnpc_failed_equal, hex6((unsigned int)snespos).data(), hex6((unsigned int)maxpos).data());
2265 }
2266
6/6
✓ Branch 0 taken 1206 times.
✓ Branch 1 taken 138 times.
✓ Branch 2 taken 603 times.
✓ Branch 3 taken 603 times.
✓ Branch 4 taken 15 times.
✓ Branch 5 taken 657 times.
1344 else if (is1("rep"))
2267 {
2268
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 int rep = (int)getnum64(par);
2269
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 if (foundlabel) asar_throw_error(0, error_type_block, error_id_rep_label);
2270
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 6 times.
24 if (rep<=1)
2271 {
2272
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 if(rep < 0){
2273
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 asar_throw_warning(0, warning_id_feature_deprecated, "rep condition < 0", "You probably want conditionals");
2274 }
2275
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (emulatexkas)
2276 {
2277
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 asar_throw_warning(0, warning_id_feature_deprecated, "rep <= 1 xkas behaviour", "You probably want conditionals");
2278
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if (rep==0) rep=1;
2279
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 9 times.
15 if (rep<0) rep=0;
2280 18 repeatnext=rep;
2281 18 return;
2282 }
2283 }
2284
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 asar_throw_warning(0, warning_id_feature_deprecated, "rep X : {command}", "Use while loops, unrolled loops, pseudo opcodes or for loops");
2285 6 repeatnext=rep;
2286 }
2287 #ifdef SANDBOX
2288 else if (is("incsrc") || is("incbin") || is("table"))
2289 {
2290 asar_throw_error(0, error_type_block, error_id_command_disabled);
2291 }
2292 #endif
2293
6/6
✓ Branch 0 taken 1176 times.
✓ Branch 1 taken 138 times.
✓ Branch 2 taken 588 times.
✓ Branch 3 taken 588 times.
✓ Branch 4 taken 309 times.
✓ Branch 5 taken 348 times.
1314 else if (is1("incsrc"))
2294 {
2295 309 string name;
2296
2/8
✗ Branch 0 not taken.
✓ Branch 1 taken 618 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 309 times.
618 if (warnxkas && (strchr(thisfilename, '/') || strchr(thisfilename, '\\')))
2297 asar_throw_warning(0, warning_id_xkas_incsrc_relative);
2298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 618 times.
618 if (strchr(par, '\\'))
2299 {
2300 if (emulatexkas)
2301 {
2302 asar_throw_warning(0, warning_id_feature_deprecated, "xkas style paths", "convert paths to crossplatform style");
2303 for (int i=0;par[i];i++)
2304 {
2305 if (par[i]=='\\') par[i]='/';//let's just hope nobody finds I could just enable this for everything.
2306 }
2307 }
2308 #ifdef _WIN32
2309 else asar_throw_warning(0, warning_id_feature_deprecated, "windows specific paths", "convert paths to crossplatform style");
2310 #endif
2311 }
2312
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 618 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
618 if (emulatexkas) name= safedequote(par);
2313
3/6
✓ Branch 0 taken 618 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 309 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 309 times.
✗ Branch 5 not taken.
927 else name=STR safedequote(par);
2314
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 498 times.
618 assemblefile(name, false);
2315 618 }
2316
10/10
✓ Branch 0 taken 558 times.
✓ Branch 1 taken 138 times.
✓ Branch 2 taken 492 times.
✓ Branch 3 taken 66 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 594 times.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 30 times.
✓ Branch 8 taken 36 times.
✓ Branch 9 taken 312 times.
696 else if (is1("incbin") || is3("incbin"))
2317 {
2318
3/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 66 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
72 if (numwords == 4 && strcmp(word[2], "->")) asar_throw_error(0, error_type_block, error_id_broken_incbin);
2319 36 int len;
2320 36 int start=0;
2321 36 int end=0;
2322
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 30 times.
72 if (strqchr(par, ':'))
2323 {
2324 42 char * lengths=strqchr(par, ':');
2325 42 *lengths=0;
2326 42 lengths++;
2327
3/4
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 6 times.
42 if(strqpstr(lengths, ".."))
2328 {
2329 // new style ranges
2330
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 char* split = strqpstr(lengths, "..");
2331
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
36 string start_str(lengths, split-lengths);
2332
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 start = getnum(start_str);
2333
5/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
36 if (foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2334
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
30 string end_str(split+2);
2335
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 end = getnum(end_str);
2336
5/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
30 if (foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2337 42 }
2338 else
2339 {
2340
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 asar_throw_warning(0, warning_id_feature_deprecated, "old style incbin ranges", "use the :start..end syntax instead");
2341
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (strchr(lengths, '"')) asar_throw_error(0, error_type_block, error_id_broken_incbin);
2342
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(*lengths=='(') {
2343
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 char* tmp = strqpchr(lengths, '-');
2344
2/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
6 if(!tmp || (*(tmp-1)!=')')) asar_throw_error(0, error_type_block, error_id_broken_incbin);
2345
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9 start = (int)getnum64(string(lengths+1, tmp-1-lengths-1));
2346 if (foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2347 lengths = tmp;
2348 } else {
2349 start=(int)strtoul(lengths, &lengths, 16);
2350 }
2351 if (*lengths!='-') asar_throw_error(0, error_type_block, error_id_broken_incbin);
2352 lengths++;
2353 if(*lengths=='(') {
2354 char* tmp = strchr(lengths, '\0');
2355 if(*(tmp-1)!=')') asar_throw_error(0, error_type_block, error_id_broken_incbin);
2356 end = (int)getnum64(string(lengths+1, tmp-1-lengths-1));
2357 if (foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2358 // no need to check end-of-string here
2359 } else {
2360 end=(int)strtoul(lengths, &lengths, 16);
2361 if (*lengths) asar_throw_error(0, error_type_block, error_id_broken_incbin);
2362 }
2363 }
2364 }
2365 27 string name;
2366
2/8
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 27 times.
54 if (warnxkas && (strchr(thisfilename, '/') || strchr(thisfilename, '\\')))
2367 asar_throw_warning(0, warning_id_xkas_incsrc_relative);
2368
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 48 times.
54 if (strchr(par, '\\'))
2369 {
2370
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (emulatexkas)
2371 {
2372
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 asar_throw_warning(0, warning_id_feature_deprecated, "xkas style paths", "convert paths to crossplatform style");
2373
2/2
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 6 times.
120 for (int i=0;par[i];i++)
2374 {
2375
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 102 times.
114 if (par[i]=='\\') par[i]='/';//let's just hope nobody finds I could just enable this for everything.
2376 }
2377 }
2378 #ifdef _WIN32
2379 else asar_throw_warning(0, warning_id_feature_deprecated, "windows specific paths", "convert paths to crossplatform style");
2380 #endif
2381 }
2382
4/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
54 if (emulatexkas) name= safedequote(par);
2383
3/6
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
72 else name=STR safedequote(par);
2384 27 char * data;//I couldn't find a way to get this into an autoptr
2385
6/10
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 48 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
54 if (!readfile(name, thisfilename, &data, &len)) asar_throw_error(0, error_type_block, vfile_error_to_error_id(asar_get_last_io_error()), name.data());
2386
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
48 autoptr<char*> datacopy=data;
2387
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
48 if (!end) end=len;
2388
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 if(start < 0) asar_throw_error(0, error_type_block, error_id_file_offset_out_of_bounds, dec(start).data(), name.data());
2389
3/10
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 48 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
48 if (end < start || end > len || end < 0) asar_throw_error(0, error_type_block, error_id_file_offset_out_of_bounds, dec(end).data(), name.data());
2390
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 42 times.
48 if (numwords==4)
2391 {
2392
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 asar_throw_warning(0, warning_id_feature_deprecated, "incbin with target location", "put an org before the incbin");
2393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!confirmname(word[3]))
2394 {
2395 int pos=(int)getnum(word[3]);
2396 if (foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2397 int offset=snestopc(pos);
2398 if (offset + end - start > 0xFFFFFF) asar_throw_error(0, error_type_block, error_id_16mb_rom_limit);
2399 if (offset+end-start>romlen) romlen=offset+end-start;
2400 if (pass==2)
2401 {
2402 writeromdata(offset, data+start, end-start);
2403 add_addr_to_line(pos);
2404 }
2405 }
2406 else
2407 {
2408 int pos;
2409
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 if (pass==0)
2410 {
2411
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 if (end - start > 65536) asar_throw_error(0, error_type_block, error_id_incbin_64kb_limit);
2412
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 pos=getpcfreespace(end-start, false, true, false);
2413
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2 if (pos < 0) asar_throw_error(0, error_type_block, error_id_no_freespace, dec(end - start).data());
2414
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 int foundfreespaceid=getfreespaceid();
2415 2 freespacepos[foundfreespaceid]=pctosnes(pos)|(/*fastrom?0x800000:*/0x000000)|(foundfreespaceid <<24);
2416
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 setlabel(word[3], freespacepos[foundfreespaceid]);
2417
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 writeromdata_bytes(pos, 0xFF, end-start);
2418 }
2419
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 if (pass==1)
2420 {
2421
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 getfreespaceid();//nothing to do here, but we want to tick the counter
2422 }
2423
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 if (pass==2)
2424 {
2425
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 int foundfreespaceid =getfreespaceid();
2426
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 if (freespaceleak[foundfreespaceid]) asar_throw_warning(2, warning_id_freespace_leaked);
2427
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 writeromdata(snestopc(freespacepos[foundfreespaceid]&0xFFFFFF), data+start, end-start);
2428
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 add_addr_to_line((freespacepos[foundfreespaceid]&0xFFFFFF) - 8);
2429 2 freespaceuse+=8+end-start;
2430 }
2431 }
2432 }
2433 else
2434 {
2435
3/4
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
✓ Branch 3 taken 42 times.
108 for (int i=start;i<end;i++) write1((unsigned int)data[i]);
2436
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 add_addr_to_line(addrToLinePos);
2437 }
2438 54 }
2439
6/6
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 216 times.
✓ Branch 3 taken 216 times.
✓ Branch 4 taken 114 times.
✓ Branch 5 taken 198 times.
624 else if (is("skip") || is("fill"))
2440 {
2441
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
228 if(numwords != 2 && numwords != 3 && numwords != 5) asar_throw_error(0, error_type_block, error_id_unknown_command);
2442
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
228 if(numwords > 2 && stricmp(word[1], "align")) asar_throw_error(0, error_type_block, error_id_unknown_command);
2443
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
228 if(numwords == 5 && stricmp(word[3], "offset")) asar_throw_error(0, error_type_block, error_id_unknown_command);
2444 int amount;
2445
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
228 if(numwords > 2)
2446 {
2447 int alignment = getnum64(word[2]);
2448 if(foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2449 int offset = 0;
2450 if(numwords==5)
2451 {
2452 offset = getnum64(word[4]);
2453 if(foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2454 }
2455 if(alignment > 0x800000) asar_throw_error(0, error_type_block, error_id_alignment_too_big);
2456 if(alignment < 1) asar_throw_error(0, error_type_block, error_id_alignment_too_small);
2457 if(alignment & (alignment-1)) asar_throw_error(0, error_type_block, error_id_invalid_alignment);
2458 // i just guessed this formula but it seems to work
2459 amount = (alignment - ((snespos - offset) & (alignment-1))) & (alignment-1);
2460 }
2461 else
2462 {
2463
1/2
✓ Branch 0 taken 228 times.
✗ Branch 1 not taken.
228 amount = (int)getnum64(par);
2464
5/6
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 114 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
228 if (foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2465 }
2466
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 30 times.
222 if(is("skip")) step(amount);
2467 else
2468 {
2469
3/4
✓ Branch 0 taken 258 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258 times.
✓ Branch 3 taken 30 times.
288 for(int i=0; i < amount; i++) write1(fillbyte[i%12]);
2470
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 add_addr_to_line(addrToLinePos);
2471 }
2472
2473 }
2474
5/6
✓ Branch 0 taken 102 times.
✓ Branch 1 taken 294 times.
✓ Branch 2 taken 51 times.
✓ Branch 3 taken 51 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 198 times.
396 else if (is0("cleartable"))
2475 {
2476 cleartable();
2477 }
2478
6/6
✓ Branch 0 taken 102 times.
✓ Branch 1 taken 294 times.
✓ Branch 2 taken 51 times.
✓ Branch 3 taken 51 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 195 times.
396 else if (is0("pushtable"))
2479 {
2480
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 tablestack.append(table);
2481 }
2482
6/6
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 294 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 48 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 192 times.
390 else if (is0("pulltable"))
2483 {
2484
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (tablestack.count <= 0) asar_throw_error(0, error_type_block, error_id_pulltable_without_table);
2485
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 table=tablestack[tablestack.count-1];
2486 6 tablestack.remove(tablestack.count-1);
2487 }
2488
5/6
✓ Branch 0 taken 264 times.
✓ Branch 1 taken 120 times.
✓ Branch 2 taken 132 times.
✓ Branch 3 taken 132 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 192 times.
384 else if (is1("table"))
2489 {
2490 asar_throw_warning(0, warning_id_feature_deprecated, "table command", "Use direct character assignments. For example: 'a' = $61");
2491 bool fliporder=false;
2492 if(0);
2493 else if (striend(par, ",ltr")) { itrim(par, "", ",ltr"); }
2494 else if (striend(par, ",rtl")) { itrim(par, "", ",rtl"); fliporder=true; }
2495 string name=STR safedequote(par);
2496 autoptr<char*> tablecontents=readfile(name, thisfilename);
2497 if (!tablecontents) asar_throw_error(0, error_type_block, vfile_error_to_error_id(asar_get_last_io_error()), name.data());
2498 autoptr<char**> tablelines=split(tablecontents, "\n");
2499 for (int i=0;i<256;i++) table.table[i]=(unsigned int)(((numopcodes+read2(0x00FFDE)+i)*0x26594131)|0x40028020);
2500 //garbage value so people will notice they're doing it wrong (for bonus points: figure out what 0x26594131 is)
2501 for (int i=0;tablelines[i];i++)
2502 {
2503 string tableline=tablelines[i];
2504 if (!*tableline) continue;
2505 if (strlen(tableline) < 4 || strlen(tableline) & 1 || strlen(tableline) > 10) asar_throw_error(0, error_type_block, error_id_invalid_table_file, i+1);
2506 if (!fliporder)
2507 {
2508 if (tableline[3]=='x' || tableline[3]=='X') asar_throw_error(0, error_type_block, error_id_invalid_table_file, i+1);
2509 char * end;
2510 table.table[(unsigned char)tableline[0]]=(unsigned int)strtol(tableline.data()+2, &end, 16);
2511 if (*end) asar_throw_error(0, error_type_block, error_id_invalid_table_file, i+1);
2512 }
2513 else
2514 {
2515 if (tableline[1]=='x' || tableline[1]=='X') asar_throw_error(0, error_type_block, error_id_invalid_table_file, i+1);
2516 char * eq;
2517 unsigned int val=(unsigned int)strtol(tableline, &eq, 16);
2518 if (eq[0]!='=' || eq[2]) asar_throw_error(0, error_type_block, error_id_invalid_table_file, i+1);
2519 table.table[(unsigned char)eq[1]]=val;
2520 }
2521 }
2522 }
2523
6/6
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 354 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 15 times.
✓ Branch 4 taken 15 times.
✓ Branch 5 taken 177 times.
384 else if (is3("function"))
2524 {
2525 //if (!pass)
2526 //{
2527
3/6
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
30 if (stricmp(word[2], "=")) asar_throw_error(0, error_type_block, error_id_broken_function_declaration);
2528
2/6
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
30 if (!confirmqpar(word[1])) asar_throw_error(0, error_type_block, error_id_broken_function_declaration);
2529
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
30 string line=word[1];
2530
4/8
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 30 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 30 times.
✗ Branch 7 not taken.
30 clean(line);
2531 30 char * startpar=strqchr(line.data(), '(');
2532
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
30 if (!startpar) asar_throw_error(0, error_type_block, error_id_broken_function_declaration);
2533 30 *startpar=0;
2534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
30 startpar++;
2535
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
30 if (!confirmname(line)) asar_throw_error(0, error_type_block, error_id_invalid_function_name);
2536 30 char * endpar=strqchr(startpar, ')');
2537 //confirmqpar requires that all parentheses are matched, and a starting one exists, therefore it is harmless to not check for nulls
2538
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
30 if (endpar[1]) asar_throw_error(0, error_type_block, error_id_broken_function_declaration);
2539 30 *endpar=0;
2540
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 createuserfunc(line, startpar, word[3]);
2541 //}
2542 30 }
2543
6/6
✓ Branch 0 taken 264 times.
✓ Branch 1 taken 90 times.
✓ Branch 2 taken 132 times.
✓ Branch 3 taken 132 times.
✓ Branch 4 taken 48 times.
✓ Branch 5 taken 129 times.
354 else if (is1("print"))
2544 {
2545
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 string out = handle_print(par);
2546
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 32 times.
96 if (pass!=2) return;
2547
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 print(out);
2548
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 32 times.
96 }
2549
5/6
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 90 times.
✓ Branch 2 taken 84 times.
✓ Branch 3 taken 84 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 129 times.
258 else if (is1("reset"))
2550 {
2551 if(0);
2552 else if (!stricmp(par, "bytes")) bytes=0;
2553 else if (!stricmp(par, "freespaceuse")) freespaceuse=0;
2554 else asar_throw_error(2, error_type_block, error_id_unknown_variable);
2555 }
2556
15/18
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 90 times.
✓ Branch 2 taken 150 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 150 times.
✓ Branch 5 taken 90 times.
✓ Branch 6 taken 150 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 150 times.
✓ Branch 9 taken 90 times.
✓ Branch 10 taken 150 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 150 times.
✓ Branch 13 taken 90 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 150 times.
✓ Branch 16 taken 9 times.
✓ Branch 17 taken 120 times.
258 else if (is1("padbyte") || is1("padword") || is1("padlong") || is1("paddword"))
2557 {
2558 9 int len = 0;
2559
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (is("padbyte")) len=1;
2560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (is("padword")) len=2;
2561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (is("padlong")) len=3;
2562
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (is("paddword")) len=4;
2563
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 unsigned int val=getnum(par);
2564
5/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
18 if(foundlabel && !foundlabel_static) asar_throw_warning(1, warning_id_feature_deprecated, "labels in padbyte", "just... don't.");
2565
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 18 times.
234 for (int i=0;i<12;i+=len)
2566 {
2567 108 unsigned int tmpval=val;
2568
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 216 times.
432 for (int j=0;j<len;j++)
2569 {
2570 216 padbyte[i+j]=(unsigned char)tmpval;
2571 216 tmpval>>=8;
2572 }
2573 }
2574 }
2575
6/6
✓ Branch 0 taken 150 times.
✓ Branch 1 taken 90 times.
✓ Branch 2 taken 75 times.
✓ Branch 3 taken 75 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 111 times.
240 else if (is1("pad"))
2576 {
2577
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18 if ((unsigned int)realsnespos & 0xFF000000) asar_throw_error(0, error_type_block, error_id_pad_in_freespace);
2578
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 int num=(int)getnum(par);
2579
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18 if ((unsigned int)num & 0xFF000000) asar_throw_error(0, error_type_block, error_id_snes_address_doesnt_map_to_rom, hex6((unsigned int)num).data());
2580
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 if (num>realsnespos)
2581 {
2582 6 int end=snestopc(num);
2583 6 int start=snestopc(realsnespos);
2584 12 int len=end-start;
2585
3/4
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 12 times.
72 for (int i=0;i<len;i++) write1(padbyte[i%12]);
2586
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 add_addr_to_line(addrToLinePos);
2587 }
2588 }
2589
18/18
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 90 times.
✓ Branch 2 taken 114 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 114 times.
✓ Branch 5 taken 90 times.
✓ Branch 6 taken 108 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 108 times.
✓ Branch 9 taken 90 times.
✓ Branch 10 taken 102 times.
✓ Branch 11 taken 6 times.
✓ Branch 12 taken 102 times.
✓ Branch 13 taken 90 times.
✓ Branch 14 taken 6 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 18 times.
✓ Branch 17 taken 93 times.
222 else if (is1("fillbyte") || is1("fillword") || is1("filllong") || is1("filldword"))
2590 {
2591 18 int len = 0;
2592
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
36 if (is("fillbyte")) len=1;
2593
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 30 times.
36 if (is("fillword")) len=2;
2594
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 30 times.
36 if (is("filllong")) len=3;
2595
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 30 times.
36 if (is("filldword")) len=4;
2596
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 unsigned int val= getnum(par);
2597
5/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
36 if(foundlabel && !foundlabel_static) asar_throw_warning(1, warning_id_feature_deprecated, "labels in fillbyte", "just... don't");
2598
2/2
✓ Branch 0 taken 294 times.
✓ Branch 1 taken 36 times.
330 for (int i=0;i<12;i+=len)
2599 {
2600 147 unsigned int tmpval=val;
2601
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 294 times.
726 for (int j=0;j<len;j++)
2602 {
2603 432 fillbyte[i+j]=(unsigned char)tmpval;
2604 432 tmpval>>=8;
2605 }
2606 }
2607 }
2608
6/6
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 90 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 48 times.
✓ Branch 4 taken 48 times.
✓ Branch 5 taken 45 times.
186 else if (is1("arch"))
2609 {
2610
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
96 if(in_spcblock) asar_throw_error(0, error_type_block, error_id_feature_unavaliable_in_spcblock);
2611
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
96 if (emulatexkas) asar_throw_warning(0, warning_id_convert_to_asar);
2612
4/4
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 36 times.
96 if (!stricmp(par, "65816")) { arch=arch_65816; return; }
2613
4/4
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 21 times.
72 if (!stricmp(par, "spc700")) { arch=arch_spc700; return; }
2614
5/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
42 if (!stricmp(par, "spc700-inline")) { asar_throw_warning(1, warning_id_feature_deprecated, "spc700-inline", " Use spcblock and endspcblock"); arch=arch_spc700_inline; return; }
2615
4/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 12 times.
36 if (!stricmp(par, "spc700-raw")) {
2616
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 asar_throw_warning(1, warning_id_feature_deprecated, "spc700-raw", " Use arch spc700 with norom");
2617 12 arch=arch_spc700;
2618 12 mapper=norom;
2619 12 mapper_set = false;
2620
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!force_checksum_fix)
2621 12 checksum_fix_enabled = false;
2622 12 return;
2623 }
2624
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
24 if (!stricmp(par, "superfx")) { arch=arch_superfx; return; }
2625 }
2626
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 45 times.
90 else if (is2("math"))
2627 {
2628 bool val = false;
2629 if(0);
2630 else if (!stricmp(word[2], "on")) val=true;
2631 else if (!stricmp(word[2], "off")) val=false;
2632 else asar_throw_error(0, error_type_block, error_id_invalid_math);
2633 if(0);
2634 else if (!stricmp(word[1], "pri")){ math_pri=val; asar_throw_warning(2, warning_id_feature_deprecated, "math pri", "Rewrite your math statements using parentheses where needed and put \"asar 1.9\" in your patch to enable the future behavior of always enforcing math prioritization rules"); }
2635 else if (!stricmp(word[1], "round")){ math_round=val; asar_throw_warning(2, warning_id_feature_deprecated, "math round", "Put \"asar 1.9\" in your patch to enable the future behavior of never rounding intermediate results. Call the round(), floor() or ceil() functions in places where intermediate rounding is required"); }
2636 else asar_throw_error(0, error_type_block, error_id_invalid_math);
2637 }
2638
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 45 times.
90 else if (is2("warn"))
2639 {
2640 bool val = false;
2641 if(0);
2642 else if (!stricmp(word[2], "on")) val=true;
2643 else if (!stricmp(word[2], "off")) val=false;
2644 else asar_throw_error(0, error_type_block, error_id_invalid_warn);
2645 if(0);
2646 else if (!stricmp(word[1], "xkas")) {
2647 asar_throw_warning(0, warning_id_feature_deprecated, "xkas compatibility warning", "If you worry about xkas I worry about you. Just stop.");
2648 warnxkas=val;
2649 }
2650 else asar_throw_error(0, error_type_block, error_id_invalid_warn);
2651 }
2652
5/6
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
✓ Branch 3 taken 45 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 42 times.
90 else if (is0("fastrom"))
2653 {
2654
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 asar_throw_warning(0, warning_id_feature_deprecated, "fastrom", "This feature has been disabled for years and is a lie. Sorry.");
2655 //removed due to causing more trouble than it's worth.
2656 //if (emulatexkas) warn0("Convert the patch to native Asar format instead of making an Asar-only xkas patch.");
2657 //if (mapper==lorom || mapper==hirom) fastrom=true;
2658 //else error(0, "Can't use fastrom in this mapper.");
2659 }
2660
8/10
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 24 times.
✓ Branch 7 taken 24 times.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 36 times.
84 else if (is0("{") || is0("}")) {}
2661 else
2662 {
2663
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (isspecialline)
2664 {
2665 asar_throw_warning(0, warning_id_unrecognized_special_command);
2666 }
2667 else
2668 {
2669
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 asar_throw_error(1, error_type_block, error_id_unknown_command);
2670 }
2671 }
2672
2673
6/6
✓ Branch 0 taken 325347 times.
✓ Branch 1 taken 112011 times.
✓ Branch 2 taken 325347 times.
✓ Branch 3 taken 112011 times.
✓ Branch 4 taken 325347 times.
✓ Branch 5 taken 112011 times.
1100718 }
2674
2675 7552 bool assemblemapper(char** word, int numwords)
2676 {
2677 7552 auto previous_mapper = mapper;
2678 if(0);
2679
6/6
✓ Branch 0 taken 716 times.
✓ Branch 1 taken 6836 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 644 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 3740 times.
7552 else if (is0("lorom"))
2680 {
2681 //this also makes xkas set snespos to $008000 for some reason
2682 72 mapper=lorom;
2683 }
2684
6/6
✓ Branch 0 taken 644 times.
✓ Branch 1 taken 6836 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 322 times.
✓ Branch 4 taken 7 times.
✓ Branch 5 taken 3733 times.
7480 else if (is0("hirom"))
2685 {
2686 //xkas makes this point to $C00000
2687 14 mapper=hirom;
2688 }
2689
6/6
✓ Branch 0 taken 630 times.
✓ Branch 1 taken 6836 times.
✓ Branch 2 taken 315 times.
✓ Branch 3 taken 315 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3730 times.
7466 else if (is0("exlorom"))
2690 {
2691 6 mapper = exlorom;
2692 }
2693
6/6
✓ Branch 0 taken 624 times.
✓ Branch 1 taken 6836 times.
✓ Branch 2 taken 312 times.
✓ Branch 3 taken 312 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3727 times.
7460 else if (is0("exhirom"))
2694 {
2695 6 mapper=exhirom;
2696 }
2697
6/6
✓ Branch 0 taken 618 times.
✓ Branch 1 taken 6836 times.
✓ Branch 2 taken 309 times.
✓ Branch 3 taken 309 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 3721 times.
7454 else if (is0("sfxrom"))
2698 {
2699 12 mapper=sfxrom;
2700 //fastrom=false;
2701 }
2702
6/6
✓ Branch 0 taken 606 times.
✓ Branch 1 taken 6836 times.
✓ Branch 2 taken 303 times.
✓ Branch 3 taken 303 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 3712 times.
7442 else if (is0("norom"))
2703 {
2704 //$000000 would be the best snespos for this, but I don't care
2705 18 mapper=norom;
2706 //fastrom=false;
2707
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!force_checksum_fix)
2708 18 checksum_fix_enabled = false;//we don't know where the header is, so don't set the checksum
2709 }
2710
6/6
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 6836 times.
✓ Branch 2 taken 294 times.
✓ Branch 3 taken 294 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3709 times.
7424 else if (is0("fullsa1rom"))
2711 {
2712 6 mapper=bigsa1rom;
2713 //fastrom=false;
2714 }
2715
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 7394 times.
7418 else if (is("sa1rom"))
2716 {
2717 //fastrom=false;
2718
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 6 times.
24 if (par)
2719 {
2720
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18 if (word[2]) asar_throw_error(0, error_type_block, error_id_invalid_mapper);
2721
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
27 if (!is_digit(par[0]) || par[1]!=',' ||
2722
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 !is_digit(par[2]) || par[3]!=',' ||
2723
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 !is_digit(par[4]) || par[5]!=',' ||
2724
4/10
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
36 !is_digit(par[6]) || par[7]) asar_throw_error(0, error_type_block, error_id_invalid_mapper);
2725 9 int len;
2726
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
18 autoptr<char**> pars=qpsplit(par, ",", &len);
2727
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18 if (len!=4) asar_throw_error(0, error_type_block, error_id_invalid_mapper);
2728 18 sa1banks[0]=(par[0]-'0')<<20;
2729 18 sa1banks[1]=(par[2]-'0')<<20;
2730 18 sa1banks[4]=(par[4]-'0')<<20;
2731 18 sa1banks[5]=(par[6]-'0')<<20;
2732 18 }
2733 else
2734 {
2735 6 sa1banks[0]=0<<20;
2736 6 sa1banks[1]=1<<20;
2737 6 sa1banks[4]=2<<20;
2738 6 sa1banks[5]=3<<20;
2739 }
2740 24 mapper=sa1rom;
2741 }
2742
4/6
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 6818 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 576 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3697 times.
7394 else if (is0("header"))
2743 {
2744 //headers are detected elsewhere; ignoring for familiarity
2745 asar_throw_warning(0, warning_id_feature_deprecated, "header", "Remove command, unnecessary.");
2746 }
2747 3697 else return false;
2748
2749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 158 times.
158 if(in_spcblock) asar_throw_error(0, error_type_block, error_id_feature_unavaliable_in_spcblock);
2750
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 66 times.
158 if(!mapper_set){
2751 92 mapper_set = true;
2752
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 33 times.
66 }else if(previous_mapper != mapper){
2753 54 asar_throw_warning(1, warning_id_mapper_already_set);
2754 }
2755 79 return true;
2756 }
2757