
/**
  Pone el registro de entrada en un formato para UI
 */
void regEnter2UI(char *buff){
  int i;  
  buff[0] = 0;
  
  for(i=0; i<(8-POS); i++){
    strcat(buff, " ");
  }
  strcat(buff, "E=");
  reg2String(REG_ENTER, MAX_ENTER, &buff[(8-POS)+2]);
}

/**
  Pone el registro acumulador en un formato para UI
 */
void regAccum2UI(char *buff){
  buff[0] = 0;

  strcpy(buff, "     A=");
  reg2String(REG_ACCUM, MAX_ACCUM, &buff[7]);
}

/**
  Pone el registro contador en un formato para UI
 */
void regCount2UI(char *buff){
  buff[0] = 0;

  strcpy(buff, "         ");
  if(ZERO_COUNTER==false){
    if(POSITIVE_FIRST==true){
      strcat(buff, "+");
    }else{
      strcat(buff, "-");
    }
  }else{
    strcat(buff, " ");
  }
  
  strcat(buff, "C=");
  reg2String(REG_COUNT, MAX_COUNT, &buff[12]);
}

/**
  Construye un string para mostrar la flecha del la posición
 */
void arrow2UI(char *buff){
  int i;
  
  buff[0] = 0;
  strcpy(buff, "Duimometer");
  for(i=0; i<(8-POS); i++){
    strcat(buff, " ");
  }
  strcat(buff, " ^");
}


/**
  Transforma un registro a string
 */
void reg2String(byte* reg, int len, char* dst){
  boolean zeroleft = true;
  int i;
  for(i=len-1; i >= 0; i--){
    if(reg[i] == 0 && zeroleft == true){
      dst[len-i-1] = '_';
    }else{
      dst[len-i-1] = '0'+reg[i];
    }
    if(reg[i] != 0){
      zeroleft = false;
    }
  }
  dst[len]=0;
}

/**
 * Expresa por la UI un overflow de registro
 */
void overflowSignal(){
  digitalWrite(A3, HIGH);
  delay(250);
  digitalWrite(A3, LOW);
  delay(100);
  digitalWrite(A3, HIGH);
  delay(250);
  digitalWrite(A3, LOW);  
}
