Пример #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();
        }
Пример #2
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog()
            {
                Filter      = "Intel HEX File (*.hex) | *.hex",
                Multiselect = false,
                FileName    = Properties.Settings.Default.LastOpenedFile
            };
            DialogResult result = dialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }
            _cpu = new PIC16FCpu(256, 1024);
            _cpu.FillProgramMemory(dialog.FileName);

            foreach (UInt16 cell in _cpu.ProgramMemory)
            {
                lstProgramMemory.Items.Add(cell.ToString("X"));
            }

            Properties.Settings.Default.LastOpenedFile = dialog.FileName;
            Properties.Settings.Default.Save();
        }
Пример #3
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();
        }
Пример #4
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();
        }
Пример #5
0
 public static void INCFSZ_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     INCF_Action(instruction, cpu);
     if (cpu.StatusRegister.Z)
     {
         cpu.IncrementPC();
     }
     cpu.IncrementPC();
 }
Пример #6
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();
        }
Пример #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();
        }
Пример #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();
        }
Пример #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();
        }
Пример #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();
        }
Пример #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();
        }
Пример #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();
        }
Пример #13
0
 public static void SLEEP_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     // TODO: Manage sleep in some way
     NOP_Action(instruction, cpu);
 }
Пример #14
0
 public static void RETURN_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.ProgramCounter = cpu.Stack.Pop();
 }
Пример #15
0
 public static void CLRWDT_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.IncrementPC();
 }                                                                                                     // Nothing to do here until WDT is implemented
Пример #16
0
 public static void RETFIE_Action(PIC16FInstruction instruction, PIC16FCpu cpu) // TODO: Implement RETFIE
 {
     NOP_Action(instruction, cpu);
 }
Пример #17
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;
 }
Пример #18
0
 public static void MOVLW_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.WRegister.Register = instruction.Operand;
     cpu.IncrementPC();
 }
Пример #19
0
 public static void GOTO_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.ProgramCounter = instruction.Operand;
 }
Пример #20
0
 public static void RETLW_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.WRegister.Register = instruction.Operand;
     cpu.ProgramCounter     = cpu.Stack.Pop();
 }
Пример #21
0
 public static void NOP_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.IncrementPC();
 }
Пример #22
0
 public static void CLRW_Action(PIC16FInstruction instruction, PIC16FCpu cpu)
 {
     cpu.WRegister.Register = 0;
     cpu.StatusRegister.Z   = true;
     cpu.IncrementPC();
 }