| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#include "asar.h" |
| 2 |
|
|
#include "assembleblock.h" |
| 3 |
|
|
#include "asar_math.h" |
| 4 |
|
|
|
| 5 |
|
|
#define write1 write1_pick |
| 6 |
|
|
|
| 7 |
|
2106 |
void asinit_65816() |
| 8 |
|
|
{ |
| 9 |
|
2106 |
} |
| 10 |
|
|
|
| 11 |
|
1968 |
void asend_65816() |
| 12 |
|
|
{ |
| 13 |
|
1968 |
} |
| 14 |
|
|
|
| 15 |
|
|
// like an address mode, but without a specific width |
| 16 |
|
|
enum class addr_kind { |
| 17 |
|
|
abs, // $00 |
| 18 |
|
|
x, // $00,x |
| 19 |
|
|
y, // $00,y |
| 20 |
|
|
ind, // ($00) |
| 21 |
|
|
lind, // [$00] |
| 22 |
|
|
xind, // ($00,x) |
| 23 |
|
|
indy, // ($00),y |
| 24 |
|
|
lindy, // [$00],y |
| 25 |
|
|
s, // $00,s |
| 26 |
|
|
sy, // ($00,s),y |
| 27 |
|
|
imp, // implied (no argument) |
| 28 |
|
|
a, // 'A' as argument |
| 29 |
|
|
imm, // #$00 |
| 30 |
|
|
}; |
| 31 |
|
|
|
| 32 |
|
5787 |
struct insn_context { |
| 33 |
|
|
string arg; |
| 34 |
|
|
char orig_insn[3]; // oops i didn't end up using this... could be useful in some error messages maybe |
| 35 |
|
|
char modifier; |
| 36 |
|
|
}; |
| 37 |
|
|
|
| 38 |
|
|
// checks for matching characters at the start of haystack, ignoring spaces. |
| 39 |
|
|
// returns index into haystack right after the match |
| 40 |
|
|
template<char... chars> |
| 41 |
|
58074 |
int64_t startmatch(const string& haystack) { |
| 42 |
|
|
static const char needle[] = {chars...}; |
| 43 |
|
29058 |
size_t haystack_i = 0; |
| 44 |
2/2
✓ Branch 0 taken 29037 times.
✓ Branch 1 taken 2415 times.
|
62904 |
for(size_t i = 0; i < sizeof...(chars); i++) { |
| 45 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29037 times.
|
58074 |
while(haystack[haystack_i] == ' ') haystack_i++; |
| 46 |
2/2
✓ Branch 0 taken 14526 times.
✓ Branch 1 taken 14511 times.
|
58074 |
if(needle[i] != to_lower(haystack[haystack_i++])) return -1; |
| 47 |
|
|
} |
| 48 |
|
4830 |
return haystack_i; |
| 49 |
|
|
} |
| 50 |
|
|
|
| 51 |
|
|
// checks for matching characters at the end of haystack, ignoring spaces. |
| 52 |
|
|
// returns index into haystack right before the match |
| 53 |
|
|
template<char... chars> |
| 54 |
1/2
✓ Branch 0 taken 12105 times.
✗ Branch 1 not taken.
|
48456 |
int64_t endmatch(const string& haystack) { |
| 55 |
|
|
static const char needle[] = {chars...}; |
| 56 |
|
48456 |
int64_t haystack_i = haystack.length()-1; |
| 57 |
2/2
✓ Branch 0 taken 28296 times.
✓ Branch 1 taken 2898 times.
|
62388 |
for(int64_t i = sizeof...(chars)-1; i >= 0; i--) { |
| 58 |
4/6
✓ Branch 0 taken 19458 times.
✓ Branch 1 taken 8838 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19458 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 14157 times.
|
56592 |
while(haystack_i >= 0 && haystack[haystack_i] == ' ') haystack_i--; |
| 59 |
6/6
✓ Branch 0 taken 19458 times.
✓ Branch 1 taken 8838 times.
✓ Branch 2 taken 9738 times.
✓ Branch 3 taken 9720 times.
✓ Branch 4 taken 10674 times.
✓ Branch 5 taken 3483 times.
|
56592 |
if(haystack_i < 0 || needle[i] != to_lower(haystack[haystack_i--])) return -1; |
| 60 |
|
|
} |
| 61 |
|
5796 |
return haystack_i+1; |
| 62 |
|
|
} |
| 63 |
|
|
|
| 64 |
|
|
/* |
| 65 |
|
|
* Parses the address kind from an argument, given a list of allowed address kinds. |
| 66 |
|
|
* Throws "invalid address mode" if the argument does not match any kinds. |
| 67 |
|
|
*/ |
| 68 |
|
|
// i still don't like this function... |
| 69 |
|
|
template<addr_kind... allowed_kinds> |
| 70 |
1/2
✓ Branch 0 taken 4824 times.
✗ Branch 1 not taken.
|
21690 |
std::pair<addr_kind, string> parse_addr_kind(insn_context& arg) { |
| 71 |
|
10854 |
int64_t start_i = 0, end_i = arg.arg.length(); |
| 72 |
|
|
// If this addressing kind is allowed, return it, along with a trimmed version of the string. |
| 73 |
|
|
#define RETURN_IF_ALLOWED(kind) \ |
| 74 |
|
|
if constexpr(((allowed_kinds == addr_kind::kind) || ...)) { \ |
| 75 |
|
|
string out(arg.arg.data() + start_i, end_i - start_i); \ |
| 76 |
|
|
return std::make_pair(addr_kind::kind, out); \ |
| 77 |
|
|
} |
| 78 |
2/2
✓ Branch 0 taken 1425 times.
✓ Branch 1 taken 9420 times.
|
21690 |
if((start_i = startmatch<'#'>(arg.arg)) >= 0) { |
| 79 |
2/4
✓ Branch 0 taken 714 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 714 times.
✗ Branch 3 not taken.
|
5736 |
RETURN_IF_ALLOWED(imm); |
| 80 |
|
✗ |
asar_throw_error(1, error_type_block, error_id_bad_addr_mode); |
| 81 |
|
|
} |
| 82 |
2/2
✓ Branch 0 taken 648 times.
✓ Branch 1 taken 8772 times.
|
18840 |
if((start_i = startmatch<'('>(arg.arg)) >= 0) { |
| 83 |
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 504 times.
|
1296 |
if((end_i = endmatch<',', 's', ')', ',', 'y'>(arg.arg)) >= 0) { |
| 84 |
2/4
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
|
576 |
RETURN_IF_ALLOWED(sy); |
| 85 |
|
✗ |
asar_throw_error(1, error_type_block, error_id_bad_addr_mode); |
| 86 |
|
|
} |
| 87 |
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 360 times.
|
1008 |
if((end_i = endmatch<')', ',', 'y'>(arg.arg)) >= 0) { |
| 88 |
2/4
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
|
576 |
RETURN_IF_ALLOWED(indy); |
| 89 |
|
✗ |
asar_throw_error(1, error_type_block, error_id_bad_addr_mode); |
| 90 |
|
|
} |
| 91 |
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 180 times.
|
720 |
if((end_i = endmatch<',', 'x', ')'>(arg.arg)) >= 0) { |
| 92 |
2/4
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
✗ Branch 3 not taken.
|
720 |
RETURN_IF_ALLOWED(xind); |
| 93 |
|
✗ |
asar_throw_error(1, error_type_block, error_id_bad_addr_mode); |
| 94 |
|
|
} |
| 95 |
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
|
360 |
if((end_i = endmatch<')'>(arg.arg)) >= 0) { |
| 96 |
2/4
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
✗ Branch 3 not taken.
|
738 |
RETURN_IF_ALLOWED(ind); |
| 97 |
|
✗ |
asar_throw_warning(1, warning_id_assuming_address_mode, "($00)", "$00", " (if this was intentional, add a +0 after the parentheses.)"); |
| 98 |
|
|
} |
| 99 |
|
|
} |
| 100 |
2/2
✓ Branch 0 taken 342 times.
✓ Branch 1 taken 8430 times.
|
17544 |
if((start_i = startmatch<'['>(arg.arg)) >= 0) { |
| 101 |
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 198 times.
|
684 |
if((end_i = endmatch<']', ',', 'y'>(arg.arg)) >= 0) { |
| 102 |
2/4
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
|
576 |
RETURN_IF_ALLOWED(lindy); |
| 103 |
|
✗ |
asar_throw_error(1, error_type_block, error_id_bad_addr_mode); |
| 104 |
|
|
} |
| 105 |
1/2
✓ Branch 0 taken 198 times.
✗ Branch 1 not taken.
|
396 |
if((end_i = endmatch<']'>(arg.arg)) >= 0) { |
| 106 |
2/4
✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 99 times.
✗ Branch 3 not taken.
|
792 |
RETURN_IF_ALLOWED(lind); |
| 107 |
|
✗ |
asar_throw_error(1, error_type_block, error_id_bad_addr_mode); |
| 108 |
|
|
} |
| 109 |
|
|
} |
| 110 |
|
8436 |
start_i = 0; |
| 111 |
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6900 times.
|
16860 |
if((end_i = endmatch<',', 'x'>(arg.arg)) >= 0) { |
| 112 |
2/4
✓ Branch 0 taken 765 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 765 times.
✗ Branch 3 not taken.
|
6120 |
RETURN_IF_ALLOWED(x); |
| 113 |
|
✗ |
asar_throw_error(1, error_type_block, error_id_bad_addr_mode); |
| 114 |
|
|
} |
| 115 |
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 6666 times.
|
13800 |
if((end_i = endmatch<',', 'y'>(arg.arg)) >= 0) { |
| 116 |
2/4
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 117 times.
✗ Branch 3 not taken.
|
936 |
RETURN_IF_ALLOWED(y); |
| 117 |
|
✗ |
asar_throw_error(1, error_type_block, error_id_bad_addr_mode); |
| 118 |
|
|
} |
| 119 |
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 6522 times.
|
13332 |
if((end_i = endmatch<',', 's'>(arg.arg)) >= 0) { |
| 120 |
2/4
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
|
576 |
RETURN_IF_ALLOWED(s); |
| 121 |
|
✗ |
asar_throw_error(1, error_type_block, error_id_bad_addr_mode); |
| 122 |
|
|
} |
| 123 |
|
|
// hoping that by now, something would have stripped whitespace lol |
| 124 |
2/2
✓ Branch 0 taken 2934 times.
✓ Branch 1 taken 3588 times.
|
13044 |
if(arg.arg.length() == 0) { |
| 125 |
2/4
✓ Branch 0 taken 1467 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1467 times.
✗ Branch 3 not taken.
|
11736 |
RETURN_IF_ALLOWED(imp); |
| 126 |
|
✗ |
asar_throw_error(1, error_type_block, error_id_bad_addr_mode); |
| 127 |
|
|
} |
| 128 |
6/6
✓ Branch 0 taken 3570 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 108 times.
✓ Branch 3 taken 3462 times.
✓ Branch 4 taken 63 times.
✓ Branch 5 taken 1734 times.
|
7176 |
if(arg.arg == "a" || arg.arg == "A") { |
| 129 |
2/4
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
✗ Branch 3 not taken.
|
432 |
RETURN_IF_ALLOWED(a); |
| 130 |
|
|
// todo: some hint for "don't name your label "a" "? |
| 131 |
|
36 |
asar_throw_error(1, error_type_block, error_id_bad_addr_mode); |
| 132 |
|
|
} |
| 133 |
|
|
if constexpr(((allowed_kinds == addr_kind::abs) || ...)) { |
| 134 |
1/2
✓ Branch 0 taken 1734 times.
✗ Branch 1 not taken.
|
7476 |
return std::make_pair(addr_kind::abs, arg.arg); |
| 135 |
|
|
} |
| 136 |
|
✗ |
asar_throw_error(1, error_type_block, error_id_bad_addr_mode); |
| 137 |
|
|
#undef RETURN_IF_ALLOWED |
| 138 |
|
|
// clang doesn't know that asar_throw_error is noreturn in this case... :( |
| 139 |
|
|
// we don't really have anything good to return either tho |
| 140 |
|
✗ |
__builtin_unreachable(); |
| 141 |
|
|
} |
| 142 |
|
|
|
| 143 |
|
✗ |
const char* format_valid_widths(int min, int max) { |
| 144 |
|
✗ |
if(min == 1) { |
| 145 |
|
✗ |
if(max == 1) return "only 8-bit"; |
| 146 |
|
✗ |
if(max == 2) return "only 8-bit or 16-bit"; |
| 147 |
|
✗ |
if(max == 3) return "any width"; // shouldn't actually happen lol |
| 148 |
|
✗ |
} else if(min == 2) { |
| 149 |
|
✗ |
if(max == 2) return "only 16-bit"; |
| 150 |
|
✗ |
if(max == 3) return "only 16-bit or 24-bit"; |
| 151 |
|
✗ |
} else if(min == 3) { |
| 152 |
|
✗ |
return "only 24-bit"; |
| 153 |
|
|
} |
| 154 |
|
✗ |
return "???"; |
| 155 |
|
|
} |
| 156 |
|
|
|
| 157 |
|
7305 |
int get_real_len(int min_len, int max_len, char modifier, int arg_min_len) { |
| 158 |
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 4965 times.
|
7305 |
if(modifier != 0) { |
| 159 |
|
2340 |
int given_len = getlenfromchar(modifier); |
| 160 |
2/4
✓ Branch 0 taken 2322 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2322 times.
|
2322 |
if(given_len < min_len || given_len > max_len) |
| 161 |
|
✗ |
asar_throw_error(2, error_type_block, error_id_bad_access_width, format_valid_widths(min_len, max_len), given_len*8); |
| 162 |
|
2322 |
return given_len; |
| 163 |
|
|
} else { |
| 164 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4965 times.
|
4965 |
if(arg_min_len > max_len) { |
| 165 |
|
✗ |
asar_throw_error(2, error_type_block, error_id_bad_access_width, format_valid_widths(min_len, max_len), arg_min_len*8); |
| 166 |
|
|
} |
| 167 |
|
|
// todo warn about widening when dpbase != 0 |
| 168 |
|
4965 |
return std::max(arg_min_len, min_len); |
| 169 |
|
|
} |
| 170 |
|
|
} |
| 171 |
|
|
|
| 172 |
|
1113 |
void check_implicit_immediate(char modifier, const string& target) { |
| 173 |
2/2
✓ Branch 0 taken 555 times.
✓ Branch 1 taken 558 times.
|
1113 |
if(modifier != 0) return; |
| 174 |
2/2
✓ Branch 0 taken 285 times.
✓ Branch 1 taken 288 times.
|
573 |
if(is_hex_constant(target.data())) return; |
| 175 |
|
87 |
asar_throw_warning(2, warning_id_implicitly_sized_immediate); |
| 176 |
|
|
} |
| 177 |
|
|
|
| 178 |
|
|
template<int base, bool allow_imm = true> |
| 179 |
|
9006 |
void the8(insn_context& arg) { |
| 180 |
|
|
using K = addr_kind; |
| 181 |
1/2
✓ Branch 0 taken 2253 times.
✗ Branch 1 not taken.
|
9006 |
auto parse_result = parse_addr_kind<K::xind, K::s, K::abs, K::lind, K::imm, K::indy, K::ind, K::sy, K::x, K::y, K::lindy>(arg); |
| 182 |
|
9006 |
addr_kind kind = parse_result.first; |
| 183 |
|
4506 |
int min_len = 0, max_len = 4; |
| 184 |
4/4
✓ Branch 0 taken 1501 times.
✓ Branch 1 taken 3002 times.
✓ Branch 2 taken 1489 times.
✓ Branch 3 taken 12 times.
|
9006 |
int64_t the_num = pass == 2 ? getnum(parse_result.second) : 0; |
| 185 |
1/2
✓ Branch 0 taken 4491 times.
✗ Branch 1 not taken.
|
8982 |
int arg_min_len = getlen(parse_result.second, kind == K::imm); |
| 186 |
14/14
✓ Branch 0 taken 2175 times.
✓ Branch 1 taken 2316 times.
✓ Branch 2 taken 2103 times.
✓ Branch 3 taken 72 times.
✓ Branch 4 taken 2031 times.
✓ Branch 5 taken 72 times.
✓ Branch 6 taken 1959 times.
✓ Branch 7 taken 72 times.
✓ Branch 8 taken 1887 times.
✓ Branch 9 taken 72 times.
✓ Branch 10 taken 1815 times.
✓ Branch 11 taken 72 times.
✓ Branch 12 taken 72 times.
✓ Branch 13 taken 1743 times.
|
8982 |
if(kind == K::xind || kind == K::s || kind == K::sy || kind == K::indy || kind == K::ind || kind == K::lind || kind == K::lindy) min_len = max_len = 1; |
| 187 |
2/2
✓ Branch 0 taken 861 times.
✓ Branch 1 taken 882 times.
|
3486 |
else if(kind == K::abs) min_len = 1, max_len = 3; |
| 188 |
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 450 times.
|
1764 |
else if(kind == K::x) min_len = 1, max_len = 3; |
| 189 |
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 378 times.
|
900 |
else if(kind == K::y) min_len = max_len = 2; |
| 190 |
1/2
✓ Branch 0 taken 378 times.
✗ Branch 1 not taken.
|
756 |
else if(kind == K::imm) min_len = 1, max_len = 2; |
| 191 |
3/4
✓ Branch 0 taken 753 times.
✓ Branch 1 taken 3738 times.
✓ Branch 2 taken 753 times.
✗ Branch 3 not taken.
|
8982 |
if(kind == K::imm) check_implicit_immediate(arg.modifier, parse_result.second); |
| 192 |
2/2
✓ Branch 0 taken 4473 times.
✓ Branch 1 taken 18 times.
|
8982 |
int real_len = get_real_len(min_len, max_len, arg.modifier, arg_min_len); |
| 193 |
|
4476 |
int opcode_offset = 0; |
| 194 |
2/2
✓ Branch 0 taken 1965 times.
✓ Branch 1 taken 2508 times.
|
8946 |
if(real_len == 1) { |
| 195 |
2/2
✓ Branch 0 taken 981 times.
✓ Branch 1 taken 984 times.
|
3930 |
if(kind == K::xind) opcode_offset = 0x1; |
| 196 |
2/2
✓ Branch 0 taken 909 times.
✓ Branch 1 taken 984 times.
|
3786 |
if(kind == K::s) opcode_offset = 0x3; |
| 197 |
2/2
✓ Branch 0 taken 909 times.
✓ Branch 1 taken 984 times.
|
3786 |
if(kind == K::abs) opcode_offset = 0x5; |
| 198 |
2/2
✓ Branch 0 taken 801 times.
✓ Branch 1 taken 984 times.
|
3570 |
if(kind == K::lind) opcode_offset = 0x7; |
| 199 |
2/2
✓ Branch 0 taken 912 times.
✓ Branch 1 taken 981 times.
|
3786 |
if(kind == K::imm) opcode_offset = 0x9; |
| 200 |
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 984 times.
|
3624 |
if(kind == K::indy) opcode_offset = 0x11; |
| 201 |
2/2
✓ Branch 0 taken 909 times.
✓ Branch 1 taken 984 times.
|
3786 |
if(kind == K::ind) opcode_offset = 0x12; |
| 202 |
2/2
✓ Branch 0 taken 909 times.
✓ Branch 1 taken 984 times.
|
3786 |
if(kind == K::sy) opcode_offset = 0x13; |
| 203 |
2/2
✓ Branch 0 taken 909 times.
✓ Branch 1 taken 984 times.
|
3786 |
if(kind == K::x) opcode_offset = 0x15; |
| 204 |
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 1677 times.
|
3642 |
if(kind == K::lindy) opcode_offset = 0x17; |
| 205 |
2/2
✓ Branch 0 taken 1602 times.
✓ Branch 1 taken 906 times.
|
5016 |
} else if(real_len == 2) { |
| 206 |
2/2
✓ Branch 0 taken 801 times.
✓ Branch 1 taken 801 times.
|
3204 |
if(kind == K::imm) opcode_offset = 0x9; |
| 207 |
2/2
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 801 times.
|
2778 |
if(kind == K::abs) opcode_offset = 0xd; |
| 208 |
2/2
✓ Branch 0 taken 429 times.
✓ Branch 1 taken 801 times.
|
2460 |
if(kind == K::y) opcode_offset = 0x19; |
| 209 |
2/2
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 1242 times.
|
3060 |
if(kind == K::x) opcode_offset = 0x1d; |
| 210 |
2/2
✓ Branch 0 taken 453 times.
✓ Branch 1 taken 453 times.
|
1812 |
} else if(real_len == 3) { |
| 211 |
2/2
✓ Branch 0 taken 453 times.
✓ Branch 1 taken 453 times.
|
1812 |
if(kind == K::abs) opcode_offset = 0xf; |
| 212 |
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 453 times.
|
1194 |
if(kind == K::x) opcode_offset = 0x1f; |
| 213 |
|
|
} |
| 214 |
1/2
✓ Branch 0 taken 4473 times.
✗ Branch 1 not taken.
|
8946 |
write1(opcode_offset + base); |
| 215 |
3/4
✓ Branch 0 taken 1965 times.
✓ Branch 1 taken 2508 times.
✓ Branch 2 taken 1965 times.
✗ Branch 3 not taken.
|
8946 |
if(real_len == 1) write1(the_num); |
| 216 |
3/4
✓ Branch 0 taken 1602 times.
✓ Branch 1 taken 906 times.
✓ Branch 2 taken 1602 times.
✗ Branch 3 not taken.
|
5016 |
else if(real_len == 2) write2(the_num); |
| 217 |
2/4
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 906 times.
✗ Branch 3 not taken.
|
1812 |
else if(real_len == 3) write3(the_num); |
| 218 |
|
8976 |
} |
| 219 |
|
|
|
| 220 |
|
|
template<int base, int accum_opc, bool is_bit = false> |
| 221 |
|
2448 |
void thenext8(insn_context& arg) { |
| 222 |
|
|
using K = addr_kind; |
| 223 |
|
|
addr_kind kind; |
| 224 |
|
1224 |
string parsed_str; |
| 225 |
|
|
if constexpr(is_bit) { |
| 226 |
1/2
✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
|
432 |
auto parse_result = parse_addr_kind<K::x, K::abs, K::imm>(arg); |
| 227 |
|
432 |
kind = parse_result.first; |
| 228 |
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
|
216 |
parsed_str = parse_result.second; |
| 229 |
|
216 |
} else { |
| 230 |
1/2
✓ Branch 0 taken 1008 times.
✗ Branch 1 not taken.
|
2016 |
auto parse_result = parse_addr_kind<K::x, K::abs, K::imm, K::a, K::imp>(arg); |
| 231 |
|
2016 |
kind = parse_result.first; |
| 232 |
1/2
✓ Branch 0 taken 504 times.
✗ Branch 1 not taken.
|
1008 |
parsed_str = parse_result.second; |
| 233 |
|
|
// todo: some checks on arg.modifier here |
| 234 |
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 972 times.
|
2016 |
if(kind == K::imm) { |
| 235 |
|
|
// implied rep |
| 236 |
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
|
72 |
int64_t rep_count = getnum(parsed_str); |
| 237 |
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
72 |
if(foundlabel) asar_throw_error(0, error_type_block, error_id_no_labels_here); |
| 238 |
3/4
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
✓ Branch 3 taken 36 times.
|
252 |
for (int64_t i=0;i<rep_count;i++) { write1(accum_opc); } |
| 239 |
|
36 |
return; |
| 240 |
|
|
} |
| 241 |
3/4
✓ Branch 0 taken 486 times.
✓ Branch 1 taken 486 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 432 times.
|
1944 |
if(kind == K::a || kind == K::imp) { |
| 242 |
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
|
216 |
write1(accum_opc); |
| 243 |
|
108 |
return; |
| 244 |
|
|
} |
| 245 |
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 72 times.
|
1008 |
} |
| 246 |
3/4
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 720 times.
✓ Branch 2 taken 360 times.
✗ Branch 3 not taken.
|
2160 |
int64_t the_num = pass == 2 ? getnum(parsed_str) : 0; |
| 247 |
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
|
2160 |
int arg_min_len = getlen(parsed_str, kind == K::imm); |
| 248 |
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
|
2160 |
int real_len = get_real_len(1, 2, arg.modifier, arg_min_len); |
| 249 |
|
1080 |
int opcode = 0; |
| 250 |
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 576 times.
|
1296 |
if(kind == K::imm) { |
| 251 |
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
144 |
check_implicit_immediate(arg.modifier, parsed_str); |
| 252 |
|
72 |
opcode = accum_opc; |
| 253 |
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 504 times.
|
2016 |
} else if(real_len == 1) { |
| 254 |
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
|
1008 |
if(kind == K::abs) opcode = base+0x6; |
| 255 |
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 252 times.
|
756 |
if(kind == K::x) opcode = base+0x16; |
| 256 |
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
|
1008 |
} else if(real_len == 2) { |
| 257 |
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
|
1008 |
if(kind == K::abs) opcode = base+0xe; |
| 258 |
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 252 times.
|
756 |
if(kind == K::x) opcode = base+0x1e; |
| 259 |
|
|
} |
| 260 |
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
|
2160 |
write1(opcode); |
| 261 |
3/4
✓ Branch 0 taken 540 times.
✓ Branch 1 taken 540 times.
✓ Branch 2 taken 540 times.
✗ Branch 3 not taken.
|
2160 |
if(real_len == 1) write1(the_num); |
| 262 |
2/4
✓ Branch 0 taken 540 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 540 times.
✗ Branch 3 not taken.
|
1080 |
else if(real_len == 2) write2(the_num); |
| 263 |
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 72 times.
|
2448 |
} |
| 264 |
|
|
|
| 265 |
|
|
template<int base> |
| 266 |
|
288 |
void tsb_trb(insn_context& arg) { |
| 267 |
|
|
using K = addr_kind; |
| 268 |
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
288 |
auto parse_result = parse_addr_kind<K::abs>(arg); |
| 269 |
3/4
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
288 |
int64_t the_num = pass == 2 ? getnum(parse_result.second) : 0; |
| 270 |
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
|
288 |
int arg_min_len = getlen(parse_result.second, false); |
| 271 |
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
|
288 |
int real_len = get_real_len(1, 2, arg.modifier, arg_min_len); |
| 272 |
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 72 times.
|
288 |
int opcode_offset = real_len == 1 ? 0x04 : 0x0c; |
| 273 |
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
|
288 |
write1(opcode_offset + base); |
| 274 |
3/4
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
|
288 |
if(real_len == 1) write1(the_num); |
| 275 |
2/4
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
|
144 |
else if(real_len == 2) write2(the_num); |
| 276 |
|
288 |
} |
| 277 |
|
|
|
| 278 |
|
|
template<int opc, int width = 1> |
| 279 |
|
432 |
void branch(insn_context& arg) { |
| 280 |
|
|
using K = addr_kind; |
| 281 |
2/2
✓ Branch 0 taken 99 times.
✓ Branch 1 taken 9 times.
|
432 |
auto parse_result = parse_addr_kind<K::abs>(arg); |
| 282 |
|
198 |
int64_t num = 0; |
| 283 |
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 132 times.
|
396 |
if(pass == 2) { |
| 284 |
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
|
132 |
num = getnum(parse_result.second); |
| 285 |
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 6 times.
|
132 |
if(foundlabel) { |
| 286 |
|
120 |
int64_t delta = num - (snespos + width + 1); |
| 287 |
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 57 times.
|
120 |
if((num & ~0xffff) != (snespos & ~0xffff)) { |
| 288 |
|
|
// todo: should throw error "can't branch to different bank" |
| 289 |
|
✗ |
asar_throw_error(2, error_type_block, error_id_relative_branch_out_of_bounds, dec(delta).data()); |
| 290 |
|
|
} |
| 291 |
3/4
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 27 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
|
108 |
if(width==1 && (delta < -128 || delta > 127)) { |
| 292 |
|
✗ |
asar_throw_error(2, error_type_block, error_id_relative_branch_out_of_bounds, dec(delta).data()); |
| 293 |
|
|
} |
| 294 |
|
60 |
num = delta; |
| 295 |
|
|
} else { |
| 296 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
12 |
if(num & ~(width==2 ? 0xffff : 0xff)) { |
| 297 |
|
✗ |
asar_throw_error(2, error_type_block, error_id_relative_branch_out_of_bounds, dec(num).data()); |
| 298 |
|
|
} |
| 299 |
|
12 |
num = (int16_t)(width==2 ? num : (int8_t)num); |
| 300 |
|
|
} |
| 301 |
|
|
} |
| 302 |
|
|
|
| 303 |
1/2
✓ Branch 0 taken 198 times.
✗ Branch 1 not taken.
|
396 |
write1(opc); |
| 304 |
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
|
324 |
if(width == 1) write1(num); |
| 305 |
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
|
72 |
else if(width == 2) write2(num); |
| 306 |
|
396 |
} |
| 307 |
|
|
|
| 308 |
|
|
template<int opc> |
| 309 |
|
1404 |
void implied(insn_context& arg) { |
| 310 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 702 times.
|
1404 |
if(arg.arg != "") { |
| 311 |
|
|
// todo: some kind of "this instruction doesn't take an argument" message? |
| 312 |
|
✗ |
asar_throw_error(0, error_type_block, error_id_bad_addr_mode); |
| 313 |
|
|
} |
| 314 |
|
1404 |
write1(opc); |
| 315 |
|
1404 |
} |
| 316 |
|
|
|
| 317 |
|
|
template<int opc> |
| 318 |
|
6120 |
void implied_rep(insn_context& arg) { |
| 319 |
|
|
using K = addr_kind; |
| 320 |
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
|
6120 |
auto parse_result = parse_addr_kind<K::imm, K::imp>(arg); |
| 321 |
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 180 times.
|
6120 |
if(parse_result.first == K::imp) { |
| 322 |
1/2
✓ Branch 0 taken 2880 times.
✗ Branch 1 not taken.
|
5760 |
write1(opc); |
| 323 |
|
|
} else { |
| 324 |
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
|
360 |
int64_t rep_count = getnum(parse_result.second); |
| 325 |
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 180 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
360 |
if(foundlabel) asar_throw_error(0, error_type_block, error_id_no_labels_here); |
| 326 |
3/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✓ Branch 3 taken 180 times.
|
1188 |
for (int64_t i=0;i<rep_count;i++) { write1(opc); } |
| 327 |
|
|
} |
| 328 |
|
6120 |
} |
| 329 |
|
|
|
| 330 |
|
|
template<int base, char op, char xy> |
| 331 |
|
1800 |
void xy_ops(insn_context& arg) { |
| 332 |
|
|
using K = addr_kind; |
| 333 |
|
900 |
std::pair<addr_kind, string> parse_result; |
| 334 |
|
|
if(op == 'S') { // stx |
| 335 |
2/4
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
✗ Branch 3 not taken.
|
360 |
parse_result = parse_addr_kind<K::abs, (xy == 'X' ? K::y : K::x)>(arg); |
| 336 |
|
|
} else if(op == 'L') { // ldx |
| 337 |
2/4
✓ Branch 0 taken 432 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 216 times.
✗ Branch 3 not taken.
|
864 |
parse_result = parse_addr_kind<K::abs, K::imm, (xy == 'X' ? K::y : K::x)>(arg); |
| 338 |
|
|
} else { // cpx |
| 339 |
2/4
✓ Branch 0 taken 288 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 144 times.
✗ Branch 3 not taken.
|
576 |
parse_result = parse_addr_kind<K::abs, K::imm>(arg); |
| 340 |
|
|
} |
| 341 |
3/4
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 600 times.
✓ Branch 2 taken 300 times.
✗ Branch 3 not taken.
|
1800 |
int64_t the_num = pass == 2 ? getnum(parse_result.second) : 0; |
| 342 |
1/2
✓ Branch 0 taken 900 times.
✗ Branch 1 not taken.
|
1800 |
int arg_min_len = getlen(parse_result.second, false); |
| 343 |
1/2
✓ Branch 0 taken 900 times.
✗ Branch 1 not taken.
|
1800 |
int real_len = get_real_len(1, 2, arg.modifier, arg_min_len); |
| 344 |
|
900 |
int opcode = 0; |
| 345 |
2/2
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 612 times.
|
1800 |
if(parse_result.first == K::imm) { |
| 346 |
1/2
✓ Branch 0 taken 288 times.
✗ Branch 1 not taken.
|
576 |
check_implicit_immediate(arg.modifier, parse_result.second); |
| 347 |
|
288 |
opcode = base; |
| 348 |
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 180 times.
|
1224 |
} else if(parse_result.first == K::abs) { |
| 349 |
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 216 times.
|
864 |
if(real_len == 1) opcode = base + 0x4; |
| 350 |
|
216 |
else opcode = base + 0xc; |
| 351 |
|
|
} else { // ,x or ,y |
| 352 |
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 90 times.
|
360 |
if(real_len == 1) opcode = base + 0x14; |
| 353 |
|
72 |
else opcode = base + 0x1c; |
| 354 |
|
|
} |
| 355 |
1/2
✓ Branch 0 taken 900 times.
✗ Branch 1 not taken.
|
1800 |
write1(opcode); |
| 356 |
3/4
✓ Branch 0 taken 468 times.
✓ Branch 1 taken 432 times.
✓ Branch 2 taken 468 times.
✗ Branch 3 not taken.
|
1800 |
if(real_len == 1) write1(the_num); |
| 357 |
2/4
✓ Branch 0 taken 432 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 432 times.
✗ Branch 3 not taken.
|
864 |
else if(real_len == 2) write2(the_num); |
| 358 |
|
1800 |
} |
| 359 |
|
|
|
| 360 |
|
|
template<int opc> |
| 361 |
|
216 |
void interrupt(insn_context& arg) { |
| 362 |
|
|
using K = addr_kind; |
| 363 |
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
216 |
auto parse_result = parse_addr_kind<K::imm, K::imp>(arg); |
| 364 |
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 54 times.
|
216 |
if(parse_result.first == K::imp) { |
| 365 |
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
108 |
write1(opc); |
| 366 |
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
108 |
write1(0); |
| 367 |
|
|
} else { |
| 368 |
3/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
|
108 |
int64_t num = pass == 2 ? getnum(parse_result.second) : 0; |
| 369 |
|
|
// this is kinda hacky |
| 370 |
2/11
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
72 |
if(num < 0 || num > 255) asar_throw_error(2, error_type_block, error_id_bad_access_width, format_valid_widths(1, 1), num > 65535 ? 24 : 16); |
| 371 |
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
108 |
write1(opc); |
| 372 |
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
108 |
write1(num); |
| 373 |
|
|
} |
| 374 |
|
216 |
} |
| 375 |
|
|
|
| 376 |
|
|
template<int opc, addr_kind k, int width> |
| 377 |
|
504 |
void oneoff(insn_context& arg) { |
| 378 |
1/2
✓ Branch 0 taken 126 times.
✗ Branch 1 not taken.
|
504 |
auto parse_result = parse_addr_kind<k>(arg); |
| 379 |
3/4
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 168 times.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
|
504 |
int64_t the_num = pass == 2 ? getnum(parse_result.second) : 0; |
| 380 |
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
|
504 |
int arg_min_len = getlen(parse_result.second, false); |
| 381 |
|
|
// only for error checking, we know the answer anyways |
| 382 |
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
|
504 |
get_real_len(width, width, arg.modifier, arg_min_len); |
| 383 |
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
|
504 |
write1(opc); |
| 384 |
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
108 |
if(width == 1) write1(the_num); |
| 385 |
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
36 |
else if(width == 2) write2(the_num); |
| 386 |
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
|
360 |
else if(width == 3) write3(the_num); |
| 387 |
|
504 |
} |
| 388 |
|
|
|
| 389 |
|
144 |
void stz(insn_context& arg) { |
| 390 |
|
|
using K = addr_kind; |
| 391 |
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
144 |
auto parse_result = parse_addr_kind<K::abs, K::x>(arg); |
| 392 |
3/4
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
144 |
int64_t the_num = pass == 2 ? getnum(parse_result.second) : 0; |
| 393 |
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
|
144 |
int arg_min_len = getlen(parse_result.second, false); |
| 394 |
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
|
144 |
int real_len = get_real_len(1, 2, arg.modifier, arg_min_len); |
| 395 |
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 72 times.
|
144 |
if(real_len == 1) { |
| 396 |
3/4
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
|
72 |
if(parse_result.first == K::abs) write1(0x64); |
| 397 |
2/4
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
|
36 |
else if(parse_result.first == K::x) write1(0x74); |
| 398 |
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
72 |
write1(the_num); |
| 399 |
|
|
} else { |
| 400 |
3/4
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
|
72 |
if(parse_result.first == K::abs) write1(0x9c); |
| 401 |
2/4
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
|
36 |
else if(parse_result.first == K::x) write1(0x9e); |
| 402 |
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
72 |
write2(the_num); |
| 403 |
|
|
} |
| 404 |
|
144 |
} |
| 405 |
|
|
|
| 406 |
|
|
template<char which> |
| 407 |
|
588 |
void jmp_jsr_jml(insn_context& arg) { |
| 408 |
|
|
using K = addr_kind; |
| 409 |
1/2
✓ Branch 0 taken 150 times.
✗ Branch 1 not taken.
|
588 |
auto parse_result = which == 'R' ? parse_addr_kind<K::abs, K::xind>(arg) |
| 410 |
|
|
: which == 'P' ? parse_addr_kind<K::abs, K::xind, K::ind, K::lind>(arg) |
| 411 |
|
|
: /* 'L' */ parse_addr_kind<K::abs, K::lind>(arg); |
| 412 |
3/4
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 196 times.
✓ Branch 2 taken 98 times.
✗ Branch 3 not taken.
|
588 |
int64_t the_num = pass == 2 ? getnum(parse_result.second) : 0; |
| 413 |
|
|
// set optimizeforbank to -1 (i.e. auto, assume DBR = current bank) |
| 414 |
|
|
// because jmp and jsr's arguments are relative to the program bank anyways |
| 415 |
|
588 |
int old_optimize = optimizeforbank; |
| 416 |
4/4
✓ Branch 0 taken 159 times.
✓ Branch 1 taken 135 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 114 times.
|
588 |
if(parse_result.first == K::lind || parse_result.first == K::ind) { |
| 417 |
|
|
// these ones for Some Reason always read the pointer from bank 0 lol |
| 418 |
|
144 |
optimizeforbank = 0; |
| 419 |
|
|
} else { |
| 420 |
|
|
// the rest use bank K |
| 421 |
|
444 |
optimizeforbank = -1; |
| 422 |
|
|
} |
| 423 |
1/2
✓ Branch 0 taken 294 times.
✗ Branch 1 not taken.
|
588 |
int arg_min_len = getlen(parse_result.second, false); |
| 424 |
|
588 |
optimizeforbank = old_optimize; |
| 425 |
3/5
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 267 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 54 times.
✗ Branch 4 not taken.
|
606 |
get_real_len(2, (which == 'L' && parse_result.first == K::abs) ? 3 : 2, arg.modifier, arg_min_len); |
| 426 |
|
|
if(which == 'R') { |
| 427 |
3/4
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 126 times.
✗ Branch 3 not taken.
|
288 |
if(parse_result.first == K::abs) write1(0x20); |
| 428 |
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
|
36 |
else if(parse_result.first == K::xind) write1(0xfc); |
| 429 |
|
|
} else if(which == 'L') { |
| 430 |
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
|
108 |
if(parse_result.first == K::abs) { |
| 431 |
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
|
72 |
write1(0x5c); |
| 432 |
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
|
72 |
write3(the_num); |
| 433 |
|
36 |
return; |
| 434 |
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
36 |
} else if(parse_result.first == K::lind) { |
| 435 |
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
36 |
write1(0xdc); |
| 436 |
|
|
} |
| 437 |
|
|
} else { |
| 438 |
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
192 |
if(parse_result.first == K::abs) write1(0x4c); |
| 439 |
3/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
|
144 |
else if(parse_result.first == K::ind) write1(0x6c); |
| 440 |
3/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
|
108 |
else if(parse_result.first == K::xind) write1(0x7c); |
| 441 |
2/4
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
|
72 |
else if(parse_result.first == K::lind) write1(0xdc); |
| 442 |
|
|
} |
| 443 |
1/2
✓ Branch 0 taken 258 times.
✗ Branch 1 not taken.
|
516 |
write2(the_num); |
| 444 |
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 18 times.
|
300 |
} |
| 445 |
|
|
|
| 446 |
|
|
template<int opc> |
| 447 |
|
72 |
void mvn_mvp(insn_context& arg) { |
| 448 |
|
|
int count; |
| 449 |
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
72 |
autoptr<char**> parts = qpsplit(arg.arg.raw(), ',', &count); |
| 450 |
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
72 |
if(count != 2) asar_throw_error(2, error_type_block, error_id_bad_addr_mode); |
| 451 |
|
|
// todo length checks ??? |
| 452 |
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
|
72 |
write1(opc); |
| 453 |
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 24 times.
|
72 |
if(pass == 2) { |
| 454 |
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
24 |
write1(getnum(parts[0])); |
| 455 |
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
24 |
write1(getnum(parts[1])); |
| 456 |
|
|
} else { |
| 457 |
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
48 |
write2(0); |
| 458 |
|
|
} |
| 459 |
|
72 |
} |
| 460 |
|
|
|
| 461 |
|
|
assocarr<void(*)(insn_context&)> mnemonics = { |
| 462 |
|
|
{ "ora", the8<0x00> }, |
| 463 |
|
|
{ "and", the8<0x20> }, |
| 464 |
|
|
{ "eor", the8<0x40> }, |
| 465 |
|
|
{ "adc", the8<0x60> }, |
| 466 |
|
|
{ "sta", the8<0x80, false> }, |
| 467 |
|
|
{ "lda", the8<0xa0> }, |
| 468 |
|
|
{ "cmp", the8<0xc0> }, |
| 469 |
|
|
{ "sbc", the8<0xe0> }, |
| 470 |
|
|
{ "asl", thenext8<0x00, 0x0a> }, |
| 471 |
|
|
{ "bit", thenext8<0x1e, 0x89, true> }, |
| 472 |
|
|
{ "rol", thenext8<0x20, 0x2a> }, |
| 473 |
|
|
{ "lsr", thenext8<0x40, 0x4a> }, |
| 474 |
|
|
{ "ror", thenext8<0x60, 0x6a> }, |
| 475 |
|
|
{ "dec", thenext8<0xc0, 0x3a> }, |
| 476 |
|
|
{ "inc", thenext8<0xe0, 0x1a> }, |
| 477 |
|
|
{ "bcc", branch<0x90> }, |
| 478 |
|
|
{ "bcs", branch<0xb0> }, |
| 479 |
|
|
{ "beq", branch<0xf0> }, |
| 480 |
|
|
{ "bmi", branch<0x30> }, |
| 481 |
|
|
{ "bne", branch<0xd0> }, |
| 482 |
|
|
{ "bpl", branch<0x10> }, |
| 483 |
|
|
{ "bra", branch<0x80> }, |
| 484 |
|
|
{ "bvc", branch<0x50> }, |
| 485 |
|
|
{ "bvs", branch<0x70> }, |
| 486 |
|
|
{ "brl", branch<0x82, 2> }, |
| 487 |
|
|
{ "clc", implied<0x18> }, |
| 488 |
|
|
{ "cld", implied<0xd8> }, |
| 489 |
|
|
{ "cli", implied<0x58> }, |
| 490 |
|
|
{ "clv", implied<0xb8> }, |
| 491 |
|
|
{ "dex", implied_rep<0xca> }, |
| 492 |
|
|
{ "dey", implied_rep<0x88> }, |
| 493 |
|
|
{ "inx", implied_rep<0xe8> }, |
| 494 |
|
|
{ "iny", implied_rep<0xc8> }, |
| 495 |
|
|
{ "nop", implied_rep<0xea> }, |
| 496 |
|
|
{ "pha", implied<0x48> }, |
| 497 |
|
|
{ "phb", implied<0x8b> }, |
| 498 |
|
|
{ "phd", implied<0x0b> }, |
| 499 |
|
|
{ "phk", implied<0x4b> }, |
| 500 |
|
|
{ "php", implied<0x08> }, |
| 501 |
|
|
{ "phx", implied<0xda> }, |
| 502 |
|
|
{ "phy", implied<0x5a> }, |
| 503 |
|
|
{ "pla", implied<0x68> }, |
| 504 |
|
|
{ "plb", implied<0xab> }, |
| 505 |
|
|
{ "pld", implied<0x2b> }, |
| 506 |
|
|
{ "plp", implied<0x28> }, |
| 507 |
|
|
{ "plx", implied<0xfa> }, |
| 508 |
|
|
{ "ply", implied<0x7a> }, |
| 509 |
|
|
{ "rti", implied<0x40> }, |
| 510 |
|
|
{ "rtl", implied<0x6b> }, |
| 511 |
|
|
{ "rts", implied<0x60> }, |
| 512 |
|
|
{ "sec", implied<0x38> }, |
| 513 |
|
|
{ "sed", implied<0xf8> }, |
| 514 |
|
|
{ "sei", implied<0x78> }, |
| 515 |
|
|
{ "stp", implied<0xdb> }, |
| 516 |
|
|
{ "tax", implied<0xaa> }, |
| 517 |
|
|
{ "tay", implied<0xa8> }, |
| 518 |
|
|
{ "tcd", implied<0x5b> }, |
| 519 |
|
|
{ "tcs", implied<0x1b> }, |
| 520 |
|
|
{ "tdc", implied<0x7b> }, |
| 521 |
|
|
{ "tsc", implied<0x3b> }, |
| 522 |
|
|
{ "tsx", implied<0xba> }, |
| 523 |
|
|
{ "txa", implied<0x8a> }, |
| 524 |
|
|
{ "txs", implied<0x9a> }, |
| 525 |
|
|
{ "txy", implied<0x9b> }, |
| 526 |
|
|
{ "tya", implied<0x98> }, |
| 527 |
|
|
{ "tyx", implied<0xbb> }, |
| 528 |
|
|
{ "wai", implied<0xcb> }, |
| 529 |
|
|
{ "xba", implied<0xeb> }, |
| 530 |
|
|
{ "xce", implied<0xfb> }, |
| 531 |
|
|
{ "ldy", xy_ops<0xa0, 'L', 'Y'> }, |
| 532 |
|
|
{ "ldx", xy_ops<0xa2, 'L', 'X'> }, |
| 533 |
|
|
{ "cpy", xy_ops<0xc0, 'C', 'Y'> }, |
| 534 |
|
|
{ "cpx", xy_ops<0xe0, 'C', 'X'> }, |
| 535 |
|
|
{ "stx", xy_ops<0x82, 'S', 'X'> }, |
| 536 |
|
|
{ "sty", xy_ops<0x80, 'S', 'Y'> }, |
| 537 |
|
|
{ "cop", interrupt<0x02> }, |
| 538 |
|
|
{ "wdm", interrupt<0x42> }, |
| 539 |
|
|
{ "brk", interrupt<0x00> }, |
| 540 |
|
|
{ "tsb", tsb_trb<0x00> }, |
| 541 |
|
|
{ "trb", tsb_trb<0x10> }, |
| 542 |
|
|
{ "rep", oneoff<0xc2, addr_kind::imm, 1> }, |
| 543 |
|
|
{ "sep", oneoff<0xe2, addr_kind::imm, 1> }, |
| 544 |
|
|
{ "pei", oneoff<0xd4, addr_kind::ind, 1> }, |
| 545 |
|
|
{ "pea", oneoff<0xf4, addr_kind::abs, 2> }, |
| 546 |
|
|
{ "mvn", mvn_mvp<0x54> }, |
| 547 |
|
|
{ "mvp", mvn_mvp<0x44> }, |
| 548 |
|
|
{ "jsl", oneoff<0x22, addr_kind::abs, 3> }, |
| 549 |
|
|
{ "per", branch<0x62, 2> }, |
| 550 |
|
|
{ "stz", stz }, |
| 551 |
|
|
{ "jmp", jmp_jsr_jml<'P'> }, |
| 552 |
|
|
{ "jsr", jmp_jsr_jml<'R'> }, |
| 553 |
|
|
{ "jml", jmp_jsr_jml<'L'> }, |
| 554 |
|
|
}; |
| 555 |
|
|
|
| 556 |
|
|
|
| 557 |
|
67332 |
bool asblock_65816(char** word, int numwords) |
| 558 |
|
|
{ |
| 559 |
|
|
#define is(test) (!stricmpwithupper(word[0], test)) |
| 560 |
2/2
✓ Branch 0 taken 36846 times.
✓ Branch 1 taken 30486 times.
|
67332 |
if(word[0][0] == '\'') return false; |
| 561 |
|
29883 |
string par; |
| 562 |
2/2
✓ Branch 0 taken 60963 times.
✓ Branch 1 taken 66126 times.
|
127089 |
for(int i = 1; i < numwords; i++){ |
| 563 |
3/4
✓ Branch 0 taken 1848 times.
✓ Branch 1 taken 59115 times.
✓ Branch 2 taken 924 times.
✗ Branch 3 not taken.
|
60963 |
if(i > 1) par += " "; |
| 564 |
1/2
✓ Branch 0 taken 27288 times.
✗ Branch 1 not taken.
|
60963 |
par += word[i]; |
| 565 |
|
|
} |
| 566 |
|
|
// todo handle code like `nop = $1234` |
| 567 |
1/2
✓ Branch 0 taken 29883 times.
✗ Branch 1 not taken.
|
66126 |
string opc = word[0]; |
| 568 |
4/4
✓ Branch 0 taken 368832 times.
✓ Branch 1 taken 36243 times.
✓ Branch 2 taken 150231 times.
✓ Branch 3 taken 29883 times.
|
441318 |
for(int i = 0; i < opc.length(); i++) opc.raw()[i] = to_lower(opc[i]); |
| 569 |
|
29883 |
char mod = 0; |
| 570 |
9/10
✓ Branch 0 taken 65982 times.
✓ Branch 1 taken 144 times.
✓ Branch 2 taken 30909 times.
✓ Branch 3 taken 35073 times.
✓ Branch 4 taken 29739 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1170 times.
✓ Branch 7 taken 28569 times.
✓ Branch 8 taken 1170 times.
✓ Branch 9 taken 28713 times.
|
66126 |
if(opc.length() >= 2 && opc[opc.length()-2] == '.') { |
| 571 |
1/2
✓ Branch 0 taken 1170 times.
✗ Branch 1 not taken.
|
2340 |
mod = opc[opc.length()-1]; |
| 572 |
2/4
✓ Branch 0 taken 1170 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1170 times.
✗ Branch 3 not taken.
|
2340 |
opc.truncate(opc.length()-2); |
| 573 |
|
|
} |
| 574 |
4/4
✓ Branch 0 taken 35670 times.
✓ Branch 1 taken 30456 times.
✓ Branch 2 taken 24087 times.
✓ Branch 3 taken 5796 times.
|
66126 |
if(!mnemonics.exists(opc.data())) return false; |
| 575 |
2/2
✓ Branch 0 taken 11559 times.
✓ Branch 1 taken 24 times.
|
11583 |
insn_context ctx{par, {}, mod}; |
| 576 |
|
11583 |
ctx.orig_insn[0] = opc[0]; |
| 577 |
|
11583 |
ctx.orig_insn[1] = opc[1]; |
| 578 |
|
11583 |
ctx.orig_insn[2] = opc[2]; |
| 579 |
4/4
✓ Branch 0 taken 11559 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 5772 times.
✓ Branch 3 taken 24 times.
|
11583 |
mnemonics.find(opc.data())(ctx); |
| 580 |
|
5772 |
return true; |
| 581 |
|
66198 |
} |
| 582 |
|
|
|