Esempio n. 1
0
        public static void MOVWF_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
        {
            int address = cpu.GetBankedAddress(instruction);

            cpu.RAMMemoryAndRegisters[address].Register = cpu.WRegister.Register;
            cpu.IncrementPC();
        }
Esempio n. 2
0
        public static void CLRF_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
        {
            int address = cpu.GetBankedAddress(instruction);

            cpu.RAMMemoryAndRegisters[address].Register = 0;
            cpu.StatusRegister.Z = true;
            cpu.IncrementPC();
        }
Esempio n. 3
0
        public static void BSF_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
        {
            int    address = cpu.GetBankedAddress(instruction);
            byte   reg     = cpu.RAMMemoryAndRegisters[address].Register;
            UInt16 result  = (UInt16)(reg | (0x01 << instruction.AffectedBit));

            cpu.RAMMemoryAndRegisters[address].Register = (byte)result;
            cpu.IncrementPC();
        }
Esempio n. 4
0
        public static void XORLW_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
        {
            byte   value  = instruction.Operand;
            UInt16 result = (UInt16)(value ^ cpu.WRegister.Register);

            cpu.WRegister.Register = (byte)result;
            cpu.StatusRegister.Z   = result == 0;
            cpu.IncrementPC();
        }
Esempio n. 5
0
 public static void INCFSZ_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     INCF_Action(instruction, cpu);
     if (cpu.StatusRegister.Z)
     {
         cpu.IncrementPC();
     }
     cpu.IncrementPC();
 }
Esempio n. 6
0
        public void ExecuteInstruction()
        {
            PIC16FInstruction instruction = Instructions.ParseMemoryCell(ProgramMemory[ProgramCounter]);

            if (instruction is null)
            {
                return;
            }
            instruction.InstructionAction.Invoke(instruction, this);
        }
Esempio n. 7
0
        public static void SUBLW_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
        {
            byte   value  = instruction.Operand;
            UInt16 result = (UInt16)(value - cpu.WRegister.Register);

            cpu.WRegister.Register = (byte)result;
            cpu.StatusRegister.Z   = result == 0;
            cpu.StatusRegister.C   = (result > 0xff);
            cpu.StatusRegister.DC  = (value & 0x0f + cpu.WRegister.Register & 0x0f) > 0x0f;
            cpu.IncrementPC();
        }
Esempio n. 8
0
        public static void BTFSC_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
        {
            int  address = cpu.GetBankedAddress(instruction);
            byte reg     = cpu.RAMMemoryAndRegisters[address].Register;

            if ((reg & (0x01 << instruction.AffectedBit)) == 0) // Do 2 increment of PC if the bit is clear
            {
                cpu.IncrementPC();
            }
            cpu.IncrementPC();
        }
Esempio n. 9
0
        public static void MOVF_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
        {
            int  address       = cpu.GetBankedAddress(instruction);
            byte registerValue = cpu.RAMMemoryAndRegisters[address].Register;

            if (instruction.Destination == OpcodeDestinations.FileRegister)
            {
                cpu.RAMMemoryAndRegisters[address].Register = registerValue;
            }
            else
            {
                cpu.WRegister.Register = registerValue;
            }
            cpu.StatusRegister.Z = registerValue == 0;
            cpu.IncrementPC();
        }
Esempio n. 10
0
        public static void SWAPF_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
        {
            int    address       = cpu.GetBankedAddress(instruction);
            byte   registerValue = cpu.RAMMemoryAndRegisters[address].Register;
            byte   highNibble    = (byte)(registerValue >> 4);
            byte   lowNibble     = (byte)(registerValue & 0x0f);
            UInt16 result        = (UInt16)(lowNibble << 4 | highNibble);

            if (instruction.Destination == OpcodeDestinations.FileRegister)
            {
                cpu.RAMMemoryAndRegisters[address].Register = (byte)result;
            }
            else
            {
                cpu.WRegister.Register = (byte)result;
            }
            cpu.IncrementPC();
        }
Esempio n. 11
0
        public static void SUBWF_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
        {
            int    address       = cpu.GetBankedAddress(instruction);
            byte   registerValue = cpu.RAMMemoryAndRegisters[address].Register;
            UInt16 result        = (UInt16)(registerValue - cpu.WRegister.Register);

            if (instruction.Destination == OpcodeDestinations.FileRegister)
            {
                cpu.RAMMemoryAndRegisters[address].Register = (byte)result;
            }
            else
            {
                cpu.WRegister.Register = (byte)result;
            }
            cpu.StatusRegister.Z  = result == 0;
            cpu.StatusRegister.C  = (result > 0xff);
            cpu.StatusRegister.DC = (registerValue & 0x0f + cpu.WRegister.Register & 0x0f) > 0x0f;
            cpu.IncrementPC();
        }
Esempio n. 12
0
        public static void RRF_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
        {
            int    address       = cpu.GetBankedAddress(instruction);
            byte   registerValue = cpu.RAMMemoryAndRegisters[address].Register;
            UInt16 result        = (UInt16)(registerValue >> 1);

            result |= cpu.StatusRegister.C ? (UInt16)0x80 : (UInt16)0x00;

            if (instruction.Destination == OpcodeDestinations.FileRegister)
            {
                cpu.RAMMemoryAndRegisters[address].Register = (byte)result;
            }
            else
            {
                cpu.WRegister.Register = (byte)result;
            }
            cpu.StatusRegister.C = (registerValue & 0x01) != 0;
            cpu.IncrementPC();
        }
Esempio n. 13
0
 public static void SLEEP_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     // TODO: Manage sleep in some way
     NOP_Action(instruction, cpu);
 }
Esempio n. 14
0
 public static void RETURN_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.ProgramCounter = cpu.Stack.Pop();
 }
Esempio n. 15
0
 public static void GOTO_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.ProgramCounter = instruction.Operand;
 }
Esempio n. 16
0
 public static void RETFIE_Action(PIC16FInstruction instruction, PIC16FCpu cpu) // TODO: Implement RETFIE
 {
     NOP_Action(instruction, cpu);
 }
Esempio n. 17
0
 public static void NOP_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.IncrementPC();
 }
Esempio n. 18
0
 public static void CALL_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.Stack.Push((UInt16)(cpu.ProgramCounter + 1)); // Add the return address to the stack
     cpu.ProgramCounter = instruction.Operand;
 }
Esempio n. 19
0
 public static void MOVLW_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.WRegister.Register = instruction.Operand;
     cpu.IncrementPC();
 }
Esempio n. 20
0
 public static void CLRW_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.WRegister.Register = 0;
     cpu.StatusRegister.Z   = true;
     cpu.IncrementPC();
 }
Esempio n. 21
0
 public static void RETLW_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.WRegister.Register = instruction.Operand;
     cpu.ProgramCounter     = cpu.Stack.Pop();
 }
Esempio n. 22
0
        public UInt16[] ProgramMemory;              // Program memory is 14 bit wide so we use a 16 bit integer


        private UInt16 GetBankedAddress(PIC16FInstruction instruction)
        {
            return((UInt16)(instruction.DestinationAddress | ((StatusRegister.Register & 0x60) << 2)));
        }
Esempio n. 23
0
 public static void CLRWDT_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.IncrementPC();
 }                                                                                                     // Nothing to do here until WDT is implemented