blob: 4e64277c34191fdb85a3f78ac06cdc7492671313 (
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
|
#include <limits.h>
#include "opcode.h"
#include <stdint.h>
uint64_t a;
uint64_t y;
uint64_t x;
uint64_t ps;
uint64_t alu(uint8_t opcode, uint64_t value) {
uint64_t sum;
uint8_t carry, vf;
switch(opcode) {
case ADC:
sum = a+value+carry;
vf = (~(a^value) & (a^sum & 0x80));
carry = (sum < value) ? 1 : 0;
a |= sum;
break;
case SBC:
sum = a-value-!carry
vf = (a^value) & (a^sum) & 0x80;
carry = (sum > value) ? 1 : 0;
a |= sum;
break;
}
}
|