asar coverage - build #187


src/asar/
File: src/asar/assembleblock.cpp
Date: 2024-01-30 03:54:04
Lines:
1378/1644
83.8%
Functions:
38/41
92.7%
Branches:
2058/3802
54.1%

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