home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 2 / FreeSoftwareCollection2pd199x-jp.img / av / crosrtn.c next >
Text File  |  1990-06-14  |  3KB  |  167 lines

  1. /*        crosrtn.c    1990.02.11    Programmed by MSどす        */
  2. /*        last update    1990.04.24                                */
  3.  
  4. extern    int    inp();
  5. extern    int    outp();
  6.  
  7. #include "crossam.h"
  8.  
  9. int    put4bit(data)
  10. UCHAR    data;
  11. {
  12.     int    i,j;
  13.     UCHAR    co,ci;
  14.     
  15.     for(i=0;i<4;i++){
  16.         co=((data & 1) ? DATA_SET : STB_OFF);        /* DATA SET & STB OFF */
  17.  
  18.         data >>= 1;
  19.         outp(PADOUT,co);
  20.                 
  21.         for(j=0;j<TIMEOUT;j++){        /* WAIT    READY = ON */
  22.             ci=(unsigned char)inp(PADIN);
  23.             if((ci & 0x42) == 0x42)    break;
  24.         }
  25.         if(j >= TIMEOUT)    return    (NG);
  26.  
  27.         co=STB_ON;                    /* STB ON    */
  28.         outp(PADOUT,co);
  29.         for(j=0;j<TIMEOUT;j++){        /* WAIT    READY = OFF */
  30.             ci=(unsigned char)inp(PADIN);
  31.             if((ci & 0x42) == 0x40)    break;
  32.         }
  33.         if(j >= TIMEOUT)    return    (NG);
  34.     }
  35.     return (OK);
  36. }
  37.  
  38. int    get8bit(data)
  39. UCHAR    *data;
  40. {
  41.     int    i,j;
  42.     UCHAR    co,ci,d;
  43.     
  44.     d=0;
  45.     for(i=0;i<8;i++){
  46.         for(j=0;j<TIMEOUT;j++){        /* WAIT    READY = ON & GET DATA */
  47.             ci=(unsigned char)inp(PADIN);
  48.             if((ci & 0x42) == 0x42)    break;
  49.         }
  50.         if(j >= TIMEOUT)    return    (NG);
  51.         d >>= 1;
  52.         d |= ((ci & 0x01) ? 0x80 : 0);
  53.         
  54.         co=STB_OFF;                    /* STB OFF    */
  55.         outp(PADOUT,co);
  56.  
  57.         for(j=0;j<TIMEOUT;j++){        /* WAIT    READY = OFF */
  58.             ci=(unsigned char)inp(PADIN);
  59.             if((ci & 0x42) == 0x40)    break;
  60.         }
  61.         if(j >= TIMEOUT)    return    (NG);
  62.  
  63.         co=STB_ON;                    /* STB ON    */
  64.         outp(PADOUT,co);
  65.     }
  66.     *data = d;
  67.     return (OK);
  68. }
  69.  
  70. void wait(loop)
  71. int    loop;
  72. {
  73.     int    i;
  74.     for(i=0;i<loop;i++)    ;
  75. }
  76.  
  77. int    xamkey(dial,key)
  78. UCHAR    *dial,*key;
  79. {
  80.     UCHAR    c,d;
  81.     
  82.     if(put4bit(FSET))    return(NG);
  83.     if(put4bit(ZERO))    return(NG);
  84.     wait(SWAIT);
  85.     if(put4bit(KSET))    return(NG);
  86.     if(put4bit(ZERO))    return(NG);        /* 下位nibble */
  87.     if(put4bit(ZERO))    return(NG);        /* 上位nibble */
  88.     wait(SWAIT);
  89.     if(put4bit(SADR))    return(NG);
  90.     wait(SWAIT);
  91.     if(put4bit(PLON))    return(NG);
  92.     wait(SWAIT);
  93.     
  94.     d=0xff;
  95.     while(d==0xff){
  96.         c=STB_ON;                    /* STB ON    */
  97.         outp(PADOUT,c);
  98.         wait(LWAIT);
  99.         if(put4bit(IKEY))    continue;
  100.         if(get8bit(&d))    return(NG);
  101.     }
  102.     
  103.     *dial = (d/40)+1;
  104.     *key = (d%40)+1;
  105.     
  106.     wait(SWAIT);
  107.     if(put4bit(PLOF))    return(NG);
  108.  
  109.     return (OK);
  110. }
  111.  
  112. int    xamout(dial,key,time)
  113. UCHAR    dial,key;
  114. int    time;
  115. {
  116.     UCHAR    c;
  117.     
  118.     if(put4bit(FSET))    return(NG);
  119.     c=dial-1;
  120.     if(put4bit(c))    return(NG);
  121.     wait(SWAIT);
  122.     if(put4bit(KSET))    return(NG);
  123.     c=((key-1) & 0x0f);
  124.     if(put4bit(c))    return(NG);        /* 下位nibble */
  125.     c=((key-1) >> 4);
  126.     if(put4bit(c))    return(NG);        /* 上位nibble */
  127.     wait(SWAIT);
  128.     if(put4bit(SADR))    return(NG);
  129.     wait(SWAIT);
  130.     if(put4bit(PLON))    return(NG);
  131.     wait(SWAIT);
  132.  
  133.     if(put4bit(COUT))    return(NG);
  134.     c=STB_OFF;                    /* STB OFF    */
  135.     outp(PADOUT,c);
  136.  
  137.     wait(time);
  138.  
  139.     c=STB_ON;                    /* STB ON    */
  140.     outp(PADOUT,c);
  141.     wait(MWAIT);            /* WAIT FIN of COUT */
  142.     c=STB_ON;                    /* STB ON    */
  143.     outp(PADOUT,c);
  144.  
  145.     wait(SWAIT);
  146.     if(put4bit(PLOF))    return(NG);
  147.     wait(SWAIT);
  148.  
  149.     return (OK);
  150. }
  151.  
  152. void    stb(flg)
  153. int    flg;
  154. {
  155.     UCHAR    c;
  156.     
  157.     if(flg){
  158.         c=STB_ON;
  159.     }
  160.     else{
  161.         c=STB_OFF;
  162.     }
  163.     
  164.     outp(PADOUT,c);
  165. }
  166.  
  167.