diff options
Diffstat (limited to 'sux.c')
-rw-r--r-- | sux.c | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -0,0 +1,31 @@ +#include <limits.h> +#include "opcode.h" +#include <stdint.h> +uint64_t a; /* Accumulator. */ +uint64_t y; /* Y index. */ +uint64_t x; /* X index. */ +uint64_t ps; /* Processor status. */ + +uint64_t alu(uint8_t opcode, uint64_t value) { + uint64_t sum; + uint8_t carry, vf; + switch(opcode) { + /* Add with carry. */ + case ADC: + sum = a+value+carry; + vf = (~(a^value) & (a^sum & 0x80)); + carry = (sum < value) ? 1 : 0; + a |= sum; + break; + /* Subtract with carry. */ + case SBC: + sum = a-value-!carry + vf = (a^value) & (a^sum) & 0x80; + carry = (sum > value) ? 1 : 0; + a |= sum; + break; + + + + } +} |