blob: 7385117a2b13f6cd75ed5cdb1c32967687f29919 (
plain)
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
|
update_flags_nz(value) {
cpu->ps.N = bit(value, msb-1);
cpu->ps.Z = value == 0;
}
get_flag(name, match, flag) {
if (name == match) {
return flag;
} else {
return !flag;
}
}
jump(addr, fallback, flag) {
if (flag) {
return addr;
} else {
return fallback;
}
}
read(addr, size) {
return read_value(addr, size);
}
write(value, addr, size) {
write_value(value, addr, size);
}
adc(a, b, carry) {
sum = a + b + carry;
update_flags_nz(sum);
cpu->ps.C = sum < b;
cpu->ps.V = bit(a^b, msb-1) && bit(a^sum, msb-1);
return sum;
}
mul(a, b) {
sum = a * b;
update_flags_nz(sum);
cpu->ps.V = bit(a^b, msb-1) && bit(a^sum, msb-1);
return sum;
}
div(a, b, *rem) {
sum = a / b;
*rem = a % b;
update_flags_nz(sum);
return sum;
}
|