Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #3
0
 public static void RETFIE(Data.Command com)
 {
     Data.SetPC(Data.PopStack());
     Data.SetPCLfromPC();
     Data.SetRegisterBit(Data.Registers.INTCON, Data.Flags.Intcon.GIE, true); //Re-enable Global-Interrupt-Bit
     SkipCycle();
 }
Beispiel #4
0
 public static void SLEEP(Data.Command com)
 {
     CLRWDT(null);
     Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.TO, true);
     Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.PD, false);
     Data.SetSleeping(true);
     Data.SetPC(Data.GetPC() - 1);
 }
Beispiel #5
0
        public static void ADDLW(Data.Command com)
        {
            byte k = com.GetLowByte();

            byte result = BitwiseAdd(Data.GetRegisterW(), k);

            Data.SetRegisterW(result);
        }
Beispiel #6
0
        public static void SUBLW(Data.Command com)
        {
            byte k = com.GetLowByte();

            byte result = BitwiseSubstract(k, Data.GetRegisterW());

            Data.SetRegisterW(result);
        }
Beispiel #7
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);
        }
Beispiel #8
0
        public static void RETLW(Data.Command com)
        {
            byte k = com.GetLowByte();

            Data.SetRegisterW(k);
            Data.SetPC(Data.PopStack());
            Data.SetPCLfromPC();
            SkipCycle();
        }
Beispiel #9
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);
        }
Beispiel #10
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);
        }
Beispiel #11
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);
        }
Beispiel #12
0
        public static void XORLW(Data.Command com)
        {
            byte k = com.GetLowByte();

            byte result = (byte)(Data.GetRegisterW() ^ k);

            CheckZFlag(result);
            Data.SetRegisterW(result);
        }
Beispiel #13
0
 public static void CLRWDT(Data.Command com)
 {
     Data.ResetWatchdog();
     Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.TO, true);
     Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.PD, false);
     if (Data.GetRegisterBit(Data.Registers.OPTION, Data.Flags.Option.PSA) == true)
     {
         Data.ResetPrePostScaler(); //Reset Postscaler if assigned to WDT
     }
 }
Beispiel #14
0
        public static void GOTO(Data.Command com)
        {
            byte k1 = com.GetLowByte();
            byte k2 = (byte)(com.GetHighByte() & 7);

            byte merge = (byte)((Data.GetRegister(Data.Registers.PCLATH) & 24) + k2);

            Data.SetPCFromBytes(merge, k1);
            Data.SetPCLfromPC();
            SkipCycle();
        }
Beispiel #15
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)));
            }
        }
Beispiel #16
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);
        }
Beispiel #17
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();
            }
        }
Beispiel #18
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);
        }
Beispiel #19
0
 /// <summary>
 /// Step function. Executes current command of loaded program and increases PC
 /// </summary>
 /// <returns>false if within program bounds, true if PC left program bounds</returns>
 public static void PCStep()
 {
     if (Data.IsProgramInitialized())
     {
         if (!Data.IsSleeping())
         {
             if (Data.GetPC() < Data.GetProgram().Count)
             {
                 Data.Command com = Data.GetProgram()[Data.GetPC()];
                 Data.IncPC();
                 InstructionProcessor.Execute(Data.InstructionLookup(com), com);
             }
             else //PC has left program area
             {
                 Data.IncPC();
             }
         }
         SkipCycle();
     }
 }
Beispiel #20
0
        public static void Execute(Data.Instruction instruction, Data.Command com)
        {
            MethodInfo theMethod = typeof(InstructionProcessor).GetMethod(instruction.ToString());

            theMethod.Invoke(null, new object[] { com });
        }
Beispiel #21
0
 public static void NOP(Data.Command com)
 {
     //NOP
 }
Beispiel #22
0
 public static void CLRW(Data.Command com)
 {
     Data.SetRegisterW(0);
     Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.Z, true);
 }
Beispiel #23
0
        public static void MOVWF(Data.Command com)
        {
            byte f = (byte)(com.GetLowByte() & 127);

            Data.SetRegister(Data.AddressResolution(f), Data.GetRegisterW());
        }
Beispiel #24
0
 public static void RETURN(Data.Command com)
 {
     Data.SetPC(Data.PopStack());
     Data.SetPCLfromPC();
     SkipCycle();
 }
Beispiel #25
0
        public static void MOVLW(Data.Command com)
        {
            byte k = com.GetLowByte();

            Data.SetRegisterW(k);
        }