OpCodeT16IfThen.cs 996 B

12345678910111213141516171819202122232425262728293031323334
  1. using System.Collections.Generic;
  2. using System.Reflection.Emit;
  3. namespace ARMeilleure.Decoders
  4. {
  5. class OpCodeT16IfThen : OpCodeT16
  6. {
  7. public Condition[] IfThenBlockConds { get; }
  8. public int IfThenBlockSize { get { return IfThenBlockConds.Length; } }
  9. public new static OpCode Create(InstDescriptor inst, ulong address, int opCode) => new OpCodeT16IfThen(inst, address, opCode);
  10. public OpCodeT16IfThen(InstDescriptor inst, ulong address, int opCode) : base(inst, address, opCode)
  11. {
  12. List<Condition> conds = new();
  13. int cond = (opCode >> 4) & 0xf;
  14. int mask = opCode & 0xf;
  15. conds.Add((Condition)cond);
  16. while ((mask & 7) != 0)
  17. {
  18. int newLsb = (mask >> 3) & 1;
  19. cond = (cond & 0xe) | newLsb;
  20. mask <<= 1;
  21. conds.Add((Condition)cond);
  22. }
  23. IfThenBlockConds = conds.ToArray();
  24. }
  25. }
  26. }