//Istance file di board.h : board.c
//Modulo per gestione della scheda parallela Spp Board
//Andrea Cipriani Ago 2004
//a71cip@tiscali.it

void SppBoard8BitOut (unsigned int addr, unsigned int boardaddr, char valu)
//Output di un byte, passare DATA address, boardadrr es. 0x00, e valore
{
 DataOut(addr,valu);
 ControlOut(addr+2,boardaddr+1);     //chip select(boardaddr) + strobe/ a 1
 ControlOut(addr+2,boardaddr);       //chip select(boardaddr) + strobe/ a 0
 ControlOut(addr+2,boardaddr+1);     //chip select(boardaddr) + strobe/ a 1 
}


unsigned char SppBoard8BitIn (unsigned int addr, unsigned int boardaddr)
//Legge 8 bit sulla sppboard, passare in addr DATA e in bordaddr indirizzo interno es. 0x02
{
 unsigned char low_nibble,high_nibble,overflow,read;

 ControlOut(addr+2,boardaddr);    //strobe/ a 0 e cs selezionato
 low_nibble = StatusIn(addr+1);   //legge 4 bit, i meno significativi perche' con strobe/ a 0
 low_nibble = low_nibble & 0xbf;  //lascia i bit che non c'entrano come erano
 //configrazione attuale : d3,X,d2,d1,d0,X,X,X
 if (low_nibble & 0x80)           //se il bit7 e' a 1 
  {
   overflow = 0x80;               //il bit7 di overflow e' a 1
  }
  else
  {
   overflow = 0x00;		   //altrimenti e' a 0
  } 
 low_nibble = low_nibble<<1;     //shifta a sx, configurazione attuale : d2,d1,d0,X,X,X,X e d3 in overflow     
 low_nibble = low_nibble & 0x7f; //lascia stare i bit che non c'entrano
 low_nibble = low_nibble | overflow; //or con overflow, configurazione attuale : d3,d2,d1,d0,X,X,X,X
 low_nibble = low_nibble>>4;     //shifta di 4 a dx, configurazione attuale : X,X,X,X,d3,d2,d1,d0
 low_nibble = low_nibble & 0x0f; //azzera i 4 bit piu' significativi, configurazione attuale : 0,0,0,0,d3,d2,d1,d0

 ControlOut(addr+2,boardaddr+1); //strobe/ a 1 e cs selezionato
 high_nibble = StatusIn(addr+1); //legge 4 bit, i piu' significativi perche' con strobe/ a 1
 high_nibble = high_nibble & 0xbf; //lascia stare i bit che non c'entrano
 //configrazione attuale : d7,X,d6,d5,d4,X,X,X
 if (high_nibble & 0x80)         //se il bit7 e' a 1 
  {
   overflow = 0x80;		  //il bit7 di overflow e' a 1
  }
  else
  {
   overflow = 0x00;            //altrimenti e' a 0
  }
 high_nibble = high_nibble<<1;   //shifta a sx, configurazione attuale : d6,d5,d4,X,X,X,X e d7 in overflow 
 high_nibble = high_nibble & 0x7f;  //lascia stare i bit che non c'entrano
 high_nibble = high_nibble | overflow; //or con overflow, configurazione attuale : d7,d6,d5,d4,X,X,X,X
 high_nibble = high_nibble & 0xf0; //azzera i 4 bit menonificativi, configurazione attuale : d7,d6,d5,d4,0,0,0,0
 return (high_nibble | low_nibble); //or fra i 2 nibble, configurazione attuale : d7,d6,d5,d4,d3,d2,d1,d0

}

