Example #1
0
unsigned int executeAlu(statusType stat)
{
  unsigned int a = getAluA();
  unsigned int b = getAluB();
  unsigned int fun = getAluFun();
  unsigned int result = 0;

  switch (fun)
  {
    case FADDL:
      result = a + b;
      break;

    case FSUBL:
      result = b - a;
      break;

    case FANDL:
      result = a & b;
      break;

    case FXORL:
      result = a ^ b;
      break;
  }

  if (needToSetCC(stat))
  {
    unsigned int isZero = result == 0;
    unsigned int isSigned = isNegative(result);
    unsigned int isOverflow = 0;

    if (fun == FADDL)
    {
      isOverflow = (isNegative(a) == isNegative(b)) &&
        (isNegative(result) != isNegative(a));
    }
    else if (fun == FSUBL)
    {
      isOverflow = (isNegative(a) != isNegative(b)) &&
        (isNegative(result) == isNegative(a));
    }

    setCC(ZF, isZero);
    setCC(SF, isSigned);
    setCC(OF, isOverflow);
  }

  return result;
}
Example #2
0
void Channel::initCtrl()
      {
      key_pressure     = 0;
      channel_pressure = 0;
      pitch_bend       = 0x2000; // Range is 0x4000, pitch bend wheel starts in centered position
      pitch_wheel_sensitivity = 12; /* twelve semi-tones */
      bank_msb         = 0;

      for (int i = 0; i < GEN_LAST; i++) {
            gen[i]     = 0.0f;
            gen_abs[i] = 0;
            }
      for (int i = 0; i < 128; i++)
            setCC(i, 0);

      /* Volume / initial attenuation (MSB & LSB) */
      setCC(VOLUME_MSB, 127);
      setCC(VOLUME_LSB, 0);

      /* Pan (MSB & LSB) */
      setCC(PAN_MSB, 64);
      setCC(PAN_LSB, 64);

      /* Expression (MSB & LSB) */
      setCC(EXPRESSION_MSB, 127);
      setCC(EXPRESSION_LSB, 127);
      }
Example #3
0
//  Function: performOpl
//  Description: performs the instruction
//  Params: statusType status
//  Returns: result (e_valE)
//  Modifies: set_cc and result (local)
unsigned int performOpl(statusType status)
{
    bool set_cc = true;
    if(status.m_stat == SADR || status.m_stat == SINS || status.m_stat == SHLT ||
        status.W_stat == SADR || status.W_stat == SINS || status.W_stat == SHLT
        ){
       set_cc = false; 
    }

    int a = (int) E.valA;//cast to int because its unsigned
    int b = (int) E.valB;
    int result = 0;

        // The CC register is cleared before every OPL
       if(set_cc){
            clearCC();
       }
    
        // perform addl
       if (E.ifun == 0 && set_cc)//THIS USE TO == ADDL WTF? 
        {
            result = b + a;
    
            if (result == 0 && set_cc)
                setCC(ZF, 1);
        
            if (result < 0 && set_cc)
                setCC(SF, 1);
       
            if (((a < 0) == (b < 0)) && ((result < 0) != (a < 0)) && set_cc)
                setCC(OF, 1);
        }
      else if(E.ifun == 1 && set_cc) //made this an else if instead of if
        {
            result = b - a;
        
            if(result == 0 && set_cc) 
            {
                setCC(ZF, 1);
            }
            if(result < 0 && set_cc)
            {
                setCC(SF, 1);
            }
            if((((a > 0) != (b > 0))) && ((result > 0) == (a > 0)) && set_cc)
            {   
                setCC(OF, 1);
            }
        }
        else if(E.ifun == 2 && set_cc) //made else
        {
            result = b & a;
            if(result == 0 && set_cc)
            {
                setCC(ZF, 1);
            }
            if(result < 0 && set_cc)
            {
                setCC(SF, 1);
            }
        }
        else //use to be an if, switched it to an else. now its 13/17
        {
            result = b ^ a;
            if(result == 0 && set_cc)
            {
                setCC(ZF, 1);
            }
            if(result < 0 && set_cc)
            {
                setCC(SF, 1);
            }
       }
       if(!set_cc){
         setCC(ZF, 0);
         setCC(SF, 0);
         setCC(OF, 0);
       } 
      return result;
}