#define c2(x) (0xff & (x>>16))
#define c1(x) (0xff & (x>> 8))
#define c0(x) (0xff & (x ))
-#define LSL(x) x <<= 1;
-#define LSR(x) x >>= 1;
+#define LSL(x) carry = x>>7; x <<= 1;
+#define LSR(x) carry = x&1; x >>= 1;
#define SWAP(x) x = ((x & 0x0F) << 4 | (x & 0xF0) >> 4);
#define AND(x,y) x &= y;
#define ANDI(x,n) x &= n;
#define OR(x,y) x |= y;
#define ORI(x,n) x |= n;
#define EOR(x,y) x ^= y;
-#define ADD(x,y) x += y;
+#define ADD(x,y) carry = (x+y)>>8; x += y;
#define ADC(x,y,c)x += y; x+=c;
#define SUB(x,y) x -= y;
#define SUBI(x,n) x -= (u8)n;
MOV (x, s)
INC (x)
#define tmp o
- unsigned short sum = 0; //XXX
- sum += x;
- sum >>= 1;
+ //NOTE: we only need 1 bit of the upper byte. instead of using a u16 and LSR'ing,
+ //we can use a u8 for sum and use ROR (which shifts the carry in)
+ CLR (tmp)
+ ADD (tmp, x)
+ ROR (tmp)
//nop
- sum >>= 1;
- sum += x;
- sum >>= 1;
+ LSR (tmp)
+ ADD (tmp, x)
+ ROR (tmp)
//nop
- sum >>= 1;
- sum += x;
- sum >>= 1;
+ LSR (tmp)
+ ADD (tmp, x)
+ ROR (tmp)
//nop
- sum >>= 1;
- sum += x;
- sum >>= 1;
+ LSR (tmp)
+ ADD (tmp, x)
+ ROR (tmp)
//nop
- sum >>= 1;
- x = sum;
+ LSR (tmp)
+ x = tmp;
#undef tmp
t = ((i3&0x01)<<13 | i2<<5 | i1>>3) % 3;
ADD (t, n)
MOV (x, s)
INC (x)
#define tmp o
- sum = 0; //XXX
+ unsigned short sum = 0; //XXX
sum += x;
sum >>= 1;
sum += x;