コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
 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);
     }
 }
コード例 #5
0
 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);
     }
 }
コード例 #6
0
 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);
     }
 }
コード例 #7
0
 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);
     }
 }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
        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);
            }
        }
コード例 #14
0
        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);
            }
        }
コード例 #15
0
        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);
            }
        }
コード例 #16
0
        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);
            }
        }
コード例 #17
0
        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);
            }
        }
コード例 #18
0
        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);
            }
        }
コード例 #19
0
        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);
            }
        }
コード例 #20
0
        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);
            }
        }
コード例 #21
0
        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);
            }
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        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);
        }