Example #1
0
        public static void RRF(Data.Command com)
        {
            byte d = (byte)(com.GetLowByte() & 128);
            byte f = (byte)(com.GetLowByte() & 127);

            byte result = (byte)(Data.GetRegister(Data.AddressResolution(f)) >> 1);

            //Add carry bit if flag is set
            if (Data.GetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.C))
            {
                result += 128;
            }

            //Set carry flag for current calculation
            if ((Data.GetRegister(Data.AddressResolution(f)) & 1) == 1)
            {
                Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.C, true);
            }
            else
            {
                Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.C, false);
            }

            DirectionalWrite(d, f, result);
        }
Example #2
0
        public static void CLRF(Data.Command com)
        {
            byte f = (byte)(com.GetLowByte() & 127);

            Data.SetRegister(Data.AddressResolution(f), 0);
            Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.Z, true);
        }
Example #3
0
        public static void BSF(Data.Command com)
        {
            int  b1 = (com.GetHighByte() & 3) << 1;
            int  b  = b1 + (((com.GetLowByte() & 128) == 128) ? 1 : 0);
            byte f  = (byte)(com.GetLowByte() & 127);

            Data.SetRegisterBit(Data.AddressResolution(f), b, true);
        }
Example #4
0
        public static void SWAPF(Data.Command com)
        {
            byte d = (byte)(com.GetLowByte() & 128);
            byte f = (byte)(com.GetLowByte() & 127);

            byte result = (byte)((Data.GetRegister(Data.AddressResolution(f)) & 0x0F) << 4 | (Data.GetRegister(Data.AddressResolution(f)) & 0xF0) >> 4);;

            DirectionalWrite(d, f, result);
        }
Example #5
0
        public static void SUBWF(Data.Command com)
        {
            byte d = (byte)(com.GetLowByte() & 128);
            byte f = (byte)(com.GetLowByte() & 127);

            byte result = BitwiseSubstract(Data.GetRegister(Data.AddressResolution(f)), Data.GetRegisterW());

            DirectionalWrite(d, f, result);
        }
Example #6
0
        public static void ANDWF(Data.Command com)
        {
            byte d = (byte)(com.GetLowByte() & 128);
            byte f = (byte)(com.GetLowByte() & 127);

            byte result = (byte)(Data.GetRegisterW() & Data.GetRegister(Data.AddressResolution(f)));

            DirectionalWrite(d, f, result);
        }
Example #7
0
        public static void INCF(Data.Command com)
        {
            byte d = (byte)(com.GetLowByte() & 128);
            byte f = (byte)(com.GetLowByte() & 127);

            byte result = (byte)(Data.GetRegister(Data.AddressResolution(f)) + 1);

            CheckZFlag(result);

            DirectionalWrite(d, f, result);
        }
Example #8
0
        public static void MOVF(Data.Command com)
        {
            byte d = (byte)(com.GetLowByte() & 128);
            byte f = (byte)(com.GetLowByte() & 127);

            CheckZFlag(Data.GetRegister(Data.AddressResolution(f)));
            if (d != 128)
            {
                Data.SetRegisterW(Data.GetRegister(Data.AddressResolution(f)));
            }
        }
Example #9
0
        public static void BTFSS(Data.Command com)
        {
            int  b1 = (com.GetHighByte() & 3) << 1;
            int  b  = b1 + (((com.GetLowByte() & 128) == 128) ? 1 : 0);
            byte f  = (byte)(com.GetLowByte() & 127);

            if (Data.GetRegisterBit(Data.AddressResolution(f), b) == true)
            {
                Data.IncPC();
                SkipCycle();
            }
        }
Example #10
0
 /// <summary>
 /// Write result according to d bit (relative address)
 /// </summary>
 /// <param name="d"></param>
 /// <param name="f"></param>
 /// <param name="result"></param>
 private static void DirectionalWrite(byte d, byte f, byte result)
 {
     //save to w register
     if (d == 0)
     {
         Data.SetRegisterW(result);
     }
     //save to f address
     else if (d == 128)
     {
         Data.SetRegister(Data.AddressResolution(f), result);
     }
 }
Example #11
0
        public static void INCFSZ(Data.Command com)
        {
            byte d = (byte)(com.GetLowByte() & 128);
            byte f = (byte)(com.GetLowByte() & 127);

            byte result = (byte)(Data.GetRegister(Data.AddressResolution(f)) + 1);

            if (result == 0)
            {
                Data.IncPC();
                SkipCycle();
            }

            DirectionalWrite(d, f, result);
        }
Example #12
0
        public static void MOVWF(Data.Command com)
        {
            byte f = (byte)(com.GetLowByte() & 127);

            Data.SetRegister(Data.AddressResolution(f), Data.GetRegisterW());
        }