public static void MOVWF_Action(PIC16FInstruction instruction, PIC16FCpu cpu) { int address = cpu.GetBankedAddress(instruction); cpu.RAMMemoryAndRegisters[address].Register = cpu.WRegister.Register; cpu.IncrementPC(); }
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(); }
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(); }
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(); }
public static void INCFSZ_Action(PIC16FInstruction instruction, PIC16FCpu cpu) { INCF_Action(instruction, cpu); if (cpu.StatusRegister.Z) { cpu.IncrementPC(); } cpu.IncrementPC(); }
public void ExecuteInstruction() { PIC16FInstruction instruction = Instructions.ParseMemoryCell(ProgramMemory[ProgramCounter]); if (instruction is null) { return; } instruction.InstructionAction.Invoke(instruction, this); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
public static void SLEEP_Action(PIC16FInstruction instruction, PIC16FCpu cpu) { // TODO: Manage sleep in some way NOP_Action(instruction, cpu); }
public static void RETURN_Action(PIC16FInstruction instruction, PIC16FCpu cpu) { cpu.ProgramCounter = cpu.Stack.Pop(); }
public static void GOTO_Action(PIC16FInstruction instruction, PIC16FCpu cpu) { cpu.ProgramCounter = instruction.Operand; }
public static void RETFIE_Action(PIC16FInstruction instruction, PIC16FCpu cpu) // TODO: Implement RETFIE { NOP_Action(instruction, cpu); }
public static void NOP_Action(PIC16FInstruction instruction, PIC16FCpu cpu) { cpu.IncrementPC(); }
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; }
public static void MOVLW_Action(PIC16FInstruction instruction, PIC16FCpu cpu) { cpu.WRegister.Register = instruction.Operand; cpu.IncrementPC(); }
public static void CLRW_Action(PIC16FInstruction instruction, PIC16FCpu cpu) { cpu.WRegister.Register = 0; cpu.StatusRegister.Z = true; cpu.IncrementPC(); }
public static void RETLW_Action(PIC16FInstruction instruction, PIC16FCpu cpu) { cpu.WRegister.Register = instruction.Operand; cpu.ProgramCounter = cpu.Stack.Pop(); }
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))); }
public static void CLRWDT_Action(PIC16FInstruction instruction, PIC16FCpu cpu) { cpu.IncrementPC(); } // Nothing to do here until WDT is implemented