Advertisement
NWPlayer123

bcx implementation

Sep 19th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1.     #define inst_BO_0 (inst.BO & (1 << 4)) //if set, ignore BO_TRUE
  2.     #define inst_BO_1 (inst.BO & (1 << 3)) //if set, check if condition is TRUE
  3.     #define inst_BO_2 (inst.BO & (1 << 2)) //if set, ignore CTR
  4.     #define inst_BO_3 (inst.BO & (1 << 1)) //if set, branch if CTR is 0 (else != 0)
  5.     #define inst_BO_4 (inst.BO & (1 << 0)) //branch predictor hint ("+")
  6.     bool CR::getbit(u8 index) {
  7.         return (this->hex >> (31 - index)) & 1;
  8.     }
  9.     void bcx(gekko::instruction& inst, std::unique_ptr<gekko::cpu>& cpu) { //opcode 16
  10.         if (!inst_BO_2) cpu->ctr--; //not ignoring ctr, decrement
  11.         ctr_ok = inst_BO_2 || ((cpu->ctr != 0) ^ inst_BO_3);
  12.         cond_ok = inst_BO_0 || (cpu->CR.getbit(inst.BI) ^ !inst_BO_1);
  13.         if (ctr_ok && cond_ok) {
  14.             if (inst.LK) //linking, update link register
  15.                 cpu->lr = cpu->pc + 4;
  16.  
  17.             if (inst.AA) //absolute address
  18.                 cpu->pc = EXTS(inst.BD << 2);
  19.             else //relative, add (will go backwards if negative)
  20.                 cpu->pc += EXTS(inst.BD << 2);
  21.         }
  22.         else {
  23.             cpu->pc += 4;
  24.         }
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement