private static byte BitwiseSubstract(byte b1, byte b2) { //calculate two's complement b2 = (byte)(~b2 + 1); //calculate result byte result = (byte)(b1 + b2); //FLAGS //set Carry flag if byte overflows OR if either b1 or b2 is zero if (result < b1 || result < b2 || b1 == 0 || b2 == 0) { Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.C, true); } else { Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.C, false); } //set DC flag if 4th low order bit overflows OR if either b1 or b2 is zero if (((((b1 & 15) + (b2 & 15)) & 16) == 16) || b1 == 0 || b2 == 0) { Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.DC, true); } else { Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.DC, false); } //set Z flag if result is zero CheckZFlag(result); return(result); }
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(); }
/// <summary> /// Bitwise add of two bytes, also sets Z, C and DC flag /// </summary> /// <param name="b1"></param> /// <param name="b2"></param> /// <returns></returns> private static byte BitwiseAdd(byte b1, byte b2) { //calculate result byte result = (byte)(b1 + b2); //FLAGS //set Carry flag if byte overflows if (result < b1 || result < b2) { Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.C, true); } else { Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.C, false); } //set DC flag if 4th low order bit overflows //if (((b1 & 8) == 8 || (b2 & 8) == 8) && (result & 8) == 0) if ((((b1 & 15) + (b2 & 15)) & 16) == 16) { Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.DC, true); } else { Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.DC, false); } //set Z flag if result is zero CheckZFlag(result); return(result); }
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); }
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); }
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); }
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); }
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 } }
/// <summary> /// sets Z flag to 1 if result is zero /// </summary> /// <param name="result"></param> private static void CheckZFlag(byte result) { if (result == 0) { Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.Z, true); } else { Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.Z, false); } }
private static void CallInterrupt() { Data.PushStack(); Data.SetPC(0x04); //Fixed interrupt routine address Data.SetRegisterBit(Data.Registers.INTCON, Data.Flags.Intcon.GIE, false); //Disable Global-Interrupt-Bit if (Data.IsSleeping()) { Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.TO, true); Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.PD, false); Data.IncPC(); Data.SetSleeping(false); } }
public static void CLRW(Data.Command com) { Data.SetRegisterW(0); Data.SetRegisterBit(Data.Registers.STATUS, Data.Flags.Status.Z, true); }