asar coverage - build #151


src/asar/
File: src/asar/assembleblock.cpp
Date: 2024-01-24 21:19:15
Lines:
1358/1618
83.9%
Functions:
37/40
92.5%
Branches:
2040/3760
54.3%

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 183 int snestopc_pick(int addr)
71 {
72 318 return snestopc(addr);
73 }
74
75 238634 inline void verifysnespos()
76 {
77
3/4
✓ Branch 0 taken 238610 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 238610 times.
238634 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 238634 }
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 237974 inline void step(int num)
150 {
151
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 237494 times.
237974 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 237494 snespos += num;
167 237494 realsnespos += num;
168 }
169 237974 bytes+=num;
170 237974 }
171
172 237770 inline void write1_65816(unsigned int num)
173 {
174 237770 verifysnespos();
175
2/2
✓ Branch 0 taken 79246 times.
✓ Branch 1 taken 158524 times.
237770 if (pass==2)
176 {
177 79246 int pcpos=snestopc(realsnespos&0xFFFFFF);
178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79246 times.
79246 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 79246 writeromdata_byte(pcpos, (unsigned char)num);
184
2/2
✓ Branch 0 taken 8240 times.
✓ Branch 1 taken 71006 times.
79246 if (pcpos>=romlen) {
185
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 8166 times.
8240 if(pcpos - romlen > 0) writeromdata_bytes(romlen, default_freespacebyte, pcpos - romlen, false);
186 8240 romlen=pcpos+1;
187 }
188 }
189 237770 step(1);
190 237770 ratsmetastate=ratsmeta_ban;
191 237770 }
192
193 int recent_opcode_num = 0;
194
195 126570 void write1_pick(unsigned int num)
196 {
197
10/20
✓ Branch 0 taken 106852 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.
233665 write1_65816(num);
198 226499 }
199
200 227822 static bool asblock_pick(char** word, int numwords)
201 {
202 227822 recent_opcode_num = 1;
203
204
4/4
✓ Branch 0 taken 225488 times.
✓ Branch 1 taken 2334 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 225458 times.
227822 if (arch==arch_spc700 || in_spcblock) return asblock_spc700(word, numwords);
205
2/2
✓ Branch 0 taken 221792 times.
✓ Branch 1 taken 3666 times.
225458 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 1508 const char * safedequote(char * str)
215 {
216 1508 const char * tmp=dequote(str);
217
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1508 times.
1508 if (!tmp) asar_throw_error(0, error_type_block, error_id_garbage_near_quoted_string);
218 1508 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 1088 void write3(unsigned int num)
231 {
232 544 write1(num);
233 1088 write1(num/256);
234 1088 write1(num/65536);
235 1088 }
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 18 int read2(int insnespos)
255 {
256 9 int addr=snestopc(insnespos);
257
3/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 9 times.
18 if (addr<0 || addr+2>romlen_r) return -1;
258 return
259 18 romdata_r[addr ] |
260 18 (romdata_r[addr+1]<< 8);
261 }
262
263 54 int read3(int insnespos)
264 {
265 27 int addr=snestopc(insnespos);
266
3/4
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✓ Branch 3 taken 27 times.
54 if (addr<0 || addr+3>romlen_r) return -1;
267 return
268 54 romdata_r[addr ] |
269 54 (romdata_r[addr+1]<< 8)|
270 54 (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 908 bool confirmname(const char * name)
308 {
309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 908 times.
908 if (!name[0]) return false;
310
2/2
✓ Branch 0 taken 150 times.
✓ Branch 1 taken 758 times.
908 if (is_digit(name[0])) return false;
311
2/2
✓ Branch 0 taken 5436 times.
✓ Branch 1 taken 752 times.
6188 for (int i=0;name[i];i++)
312 {
313
6/6
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 5160 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 270 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 2715 times.
5436 if (!is_alnum(name[i]) && name[i]!='_') return false;
314 }
315 376 return true;
316 }
317
318 2282284 string posneglabelname(const char ** input, bool define)
319 {
320 2282284 const char* label = *input;
321
322 1141142 string output;
323
324 1141142 int depth = 0;
325 1141142 bool ismacro = false;
326
327
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 2282234 times.
2282284 if (label[0] == '?')
328 {
329 25 ismacro = true;
330 50 label++;
331 }
332
4/4
✓ Branch 0 taken 1141142 times.
✓ Branch 1 taken 1141142 times.
✓ Branch 2 taken 216 times.
✓ Branch 3 taken 2281986 times.
2282284 if (label[0] == '-' || label[0] == '+')
333 {
334 149 char first = label[0];
335
4/4
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 212 times.
✓ Branch 2 taken 298 times.
✓ Branch 3 taken 86 times.
596 for (depth = 0; label[0] && label[0] == first; depth++) label++;
336
337
2/2
✓ Branch 0 taken 278 times.
✓ Branch 1 taken 20 times.
298 if (!ismacro)
338 {
339
2/2
✓ Branch 0 taken 206 times.
✓ Branch 1 taken 72 times.
278 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 72 *input = label;
348
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 66 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
75 if (define) neglabels[depth]++;
349
8/16
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 36 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 36 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 36 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 36 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 36 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 36 times.
✗ Branch 15 not taken.
108 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 2282284 return output;
377 }
378
379 2550 static string labelname(const char ** rawname, bool define=false)
380 {
381 #define deref_rawname (*rawname)
382 2550 bool ismacro = (deref_rawname[0] == '?');
383
384
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 2526 times.
2550 if (ismacro)
385 {
386 24 deref_rawname++;
387 }
388
389 1275 bool issublabel = false;
390
391 1275 string name;
392 1275 int i=-1;
393
394 1275 autoarray<string>* sublabellist = &sublabels;
395
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 2526 times.
2550 if (ismacro)
396 {
397 24 sublabellist = macrosublabels;
398 }
399
400
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2550 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2550 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 2454 times.
2550 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 1227 times.
✓ Branch 1 taken 1227 times.
✓ Branch 2 taken 1137 times.
✓ Branch 3 taken 1137 times.
2454 else if (!in_struct && !in_sub_struct)
407 {
408
2/2
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 2250 times.
2318 for (i=0;(*deref_rawname =='.');i++) deref_rawname++;
409
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2250 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2250 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 2234 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2250 if (emulatexkas && i>1) asar_throw_warning(1, warning_id_convert_to_asar);
411
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 2188 times.
2250 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 2531 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 5 times.
2550 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 2526 times.
2550 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 2370 times.
✓ Branch 1 taken 180 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 2346 times.
2550 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 2550 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2550 if (!is_ualnum(*deref_rawname)) asar_throw_error(1, error_type_block, error_id_invalid_label_name);
441
442
8/8
✓ Branch 0 taken 11559 times.
✓ Branch 1 taken 11559 times.
✓ Branch 2 taken 1474 times.
✓ Branch 3 taken 1474 times.
✓ Branch 4 taken 78 times.
✓ Branch 5 taken 2550 times.
✓ Branch 6 taken 10284 times.
✓ Branch 7 taken 1275 times.
23118 while (is_ualnum(*deref_rawname) || *deref_rawname == '.' || *deref_rawname == '[')
443 {
444
6/6
✓ Branch 0 taken 19362 times.
✓ Branch 1 taken 1206 times.
✓ Branch 2 taken 19290 times.
✓ Branch 3 taken 72 times.
✓ Branch 4 taken 78 times.
✓ Branch 5 taken 19212 times.
20568 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 20490 times.
20490 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 10284 times.
✗ Branch 1 not taken.
20568 name+=*(deref_rawname++);
466 }
467
4/4
✓ Branch 0 taken 624 times.
✓ Branch 1 taken 1926 times.
✓ Branch 2 taken 261 times.
✓ Branch 3 taken 102 times.
2550 if (define && i>=0)
468 {
469
1/2
✓ Branch 0 taken 261 times.
✗ Branch 1 not taken.
522 (*sublabellist).reset(i);
470
2/4
✓ Branch 0 taken 261 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 261 times.
✗ Branch 3 not taken.
261 (*sublabellist)[i]=name;
471 }
472 2550 return name;
473 #undef deref_rawname
474 }
475
476 1800 inline bool labelvalcore(const char ** rawname, snes_label * rval, bool define, bool shouldthrow)
477 {
478
1/2
✓ Branch 0 taken 900 times.
✗ Branch 1 not taken.
1800 string name=labelname(rawname, define);
479 900 snes_label rval_;
480
24/36
✓ Branch 0 taken 945 times.
✓ Branch 1 taken 855 times.
✓ Branch 2 taken 90 times.
✓ Branch 3 taken 1710 times.
✓ Branch 4 taken 90 times.
✓ Branch 5 taken 855 times.
✓ Branch 6 taken 74 times.
✓ Branch 7 taken 871 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 855 times.
✓ Branch 14 taken 45 times.
✓ Branch 15 taken 855 times.
✓ Branch 16 taken 45 times.
✓ Branch 17 taken 855 times.
✓ Branch 18 taken 45 times.
✓ Branch 19 taken 855 times.
✓ Branch 20 taken 29 times.
✓ Branch 21 taken 871 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.
1874 if (ns && labels.exists(STR ns+name)) {rval_ = labels.find(STR ns+name);}
481
5/6
✓ Branch 0 taken 1680 times.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 809 times.
✓ Branch 3 taken 62 times.
✓ Branch 4 taken 809 times.
✗ Branch 5 not taken.
1742 else if (labels.exists(name)) {rval_ = labels.find(name);}
482 else
483 {
484
3/4
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 86 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 38 times.
124 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 124 times.
✗ Branch 1 not taken.
124 if (rval) { rval->pos = (unsigned int)-1; rval->is_static = false; }
489 124 return false;
490 }
491
1/2
✓ Branch 0 taken 1676 times.
✗ Branch 1 not taken.
1676 if (rval)
492 {
493 1676 *rval=rval_;
494 //if (fastrom && (rval_&0x700000)!=0x700000) *rval|=0x800000;
495 }
496 838 return true;
497 1800 }
498
499 1096 snes_label labelval(const char ** rawname, bool define)
500 {
501 548 snes_label rval;
502
1/2
✓ Branch 0 taken 548 times.
✗ Branch 1 not taken.
1096 labelvalcore(rawname, &rval, define, true);
503 1096 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 1028 static void setlabel(string name, int loc=-1, bool is_static=false)
538 {
539
2/2
✓ Branch 0 taken 864 times.
✓ Branch 1 taken 164 times.
1028 if (loc==-1)
540 {
541
1/2
✓ Branch 0 taken 432 times.
✗ Branch 1 not taken.
864 verifysnespos();
542 864 loc=snespos;
543 }
544
545 514 snes_label label_data;
546 1028 label_data.pos = (unsigned int)loc;
547 1028 label_data.is_static = is_static;
548
549 unsigned int labelpos;
550
2/2
✓ Branch 0 taken 344 times.
✓ Branch 1 taken 684 times.
1028 if (pass==0)
551 {
552
4/4
✓ Branch 0 taken 173 times.
✓ Branch 1 taken 171 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 171 times.
344 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 171 times.
✗ Branch 1 not taken.
342 labels.create(name) = label_data;
558 }
559
2/2
✓ Branch 0 taken 342 times.
✓ Branch 1 taken 342 times.
684 else if (pass==1)
560 {
561
1/2
✓ Branch 0 taken 171 times.
✗ Branch 1 not taken.
342 labels.create(name) = label_data;
562 }
563
1/2
✓ Branch 0 taken 342 times.
✗ Branch 1 not taken.
342 else if (pass==2)
564 {
565 //all label locations are known at this point, add a sanity check
566
3/6
✓ Branch 0 taken 171 times.
✓ Branch 1 taken 171 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 171 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
342 if (!labels.exists(name)) asar_throw_error(2, error_type_block, error_id_label_on_third_pass);
567
1/2
✓ Branch 0 taken 171 times.
✗ Branch 1 not taken.
342 labelpos = labels.find(name).pos;
568
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 342 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
342 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 562 static void cleartable()
599 {
600
2/2
✓ Branch 0 taken 143872 times.
✓ Branch 1 taken 562 times.
144434 for (unsigned int i=0;i<256;i++) table.table[i]=i;
601 562 }
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 98 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 894 static int getfreespaceid()
639 {
640 static const int max_num_freespaces = 125;
641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 894 times.
894 if (freespaceidnext > max_num_freespaces) asar_throw_error(pass, error_type_fatal, error_id_freespace_limit_reached, max_num_freespaces);
642 894 return freespaceidnext++;
643 }
644
645 873800 void checkbankcross()
646 {
647
6/8
✓ Branch 0 taken 6780 times.
✓ Branch 1 taken 867020 times.
✓ Branch 2 taken 6780 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6780 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3390 times.
✓ Branch 7 taken 3390 times.
873800 if (snespos<0 && realsnespos<0 && startpos<0 && realstartpos<0) return;
648
2/2
✓ Branch 0 taken 433510 times.
✓ Branch 1 taken 433510 times.
867020 if (disable_bank_cross_errors) return;
649
2/2
✓ Branch 0 taken 433177 times.
✓ Branch 1 taken 433177 times.
866354 unsigned int mask = 0x7FFF0000 | (check_half_banks_crossed ? 0x8000 : 0);
650
4/4
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 866316 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 36 times.
866354 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 866316 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 36 times.
866352 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 2144 static void freespaceend()
661 {
662
4/4
✓ Branch 0 taken 1430 times.
✓ Branch 1 taken 714 times.
✓ Branch 2 taken 888 times.
✓ Branch 3 taken 542 times.
2144 if ((snespos&0x7F000000) && ((unsigned int)snespos&0x80000000)==0)
663 {
664 888 freespacelen[freespaceid]=snespos-freespacestart+freespaceextra;
665 888 snespos=(int)0xFFFFFFFF;
666 }
667 2144 freespaceextra=0;
668 2144 }
669
670 int numopcodes;
671
672 bool warnxkas;
673
674
1/2
✓ Branch 0 taken 2810 times.
✗ Branch 1 not taken.
5620 static void adddefine(const string & key, string & value)
675 {
676
1/2
✓ Branch 0 taken 5620 times.
✗ Branch 1 not taken.
5620 if (!defines.exists(key)) defines.create(key) = value;
677 5620 }
678
679 562 void initstuff()
680 {
681
2/2
✓ Branch 0 taken 190 times.
✓ Branch 1 taken 372 times.
562 if (pass==0)
682 {
683
2/2
✓ Branch 0 taken 48640 times.
✓ Branch 1 taken 190 times.
48830 for (int i=0;i<256;i++)
684 {
685 48640 freespaceleak[i]=true;
686 48640 freespaceorgpos[i]=-2;
687 48640 freespaceorglen[i]=-1;
688 48640 freespacebyte[i] = 0x00;
689 }
690 }
691 562 arch=arch_65816;
692 562 mapper=lorom;
693 562 mapper_set = false;
694 562 reallycalledmacros=0;
695 562 calledmacros=0;
696 562 macrorecursion=0;
697 562 repeatnext=1;
698 562 defines.reset();
699 562 builtindefines.each(adddefine);
700 562 clidefines.each(adddefine);
701 281 ns="";
702 562 namespace_list.reset();
703 562 sublabels.reset();
704 562 poslabels.reset();
705 562 neglabels.reset();
706 562 macroposlabels = nullptr;
707 562 macroneglabels = nullptr;
708 562 macrosublabels = nullptr;
709 562 cleartable();
710 562 pushpc.reset();
711 562 pushpcnum=0;
712 562 pushns.reset();
713 562 pushnsnum = 0;
714 562 bytes=0;
715 562 memset(fillbyte, 0, sizeof(fillbyte));
716 562 memset(padbyte, 0, sizeof(padbyte));
717 562 snespos=(int)0xFFFFFFFF;
718 562 realsnespos= (int)0xFFFFFFFF;
719 562 startpos= (int)0xFFFFFFFF;
720 562 realstartpos= (int)0xFFFFFFFF;
721 //fastrom=false;
722 562 freespaceidnext=1;
723 562 freespaceid=1;
724 562 freespaceextra=0;
725 562 default_freespacebyte=0x00;
726 562 numopcodes=0;
727 562 specifiedasarver = false;
728 562 incsrcdepth = 0;
729
730 562 optimizeforbank = -1;
731 562 optimize_dp = optimize_dp_flag::NONE;
732 562 dp_base = 0;
733 562 optimize_address = optimize_address_flag::DEFAULT;
734
735 562 in_struct = false;
736 562 in_sub_struct = false;
737 562 in_spcblock = false;
738
739 562 math_pri=false;
740 562 math_round=true;
741
742
1/2
✓ Branch 0 taken 562 times.
✗ Branch 1 not taken.
562 if (arch==arch_65816) asinit_65816();
743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 562 times.
562 if (arch==arch_spc700) asinit_spc700();
744
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 562 times.
562 if (arch==arch_spc700_inline) asinit_spc700();
745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 562 times.
562 if (arch==arch_superfx) asinit_superfx();
746
747 562 warnxkas=false;
748 562 emulatexkas=false;
749 562 disable_bank_cross_errors = false;
750 562 check_half_banks_crossed = false;
751 562 nested_namespaces = false;
752
753 281 thisfilename = "";
754
755 562 includeonce.reset();
756
757 extern AddressToLineMapping addressToLineMapping;
758 562 addressToLineMapping.reset();
759
760 562 push_warnings(false);
761
762 562 initmathcore();
763 562 }
764
765
766 //void nerf(const string& left, string& right){puts(S left+" = "+right);}
767
768 558 void finishpass()
769 {
770 558 verify_warnings();
771 558 pull_warnings(false);
772
773 //defines.traverse(nerf);
774
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 558 times.
558 if(in_spcblock) asar_throw_error(0, error_type_block, error_id_missing_endspcblock);
775
2/4
✓ Branch 0 taken 558 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 558 times.
558 if (in_struct || in_sub_struct) asar_throw_error(pass, error_type_null, error_id_struct_without_endstruct);
776
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 558 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
558 else if (pushpcnum && pass == 0) asar_throw_error(pass, error_type_null, error_id_pushpc_without_pullpc);
777
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 558 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
558 else if (pushnsnum && pass == 0) asar_throw_error(pass, error_type_null, error_id_pushns_without_pullns);
778 558 freespaceend();
779
2/2
✓ Branch 0 taken 516 times.
✓ Branch 1 taken 42 times.
558 if (arch==arch_65816) asend_65816();
780
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 534 times.
558 if (arch==arch_spc700) asend_spc700();
781
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 552 times.
558 if (arch==arch_spc700_inline) asend_spc700();
782
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 546 times.
558 if (arch==arch_superfx) asend_superfx();
783
784 558 deinitmathcore();
785 558 }
786
787 872874 static bool addlabel(const char * label, int pos=-1, bool global_label = false)
788 {
789
4/4
✓ Branch 0 taken 651692 times.
✓ Branch 1 taken 221182 times.
✓ Branch 2 taken 325846 times.
✓ Branch 3 taken 325846 times.
872874 if (!label[0] || label[0]==':') return false;//colons are reserved for special labels
790
791 651692 const char* posneglabel = label;
792
1/2
✓ Branch 0 taken 325846 times.
✗ Branch 1 not taken.
651692 string posnegname = posneglabelname(&posneglabel, true);
793
794
4/4
✓ Branch 0 taken 325906 times.
✓ Branch 1 taken 325786 times.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 325786 times.
651692 if (posnegname.length() > 0)
795 {
796
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 60 times.
120 if (global_label) return false;
797
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);
798
2/4
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
✗ Branch 3 not taken.
120 setlabel(posnegname, pos);
799 120 return true;
800 }
801
7/8
✓ Branch 0 taken 650864 times.
✓ Branch 1 taken 708 times.
✓ Branch 2 taken 650810 times.
✓ Branch 3 taken 54 times.
✓ Branch 4 taken 650804 times.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 650804 times.
651572 if (label[strlen(label)-1]==':' || label[0]=='.' || label[0]=='?' || label[0] == '#')
802 {
803
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 384 times.
768 if (!label[1]) return false;
804
6/8
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 714 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.
756 if(global_label && (in_struct || in_sub_struct || label[0]=='?')) return false;
805
806 375 bool define = true;
807
808
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 726 times.
750 if (label[0] == '#')
809 {
810 12 define = false;
811 24 label++;
812 }
813
814 // RPG Hacker: Also checking label[1] now, since it might be a macro sublabel.
815 // Also, apparently this here doesn't account for main labels. I guess because
816 // we don't even get here in the first place if they don't include a colon?
817
6/8
✓ Branch 0 taken 498 times.
✓ Branch 1 taken 252 times.
✓ Branch 2 taken 492 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 492 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 246 times.
750 bool requirecolon = (label[0] != '.' && label[1] != '.') && (in_struct || in_sub_struct);
818
1/2
✓ Branch 0 taken 750 times.
✗ Branch 1 not taken.
750 string name=labelname(&label, define);
819
2/2
✓ Branch 0 taken 708 times.
✓ Branch 1 taken 42 times.
750 if (label[0]==':') label++;
820
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);
821
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 21 times.
42 else if (global_label) return false;
822
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 744 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
744 if (label[0]) asar_throw_error(0, error_type_block, error_id_broken_label_definition);
823
11/14
✓ Branch 0 taken 426 times.
✓ Branch 1 taken 318 times.
✓ Branch 2 taken 102 times.
✓ Branch 3 taken 324 times.
✓ Branch 4 taken 48 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 48 times.
✓ Branch 7 taken 324 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.
792 if (ns && !global_label) name=STR ns+name;
824
9/10
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 180 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 540 times.
✓ Branch 4 taken 446 times.
✓ Branch 5 taken 28 times.
✓ Branch 6 taken 372 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 371 times.
✓ Branch 9 taken 1 times.
745 setlabel(name, pos, ((in_struct || in_sub_struct) && static_struct));
825 742 return true;
826 750 }
827 325402 return false;
828 651692 }
829
830 223992 static void add_addr_to_line(int pos)
831 {
832
2/2
✓ Branch 0 taken 74866 times.
✓ Branch 1 taken 149126 times.
223992 if (pass == 2)
833 74866 addressToLineMapping.includeMapping(thisfilename.data(), thisline + 1, pos);
834 223992 }
835
836 static autoarray<bool> elsestatus;
837 int numtrue=0;//if 1 -> increase both
838 int numif = 0; //if 0 or inside if 0 -> increase only numif
839
840 autoarray<whiletracker> whilestatus;
841 int single_line_for_tracker;
842
843 static int freespaceuse=0;
844
845
846 78 static void push_pc()
847 {
848 78 pushpc[pushpcnum].arch=arch;
849 78 pushpc[pushpcnum].snespos=snespos;
850 78 pushpc[pushpcnum].snesstart=startpos;
851 78 pushpc[pushpcnum].snesposreal=realsnespos;
852 78 pushpc[pushpcnum].snesstartreal=realstartpos;
853 78 pushpc[pushpcnum].freeid=freespaceid;
854 78 pushpc[pushpcnum].freeex=freespaceextra;
855 78 pushpc[pushpcnum].freest=freespacestart;
856 78 pushpcnum++;
857 78 }
858
859 78 static void pop_pc()
860 {
861 78 pushpcnum--;
862 78 snespos=pushpc[pushpcnum].snespos;
863 78 startpos=pushpc[pushpcnum].snesstart;
864 78 realsnespos=pushpc[pushpcnum].snesposreal;
865 78 realstartpos=pushpc[pushpcnum].snesstartreal;
866 78 freespaceid=pushpc[pushpcnum].freeid;
867 78 freespaceextra=pushpc[pushpcnum].freeex;
868 78 freespacestart=pushpc[pushpcnum].freest;
869 78 }
870
871
872 132 string handle_print(char* input)
873 {
874
3/6
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 66 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 66 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
132 if (!confirmqpar(input)) asar_throw_error(0, error_type_block, error_id_mismatched_parentheses);
875 66 string out;
876
1/2
✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
132 autoptr<char**> pars = qpsplit(input, ",");
877
2/2
✓ Branch 0 taken 324 times.
✓ Branch 1 taken 132 times.
456 for (int i = 0; pars[i]; i++)
878 {
879 if (0);
880
4/6
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 114 times.
✓ Branch 2 taken 210 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 105 times.
✗ Branch 5 not taken.
324 else if (pars[i][0] == '"') out += safedequote(pars[i]);
881
3/6
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 57 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
114 else if (!stricmp(pars[i], "bytes")) out += dec(bytes);
882
3/6
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 57 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
114 else if (!stricmp(pars[i], "freespaceuse")) out += dec(freespaceuse);
883
3/6
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 57 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
114 else if (!stricmp(pars[i], "pc")) out += hex6((unsigned int)(snespos & 0xFFFFFF));
884
3/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 12 times.
159 else if (!strncasecmp(pars[i], "bin(", strlen("bin(")) ||
885
4/4
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 12 times.
123 !strncasecmp(pars[i], "dec(", strlen("dec(")) ||
886
5/6
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 54 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 78 times.
✗ Branch 5 not taken.
234 !strncasecmp(pars[i], "hex(", strlen("hex(")) ||
887
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 !strncasecmp(pars[i], "double(", strlen("double(")))
888 {
889 114 char * arg1pos = strchr(pars[i], '(') + 1;
890 114 char * endpos = strchr(arg1pos, '\0');
891
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
✓ Branch 2 taken 114 times.
✓ Branch 3 taken 114 times.
228 while (*endpos == ' ' || *endpos == '\0') endpos--;
892
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
114 if (*endpos != ')') asar_throw_error(0, error_type_block, error_id_invalid_print_function_syntax);
893
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
114 string paramstr = string(arg1pos, (int)(endpos - arg1pos));
894
895 57 int numargs;
896
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 autoptr<char**> params = qpsplit(paramstr.temp_raw(), ",", &numargs);
897
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
114 if (numargs > 2) asar_throw_error(0, error_type_block, error_id_wrong_num_parameters);
898 57 int precision = 0;
899 114 bool hasprec = numargs == 2;
900
2/2
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 57 times.
114 if (hasprec)
901 {
902
1/2
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
78 precision = getnum64(params[1]);
903
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
78 if (precision < 0) precision = 0;
904
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
78 if (precision > 64) precision = 64;
905 }
906 114 *(arg1pos - 1) = '\0'; // allows more convenient comparsion functions
907
4/4
✓ Branch 0 taken 69 times.
✓ Branch 1 taken 45 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 45 times.
114 if (!stricmp(pars[i], "bin"))
908 {
909 // sadly printf doesn't have binary, so let's roll our own
910
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 int64_t value = getnum64(params[0]);
911 12 char buffer[65];
912
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (value < 0) {
913 out += '-';
914 value = -value;
915 // decrement precision because we've output one char already
916 precision -= 1;
917 if (precision<0) precision = 0;
918 }
919
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 24 times.
1560 for (int j = 0; j < 64; j++) {
920 1536 buffer[63 - j] = '0' + ((value & (1ull << j)) >> j);
921 }
922 24 buffer[64] = 0;
923 12 int startidx = 0;
924
3/4
✓ Branch 0 taken 1344 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 1344 times.
✗ Branch 3 not taken.
1368 while (startidx < 64 - precision && buffer[startidx] == '0') startidx++;
925
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (startidx == 64) startidx--; // always want to print at least one digit
926
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
24 out += buffer + startidx;
927 }
928
4/4
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 33 times.
90 else if (!stricmp(pars[i], "dec"))
929 {
930
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 int64_t value = getnum64(params[0]);
931 12 char buffer[65];
932
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
24 snprintf(buffer, 65, "%0*" PRId64, precision, value);
933
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
24 out += buffer;
934 }
935
4/4
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 21 times.
66 else if (!stricmp(pars[i], "hex"))
936 {
937
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 int64_t value = getnum64(params[0]);
938 12 char buffer[65];
939
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
24 snprintf(buffer, 65, "%0*" PRIX64, precision, value);
940
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
24 out += buffer;
941 }
942
2/4
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
42 else if (!stricmp(pars[i], "double"))
943 {
944
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 6 times.
42 if (!hasprec) precision = 5;
945
3/6
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
42 out += ftostrvar(getnumdouble(params[0]), precision);
946 }
947 114 }
948 else asar_throw_error(2, error_type_block, error_id_unknown_variable);
949 }
950 198 return out;
951 132 }
952
953
954 874458 void assembleblock(const char * block, bool isspecialline)
955 {
956
1/2
✓ Branch 0 taken 437229 times.
✗ Branch 1 not taken.
437229 string tmp=block;
957 437229 int numwords;
958
1/2
✓ Branch 0 taken 874458 times.
✗ Branch 1 not taken.
874458 char ** word = qsplit(tmp.temp_raw(), " ", &numwords);
959 437229 string resolved;
960 // when writing out the data for the addrToLine mapping,
961 // we want to write out the snespos we had before writing opcodes
962 874458 int addrToLinePos = realsnespos & 0xFFFFFF;
963
964 #define is(test) (!stricmpwithlower(word[0], test))
965 #define is0(test) (numwords==1 && !stricmpwithlower(word[0], test))
966 #define is1(test) (numwords==2 && !stricmpwithlower(word[0], test))
967 #define is2(test) (numwords==3 && !stricmpwithlower(word[0], test))
968 #define is3(test) (numwords==4 && !stricmpwithlower(word[0], test))
969 #define par word[1]
970
971
2/8
✗ Branch 0 not taken.
✓ Branch 1 taken 874458 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 437229 times.
874458 if(!moreonlinecond && !(is("elseif") || is("else"))){
972 return;
973 }
974
975 // RPG Hacker: Hack to fix the bug where defines in elseifs would never get resolved
976 // This really seems like the only possible place for the fix
977
6/6
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 874320 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 66 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 437193 times.
874458 if (is("elseif") && numtrue+1==numif)
978 {
979
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 resolvedefines(resolved, block);
980
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
72 free(word);
981
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 word = qsplit(resolved.temp_raw(), " ", &numwords);
982 }
983
984 437229 autoptr<char**> wordcopy=word;
985
8/8
✓ Branch 0 taken 872928 times.
✓ Branch 1 taken 1530 times.
✓ Branch 2 taken 436464 times.
✓ Branch 3 taken 436464 times.
✓ Branch 4 taken 112679 times.
✓ Branch 5 taken 112679 times.
✓ Branch 6 taken 21 times.
✓ Branch 7 taken 437208 times.
874458 if (numif==numtrue && is1("global")) {
986
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)) {
987
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]);
988 }
989 30 return;
990 }
991
14/14
✓ Branch 0 taken 873718 times.
✓ Branch 1 taken 1530 times.
✓ Branch 2 taken 873072 times.
✓ Branch 3 taken 646 times.
✓ Branch 4 taken 437760 times.
✓ Branch 5 taken 435312 times.
✓ Branch 6 taken 437520 times.
✓ Branch 7 taken 240 times.
✓ Branch 8 taken 872830 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 436415 times.
✓ Branch 11 taken 436415 times.
✓ Branch 12 taken 416 times.
✓ Branch 13 taken 437207 times.
875248 while (numif==numtrue && word[0] && (!word[1] || strcmp(word[1], "=")) && addlabel(word[0]))
992 {
993 832 word++;
994 832 numwords--;
995 }
996
4/4
✓ Branch 0 taken 873768 times.
✓ Branch 1 taken 646 times.
✓ Branch 2 taken 436884 times.
✓ Branch 3 taken 436884 times.
874414 if (!word[0] || !word[0][0]) return;
997
4/4
✓ Branch 0 taken 651056 times.
✓ Branch 1 taken 1482 times.
✓ Branch 2 taken 216 times.
✓ Branch 3 taken 650840 times.
652538 if (numif==numtrue && word[0][0]=='%')
998 {
999
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 6 times.
216 if (!macrorecursion)
1000 {
1001
1/2
✓ Branch 0 taken 105 times.
✗ Branch 1 not taken.
105 callerfilename=thisfilename;
1002 210 callerline=thisline;
1003 }
1004 216 int fakeendif_prev = fakeendif;
1005 216 int moreonlinecond_prev = moreonlinecond;
1006 216 int calledmacros_prev = calledmacros;
1007 216 int single_line_for_tracker_prev = single_line_for_tracker;
1008
2/2
✓ Branch 0 taken 204 times.
✓ Branch 1 taken 12 times.
216 callmacro(strchr(block, '%')+1);
1009 204 fakeendif = fakeendif_prev;
1010 204 moreonlinecond = moreonlinecond_prev;
1011 204 calledmacros = calledmacros_prev;
1012 204 single_line_for_tracker = single_line_for_tracker_prev;
1013
2/2
✓ Branch 0 taken 198 times.
✓ Branch 1 taken 6 times.
204 if (!macrorecursion)
1014 {
1015
1/2
✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
99 callerfilename="";
1016 198 callerline=-1;
1017 }
1018 204 return;
1019 }
1020
12/12
✓ Branch 0 taken 651998 times.
✓ Branch 1 taken 324 times.
✓ Branch 2 taken 651860 times.
✓ Branch 3 taken 138 times.
✓ Branch 4 taken 651830 times.
✓ Branch 5 taken 30 times.
✓ Branch 6 taken 440846 times.
✓ Branch 7 taken 210984 times.
✓ Branch 8 taken 220423 times.
✓ Branch 9 taken 220423 times.
✓ Branch 10 taken 105912 times.
✓ Branch 11 taken 220249 times.
652322 if (is("if") || is("elseif") || is("assert") || is("while") || is("for"))
1021 {
1022
6/6
✓ Branch 0 taken 324 times.
✓ Branch 1 taken 211500 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 318 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 105909 times.
211824 if(is("if") && moreonline) fakeendif++;
1023
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 211824 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
211824 if (emulatexkas) asar_throw_warning(0, warning_id_convert_to_asar);
1024 105912 string errmsg;
1025 105912 whiletracker wstatus;
1026 211824 wstatus.startline = thisline;
1027 211824 wstatus.iswhile = false;
1028 211824 wstatus.cond = false;
1029 211824 wstatus.is_for = false;
1030 211824 wstatus.for_start = wstatus.for_end = wstatus.for_cur = 0;
1031 211824 wstatus.for_has_var_backup = false;
1032
2/2
✓ Branch 0 taken 210984 times.
✓ Branch 1 taken 840 times.
211824 if (is("while")) wstatus.iswhile = true;
1033
2/2
✓ Branch 0 taken 348 times.
✓ Branch 1 taken 211476 times.
211824 if (is("for")) wstatus.is_for = true;
1034 // if we are a for loop and:
1035 // 1) whilestatus has an entry at this level already
1036 // 2) said entry represents an incomplete for loop
1037 // then this loop must be meant "for us".
1038 // check number 2 is necessary because otherwise, 2 for loops back-to-back (not nested) would try to use the same whilestatus entry
1039 105912 bool is_for_cont = false;
1040
14/16
✓ Branch 0 taken 348 times.
✓ Branch 1 taken 211476 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 105789 times.
211997 if (is("for") && whilestatus.count > numif && whilestatus[numif].is_for && whilestatus[numif].for_cur < whilestatus[numif].for_end)
1041 {
1042 // continuation of a for loop
1043 123 is_for_cont = true;
1044 }
1045
5/8
✓ Branch 0 taken 123 times.
✓ Branch 1 taken 105789 times.
✓ Branch 2 taken 123 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 105789 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 105789 times.
✗ Branch 7 not taken.
211824 whiletracker& addedwstatus = is_for_cont ? whilestatus[numif] : (whilestatus[numif] = wstatus);
1046
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 211794 times.
211824 if (is("assert"))
1047 {
1048
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 autoptr<char**> tokens = qpsplit(word[numwords - 1], ",");
1049
5/6
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 9 times.
30 if (tokens[0] != NULL && tokens[1] != NULL)
1050 {
1051 6 string rawerrmsg;
1052 6 size_t pos = 1;
1053
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 12 times.
54 while (tokens[pos])
1054 {
1055
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
42 rawerrmsg += tokens[pos];
1056
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 12 times.
42 if (tokens[pos + 1] != NULL)
1057 {
1058
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
30 rawerrmsg += ",";
1059 }
1060 21 pos++;
1061 }
1062
1063
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());
1064 12 }
1065 30 }
1066
8/8
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 211716 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 105894 times.
211824 if (numtrue!=numif && !(is("elseif") && numtrue+1==numif))
1067 {
1068
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++;
1069 18 return;
1070 }
1071
8/8
✓ Branch 0 taken 211464 times.
✓ Branch 1 taken 324 times.
✓ Branch 2 taken 498 times.
✓ Branch 3 taken 210966 times.
✓ Branch 4 taken 330 times.
✓ Branch 5 taken 168 times.
✓ Branch 6 taken 105810 times.
✓ Branch 7 taken 84 times.
211788 if ((is("if") || is("while") || is("for"))) numif++;
1072 bool cond;
1073
1074 211788 bool isassert = is("assert");
1075
1076 211788 char ** nextword=word+1;
1077 105894 char * condstr= nullptr;
1078
2/2
✓ Branch 0 taken 211458 times.
✓ Branch 1 taken 330 times.
211788 if(!is("for")) {
1079 while (true)
1080 {
1081
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 211464 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
211464 if (!nextword[0]) asar_throw_error(0, error_type_block, error_id_broken_conditional, word[0]);
1082 105732 bool thiscond = false;
1083
4/6
✓ Branch 0 taken 211110 times.
✓ Branch 1 taken 354 times.
✓ Branch 2 taken 211110 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 211110 times.
211464 if (!nextword[1] || !strcmp(nextword[1], "&&") || !strcmp(nextword[1], "||"))
1084 {
1085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 354 times.
354 if (nextword[0][0] == '!')
1086 {
1087 asar_throw_warning(0, warning_id_feature_deprecated, "old style conditional negation (if !condition) ", "the not function");
1088 double val = getnumdouble(nextword[0]+1);
1089 if (foundlabel && !foundlabel_static && !isassert) asar_throw_error(0, error_type_block, error_id_label_in_conditional, word[0]);
1090 thiscond = !(val > 0);
1091 }
1092 else
1093 {
1094
1/2
✓ Branch 0 taken 354 times.
✗ Branch 1 not taken.
354 double val = getnumdouble(nextword[0]);
1095
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]);
1096 354 thiscond = (val > 0);
1097 }
1098
1099
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 354 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
354 if (condstr && nextword[1])
1100 {
1101 if (strcmp(condstr, nextword[1])) asar_throw_error(1, error_type_block, error_id_invalid_condition);
1102 }
1103 354 else condstr=nextword[1];
1104 354 nextword+=2;
1105 354 }
1106 else
1107 {
1108
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 211110 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
211110 if (!nextword[2]) asar_throw_error(0, error_type_block, error_id_broken_conditional, word[0]);
1109
1/2
✓ Branch 0 taken 211110 times.
✗ Branch 1 not taken.
211110 double par1=getnumdouble(nextword[0]);
1110
6/8
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 211050 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.
211110 if (foundlabel && !foundlabel_static && !isassert) asar_throw_error(0, error_type_block, error_id_label_in_conditional, word[0]);
1111
1/2
✓ Branch 0 taken 211080 times.
✗ Branch 1 not taken.
211080 double par2=getnumdouble(nextword[2]);
1112
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 211080 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.
211080 if (foundlabel && !foundlabel_static && !isassert) asar_throw_error(0, error_type_block, error_id_label_in_conditional, word[0]);
1113 if(0);
1114
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 210960 times.
211080 else if (!strcmp(nextword[1], ">")) thiscond=(par1>par2);
1115
2/2
✓ Branch 0 taken 210858 times.
✓ Branch 1 taken 102 times.
210960 else if (!strcmp(nextword[1], "<")) thiscond=(par1<par2);
1116
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 96 times.
102 else if (!strcmp(nextword[1], ">=")) thiscond=(par1>=par2);
1117
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 else if (!strcmp(nextword[1], "<=")) thiscond=(par1<=par2);
1118
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 else if (!strcmp(nextword[1], "="))
1119 {
1120 asar_throw_warning(0, warning_id_feature_deprecated, "if a = b", "use \"if a == b\" instead");
1121 thiscond=(par1==par2);
1122 }
1123
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 else if (!strcmp(nextword[1], "==")) thiscond=(par1==par2);
1124 else if (!strcmp(nextword[1], "!=")) thiscond=(par1!=par2);
1125 //else if (!strcmp(nextword[1], "<>")) thiscond=(par1!=par2);
1126 else asar_throw_error(0, error_type_block, error_id_broken_conditional, word[0]);
1127
1128
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 211074 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
211080 if (condstr && nextword[3])
1129 {
1130 if (strcmp(condstr, nextword[3])) asar_throw_error(1, error_type_block, error_id_invalid_condition);
1131 }
1132 211080 else condstr=nextword[3];
1133 211080 nextword+=4;
1134 }
1135
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 211416 times.
211434 if (condstr)
1136 {
1137
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; }
1138 else if (!strcmp(condstr, "||")) { if(!thiscond) continue; }
1139 else asar_throw_error(0, error_type_block, error_id_broken_conditional, word[0]);
1140 }
1141 105714 cond=thiscond;
1142 105714 break;
1143 3 }
1144 }
1145
1146
2/2
✓ Branch 0 taken 330 times.
✓ Branch 1 taken 211428 times.
211758 if (is("for"))
1147 {
1148 // for loops as anything except the first block cause weirdness
1149 // (while loops do too, but let's not talk about it)
1150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 330 times.
330 if(single_line_for_tracker != 1) {
1151 numif--;
1152 asar_throw_error(0, error_type_line, error_id_bad_single_line_for);
1153 }
1154 // TODO: these errors could probably be a bit more descriptive
1155
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 246 times.
330 if(!is_for_cont)
1156 {
1157 // "for i = 0..16"
1158
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);
1159
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);
1160
1161
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 char* range_sep = strqpstr(word[3], "..");
1162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 if(!range_sep)
1163 asar_throw_error(0, error_type_block, error_id_broken_for_loop, "invalid loop range");
1164
1165
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
84 string for_start(word[3], range_sep - word[3]);
1166
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
84 string for_end(range_sep+2);
1167
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 addedwstatus.for_start = getnum(for_start);
1168
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");
1169
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 addedwstatus.for_end = getnum(for_end);
1170
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");
1171
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
84 string varname = word[1];
1172
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);
1173
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
84 addedwstatus.for_variable = varname;
1174 84 addedwstatus.for_cur = addedwstatus.for_start;
1175 84 }
1176 else
1177 {
1178 246 addedwstatus.for_cur++;
1179 }
1180 // this cond is actually also used to tell assemblefile whether to jump back to the beginning of the loop, so keep it updated
1181 330 addedwstatus.cond = addedwstatus.for_cur < addedwstatus.for_end;
1182 330 single_line_for_tracker = 2;
1183
2/2
✓ Branch 0 taken 246 times.
✓ Branch 1 taken 84 times.
330 if(addedwstatus.cond)
1184 {
1185
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 27 times.
246 numtrue++;
1186
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)) {
1187 192 addedwstatus.for_has_var_backup = true;
1188
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);
1189 }
1190
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);
1191 }
1192 }
1193
6/6
✓ Branch 0 taken 211134 times.
✓ Branch 1 taken 294 times.
✓ Branch 2 taken 105567 times.
✓ Branch 3 taken 105567 times.
✓ Branch 4 taken 105630 times.
✓ Branch 5 taken 84 times.
211428 else if (is("if") || is("while"))
1194 {
1195 if(0);
1196
2/2
✓ Branch 0 taken 211044 times.
✓ Branch 1 taken 216 times.
211260 else if (cond)
1197 {
1198 211044 numtrue++;
1199
1/2
✓ Branch 0 taken 105522 times.
✗ Branch 1 not taken.
211044 elsestatus[numif]=true;
1200 }
1201
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 else if (!cond)
1202 {
1203
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 if(moreonline) moreonlinecond=false;
1204
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
216 elsestatus[numif]=false;
1205 }
1206 211260 addedwstatus.cond = cond;
1207 }
1208
2/2
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 30 times.
168 else if (is("elseif"))
1209 {
1210
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);
1211
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);
1212
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 72 times.
138 if (numif==numtrue) numtrue--;
1213
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])
1214 {
1215
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if(moreonline) moreonlinecond = true;
1216 36 numtrue++;
1217
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
36 elsestatus[numif]=true;
1218 }
1219 }
1220 // otherwise, must be assert command
1221
4/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 2 times.
30 else if (pass == 2 && !cond)
1222 {
1223
7/10
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 4 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.
18 if (errmsg) asar_throw_error(2, error_type_block, error_id_assertion_failed, (string(": ") + errmsg).data());
1224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 else asar_throw_error(2, error_type_block, error_id_assertion_failed, ".");
1225 }
1226
4/4
✓ Branch 0 taken 105875 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 105875 times.
✓ Branch 3 taken 18 times.
211880 }
1227
8/8
✓ Branch 0 taken 439328 times.
✓ Branch 1 taken 1170 times.
✓ Branch 2 taken 229190 times.
✓ Branch 3 taken 210138 times.
✓ Branch 4 taken 114595 times.
✓ Branch 5 taken 114595 times.
✓ Branch 6 taken 105828 times.
✓ Branch 7 taken 114421 times.
440498 else if (is("endif") || is("endwhile") || is("endfor"))
1228 {
1229
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 211650 times.
211656 if(fakeendif) fakeendif--;
1230
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 211656 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
211656 if (numwords != 1) asar_throw_error(1, error_type_block, error_id_unknown_command);
1231
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 211656 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
211656 if (!numif) asar_throw_error(1, error_type_block, error_id_misplaced_endif);
1232
2/2
✓ Branch 0 taken 211194 times.
✓ Branch 1 taken 462 times.
211656 if (numif==numtrue) numtrue--;
1233 211656 numif--;
1234
4/4
✓ Branch 0 taken 106002 times.
✓ Branch 1 taken 105654 times.
✓ Branch 2 taken 174 times.
✓ Branch 3 taken 105654 times.
211656 if(whilestatus[numif].is_for) {
1235
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 288 times.
348 if(single_line_for_tracker == 2) single_line_for_tracker = 3;
1236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 348 times.
348 if(moreonline) {
1237 // sabotage the whilestatus to prevent the loop running again
1238 // and spamming more of the same error
1239 whilestatus[numif].for_cur = whilestatus[numif].for_end;
1240 whilestatus[numif].cond = false;
1241 asar_throw_error(0, error_type_block, error_id_bad_single_line_for);
1242 }
1243
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) {
1244
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)
1245
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;
1246
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);
1247 }
1248 }
1249
2/2
✓ Branch 0 taken 210806 times.
✓ Branch 1 taken 850 times.
211656 if(warn_endwhile) {
1250
4/4
✓ Branch 0 taken 210473 times.
✓ Branch 1 taken 333 times.
✓ Branch 2 taken 105070 times.
✓ Branch 3 taken 333 times.
210806 if(whilestatus[numif].iswhile) {
1251
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 210138 times.
210140 if(!is("endwhile")) {
1252 2 warn_endwhile = false;
1253
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");
1254 }
1255 }
1256
4/4
✓ Branch 0 taken 507 times.
✓ Branch 1 taken 159 times.
✓ Branch 2 taken 174 times.
✓ Branch 3 taken 159 times.
666 else if(whilestatus[numif].is_for) {
1257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 348 times.
348 if(!is("endfor")) {
1258 warn_endwhile = false;
1259 asar_throw_warning(0, warning_id_feature_deprecated, "mismatched terminators", "use endfor to terminate a for statement");
1260 }
1261 }
1262
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 318 times.
318 else if(!is("endif")) {
1263 warn_endwhile = false;
1264 asar_throw_warning(0, warning_id_feature_deprecated, "mismatched terminators", "use endif to terminate an if statement");
1265 }
1266 }
1267 }
1268
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 228626 times.
228842 else if (is("else"))
1269 {
1270
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 if(!moreonlinecond) moreonlinecond = true;
1271
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
216 if (numwords != 1) asar_throw_error(1, error_type_block, error_id_unknown_command);
1272
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
216 if (!numif) asar_throw_error(1, error_type_block, error_id_misplaced_else);
1273
5/12
✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 216 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 108 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 108 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 108 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
216 if (whilestatus[numif - 1].iswhile || whilestatus[numif - 1].is_for) asar_throw_error(1, error_type_block, error_id_else_in_while_loop);
1274
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 108 times.
216 else if (numif==numtrue) numtrue--;
1275
7/8
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 75 times.
✓ Branch 3 taken 33 times.
✓ Branch 4 taken 21 times.
✓ Branch 5 taken 33 times.
✓ Branch 6 taken 21 times.
✓ Branch 7 taken 33 times.
162 else if (numif==numtrue+1 && !elsestatus[numif])
1276 {
1277 42 numtrue++;
1278
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
42 elsestatus[numif]=true;
1279 }
1280 }
1281
2/2
✓ Branch 0 taken 114313 times.
✓ Branch 1 taken 114313 times.
228626 else if (numif!=numtrue) return;
1282
4/4
✓ Branch 0 taken 227820 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 9688 times.
✓ Branch 3 taken 218132 times.
227822 else if (asblock_pick(word, numwords))
1283 {
1284
1/2
✓ Branch 0 taken 9688 times.
✗ Branch 1 not taken.
9688 add_addr_to_line(addrToLinePos);
1285 9688 numopcodes += recent_opcode_num;
1286 }
1287
6/6
✓ Branch 0 taken 216970 times.
✓ Branch 1 taken 1162 times.
✓ Branch 2 taken 108485 times.
✓ Branch 3 taken 108485 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 109063 times.
218132 else if (is1("undef"))
1288 {
1289 3 string def;
1290 // RPG Hacker: Not sure if we should allow this?
1291 // Currently, the manual states that we should not include the
1292 // exclamation mark, and I believe that this is for the better
1293 // because I can see this leading to ambiguities or causing
1294 // problems. If we add this back in, we should definitely
1295 // also added it to the defined() function for consistency, though.
1296 // Well, actually I just check and we can't support this in
1297 // defined() (the defined is already replaced at that point), so
1298 // I think we should not support it here, either.
1299 /*if (*par == '!') def = S safedequote(par) + 1;
1300
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);
1301
1302
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))
1303 {
1304
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 defines.remove(def);
1305 }
1306 else
1307 {
1308 asar_throw_error(0, error_type_block, error_id_define_not_found, def.data());
1309 }
1310 6 }
1311
6/6
✓ Branch 0 taken 518 times.
✓ Branch 1 taken 217608 times.
✓ Branch 2 taken 259 times.
✓ Branch 3 taken 259 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 109060 times.
218126 else if (is0("error"))
1312 {
1313
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 asar_throw_error(0, error_type_block, error_id_error_command, ".");
1314 }
1315
6/6
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 217608 times.
✓ Branch 2 taken 256 times.
✓ Branch 3 taken 256 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 109057 times.
218120 else if (is0("warn"))
1316 {
1317
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 asar_throw_warning(2, warning_id_warn_command, ".");
1318 }
1319
6/6
✓ Branch 0 taken 216964 times.
✓ Branch 1 taken 1150 times.
✓ Branch 2 taken 108482 times.
✓ Branch 3 taken 108482 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 109051 times.
218114 else if (is1("error"))
1320 {
1321
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 string out = handle_print(par);
1322 // RPG Hacker: This used to be on pass 0, which had its merits (you don't want to miss a potentially critical
1323 // user-generated error, just because a bazillion other errors are thrown in passes before it). However, I
1324 // don't see how to support print functions with this without moving it to pass 2. Suggestions are welcome.
1325
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());
1326 12 }
1327
6/6
✓ Branch 0 taken 216952 times.
✓ Branch 1 taken 1150 times.
✓ Branch 2 taken 108476 times.
✓ Branch 3 taken 108476 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 109045 times.
218102 else if (is1("warn"))
1328 {
1329
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 string out = handle_print(par);
1330
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());
1331 12 }
1332
6/6
✓ Branch 0 taken 216940 times.
✓ Branch 1 taken 1150 times.
✓ Branch 2 taken 108470 times.
✓ Branch 3 taken 108470 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 109027 times.
218090 else if (is1("warnings"))
1333 {
1334
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)
1335 {
1336
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 push_warnings();
1337 }
1338
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)
1339 {
1340
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 pull_warnings();
1341 }
1342 }
1343
6/6
✓ Branch 0 taken 584 times.
✓ Branch 1 taken 217470 times.
✓ Branch 2 taken 292 times.
✓ Branch 3 taken 292 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 108991 times.
218054 else if (is2("warnings"))
1344 {
1345
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)
1346 {
1347
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 asar_warning_id warnid = parse_warning_id_from_string(word[2]);
1348
1349
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (warnid != warning_id_end)
1350 {
1351
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 set_warning_enabled(warnid, true);
1352 }
1353 else
1354 {
1355 asar_throw_error(0, error_type_null, error_id_invalid_warning_id, "warnings enable", (int)(warning_id_start + 1), (int)(warning_id_end - 1));
1356 }
1357 }
1358
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)
1359 {
1360
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 asar_warning_id warnid = parse_warning_id_from_string(word[2]);
1361
1362
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if (warnid != warning_id_end)
1363 {
1364
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 set_warning_enabled(warnid, false);
1365 }
1366 else
1367 {
1368 asar_throw_error(0, error_type_null, error_id_invalid_warning_id, "warnings disable", (int)(warning_id_start + 1), (int)(warning_id_end - 1));
1369 }
1370 }
1371 }
1372
6/6
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 217470 times.
✓ Branch 2 taken 256 times.
✓ Branch 3 taken 256 times.
✓ Branch 4 taken 34 times.
✓ Branch 5 taken 108957 times.
217982 else if (is2("check"))
1373 {
1374
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)
1375 {
1376 // RPG Hacker: Removed trimming for now - I think requiring an exact match is probably
1377 // better here (not sure, though, it's worth discussing)
1378
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]);
1379 // randomdude999: this also removes leading spaces because itrim gets stuck in an endless
1380 // loop when multi is true and one argument is empty
1381 //expected_title = itrim(expected_title.data(), " ", " ", true); // remove trailing spaces
1382 // in hirom the rom needs to be an entire bank for it to have a title, other modes only need 0x8000 bytes
1383
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
1384 {
1385 if (!ignoretitleerrors) // title errors shouldn't be ignored
1386 asar_throw_error(0, error_type_block, error_id_rom_too_short, expected_title.data());
1387 else // title errors should be ignored, throw a warning anyways
1388 asar_throw_warning(0, warning_id_rom_too_short, expected_title.data());
1389 }
1390 else {
1391 3 string actual_title;
1392 3 string actual_display_title;
1393
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 6 times.
132 for (int i = 0;i < 21;i++)
1394 {
1395 126 unsigned char c = romdata[snestopc(0x00FFC0 + i)];
1396
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
126 actual_title += (char)c;
1397 // the replacements are from interface-cli.cpp
1398
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 63 times.
126 if (c == 7) c = 14;
1399
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 63 times.
126 if (c == 8) c = 27;
1400
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 63 times.
126 if (c == 9) c = 26;
1401
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 63 times.
126 if (c == '\r') c = 17;
1402
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 63 times.
126 if (c == '\n') c = 25;
1403
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 126 times.
126 if (c == '\0') c = 155;
1404
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
126 actual_display_title += (char)c;
1405 }
1406 //actual_display_title = itrim(actual_display_title.data(), " ", " ", true); // remove trailing spaces
1407 //actual_title = itrim(actual_title.data(), " ", " ", true); // remove trailing spaces
1408
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (strncmp(expected_title, actual_title, 21) != 0)
1409 {
1410 if (!ignoretitleerrors) // title errors shouldn't be ignored
1411 asar_throw_error(0, error_type_block, error_id_rom_title_incorrect, expected_title.data(), actual_display_title.data());
1412 else // title errors should be ignored, throw a warning anyways
1413 asar_throw_warning(0, warning_id_rom_title_incorrect, expected_title.data(), actual_display_title.data());
1414 }
1415 6 }
1416 6 }
1417
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)
1418 {
1419 if (0);
1420
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"))
1421 {
1422
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");
1423 }
1424
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"))
1425 {
1426 30 disable_bank_cross_errors = true;
1427 }
1428
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"))
1429 {
1430 2 disable_bank_cross_errors = false;
1431 2 check_half_banks_crossed = true;
1432 }
1433 else if (!stricmp(word[2], "full"))
1434 {
1435 disable_bank_cross_errors = false;
1436 check_half_banks_crossed = false;
1437 }
1438 else asar_throw_error(0, error_type_block, error_id_invalid_check);
1439
1440 }
1441 else
1442 {
1443 asar_throw_error(0, error_type_block, error_id_invalid_check);
1444 }
1445 }
1446
9/10
✓ Branch 0 taken 506 times.
✓ Branch 1 taken 217408 times.
✓ Branch 2 taken 506 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 216904 times.
✓ Branch 5 taken 1010 times.
✓ Branch 6 taken 30 times.
✓ Branch 7 taken 216874 times.
✓ Branch 8 taken 15 times.
✓ Branch 9 taken 108942 times.
217914 else if (is0("asar") || is1("asar"))
1447 {
1448
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);
1449
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 15 times.
30 if (!par) return;
1450
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);
1451 15 int dots=0;
1452 15 int dig=0;
1453
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 30 times.
150 for (int i=0;par[i];i++)
1454 {
1455
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 90 times.
120 if (par[i]=='.')
1456 {
1457
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);
1458 15 dig=0;
1459 30 dots++;
1460 }
1461
1/2
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
90 else if (is_digit(par[i])) dig++;
1462 else asar_throw_error(0, error_type_block, error_id_invalid_version_number);
1463 }
1464
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);
1465
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 autoptr<char**> vers=split(par, ".");
1466 30 int vermaj=atoi(vers[0]);
1467
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);
1468
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (vermaj<asarver_maj) return;
1469
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (dots==1)
1470 {
1471
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);
1472 //if (asarver_min<10 && asarver_bug<10 && strlen(vers[1])>2) error(0, "This version of Asar is too old for this patch.");
1473 30 int verminbug=atoi(vers[1]);
1474 30 int tmpver=asarver_bug;
1475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
30 if (tmpver>9) tmpver=9;
1476
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);
1477
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; }
1478 }
1479 else
1480 {
1481 int vermin=atoi(vers[1]);
1482 if (vermin>asarver_min) asar_throw_error(pass, error_type_fatal, error_id_asar_too_old);
1483 int verbug=atoi(vers[2]);
1484 if (vermin==asarver_min && verbug>asarver_bug) asar_throw_error(pass, error_type_fatal, error_id_asar_too_old);
1485 if(vermaj == 1 && vermin >= 9) { default_math_pri = true; default_math_round_off = true; }
1486 }
1487 30 specifiedasarver = true;
1488
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
30 }
1489
6/6
✓ Branch 0 taken 506 times.
✓ Branch 1 taken 217378 times.
✓ Branch 2 taken 253 times.
✓ Branch 3 taken 253 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 108936 times.
217884 else if (is0("xkas"))
1490 {
1491
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!!!");
1492
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);
1493
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);
1494
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);
1495 6 emulatexkas=true;
1496 6 optimizeforbank=0x100;
1497
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!force_checksum_fix)
1498 6 checksum_fix_enabled = false;
1499
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 sublabels[0]=":xkasdefault:";
1500 }
1501
7/10
✓ Branch 0 taken 494 times.
✓ Branch 1 taken 217378 times.
✓ Branch 2 taken 494 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 216874 times.
✓ Branch 5 taken 998 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 216874 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 108936 times.
217872 else if (is0("include") || is1("includefrom"))
1502 {
1503 if (!asarverallowed) asar_throw_error(0, error_type_block, error_id_start_of_file);
1504 if (istoplevel)
1505 {
1506 if (par) asar_throw_error(pass, error_type_fatal, error_id_cant_be_main_file, (string(" The main file is '") + STR par + STR "'.").data());
1507 else asar_throw_error(pass, error_type_fatal, error_id_cant_be_main_file, "");
1508 }
1509 }
1510
6/6
✓ Branch 0 taken 494 times.
✓ Branch 1 taken 217378 times.
✓ Branch 2 taken 247 times.
✓ Branch 3 taken 247 times.
✓ Branch 4 taken 15 times.
✓ Branch 5 taken 108921 times.
217872 else if (is0("includeonce"))
1511 {
1512
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))
1513 {
1514
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
30 includeonce.append(thisfilename);
1515 }
1516 }
1517
18/18
✓ Branch 0 taken 216874 times.
✓ Branch 1 taken 968 times.
✓ Branch 2 taken 3724 times.
✓ Branch 3 taken 213150 times.
✓ Branch 4 taken 3724 times.
✓ Branch 5 taken 968 times.
✓ Branch 6 taken 3680 times.
✓ Branch 7 taken 44 times.
✓ Branch 8 taken 3680 times.
✓ Branch 9 taken 968 times.
✓ Branch 10 taken 3098 times.
✓ Branch 11 taken 582 times.
✓ Branch 12 taken 3098 times.
✓ Branch 13 taken 968 times.
✓ Branch 14 taken 72 times.
✓ Branch 15 taken 3026 times.
✓ Branch 16 taken 106924 times.
✓ Branch 17 taken 1997 times.
217842 else if (is1("db") || is1("dw") || is1("dl") || is1("dd"))
1518 {
1519 106924 int len = 0;
1520
2/6
✓ Branch 0 taken 213848 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 213848 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
213848 if (!confirmqpar(par)) asar_throw_error(0, error_type_block, error_id_mismatched_parentheses);
1521
5/6
✓ Branch 0 taken 213848 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106924 times.
✓ Branch 3 taken 106924 times.
✓ Branch 4 taken 106575 times.
✓ Branch 5 taken 349 times.
213848 if (is1("db")) len=1;
1522
5/6
✓ Branch 0 taken 213848 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106924 times.
✓ Branch 3 taken 106924 times.
✓ Branch 4 taken 22 times.
✓ Branch 5 taken 106902 times.
213848 if (is1("dw")) len=2;
1523
5/6
✓ Branch 0 taken 213848 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106924 times.
✓ Branch 3 taken 106924 times.
✓ Branch 4 taken 291 times.
✓ Branch 5 taken 106633 times.
213848 if (is1("dl")) len=3;
1524
5/6
✓ Branch 0 taken 213848 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106924 times.
✓ Branch 3 taken 106924 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 106888 times.
213848 if (is1("dd")) len=4;
1525
1/2
✓ Branch 0 taken 213848 times.
✗ Branch 1 not taken.
213848 autoptr<char**> pars=qpsplit(par, ",");
1526
2/2
✓ Branch 0 taken 214562 times.
✓ Branch 1 taken 213838 times.
428400 for (int i=0;pars[i];i++)
1527 {
1528
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 214394 times.
214562 if (pars[i][0]=='"')
1529 {
1530
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)
1531 asar_throw_warning(0, warning_id_xkas_patch);
1532
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++)
1533 {
1534
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]);
1535
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]);
1536
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]);
1537
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]);
1538 }
1539 }
1540 else
1541 {
1542 107197 const char * math=pars[i];
1543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 214394 times.
214394 if (math[0]=='#') math++;
1544
4/4
✓ Branch 0 taken 71464 times.
✓ Branch 1 taken 142930 times.
✓ Branch 2 taken 71454 times.
✓ Branch 3 taken 10 times.
214394 unsigned int num=(pass==2)?getnum(math):0;
1545
3/4
✓ Branch 0 taken 213704 times.
✓ Branch 1 taken 680 times.
✓ Branch 2 taken 106852 times.
✗ Branch 3 not taken.
214384 if (len == 1) write1(num);
1546
3/4
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 214346 times.
✓ Branch 2 taken 38 times.
✗ Branch 3 not taken.
214384 if (len == 2) write2(num);
1547
3/4
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 213808 times.
✓ Branch 2 taken 576 times.
✗ Branch 3 not taken.
214384 if (len == 3) write3(num);
1548
3/4
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 214318 times.
✓ Branch 2 taken 66 times.
✗ Branch 3 not taken.
214384 if (len == 4) write4(num);
1549 }
1550 }
1551
1/2
✓ Branch 0 taken 213838 times.
✗ Branch 1 not taken.
213838 add_addr_to_line(addrToLinePos);
1552 213848 }
1553
6/6
✓ Branch 0 taken 444 times.
✓ Branch 1 taken 3550 times.
✓ Branch 2 taken 342 times.
✓ Branch 3 taken 102 times.
✓ Branch 4 taken 102 times.
✓ Branch 5 taken 120 times.
3994 else if (numwords==3 && !stricmp(word[1], "="))
1554 {
1555
5/8
✓ Branch 0 taken 150 times.
✓ Branch 1 taken 90 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.
240 if (word[0][0]=='\'' && word[0][1] && word[0][2]=='\'' && word[0][3]=='\0')
1556 {
1557
1/2
✓ Branch 0 taken 150 times.
✗ Branch 1 not taken.
150 table.table[(unsigned char)word[0][1]]=getnum(word[2]);
1558
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);
1559 150 return;
1560 }
1561 // randomdude999: int cast b/c i'm too lazy to also mess with making setlabel()
1562 // unsigned, besides it wouldn't matter anyways.
1563
1/2
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
90 int num=(int)getnum(word[2]);
1564
5/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 78 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
90 if (foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_label_cross_assignment);
1565
1566 84 const char* newlabelname = word[0];
1567 42 bool ismacro = false;
1568
1569
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 78 times.
84 if (newlabelname[0] == '?')
1570 {
1571 3 ismacro = true;
1572 6 newlabelname++;
1573 }
1574
1575
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 39 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
45 if (ismacro && macrorecursion == 0)
1576 {
1577 asar_throw_error(0, error_type_block, error_id_macro_label_outside_of_macro);
1578 }
1579
1580
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
84 if (!confirmname(newlabelname)) asar_throw_error(0, error_type_block, error_id_invalid_label_name);
1581
1582 42 string completename;
1583
1584
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 78 times.
84 if (ismacro)
1585 {
1586
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) + "_";
1587 }
1588
1589
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
84 completename += newlabelname;
1590
1591
2/4
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
84 setlabel(ns + completename, num, true);
1592 126 }
1593
3/4
✓ Branch 0 taken 3754 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3596 times.
✓ Branch 3 taken 158 times.
3754 else if (assemblemapper(word, numwords)) {}
1594
6/6
✓ Branch 0 taken 3008 times.
✓ Branch 1 taken 588 times.
✓ Branch 2 taken 1504 times.
✓ Branch 3 taken 1504 times.
✓ Branch 4 taken 346 times.
✓ Branch 5 taken 1452 times.
3596 else if (is1("org"))
1595 {
1596
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 692 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
692 if(in_spcblock) asar_throw_error(0, error_type_block, error_id_feature_unavaliable_in_spcblock);
1597 692 freespaceend();
1598
1/2
✓ Branch 0 taken 692 times.
✗ Branch 1 not taken.
692 unsigned int num=getnum(par);
1599
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 692 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
692 if (forwardlabel) asar_throw_error(0, error_type_block, error_id_org_label_forward);
1600
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 692 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
692 if (num&~0xFFFFFF) asar_throw_error(1, error_type_block, error_id_snes_address_out_of_bounds, hex6(num).data());
1601
5/10
✓ Branch 0 taken 266 times.
✓ Branch 1 taken 426 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 260 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 432 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
692 if ((mapper==lorom || mapper==exlorom) && (num&0x408000)==0x400000 && (num&0x700000)!=0x700000) asar_throw_warning(0, warning_id_set_middle_byte);
1602 //if (fastrom) num|=0x800000;
1603 692 snespos=(int)num;
1604 692 realsnespos=(int)num;
1605 692 startpos=(int)num;
1606 692 realstartpos=(int)num;
1607 }
1608 #define ret_error(errid) { asar_throw_error(0, error_type_block, errid); return; }
1609 #define ret_error_params(errid, ...) { asar_throw_error(0, error_type_block, errid, __VA_ARGS__); return; }
1610
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 2826 times.
2904 else if (is("struct"))
1611 {
1612 //verifysnespos();
1613
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);
1614
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);
1615
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);
1616
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);
1617
1618
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]);
1619
1620 78 static_struct = false;
1621 78 old_snespos = snespos;
1622 78 old_startpos = startpos;
1623 78 old_optimizeforbank = optimizeforbank;
1624 39 unsigned int base = 0;
1625
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 48 times.
78 if (numwords == 3)
1626 {
1627 30 static_struct = true;
1628
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 base = getnum(word[2]);
1629
1630
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;
1631 }
1632
1633 78 bool old_in_struct = in_struct;
1634 78 bool old_in_sub_struct = in_sub_struct;
1635
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;
1636 78 in_sub_struct = numwords == 4;
1637
1638 #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; }
1639 #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; }
1640
1641
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 48 times.
78 if (numwords == 3)
1642 {
1643
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());
1644 30 snespos = (int)base;
1645 30 startpos = (int)base;
1646 }
1647
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
48 else if (numwords == 4)
1648 {
1649
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);
1650
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);
1651
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 string tmp_struct_parent = word[3];
1652
1653
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());
1654
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);
1655
1656 24 static_struct = structure.is_static;
1657
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 struct_parent = tmp_struct_parent;
1658 24 snespos = structure.base_end;
1659 24 startpos = structure.base_end;
1660
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
24 }
1661
1662
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
78 push_pc();
1663
1664 78 optimizeforbank = -1;
1665
1666
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
78 struct_name = word[1];
1667 78 struct_base = snespos;
1668 78 realsnespos = 0;
1669 78 realstartpos = 0;
1670
1671
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);
1672
1673 #undef ret_error_cleanup
1674 #undef ret_error_params_cleanup
1675 }
1676
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 2748 times.
2826 else if (is("endstruct"))
1677 {
1678
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);
1679
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);
1680
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);
1681
1682
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;
1683
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);
1684
1685 39 snes_struct structure;
1686 78 structure.base_end = snespos;
1687 78 structure.struct_size = alignment * ((snespos - struct_base + alignment - 1) / alignment);
1688 78 structure.object_size = structure.struct_size;
1689 78 structure.is_static = static_struct;
1690
1691
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 24 times.
78 if (in_struct)
1692 {
1693
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;
1694 }
1695
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 else if (in_sub_struct)
1696 {
1697 12 snes_struct parent;
1698
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);
1699
1700
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (parent.object_size < parent.struct_size + structure.struct_size) {
1701 24 parent.object_size = parent.struct_size + structure.struct_size;
1702 }
1703
1704
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;
1705
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;
1706 12 }
1707
1708
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
78 pop_pc();
1709 78 in_struct = false;
1710 78 in_sub_struct = false;
1711 78 snespos = old_snespos;
1712 78 startpos = old_startpos;
1713 78 optimizeforbank = old_optimizeforbank;
1714 78 static_struct = false;
1715 39 }
1716 #undef ret_error
1717
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2736 times.
2748 else if(is("spcblock"))
1718 {
1719 //banned features when active: org, freespace(and variants), arch, mapper,namespace,pushns
1720
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);
1721
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);
1722
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);
1723
1724
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 spcblock.destination = getnum(par);
1725 12 spcblock.type = spcblock_nspc;
1726
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 spcblock.macro_name = "";
1727
1728
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());
1729
1730
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(numwords == 3)
1731 {
1732 if(!stricmp(word[2], "nspc")) spcblock.type = spcblock_nspc;
1733 else if(!stricmp(word[2], "custom")) asar_throw_error(0, error_type_block, error_id_custom_spcblock_missing_macro);
1734 else asar_throw_error(0, error_type_block, error_id_unknown_spcblock_type);
1735 }
1736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 else if(numwords == 4)
1737 {
1738 if(!stricmp(word[2], "custom")) spcblock.type = spcblock_custom;
1739 else asar_throw_error(0, error_type_block, error_id_extra_spcblock_arg_for_type);
1740
1741 if(macros.exists(word[3]))
1742 {
1743 macrodata *macro = macros.find(word[3]);
1744 if(!macro->variadic) asar_throw_error(0, error_type_block, error_id_spcblock_macro_must_be_varadic);
1745 if(macro->numargs != 3) asar_throw_error(0, error_type_block, error_id_spcblock_macro_invalid_static_args);
1746 spcblock.macro_name = word[3];
1747 }
1748 else asar_throw_error(0, error_type_block, error_id_spcblock_macro_doesnt_exist);
1749 }
1750
1751
1/3
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
12 switch(spcblock.type)
1752 {
1753 12 case spcblock_nspc:
1754 12 spcblock.size_address=realsnespos;
1755
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 write2(0x0000);
1756
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 write2(spcblock.destination);
1757 12 snespos=(int)spcblock.destination;
1758 12 startpos=(int)spcblock.destination;
1759 12 spcblock.execute_address = -1u;
1760
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 add_addr_to_line(addrToLinePos);
1761 6 break;
1762 case spcblock_custom:
1763 //this is a todo that probably won't be ready for 1.9
1764 //mostly so we can leverage some cleanups we make in 2.0 for practicality
1765 asar_throw_error(0, error_type_block, error_id_spcblock_custom_types_incomplete);
1766 push_pc();
1767 spcblock.old_mapper = mapper;
1768 mapper = norom;
1769 break;
1770 default:
1771 asar_throw_error(0, error_type_fatal, error_id_internal_error, "invalid spcblock type");
1772 }
1773
1774
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 ns_backup = ns;
1775
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;
1776 12 in_spcblock = true;
1777 }
1778
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2724 times.
2736 else if(is("endspcblock"))
1779 {
1780
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);
1781
1782
1/3
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
12 switch(spcblock.type)
1783 {
1784 12 case spcblock_nspc:
1785
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
12 if (pass==2)
1786 {
1787 4 int pcpos=snestopc(spcblock.size_address&0xFFFFFF);
1788
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());
1789 4 int num=snespos-startpos;
1790
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 writeromdata_byte(pcpos, (unsigned char)num);
1791
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 writeromdata_byte(pcpos+1, (unsigned char)(num >> 8));
1792 }
1793
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (numwords == 3)
1794 {
1795
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);
1796 else
1797 {
1798
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 write2(0x0000);
1799
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]));
1800 }
1801 }
1802
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 else if (numwords != 1)
1803 {
1804 asar_throw_error(0, error_type_null, error_id_unknown_endspcblock_format);
1805 }
1806
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 else if(spcblock.execute_address != -1u)
1807 {
1808 // Legacy case, will be removed with Asar 2.0.
1809 write2(0x0000);
1810 write2((unsigned int)spcblock.execute_address);
1811 }
1812 6 break;
1813 case spcblock_custom:
1814 mapper = spcblock.old_mapper;
1815 pop_pc();
1816 break;
1817 default:
1818 asar_throw_error(0, error_type_fatal, error_id_internal_error, "invalid spcblock type");
1819 }
1820
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 ns = ns_backup;
1821 12 in_spcblock = false;
1822 }
1823 // Remember to also remove execute_address entirely from spcblock once removing this deprecated command.
1824
5/6
✓ Branch 0 taken 2280 times.
✓ Branch 1 taken 444 times.
✓ Branch 2 taken 1140 times.
✓ Branch 3 taken 1140 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1362 times.
2724 else if (is1("startpos"))
1825 {
1826 asar_throw_warning(0, warning_id_feature_deprecated, "startpos", "Use the optional argument to \"endspcblock\"");
1827 if(!in_spcblock) asar_throw_error(0, error_type_block, error_id_startpos_without_spcblock);
1828 spcblock.execute_address=getnum64(par);
1829 }
1830
6/6
✓ Branch 0 taken 2280 times.
✓ Branch 1 taken 444 times.
✓ Branch 2 taken 1140 times.
✓ Branch 3 taken 1140 times.
✓ Branch 4 taken 42 times.
✓ Branch 5 taken 1320 times.
2724 else if (is1("base"))
1831 {
1832
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"))
1833 {
1834 30 snespos=realsnespos;
1835 30 startpos=realstartpos;
1836 30 return;
1837 }
1838
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 unsigned int num=getnum(par);
1839
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);
1840
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());
1841 54 snespos=(int)num;
1842 54 startpos=(int)num;
1843 54 optimizeforbank=-1;
1844 }
1845
6/6
✓ Branch 0 taken 2196 times.
✓ Branch 1 taken 444 times.
✓ Branch 2 taken 1098 times.
✓ Branch 3 taken 1098 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 1314 times.
2640 else if (is1("dpbase"))
1846 {
1847
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 unsigned int num=(int)getnum(par);
1848
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);
1849
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());
1850 12 dp_base = (int)num;
1851 }
1852
6/6
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 2466 times.
✓ Branch 2 taken 81 times.
✓ Branch 3 taken 81 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 1278 times.
2628 else if (is2("optimize"))
1853 {
1854
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"))
1855 {
1856
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"))
1857 {
1858 12 optimize_dp = optimize_dp_flag::NONE;
1859 12 return;
1860 }
1861
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"))
1862 {
1863 6 optimize_dp = optimize_dp_flag::RAM;
1864 6 return;
1865 }
1866
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"))
1867 {
1868 6 optimize_dp = optimize_dp_flag::ALWAYS;
1869 6 return;
1870 }
1871 asar_throw_error(1, error_type_block, error_id_bad_dp_optimize, word[2]);
1872 }
1873
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"))
1874 {
1875
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"))
1876 {
1877 12 optimize_address = optimize_address_flag::DEFAULT;
1878 12 return;
1879 }
1880
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"))
1881 {
1882 18 optimize_address = optimize_address_flag::RAM;
1883 18 return;
1884 }
1885
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"))
1886 {
1887 18 optimize_address = optimize_address_flag::MIRRORS;
1888 18 return;
1889 }
1890 asar_throw_error(1, error_type_block, error_id_bad_address_optimize, word[2]);
1891 }
1892 asar_throw_error(1, error_type_block, error_id_bad_optimize, par);
1893 }
1894
5/6
✓ Branch 0 taken 2184 times.
✓ Branch 1 taken 372 times.
✓ Branch 2 taken 1092 times.
✓ Branch 3 taken 1092 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1278 times.
2556 else if (is1("bank"))
1895 {
1896 if (!stricmp(par, "auto"))
1897 {
1898 optimizeforbank=-1;
1899 return;
1900 }
1901 if (!stricmp(par, "noassume"))
1902 {
1903 optimizeforbank=0x100;
1904 return;
1905 }
1906 unsigned int num=getnum(par);
1907 //if (forwardlabel) error(0, "bank Label is not valid");
1908 //if (foundlabel) num>>=16;
1909 if (num&~0x0000FF) asar_throw_error(1, error_type_block, error_id_snes_address_out_of_bounds, hex6((unsigned int)num).data());
1910 optimizeforbank=(int)num;
1911 }
1912
7/8
✓ Branch 0 taken 2556 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1752 times.
✓ Branch 3 taken 804 times.
✓ Branch 4 taken 876 times.
✓ Branch 5 taken 876 times.
✓ Branch 6 taken 444 times.
✓ Branch 7 taken 834 times.
2556 else if (is("freespace") || is("freecode") || is("freedata"))
1913 {
1914
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 888 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
888 if(in_spcblock) asar_throw_error(0, error_type_block, error_id_feature_unavaliable_in_spcblock);
1915
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 888 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
888 if (emulatexkas) asar_throw_warning(0, warning_id_convert_to_asar);
1916 444 string parstr;
1917
3/4
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 792 times.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
888 if (numwords==1) parstr="\n";//crappy hack: impossible character to cut out extra commas
1918
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];
1919 else asar_throw_error(0, error_type_block, error_id_invalid_freespace_request);
1920
5/8
✓ Branch 0 taken 804 times.
✓ Branch 1 taken 84 times.
✓ Branch 2 taken 402 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 402 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 402 times.
✗ Branch 7 not taken.
1290 if (is("freecode")) parstr=STR"ram,"+parstr;
1921
5/8
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 804 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.
930 if (is("freedata")) parstr=STR"noram,"+parstr;
1922
1/2
✓ Branch 0 taken 888 times.
✗ Branch 1 not taken.
888 autoptr<char**> pars=split(parstr.temp_raw(), ",");
1923 888 unsigned char fsbyte = default_freespacebyte;
1924 444 int useram=-1;
1925 444 bool fixedpos=false;
1926 444 bool align=false;
1927 444 bool leakwarn=true;
1928
2/2
✓ Branch 0 taken 1776 times.
✓ Branch 1 taken 888 times.
2664 for (int i=0;pars[i];i++)
1929 {
1930
2/2
✓ Branch 0 taken 1680 times.
✓ Branch 1 taken 96 times.
1776 if (pars[i][0]=='\n') {}
1931
4/4
✓ Branch 0 taken 1242 times.
✓ Branch 1 taken 438 times.
✓ Branch 2 taken 402 times.
✓ Branch 3 taken 438 times.
1680 else if (!stricmp(pars[i], "ram"))
1932 {
1933
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 804 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
804 if (useram!=-1) asar_throw_error(0, error_type_block, error_id_invalid_freespace_request);
1934 402 useram=1;
1935 }
1936
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"))
1937 {
1938
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);
1939 42 useram=0;
1940 }
1941
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"))
1942 {
1943 if (!stricmp(pars[i], "fixed")) asar_throw_warning(0, warning_id_feature_deprecated, "freespace/code/data fixed", "freespace/code/data static");
1944 if (fixedpos) asar_throw_error(0, error_type_block, error_id_invalid_freespace_request);
1945 fixedpos=true;
1946 }
1947
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"))
1948 {
1949
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);
1950 3 align=true;
1951 }
1952
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"))
1953 {
1954
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);
1955 393 leakwarn=false;
1956 }
1957 else
1958 {
1959 asar_throw_warning(0, warning_id_feature_deprecated, "specifying the freespacebyte in the freespace command", "use the separate freespacebyte command");
1960 fsbyte = (unsigned char)getnum(pars[i]);
1961 }
1962 }
1963
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 888 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
888 if (useram==-1) asar_throw_error(0, error_type_block, error_id_invalid_freespace_request);
1964
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 888 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
888 if (mapper == norom) asar_throw_error(0, error_type_block, error_id_no_freespace_norom);
1965 888 freespaceend();
1966
1/2
✓ Branch 0 taken 888 times.
✗ Branch 1 not taken.
888 freespaceid=getfreespaceid();
1967 888 freespacebyte[freespaceid] = fsbyte;
1968 888 freespace_is_freecode = (useram != 0);
1969
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 592 times.
888 if (pass==0) snespos=(freespaceid<<24)|0x8000;
1970
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 592 times.
888 if (pass==1)
1971 {
1972
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 296 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
296 if (fixedpos && freespaceorgpos[freespaceid]<0)
1973 {
1974 freespacepos[freespaceid]=0x008000;
1975 freespaceleak[freespaceid]=false;//mute some other errors
1976 asar_throw_error(1, error_type_block, error_id_static_freespace_autoclean);
1977 }
1978
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 148 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
148 if (fixedpos && freespaceorgpos[freespaceid]) freespacepos[freespaceid]=snespos=(freespaceid<<24)|freespaceorgpos[freespaceid];
1979
1/2
✓ Branch 0 taken 296 times.
✗ Branch 1 not taken.
296 else freespacepos[freespaceid]=snespos=(freespaceid<<24)|getsnesfreespace(freespacelen[freespaceid], (useram != 0), true, true, align, freespacebyte[freespaceid]);
1980 }
1981
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 592 times.
888 if (pass==2)
1982 {
1983
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 296 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
296 if (fixedpos && freespaceorgpos[freespaceid]==-1) return;//to kill some errors
1984 296 snespos=(freespaceid<<24)|freespacepos[freespaceid];
1985
1/2
✓ Branch 0 taken 296 times.
✗ Branch 1 not taken.
296 resizerats(snespos&0xFFFFFF, freespacelen[freespaceid]);
1986
3/6
✓ Branch 0 taken 258 times.
✓ Branch 1 taken 38 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 258 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
296 if (freespaceleak[freespaceid] && leakwarn) asar_throw_warning(2, warning_id_freespace_leaked);
1987
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 296 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
296 if (fixedpos && freespaceorgpos[freespaceid]>0 && freespacelen[freespaceid]>freespaceorglen[freespaceid])
1988 asar_throw_error(2, error_type_block, error_id_static_freespace_growing);
1989 296 freespaceuse+=8+freespacelen[freespaceid];
1990
1991 // add a mapping for the start of the rats tag
1992
1/2
✓ Branch 0 taken 296 times.
✗ Branch 1 not taken.
296 add_addr_to_line(snespos-8);
1993 }
1994 888 freespacestatic[freespaceid]=fixedpos;
1995
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 888 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.
888 if (snespos < 0 && mapper == sa1rom) asar_throw_error(pass, error_type_fatal, error_id_no_freespace_in_mapped_banks, dec(freespacelen[freespaceid]).data());
1996
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 888 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
888 if (snespos < 0) asar_throw_error(pass, error_type_fatal, error_id_no_freespace, dec(freespacelen[freespaceid]).data());
1997 888 bytes+=8;
1998 888 freespacestart=snespos;
1999 888 startpos=snespos;
2000 888 realstartpos=snespos;
2001 888 realsnespos=snespos;
2002 888 optimizeforbank=-1;
2003 888 ratsmetastate=ratsmeta_allow;
2004
2/4
✓ Branch 0 taken 444 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 444 times.
✗ Branch 3 not taken.
888 }
2005
6/6
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 276 times.
✓ Branch 2 taken 696 times.
✓ Branch 3 taken 696 times.
✓ Branch 4 taken 27 times.
✓ Branch 5 taken 807 times.
1668 else if (is1("prot"))
2006 {
2007
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);
2008
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);
2009
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);
2010
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 42 times.
54 if (ratsmetastate==ratsmeta_used) step(-5);
2011 27 int num;
2012
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 autoptr<char**> pars=qpsplit(par, ",", &num);
2013
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('P');
2014
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('R');
2015
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('O');
2016
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('T');
2017
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);
2018
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 write1((unsigned int)(num*3));
2019
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 54 times.
120 for (int i=0;i<num;i++)
2020 {
2021 //int num=getnum(pars[i]);
2022 66 const char * labeltest=pars[i];
2023
1/2
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
33 string testlabel = labeltest;
2024
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 int labelnum=(int)labelval(&labeltest).pos;
2025
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());
2026
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 write3((unsigned int)labelnum);
2027
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 44 times.
66 if (pass==1) freespaceleak[labelnum >>24]=false;
2028 66 }
2029
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('S');
2030
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('T');
2031
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('O');
2032
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1('P');
2033
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 write1(0);
2034 54 ratsmetastate=ratsmeta_used;
2035
2036
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 add_addr_to_line(addrToLinePos);
2037 54 }
2038
15/18
✓ Branch 0 taken 1338 times.
✓ Branch 1 taken 276 times.
✓ Branch 2 taken 1338 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 90 times.
✓ Branch 5 taken 1524 times.
✓ Branch 6 taken 36 times.
✓ Branch 7 taken 54 times.
✓ Branch 8 taken 1338 times.
✓ Branch 9 taken 222 times.
✓ Branch 10 taken 1338 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 36 times.
✓ Branch 13 taken 1524 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 36 times.
✓ Branch 16 taken 27 times.
✓ Branch 17 taken 780 times.
1614 else if (is1("autoclean") || is2("autoclean") || is1("autoclear") || is2("autoclear"))
2039 {
2040
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);
2041
4/12
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 54 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 54 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 27 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
54 if (is1("autoclear") || is2("autoclear")) asar_throw_warning(0, warning_id_autoclear_deprecated);
2042
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if (numwords==3)
2043 {
2044
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
54 if ((unsigned int)snespos & 0xFF000000) asar_throw_error(0, error_type_block, error_id_autoclean_in_freespace);
2045 54 const char * labeltest = word[2];
2046
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 string testlabel = labeltest;
2047
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 int num=(int)labelval(&labeltest).pos;
2048
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
54 if (*labeltest) asar_throw_error(0, error_type_block, error_id_label_not_found, testlabel.data());
2049 27 unsigned char targetid=(unsigned char)(num>>24);
2050
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 36 times.
54 if (pass==1) freespaceleak[targetid]=false;
2051 54 num&=0xFFFFFF;
2052
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 (strlen(par)>3 && !stricmp(par+3, ".l")) par[3]=0;
2053
6/8
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 15 times.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 12 times.
54 if (!stricmp(par, "JSL") || !stricmp(par, "JML"))
2054 {
2055 54 int orgpos=read3(snespos+1);
2056 54 int ratsloc=freespaceorgpos[targetid];
2057
4/4
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 15 times.
54 int firstbyte = ((!stricmp(par, "JSL")) ? 0x22 : 0x5C);
2058 54 int pcpos=snestopc(snespos);
2059
4/6
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 36 times.
54 if (/*pass==1 && */pcpos>=0 && pcpos<romlen_r && romdata_r[pcpos]==firstbyte)
2060 {
2061
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 ratsloc=ratsstart(orgpos)+8;
2062 18 freespaceorglen[targetid]=read2(ratsloc-4)+1;
2063
4/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
18 if (!freespacestatic[targetid] && pass==1) removerats(orgpos, freespacebyte[targetid]);
2064 }
2065
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
36 else if (ratsloc<0) ratsloc=0;
2066
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 write1((unsigned int)firstbyte);
2067
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 write3((unsigned int)num);
2068
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 36 times.
54 if (pass==2)
2069 {
2070
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 int start=ratsstart(num);
2071
3/4
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
18 if (start>=num || start<0)
2072 {
2073 asar_throw_error(2, error_type_block, error_id_autoclean_label_at_freespace_end);
2074 }
2075
2076
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 add_addr_to_line(addrToLinePos);
2077 }
2078 //freespaceorglen[targetid]=read2(ratsloc-4)+1;
2079 54 freespaceorgpos[targetid]=ratsloc;
2080 27 }
2081 else if (!stricmp(par, "dl"))
2082 {
2083 int orgpos=read3(snespos);
2084 int ratsloc=freespaceorgpos[targetid];
2085 int start=ratsstart(num);
2086 if (pass==1 && num>=0)
2087 {
2088 ratsloc=ratsstart(orgpos)+8;
2089 if (!freespacestatic[targetid]) removerats(orgpos, freespacebyte[targetid]);
2090 }
2091 else if (!ratsloc) ratsloc=0;
2092 if ((start==num || start<0) && pass==2)
2093 asar_throw_error(2, error_type_block, error_id_autoclean_label_at_freespace_end);
2094 write3((unsigned int)num);
2095 freespaceorgpos[targetid]=ratsloc;
2096 freespaceorglen[targetid]=read2(ratsloc-4)+1;
2097
2098 add_addr_to_line(addrToLinePos);
2099 }
2100 else asar_throw_error(0, error_type_block, error_id_broken_autoclean);
2101 54 }
2102 else if (pass==0) removerats((int)getnum(word[1]), default_freespacebyte);
2103 }
2104
5/6
✓ Branch 0 taken 1338 times.
✓ Branch 1 taken 222 times.
✓ Branch 2 taken 669 times.
✓ Branch 3 taken 669 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 780 times.
1560 else if (is1("freespacebyte"))
2105 {
2106 default_freespacebyte = getnum(word[1]);
2107 if (foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2108 }
2109
6/6
✓ Branch 0 taken 150 times.
✓ Branch 1 taken 1410 times.
✓ Branch 2 taken 75 times.
✓ Branch 3 taken 75 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 777 times.
1560 else if (is0("pushpc"))
2110 {
2111
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);
2112
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].arch=arch;
2113
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].snespos=snespos;
2114
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].snesstart=startpos;
2115
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].snesposreal=realsnespos;
2116
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].snesstartreal=realstartpos;
2117
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].freeid=freespaceid;
2118
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].freeex=freespaceextra;
2119
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 pushpc[pushpcnum].freest=freespacestart;
2120 6 pushpcnum++;
2121 6 snespos=(int)0xFFFFFFFF;
2122 6 startpos= (int)0xFFFFFFFF;
2123 6 realsnespos= (int)0xFFFFFFFF;
2124 6 realstartpos= (int)0xFFFFFFFF;
2125 }
2126
6/6
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 1410 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 72 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 774 times.
1554 else if (is0("pullpc"))
2127 {
2128
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);
2129 6 pushpcnum--;
2130 6 freespaceend();
2131
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);
2132
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 snespos=pushpc[pushpcnum].snespos;
2133
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 startpos=pushpc[pushpcnum].snesstart;
2134
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 realsnespos=pushpc[pushpcnum].snesposreal;
2135
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 realstartpos=pushpc[pushpcnum].snesstartreal;
2136
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 freespaceid=pushpc[pushpcnum].freeid;
2137
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 freespaceextra=pushpc[pushpcnum].freeex;
2138
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 freespacestart=pushpc[pushpcnum].freest;
2139 }
2140
6/6
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 1410 times.
✓ Branch 2 taken 69 times.
✓ Branch 3 taken 69 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 771 times.
1548 else if (is0("pushbase"))
2141 {
2142
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);
2143
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 basestack[basestacknum] = snespos;
2144 6 basestacknum++;
2145 }
2146
6/6
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 1410 times.
✓ Branch 2 taken 66 times.
✓ Branch 3 taken 66 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 768 times.
1542 else if (is0("pullbase"))
2147 {
2148
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);
2149 6 basestacknum--;
2150
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 snespos = basestack[basestacknum];
2151
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 startpos = basestack[basestacknum];
2152
2153
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (snespos != realstartpos)
2154 {
2155 6 optimizeforbank = -1;
2156 }
2157 }
2158
6/6
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 1410 times.
✓ Branch 2 taken 63 times.
✓ Branch 3 taken 63 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 762 times.
1536 else if (is0("pushns"))
2159 {
2160
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);
2161
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;
2162
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 for(int i = 0; i < namespace_list.count; i++)
2163 {
2164
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]);
2165 }
2166
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 pushns[pushnsnum].nested_namespaces = nested_namespaces;
2167 12 pushnsnum++;
2168
2169
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 namespace_list.reset();
2170
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 ns = "";
2171 12 nested_namespaces = false;
2172 }
2173
6/6
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 1410 times.
✓ Branch 2 taken 57 times.
✓ Branch 3 taken 57 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 756 times.
1524 else if (is0("pullns"))
2174 {
2175
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);
2176
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);
2177 12 pushnsnum--;
2178
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;
2179
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 nested_namespaces = pushns[pushnsnum].nested_namespaces;
2180
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 namespace_list.reset();
2181
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++)
2182 {
2183
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]);
2184 }
2185 }
2186
9/10
✓ Branch 0 taken 1338 times.
✓ Branch 1 taken 174 times.
✓ Branch 2 taken 1212 times.
✓ Branch 3 taken 126 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 1350 times.
✓ Branch 6 taken 36 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 81 times.
✓ Branch 9 taken 675 times.
1512 else if (is1("namespace") || is2("namespace"))
2187 {
2188
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);
2189 81 bool leave = false;
2190
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if (par)
2191 {
2192
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"))
2193 {
2194
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);
2195 24 leave = true;
2196 }
2197
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"))
2198 {
2199
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);
2200
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;
2201
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;
2202 }
2203 else
2204 {
2205
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);
2206
1/2
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
78 const char * tmpstr= safedequote(par);
2207
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);
2208
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 48 times.
78 if (!nested_namespaces)
2209 {
2210
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
30 namespace_list.reset();
2211 }
2212
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);
2213 }
2214 }
2215 else
2216 {
2217 leave = true;
2218 }
2219
2220
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 57 times.
81 if (leave)
2221 {
2222
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 if (nested_namespaces)
2223 {
2224
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
36 namespace_list.remove(namespace_list.count - 1);
2225 }
2226 else
2227 {
2228
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 namespace_list.reset();
2229 }
2230 }
2231
2232 // recompute ns
2233
1/2
✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
81 ns = "";
2234
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 162 times.
354 for (int i = 0; i < namespace_list.count; i++)
2235 {
2236
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];
2237
2/4
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
192 ns += STR"_";
2238 }
2239 }
2240
6/6
✓ Branch 0 taken 1212 times.
✓ Branch 1 taken 138 times.
✓ Branch 2 taken 606 times.
✓ Branch 3 taken 606 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 672 times.
1350 else if (is1("warnpc"))
2241 {
2242
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 unsigned int maxpos=getnum(par);
2243
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if ((unsigned int)snespos & 0xFF000000) asar_throw_error(0, error_type_block, error_id_warnpc_in_freespace);
2244
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if ((unsigned int)maxpos & 0xFF000000) asar_throw_error(0, error_type_block, error_id_warnpc_broken_param);
2245
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6 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.
6 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());
2246
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
6 if (warnxkas && (unsigned int)snespos == maxpos) asar_throw_warning(0, warning_id_xkas_warnpc_relaxed);
2247
1/10
✗ Branch 0 not taken.
✓ Branch 1 taken 6 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.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
6 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());
2248 }
2249
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"))
2250 {
2251
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 int rep = (int)getnum64(par);
2252
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);
2253
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 6 times.
24 if (rep<=1)
2254 {
2255
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 if(rep < 0){
2256
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");
2257 }
2258
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (emulatexkas)
2259 {
2260
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");
2261
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if (rep==0) rep=1;
2262
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 9 times.
15 if (rep<0) rep=0;
2263 18 repeatnext=rep;
2264 18 return;
2265 }
2266 }
2267
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");
2268 6 repeatnext=rep;
2269 }
2270 #ifdef SANDBOX
2271 else if (is("incsrc") || is("incbin") || is("table"))
2272 {
2273 asar_throw_error(0, error_type_block, error_id_command_disabled);
2274 }
2275 #endif
2276
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"))
2277 {
2278 309 string name;
2279
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, '\\')))
2280 asar_throw_warning(0, warning_id_xkas_incsrc_relative);
2281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 618 times.
618 if (strchr(par, '\\'))
2282 {
2283 if (emulatexkas)
2284 {
2285 asar_throw_warning(0, warning_id_feature_deprecated, "xkas style paths", "convert paths to crossplatform style");
2286 for (int i=0;par[i];i++)
2287 {
2288 if (par[i]=='\\') par[i]='/';//let's just hope nobody finds I could just enable this for everything.
2289 }
2290 }
2291 #ifdef _WIN32
2292 else asar_throw_warning(0, warning_id_feature_deprecated, "windows specific paths", "convert paths to crossplatform style");
2293 #endif
2294 }
2295
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);
2296
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);
2297
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 498 times.
618 assemblefile(name, false);
2298 618 }
2299
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"))
2300 {
2301
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);
2302 36 int len;
2303 36 int start=0;
2304 36 int end=0;
2305
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 30 times.
72 if (strqchr(par, ':'))
2306 {
2307 42 char * lengths=strqchr(par, ':');
2308 42 *lengths=0;
2309 42 lengths++;
2310
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, ".."))
2311 {
2312 // new style ranges
2313
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 char* split = strqpstr(lengths, "..");
2314
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
36 string start_str(lengths, split-lengths);
2315
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 start = getnum(start_str);
2316
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);
2317
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
30 string end_str(split+2);
2318
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 end = getnum(end_str);
2319
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);
2320 42 }
2321 else
2322 {
2323
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");
2324
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);
2325
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(*lengths=='(') {
2326
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 char* tmp = strqpchr(lengths, '-');
2327
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);
2328
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));
2329 if (foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2330 lengths = tmp;
2331 } else {
2332 start=(int)strtoul(lengths, &lengths, 16);
2333 }
2334 if (*lengths!='-') asar_throw_error(0, error_type_block, error_id_broken_incbin);
2335 lengths++;
2336 if(*lengths=='(') {
2337 char* tmp = strchr(lengths, '\0');
2338 if(*(tmp-1)!=')') asar_throw_error(0, error_type_block, error_id_broken_incbin);
2339 end = (int)getnum64(string(lengths+1, tmp-1-lengths-1));
2340 if (foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2341 // no need to check end-of-string here
2342 } else {
2343 end=(int)strtoul(lengths, &lengths, 16);
2344 if (*lengths) asar_throw_error(0, error_type_block, error_id_broken_incbin);
2345 }
2346 }
2347 }
2348 27 string name;
2349
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, '\\')))
2350 asar_throw_warning(0, warning_id_xkas_incsrc_relative);
2351
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 48 times.
54 if (strchr(par, '\\'))
2352 {
2353
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (emulatexkas)
2354 {
2355
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");
2356
2/2
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 6 times.
120 for (int i=0;par[i];i++)
2357 {
2358
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.
2359 }
2360 }
2361 #ifdef _WIN32
2362 else asar_throw_warning(0, warning_id_feature_deprecated, "windows specific paths", "convert paths to crossplatform style");
2363 #endif
2364 }
2365
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);
2366
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);
2367 27 char * data;//I couldn't find a way to get this into an autoptr
2368
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());
2369
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
48 autoptr<char*> datacopy=data;
2370
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
48 if (!end) end=len;
2371
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());
2372
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());
2373
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 42 times.
48 if (numwords==4)
2374 {
2375
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");
2376
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!confirmname(word[3]))
2377 {
2378 int pos=(int)getnum(word[3]);
2379 if (foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2380 int offset=snestopc(pos);
2381 if (offset + end - start > 0xFFFFFF) asar_throw_error(0, error_type_block, error_id_16mb_rom_limit);
2382 if (offset+end-start>romlen) romlen=offset+end-start;
2383 if (pass==2)
2384 {
2385 writeromdata(offset, data+start, end-start);
2386 add_addr_to_line(pos);
2387 }
2388 }
2389 else
2390 {
2391 int pos;
2392
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 if (pass==0)
2393 {
2394
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);
2395
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 pos=getpcfreespace(end-start, false, true, false);
2396
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());
2397
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 int foundfreespaceid=getfreespaceid();
2398 2 freespacepos[foundfreespaceid]=pctosnes(pos)|(/*fastrom?0x800000:*/0x000000)|(foundfreespaceid <<24);
2399
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]);
2400
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 writeromdata_bytes(pos, 0xFF, end-start);
2401 }
2402
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 if (pass==1)
2403 {
2404
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 getfreespaceid();//nothing to do here, but we want to tick the counter
2405 }
2406
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 if (pass==2)
2407 {
2408
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 int foundfreespaceid =getfreespaceid();
2409
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);
2410
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 writeromdata(snestopc(freespacepos[foundfreespaceid]&0xFFFFFF), data+start, end-start);
2411
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 add_addr_to_line((freespacepos[foundfreespaceid]&0xFFFFFF) - 8);
2412 2 freespaceuse+=8+end-start;
2413 }
2414 }
2415 }
2416 else
2417 {
2418
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]);
2419
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 add_addr_to_line(addrToLinePos);
2420 }
2421 54 }
2422
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"))
2423 {
2424
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);
2425
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);
2426
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);
2427 int amount;
2428
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
228 if(numwords > 2)
2429 {
2430 int alignment = getnum64(word[2]);
2431 if(foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2432 int offset = 0;
2433 if(numwords==5)
2434 {
2435 offset = getnum64(word[4]);
2436 if(foundlabel && !foundlabel_static) asar_throw_error(0, error_type_block, error_id_no_labels_here);
2437 }
2438 if(alignment > 0x800000) asar_throw_error(0, error_type_block, error_id_alignment_too_big);
2439 if(alignment < 1) asar_throw_error(0, error_type_block, error_id_alignment_too_small);
2440 if(alignment & (alignment-1)) asar_throw_error(0, error_type_block, error_id_invalid_alignment);
2441 // i just guessed this formula but it seems to work
2442 amount = (alignment - ((snespos - offset) & (alignment-1))) & (alignment-1);
2443 }
2444 else
2445 {
2446
1/2
✓ Branch 0 taken 228 times.
✗ Branch 1 not taken.
228 amount = (int)getnum64(par);
2447
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);
2448 }
2449
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 30 times.
222 if(is("skip")) step(amount);
2450 else
2451 {
2452
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]);
2453
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 add_addr_to_line(addrToLinePos);
2454 }
2455
2456 }
2457
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"))
2458 {
2459 cleartable();
2460 }
2461
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"))
2462 {
2463
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 tablestack.append(table);
2464 }
2465
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"))
2466 {
2467
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);
2468
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 table=tablestack[tablestack.count-1];
2469 6 tablestack.remove(tablestack.count-1);
2470 }
2471
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"))
2472 {
2473 asar_throw_warning(0, warning_id_feature_deprecated, "table command", "Use direct character assignments. For example: 'a' = $61");
2474 bool fliporder=false;
2475 if(0);
2476 else if (striend(par, ",ltr")) { itrim(par, "", ",ltr"); }
2477 else if (striend(par, ",rtl")) { itrim(par, "", ",rtl"); fliporder=true; }
2478 string name=STR safedequote(par);
2479 autoptr<char*> tablecontents=readfile(name, thisfilename);
2480 if (!tablecontents) asar_throw_error(0, error_type_block, vfile_error_to_error_id(asar_get_last_io_error()), name.data());
2481 autoptr<char**> tablelines=split(tablecontents, "\n");
2482 for (int i=0;i<256;i++) table.table[i]=(unsigned int)(((numopcodes+read2(0x00FFDE)+i)*0x26594131)|0x40028020);
2483 //garbage value so people will notice they're doing it wrong (for bonus points: figure out what 0x26594131 is)
2484 for (int i=0;tablelines[i];i++)
2485 {
2486 string tableline=tablelines[i];
2487 if (!*tableline) continue;
2488 if (strlen(tableline) < 4 || strlen(tableline) & 1 || strlen(tableline) > 10) asar_throw_error(0, error_type_block, error_id_invalid_table_file, i+1);
2489 if (!fliporder)
2490 {
2491 if (tableline[3]=='x' || tableline[3]=='X') asar_throw_error(0, error_type_block, error_id_invalid_table_file, i+1);
2492 char * end;
2493 table.table[(unsigned char)tableline[0]]=(unsigned int)strtol(tableline.data()+2, &end, 16);
2494 if (*end) asar_throw_error(0, error_type_block, error_id_invalid_table_file, i+1);
2495 }
2496 else
2497 {
2498 if (tableline[1]=='x' || tableline[1]=='X') asar_throw_error(0, error_type_block, error_id_invalid_table_file, i+1);
2499 char * eq;
2500 unsigned int val=(unsigned int)strtol(tableline, &eq, 16);
2501 if (eq[0]!='=' || eq[2]) asar_throw_error(0, error_type_block, error_id_invalid_table_file, i+1);
2502 table.table[(unsigned char)eq[1]]=val;
2503 }
2504 }
2505 }
2506
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"))
2507 {
2508 //if (!pass)
2509 //{
2510
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);
2511
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);
2512
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
30 string line=word[1];
2513
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);
2514 30 char * startpar=strqchr(line.data(), '(');
2515
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);
2516 30 *startpar=0;
2517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
30 startpar++;
2518
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);
2519 30 char * endpar=strqchr(startpar, ')');
2520 //confirmqpar requires that all parentheses are matched, and a starting one exists, therefore it is harmless to not check for nulls
2521
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);
2522 30 *endpar=0;
2523
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 createuserfunc(line, startpar, word[3]);
2524 //}
2525 30 }
2526
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"))
2527 {
2528
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 string out = handle_print(par);
2529
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 32 times.
96 if (pass!=2) return;
2530
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 print(out);
2531
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 32 times.
96 }
2532
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"))
2533 {
2534 if(0);
2535 else if (!stricmp(par, "bytes")) bytes=0;
2536 else if (!stricmp(par, "freespaceuse")) freespaceuse=0;
2537 else asar_throw_error(2, error_type_block, error_id_unknown_variable);
2538 }
2539
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"))
2540 {
2541 9 int len = 0;
2542
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (is("padbyte")) len=1;
2543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (is("padword")) len=2;
2544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (is("padlong")) len=3;
2545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (is("paddword")) len=4;
2546
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 unsigned int val=getnum(par);
2547
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.");
2548
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 18 times.
234 for (int i=0;i<12;i+=len)
2549 {
2550 108 unsigned int tmpval=val;
2551
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 216 times.
432 for (int j=0;j<len;j++)
2552 {
2553 216 padbyte[i+j]=(unsigned char)tmpval;
2554 216 tmpval>>=8;
2555 }
2556 }
2557 }
2558
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"))
2559 {
2560
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);
2561
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 int num=(int)getnum(par);
2562
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());
2563
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 if (num>realsnespos)
2564 {
2565 6 int end=snestopc(num);
2566 6 int start=snestopc(realsnespos);
2567 12 int len=end-start;
2568
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]);
2569
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 add_addr_to_line(addrToLinePos);
2570 }
2571 }
2572
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"))
2573 {
2574 18 int len = 0;
2575
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
36 if (is("fillbyte")) len=1;
2576
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 30 times.
36 if (is("fillword")) len=2;
2577
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 30 times.
36 if (is("filllong")) len=3;
2578
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 30 times.
36 if (is("filldword")) len=4;
2579
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 unsigned int val= getnum(par);
2580
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");
2581
2/2
✓ Branch 0 taken 294 times.
✓ Branch 1 taken 36 times.
330 for (int i=0;i<12;i+=len)
2582 {
2583 147 unsigned int tmpval=val;
2584
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 294 times.
726 for (int j=0;j<len;j++)
2585 {
2586 432 fillbyte[i+j]=(unsigned char)tmpval;
2587 432 tmpval>>=8;
2588 }
2589 }
2590 }
2591
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"))
2592 {
2593
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);
2594
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);
2595
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; }
2596
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; }
2597
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; }
2598
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")) {
2599
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");
2600 12 arch=arch_spc700;
2601 12 mapper=norom;
2602 12 mapper_set = false;
2603
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!force_checksum_fix)
2604 12 checksum_fix_enabled = false;
2605 12 return;
2606 }
2607
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; }
2608 }
2609
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"))
2610 {
2611 bool val = false;
2612 if(0);
2613 else if (!stricmp(word[2], "on")) val=true;
2614 else if (!stricmp(word[2], "off")) val=false;
2615 else asar_throw_error(0, error_type_block, error_id_invalid_math);
2616 if(0);
2617 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"); }
2618 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"); }
2619 else asar_throw_error(0, error_type_block, error_id_invalid_math);
2620 }
2621
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"))
2622 {
2623 bool val = false;
2624 if(0);
2625 else if (!stricmp(word[2], "on")) val=true;
2626 else if (!stricmp(word[2], "off")) val=false;
2627 else asar_throw_error(0, error_type_block, error_id_invalid_warn);
2628 if(0);
2629 else if (!stricmp(word[1], "xkas")) {
2630 asar_throw_warning(0, warning_id_feature_deprecated, "xkas compatibility warning", "If you worry about xkas I worry about you. Just stop.");
2631 warnxkas=val;
2632 }
2633 else asar_throw_error(0, error_type_block, error_id_invalid_warn);
2634 }
2635
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"))
2636 {
2637
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.");
2638 //removed due to causing more trouble than it's worth.
2639 //if (emulatexkas) warn0("Convert the patch to native Asar format instead of making an Asar-only xkas patch.");
2640 //if (mapper==lorom || mapper==hirom) fastrom=true;
2641 //else error(0, "Can't use fastrom in this mapper.");
2642 }
2643
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("}")) {}
2644 else
2645 {
2646
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (isspecialline)
2647 {
2648 asar_throw_warning(0, warning_id_unrecognized_special_command);
2649 }
2650 else
2651 {
2652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 asar_throw_error(1, error_type_block, error_id_unknown_command);
2653 }
2654 }
2655
2656
6/6
✓ Branch 0 taken 325210 times.
✓ Branch 1 taken 111690 times.
✓ Branch 2 taken 325210 times.
✓ Branch 3 taken 111690 times.
✓ Branch 4 taken 325210 times.
✓ Branch 5 taken 111690 times.
1099154 }
2657
2658 7408 bool assemblemapper(char** word, int numwords)
2659 {
2660 7408 auto previous_mapper = mapper;
2661 if(0);
2662
6/6
✓ Branch 0 taken 674 times.
✓ Branch 1 taken 6734 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 602 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 3668 times.
7408 else if (is0("lorom"))
2663 {
2664 //this also makes xkas set snespos to $008000 for some reason
2665 72 mapper=lorom;
2666 }
2667
6/6
✓ Branch 0 taken 602 times.
✓ Branch 1 taken 6734 times.
✓ Branch 2 taken 301 times.
✓ Branch 3 taken 301 times.
✓ Branch 4 taken 7 times.
✓ Branch 5 taken 3661 times.
7336 else if (is0("hirom"))
2668 {
2669 //xkas makes this point to $C00000
2670 14 mapper=hirom;
2671 }
2672
6/6
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 6734 times.
✓ Branch 2 taken 294 times.
✓ Branch 3 taken 294 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3658 times.
7322 else if (is0("exlorom"))
2673 {
2674 6 mapper = exlorom;
2675 }
2676
6/6
✓ Branch 0 taken 582 times.
✓ Branch 1 taken 6734 times.
✓ Branch 2 taken 291 times.
✓ Branch 3 taken 291 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3655 times.
7316 else if (is0("exhirom"))
2677 {
2678 6 mapper=exhirom;
2679 }
2680
6/6
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 6734 times.
✓ Branch 2 taken 288 times.
✓ Branch 3 taken 288 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 3649 times.
7310 else if (is0("sfxrom"))
2681 {
2682 12 mapper=sfxrom;
2683 //fastrom=false;
2684 }
2685
6/6
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 6734 times.
✓ Branch 2 taken 282 times.
✓ Branch 3 taken 282 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 3640 times.
7298 else if (is0("norom"))
2686 {
2687 //$000000 would be the best snespos for this, but I don't care
2688 18 mapper=norom;
2689 //fastrom=false;
2690
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!force_checksum_fix)
2691 18 checksum_fix_enabled = false;//we don't know where the header is, so don't set the checksum
2692 }
2693
6/6
✓ Branch 0 taken 546 times.
✓ Branch 1 taken 6734 times.
✓ Branch 2 taken 273 times.
✓ Branch 3 taken 273 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3637 times.
7280 else if (is0("fullsa1rom"))
2694 {
2695 6 mapper=bigsa1rom;
2696 //fastrom=false;
2697 }
2698
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 7250 times.
7274 else if (is("sa1rom"))
2699 {
2700 //fastrom=false;
2701
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 6 times.
24 if (par)
2702 {
2703
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);
2704
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
27 if (!is_digit(par[0]) || par[1]!=',' ||
2705
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]!=',' ||
2706
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]!=',' ||
2707
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);
2708 9 int len;
2709
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
18 autoptr<char**> pars=qpsplit(par, ",", &len);
2710
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);
2711 18 sa1banks[0]=(par[0]-'0')<<20;
2712 18 sa1banks[1]=(par[2]-'0')<<20;
2713 18 sa1banks[4]=(par[4]-'0')<<20;
2714 18 sa1banks[5]=(par[6]-'0')<<20;
2715 18 }
2716 else
2717 {
2718 6 sa1banks[0]=0<<20;
2719 6 sa1banks[1]=1<<20;
2720 6 sa1banks[4]=2<<20;
2721 6 sa1banks[5]=3<<20;
2722 }
2723 24 mapper=sa1rom;
2724 }
2725
4/6
✓ Branch 0 taken 534 times.
✓ Branch 1 taken 6716 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 534 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3625 times.
7250 else if (is0("header"))
2726 {
2727 //headers are detected elsewhere; ignoring for familiarity
2728 asar_throw_warning(0, warning_id_feature_deprecated, "header", "Remove command, unnecessary.");
2729 }
2730 3625 else return false;
2731
2732
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);
2733
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 66 times.
158 if(!mapper_set){
2734 92 mapper_set = true;
2735
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 33 times.
66 }else if(previous_mapper != mapper){
2736 54 asar_throw_warning(1, warning_id_mapper_already_set);
2737 }
2738 79 return true;
2739 }
2740