home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 3
/
FREEWARE.BIN
/
towns_os
/
hal
/
crosrtn.c
next >
Wrap
Text File
|
1980-01-02
|
3KB
|
167 lines
/* crosrtn.c 1990.02.11 Programmed by MSどす */
/* last update 1990.04.24 */
extern int inp();
extern int outp();
#include "crossam.h"
int put4bit(data)
UCHAR data;
{
int i,j;
UCHAR co,ci;
for(i=0;i<4;i++){
co=((data & 1) ? DATA_SET : STB_OFF); /* DATA SET & STB OFF */
data >>= 1;
outp(PADOUT,co);
for(j=0;j<TIMEOUT;j++){ /* WAIT READY = ON */
ci=(unsigned char)inp(PADIN);
if((ci & 0x42) == 0x42) break;
}
if(j >= TIMEOUT) return (NG);
co=STB_ON; /* STB ON */
outp(PADOUT,co);
for(j=0;j<TIMEOUT;j++){ /* WAIT READY = OFF */
ci=(unsigned char)inp(PADIN);
if((ci & 0x42) == 0x40) break;
}
if(j >= TIMEOUT) return (NG);
}
return (OK);
}
int get8bit(data)
UCHAR *data;
{
int i,j;
UCHAR co,ci,d;
d=0;
for(i=0;i<8;i++){
for(j=0;j<TIMEOUT;j++){ /* WAIT READY = ON & GET DATA */
ci=(unsigned char)inp(PADIN);
if((ci & 0x42) == 0x42) break;
}
if(j >= TIMEOUT) return (NG);
d >>= 1;
d |= ((ci & 0x01) ? 0x80 : 0);
co=STB_OFF; /* STB OFF */
outp(PADOUT,co);
for(j=0;j<TIMEOUT;j++){ /* WAIT READY = OFF */
ci=(unsigned char)inp(PADIN);
if((ci & 0x42) == 0x40) break;
}
if(j >= TIMEOUT) return (NG);
co=STB_ON; /* STB ON */
outp(PADOUT,co);
}
*data = d;
return (OK);
}
void wait(loop)
int loop;
{
int i;
for(i=0;i<loop;i++) ;
}
int xamkey(dial,key)
UCHAR *dial,*key;
{
UCHAR c,d;
if(put4bit(FSET)) return(NG);
if(put4bit(ZERO)) return(NG);
wait(SWAIT);
if(put4bit(KSET)) return(NG);
if(put4bit(ZERO)) return(NG); /* 下位nibble */
if(put4bit(ZERO)) return(NG); /* 上位nibble */
wait(SWAIT);
if(put4bit(SADR)) return(NG);
wait(SWAIT);
if(put4bit(PLON)) return(NG);
wait(SWAIT);
d=0xff;
while(d==0xff){
c=STB_ON; /* STB ON */
outp(PADOUT,c);
wait(LWAIT);
if(put4bit(IKEY)) continue;
if(get8bit(&d)) return(NG);
}
*dial = (d/40)+1;
*key = (d%40)+1;
wait(SWAIT);
if(put4bit(PLOF)) return(NG);
return (OK);
}
int xamout(dial,key,time)
UCHAR dial,key;
int time;
{
UCHAR c;
if(put4bit(FSET)) return(NG);
c=dial-1;
if(put4bit(c)) return(NG);
wait(SWAIT);
if(put4bit(KSET)) return(NG);
c=((key-1) & 0x0f);
if(put4bit(c)) return(NG); /* 下位nibble */
c=((key-1) >> 4);
if(put4bit(c)) return(NG); /* 上位nibble */
wait(SWAIT);
if(put4bit(SADR)) return(NG);
wait(SWAIT);
if(put4bit(PLON)) return(NG);
wait(SWAIT);
if(put4bit(COUT)) return(NG);
c=STB_OFF; /* STB OFF */
outp(PADOUT,c);
wait(time);
c=STB_ON; /* STB ON */
outp(PADOUT,c);
wait(MWAIT); /* WAIT FIN of COUT */
c=STB_ON; /* STB ON */
outp(PADOUT,c);
wait(SWAIT);
if(put4bit(PLOF)) return(NG);
wait(SWAIT);
return (OK);
}
void stb(flg)
int flg;
{
UCHAR c;
if(flg){
c=STB_ON;
}
else{
c=STB_OFF;
}
outp(PADOUT,c);
}