public static void RRF(UInt16 Befehl, Arbeitsspeicher RAM, byte bank) { byte tempState = RAM.RAM[0, 3]; byte regValue = RAM.getRegisterValue(bank, (byte)(Befehl & 0x7F)); if ((regValue & 0x1) == 0) { RAM.CarryBit(bank, 0); //wenn das niedrigste Bit == 0, schreibe 0 in C-Bit } else { RAM.CarryBit(bank, 1); // ansonsten 1 in C-Bit } regValue = (byte)(regValue / 2); if ((tempState & 0x1) == 0) { regValue = (byte)(regValue & 0x7F); // wenn C-Bit == 0, dann wird 0 an das höchste Bit geschrieben } else { regValue = (byte)(regValue | 0x80); // ansonsten 1 } if ((Befehl & 0x80) == 0) { RAM.ChangeW(regValue); } else { RAM.ChangeRegister(bank, (byte)(Befehl & 0x7F), regValue); } ++RAM.RAM[bank, 2]; RAM.incInternalTimer(1); }
static void SUBWF(UInt16 Befehl, Arbeitsspeicher RAM, byte bank) { byte regValue = RAM.getRegisterValue(bank, (byte)(Befehl & 0x7F)); if (regValue >= RAM.W) { RAM.CarryBit(bank, 1); } else { RAM.CarryBit(bank, 0); //C } if ((regValue & 0x0F) >= (RAM.W & 0x0F)) { RAM.DigitCarryBit(bank, 1); } else { RAM.DigitCarryBit(bank, 0); //DC, wenn Low Byte von W } if ((Befehl & 0x80) == 0) { RAM.ChangeW((byte)(regValue - RAM.W)); RAM.ZeroBit(bank); } else { RAM.ChangeRegister(bank, (byte)(Befehl & 0x7F), (byte)(regValue - RAM.W)); RAM.ZeroBit(bank, Befehl); } ++RAM.RAM[bank, 2]; RAM.incInternalTimer(1); }
public static void ADDWF(UInt16 Befehl, Arbeitsspeicher RAM, byte bank) { byte regValue = RAM.getRegisterValue(bank, (byte)(Befehl & 0x7F)); if ((regValue + RAM.W) > 0xFF) { RAM.CarryBit(bank, 1); } else { RAM.CarryBit(bank, 0); //C } if (((RAM.W & 0xF) + (regValue & 0xF)) > 0xF) { RAM.DigitCarryBit(bank, 1); } else { RAM.DigitCarryBit(bank, 0); //DC, wenn die beiden Low Byte addiert >15 sind } if ((Befehl & 0x80) == 0) { RAM.ChangeW((byte)(RAM.W + regValue)); RAM.ZeroBit(bank); } else { RAM.ChangeRegister(bank, (byte)(Befehl & 0x7F), (byte)(RAM.W + regValue)); RAM.ZeroBit(bank, Befehl); } ++RAM.RAM[bank, 2]; RAM.incInternalTimer(1); }
public static void INCFSZ(UInt16 Befehl, Arbeitsspeicher RAM, byte bank) { byte regValue = RAM.getRegisterValue(bank, (byte)(Befehl & 0x7F)); bool zeroFlag = false; if ((Befehl & 0x80) == 0) { RAM.ChangeW((byte)(regValue + 1)); if (RAM.W == 0) { zeroFlag = true; } } else { RAM.ChangeRegister(bank, (byte)(Befehl & 0x7F), (byte)(regValue + 1)); if ((byte)(regValue + 1) == 0) { zeroFlag = true; } } if (zeroFlag == false) //Wenn das Zero Flag nicht gesetzt ist, führe nächsten Befehl aus { ++RAM.RAM[bank, 2]; RAM.incInternalTimer(1); } else //ansonsten überspringe den nächsten { RAM.RAM[bank, 2] += 2; RAM.incInternalTimer(2); } }
public static void BCF(UInt16 Befehl, Arbeitsspeicher RAM, byte bank) { byte regValue = RAM.getRegisterValue(bank, (byte)(Befehl & 0x7F)); int tempBit = (int)Math.Pow(2, ((Befehl & 0x0380) >> 7)); RAM.ChangeRegister(bank, (byte)(Befehl & 0x7F), (byte)(regValue & ~tempBit)); ++RAM.RAM[bank, 2]; RAM.incInternalTimer(1); }
public static void BTFSS(UInt16 Befehl, Arbeitsspeicher RAM, byte bank) { byte regValue = RAM.getRegisterValue(bank, (byte)(Befehl & 0x7F)); int tempBit = (int)Math.Pow(2, ((Befehl & 0x0380) >> 7)); if ((regValue & tempBit) == 0) { ++RAM.RAM[bank, 2]; RAM.incInternalTimer(1); } else { RAM.RAM[bank, 2] += 2; RAM.incInternalTimer(2); } }
static void SWAPF(UInt16 Befehl, Arbeitsspeicher RAM, byte bank) { byte regValue = RAM.getRegisterValue(bank, (byte)(Befehl & 0x7F)); byte temp = (byte)(((regValue & 0x0F) * 16) + ((regValue & 0xF0) / 16)); if ((Befehl & 0x80) == 0) { RAM.ChangeW(temp); } else { RAM.ChangeRegister(bank, (byte)(Befehl & 0x7F), temp); } ++RAM.RAM[bank, 2]; RAM.incInternalTimer(1); }
public static void ANDWF(UInt16 Befehl, Arbeitsspeicher RAM, byte bank) { byte regValue = RAM.getRegisterValue(bank, (byte)(Befehl & 0x7F)); if ((Befehl & 0x80) == 0) { RAM.ChangeW((byte)(RAM.W & regValue)); RAM.ZeroBit(bank); } else { RAM.ChangeRegister(bank, (byte)(Befehl & 0x7F), (byte)(RAM.W & regValue)); RAM.ZeroBit(bank, Befehl); } ++RAM.RAM[bank, 2]; RAM.incInternalTimer(1); }