asar coverage - build #245


src/asar/
File: src/asar/assembleblock.cpp
Date: 2025-02-21 04:50:03
Lines:
1386/1652
83.9%
Functions:
38/41
92.7%
Branches:
2070/3822
54.2%

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