Exemple #1
0
        private ushort Perform(ushort a, ushort b, Func <ushort, ushort, int> operation, RegisterFlags affectedFlags)
        {
            int    intermediate = operation(a, b);
            ushort result       = (ushort)(intermediate & 0xFFFF);

            _registers.ClearFlags(affectedFlags);
            var setAffected = RegisterFlags.None;

            if ((intermediate & (1 << 16)) == (1 << 16))
            {
                setAffected |= RegisterFlags.C;
            }
            if ((operation((ushort)(a & 0xFFF), (ushort)(b & 0xFFF)) & (1 << 12)) == (1 << 12))
            {
                setAffected |= RegisterFlags.H;
            }
            if (result == 0)
            {
                setAffected |= RegisterFlags.Z;
            }
            _registers.SetFlags(setAffected & affectedFlags);
            return(result);
        }
Exemple #2
0
        private ushort Perform(ushort a, ushort b, Func <ushort, ushort, int> operation, RegisterFlags affectedFlags)
        {
            int    intermediate  = operation(a, b);
            ushort result        = (ushort)(intermediate & 0xFFFF);
            int    carryBits     = (a ^ b ^ intermediate);
            int    halfCarryBits = (a ^ b ^ result);

            _registers.ClearFlags(affectedFlags);

            var setAffected = RegisterFlags.None;

            if ((carryBits & 0x10000) == 0x10000)
            {
                setAffected |= RegisterFlags.C;
            }

            if ((halfCarryBits & 0x1000) == 0x1000)
            {
                setAffected |= RegisterFlags.H;
            }

            if (result == 0)
            {
                setAffected |= RegisterFlags.Z;
            }

            _registers.SetFlags(setAffected & affectedFlags);
            return(result);
        }