forked from vhelin/wla-dx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decode_6510.c
144 lines (131 loc) · 3.73 KB
/
decode_6510.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
case 0:
for ( ; x < OP_SIZE_MAX; inz++, x++) {
if (opt_tmp->op[x] == 0 && buffer[inz] == 0x0A) {
output_assembled_opcode(opt_tmp, "d%d ", opt_tmp->hex);
i = inz;
return SUCCEEDED;
}
if (opt_tmp->op[x] != toupper((int)buffer[inz]))
break;
}
break;
case 5:
case 1:
if (xbit_size > 8 && opt_tmp->skip_8bit == 1)
break;
for ( ; x < OP_SIZE_MAX; inz++, x++) {
if (opt_tmp->op[x] == 'x') {
y = i;
i = inz;
z = input_number();
inz = i;
i = y;
if (!(z == SUCCEEDED || z == INPUT_NUMBER_ADDRESS_LABEL || z == INPUT_NUMBER_STACK))
return FAILED;
if (z == SUCCEEDED && (d > 255 || d < -128))
break;
if (operand_hint == HINT_16BIT)
break;
for (x++ ; x < OP_SIZE_MAX; inz++, x++) {
if (opt_tmp->op[x] == 0 && buffer[inz] == 0x0A) {
if (z == SUCCEEDED)
output_assembled_opcode(opt_tmp, "d%d d%d ", opt_tmp->hex, d);
else if (z == INPUT_NUMBER_ADDRESS_LABEL)
output_assembled_opcode(opt_tmp, "k%d d%d R%s ", active_file_info_last->line_current, opt_tmp->hex, label);
else {
output_assembled_opcode(opt_tmp, "d%d c%d ", opt_tmp->hex, latest_stack);
if (opt_tmp->type == 5) {
/* 5 -> let's configure the stack so that all label references inside are relative */
stacks_tmp->relative_references = 1;
}
}
i = inz;
return SUCCEEDED;
}
if (opt_tmp->op[x] != toupper((int)buffer[inz]))
break;
}
}
if (opt_tmp->op[x] != toupper((int)buffer[inz]))
break;
}
break;
case 2:
for ( ; x < OP_SIZE_MAX; inz++, x++) {
if (opt_tmp->op[x] == '?') {
y = i;
i = inz;
z = input_number();
inz = i;
i = y;
if (!(z == SUCCEEDED || z == INPUT_NUMBER_ADDRESS_LABEL || z == INPUT_NUMBER_STACK))
return FAILED;
if (z == SUCCEEDED && (d > 65535 || d < -32768)) {
print_error("Out of 16-bit range.\n", ERROR_NUM);
return FAILED;
}
for (x++ ; x < OP_SIZE_MAX; inz++, x++) {
if (opt_tmp->op[x] == 0 && buffer[inz] == 0x0A) {
if (z == SUCCEEDED)
output_assembled_opcode(opt_tmp, "d%d y%d ", opt_tmp->hex, d);
else if (z == INPUT_NUMBER_ADDRESS_LABEL)
output_assembled_opcode(opt_tmp, "k%d d%d r%s ", active_file_info_last->line_current, opt_tmp->hex, label);
else
output_assembled_opcode(opt_tmp, "d%d C%d ", opt_tmp->hex, latest_stack);
i = inz;
return SUCCEEDED;
}
if (opt_tmp->op[x] != toupper((int)buffer[inz]))
break;
}
}
if (opt_tmp->op[x] != toupper((int)buffer[inz]))
break;
}
break;
case 3:
for ( ; x < OP_SIZE_MAX; inz++, x++) {
if (opt_tmp->op[x] == 0 && buffer[inz] == 0x0A) {
output_assembled_opcode(opt_tmp, "y%d ", opt_tmp->hex);
i = inz;
return SUCCEEDED;
}
if (opt_tmp->op[x] != toupper((int)buffer[inz]))
break;
}
break;
case 4:
if (xbit_size > 8 && opt_tmp->skip_8bit == 1)
break;
for ( ; x < OP_SIZE_MAX; inz++, x++) {
if (opt_tmp->op[x] == 'x') {
y = i;
i = inz;
z = input_number();
inz = i;
i = y;
if (!(z == SUCCEEDED || z == INPUT_NUMBER_ADDRESS_LABEL || z == INPUT_NUMBER_STACK))
return FAILED;
if (z == SUCCEEDED && (d > 255 || d < -128))
break;
if (operand_hint == HINT_16BIT)
break;
for (x++ ; x < OP_SIZE_MAX; inz++, x++) {
if (opt_tmp->op[x] == 0 && buffer[inz] == 0x0A) {
if (z == SUCCEEDED)
output_assembled_opcode(opt_tmp, "d%d d%d ", opt_tmp->hex, d);
else if (z == INPUT_NUMBER_ADDRESS_LABEL)
output_assembled_opcode(opt_tmp, "k%d d%d Q%s ", active_file_info_last->line_current, opt_tmp->hex, label);
else
output_assembled_opcode(opt_tmp, "d%d c%d ", opt_tmp->hex, latest_stack);
i = inz;
return SUCCEEDED;
}
if (opt_tmp->op[x] != toupper((int)buffer[inz]))
break;
}
}
if (opt_tmp->op[x] != toupper((int)buffer[inz]))
break;
}
break;