public byte Shl8(byte a, byte b) { unchecked { if (b == 0) { return(a); } _aluResult = (uint)(a << (b & 0x1f)); _fm = fm.Bit8 | fm.CFromResult | fm.PFromResult | fm.SFromResult | fm.ZFromResult; // Single bit shifts update FlagO to the xor of // the carry flag and the msb of the result if (b == 1) { if (((_aluResult ^ (_aluResult << 1)) & 0x100) != 0) { _fm |= fm.OFlag; } } else { if (((_aluResult ^ (_aluResult << 1)) & (0x80 << b)) != 0) { _fm |= fm.OFlag; } } return((byte)_aluResult); } }
public ushort Shr16(ushort a, byte b) { unchecked { if (b == 0) { return(a); } b &= 0x1f; _aluResult = (uint)(a >> b); _fm = fm.PFromResult | fm.SFromResult | fm.ZFromResult; if (((a >> (b - 1)) & 0x01) != 0) { _fm |= fm.CFlag; } if (((_aluResult ^ a) & 0x8000) != 0) { _fm |= fm.OFlag; } return((ushort)_aluResult); } }
public byte Shr8(byte a, byte b) { unchecked { if (b == 0) { return(a); } b &= 0x1f; _aluResult = (uint)(a >> b); _fm = fm.Bit8 | fm.PFromResult | fm.SFromResult | fm.ZFromResult; if (((a >> (b - 1)) & 0x01) != 0) { _fm |= fm.CFlag; } if (((_aluResult ^ a) & 0x80) != 0) { _fm |= fm.OFlag; } return((byte)_aluResult); } }
public byte Xor8(byte a, byte b) { unchecked { _aluResult = (uint)a ^ (uint)b; _fm = fm.Bit8 | fm.CFromResult | fm.PFromResult | fm.SFromResult | fm.ZFromResult; return((byte)_aluResult); } }
public ushort Xor16(ushort a, ushort b) { unchecked { _aluResult = (uint)a ^ (uint)b; _fm = fm.CFromResult | fm.PFromResult | fm.SFromResult | fm.ZFromResult; return((ushort)_aluResult); } }
public ushort Dec16(ushort a) { unchecked { _aluOperA = a; _aluOperB = 1; _fm = fm.AFromResult | (FlagC ? fm.CFlag : 0) | fm.OFromSub | fm.PFromResult | fm.SFromResult | fm.ZFromResult; _aluResult = (uint)a - 1; return((ushort)_aluResult); } }
public byte Dec8(byte a) { unchecked { _aluOperA = a; _aluOperB = 1; _fm = fm.Bit8 | fm.AFromResult | (FlagC ? fm.CFlag : 0) | fm.OFromSub | fm.PFromResult | fm.SFromResult | fm.ZFromResult; _aluResult = (uint)a - 1; return((byte)_aluResult); } }
public ushort Mul8(byte a, byte b) { unchecked { _aluResult = (uint)a * (uint)b; _fm = fm.Bit8 | fm.PFromResult | fm.SFromResult; FlagC = FlagO = (_aluResult & 0xFFFFFF00) != 0; return((ushort)_aluResult); } }
public byte Sbb8(byte a, byte b) { unchecked { _aluResult = ((uint)a - ((uint)b + (FlagC ? 1U : 0)) & 0x1FFFF); _aluOperA = a; _aluOperB = b; _fm = fm.Bit8 | fm.AFromResult | fm.CFromResult | fm.OFromSub | fm.PFromResult | fm.SFromResult | fm.ZFromResult; return((byte)_aluResult); } }
public ushort Sbb16(ushort a, ushort b) { unchecked { _aluResult = ((uint)a - ((uint)b + (FlagC ? 1U : 0))) & 0x1FFFF; _aluOperA = a; _aluOperB = b; _fm = fm.AFromResult | fm.CFromResult | fm.OFromSub | fm.PFromResult | fm.SFromResult | fm.ZFromResult; return((ushort)_aluResult); } }
public byte Adc8(byte a, byte b) { unchecked { _aluResult = (uint)a + (uint)b + (FlagC ? 1U : 0); _aluOperA = a; _aluOperB = b; _fm = fm.Bit8 | fm.AFromResult | fm.CFromResult | fm.OFromAdd | fm.PFromResult | fm.SFromResult | fm.ZFromResult; return((byte)_aluResult); } }
public ushort Adc16(ushort a, ushort b) { unchecked { _aluResult = (uint)a + (uint)b + (FlagC ? 1U : 0); _aluOperA = a; _aluOperB = b; _fm = fm.AFromResult | fm.CFromResult | fm.OFromAdd | fm.PFromResult | fm.SFromResult | fm.ZFromResult; return((ushort)_aluResult); } }
public byte Neg8(byte b) { unchecked { _aluResult = ((uint)0 - (uint)b) & 0x1FFFF; _aluOperA = 0; _aluOperB = b; _fm = fm.Bit8 | fm.AFromResult | fm.CFromResult | fm.OFromSub | fm.PFromResult | fm.SFromResult | fm.ZFromResult; return((byte)_aluResult); } }
public uint Mul16(ushort a, ushort b) { unchecked { _aluResult = (uint)a * (uint)b; _fm = fm.PFromResult | fm.SFromResult; FlagC = FlagO = (_aluResult & 0xFFFF0000) != 0; return(_aluResult); } }
public uint IMul16(ushort a, ushort b) { unchecked { _aluResult = (uint)((int)(short)a * (int)(short)b); _fm = fm.PFromResult | fm.SFromResult; FlagC = FlagO = (int)(short)(_aluResult & 0xFFFF) != (int)_aluResult; return((uint)_aluResult); } }
public ushort Neg16(ushort b) { unchecked { _aluResult = ((uint)0 - (uint)b) & 0x1FFFF; _aluOperA = 0; _aluOperB = b; _fm = fm.AFromResult | fm.CFromResult | fm.OFromSub | fm.PFromResult | fm.SFromResult | fm.ZFromResult; return((ushort)_aluResult); } }
public ushort IMul8(byte a, byte b) { unchecked { _aluResult = (uint)((int)(sbyte)a * (int)(sbyte)b); _fm = fm.Bit8 | fm.PFromResult | fm.SFromResult; FlagC = FlagO = (int)(sbyte)(_aluResult & 0xFF) != (int)_aluResult; return((ushort)_aluResult); } }
public byte Rcr8(byte a, byte b) { unchecked { if (b == 0) { return(a); } b %= 9; _aluResult = (uint)((FlagC ? 0x100 : 0) | (a & 0xFF)); _aluResult = (_aluResult >> b) | (_aluResult << (9 - b)); bool o; if (b == 1) { o = ((_aluResult ^ (_aluResult >> 1)) & 0x40) != 0; } else { if ((a & 0x80) == 0) { o = FlagO; } else { o = !FlagO; } } _fm = fm.Bit8 | fm.CFromResult | (o ? fm.OFlag : 0) | (FlagS ? fm.SFlag : 0) | (FlagZ ? fm.ZFlag : 0) | (FlagP ? fm.PFlag : 0) | (FlagA ? fm.AFlag : 0); return((byte)_aluResult); } }
public ushort Rcr16(ushort a, byte b) { unchecked { if (b == 0) { return(a); } b %= 17; _aluResult = (uint)((FlagC ? 0x10000 : 0) | (a & 0xFFFF)); _aluResult = (_aluResult >> b) | (_aluResult << (17 - b)); bool o; if (b == 1) { o = ((_aluResult ^ (_aluResult >> 1)) & 0x4000) != 0; } else { if ((a & 0x8000) == 0) { o = FlagO; } else { o = !FlagO; } } _fm = fm.CFromResult | (o ? fm.OFlag : 0) | (FlagS ? fm.SFlag : 0) | (FlagZ ? fm.ZFlag : 0) | (FlagP ? fm.PFlag : 0) | (FlagA ? fm.AFlag : 0); return((ushort)_aluResult); } }
public byte Ror8(byte a, byte b) { unchecked { if (b == 0) { return(a); } b %= 8; _aluResult = (uint)((a >> b) | (a << (8 - b))); bool o; if (b == 1) { o = ((_aluResult ^ (_aluResult >> 1)) & 0x40) != 0; } else { if ((a & 0x0001) == ((a >> 7) & 0x0001)) { o = false; } else { o = true; } } _fm = ((_aluResult & 0x80) != 0 ? fm.CFlag : 0) | (o ? fm.OFlag : 0) | (FlagS ? fm.SFlag : 0) | (FlagZ ? fm.ZFlag : 0) | (FlagP ? fm.PFlag : 0) | (FlagA ? fm.AFlag : 0); return((byte)_aluResult); } }
public ushort Ror16(ushort a, byte b) { unchecked { if (b == 0) { return(a); } b %= 16; _aluResult = (uint)((a >> b) | (a << (16 - b))); bool o; if (b == 1) { o = ((_aluResult ^ (_aluResult >> 1)) & 0x4000) != 0; } else { if ((a & 0x0001) == ((a >> 15) & 0x0001)) { o = false; } else { o = true; } } _fm = ((_aluResult & 0x8000) != 0 ? fm.CFlag : 0) | (o ? fm.OFlag : 0) | (FlagS ? fm.SFlag : 0) | (FlagZ ? fm.ZFlag : 0) | (FlagP ? fm.PFlag : 0) | (FlagA ? fm.AFlag : 0); return((ushort)_aluResult); } }
public byte Rcl8(byte a, byte b) { if (b == 0) { return(a); } b %= 9; _aluResult = (uint)((FlagC ? 0x100 : 0) | (a & 0xFF)); _aluResult = (_aluResult << b) | (_aluResult >> (9 - b)); bool o; if (b == 1) { o = ((_aluResult ^ (_aluResult << 1)) & 0x100) != 0; } else { if (((a >> 1) & 0x40) == (a & 0x40)) { o = false; } else { o = true; } } _fm = fm.Bit8 | fm.CFromResult | (o ? fm.OFlag : 0) | (FlagS ? fm.SFlag : 0) | (FlagZ ? fm.ZFlag : 0) | (FlagP ? fm.PFlag : 0) | (FlagA ? fm.AFlag : 0); return((byte)_aluResult); }
public ushort Rcl16(ushort a, byte b) { if (b == 0) { return(a); } b %= 17; _aluResult = (uint)((FlagC ? 0x10000 : 0) | (a & 0xFFFF)); _aluResult = (_aluResult << b) | (_aluResult >> (17 - b)); bool o; if (b == 1) { o = ((_aluResult ^ (_aluResult << 1)) & 0x10000) != 0; } else { if (((a >> 1) & 0x4000) == (a & 0x4000)) { o = false; } else { o = true; } } _fm = fm.CFromResult | (o ? fm.OFlag : 0) | (FlagS ? fm.SFlag : 0) | (FlagZ ? fm.ZFlag : 0) | (FlagP ? fm.PFlag : 0) | (FlagA ? fm.AFlag : 0); return((ushort)_aluResult); }