home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 July
/
VPR9707B.ISO
/
DRIVER
/
IODATA
/
RSA3120
/
M120.EXE
/
DOS
/
BIOSSAMP.C
next >
Wrap
Text File
|
1995-02-17
|
14KB
|
654 lines
/*
/* BIOS使用サンプルプログラム
/* Copyright (C) 1995 I-O DATA DEVICE,INC
/*
/* 記述言語:Microsoft (R) C Compiler Version 6.00
/*
/*
/* 1995.02.17 Ver1.00
/*
/*
/* [注意]
/*
/* ・BIOSを組み込んでください。
/* ・ラージメモリモデルでコンパイルしてください。
/* cl /AL /J biossamp.c
/*
/*/
#include <stdio.h>
#include <dos.h>
#include <conio.h>
typedef struct {
unsigned int baseadr; /* ボードベースポートアドレス */
unsigned int reserve1; /* 9032B 互換のためのリザーブ1 */
unsigned int reserve2; /* 9032B 互換のためのリザーブ2 */
unsigned char mode; /* 通信モード */
unsigned char bps; /* ボーレート */
unsigned int (*rxbuf)[]; /* 受信バッファアドレス */
unsigned int rxbuflen; /* 受信バッファ長 */
unsigned int txtim; /* 送信タイムアウト時間 */
unsigned int rxtim; /* 受信タイムアウト時間 */
void (*rxcall)(); /* 受信通知アドレス */
unsigned char intno; /* INT割り込み番号 0~6 */
unsigned char timercount; /* タイマカウントの設定 1~0ffh (1=1.25ms) */
/***** BIOSのワーク *****/
char bioswork[113];
} PPacket;
#define FNCINT 0x60 /* ソフトウェア割り込み番号 */
#define CHANNEL 2 /* 回線番号 */
#define RX_BUF_CNT 2048 /* 受信バッファカウント */
static PPacket PP; /* 通信パラメータパケット */
static unsigned int RsRxBuf[RX_BUF_CNT * 2]; /* 受信バッファ */
/* 2048キャラクタ分(4096バイト) */
main() {
if(BiosCheck()) { /* BIOSの組み込みチェック */
if(RsOpen()) { /* 回線オープン */
/* RsIn(); /* データ受信 */
/* RsOut(); /* データ送信 */
/* RsRxBufInit(); /* 受信バッファの初期化 */
/* RsSts(); /* 回線ステータスの読み取り */
/* RsRxCnt(); /* 受信データ数の読み取り */
/* RsModem(); /* モデム制御 */
/* RsBreak(); /* ブレーク信号の送信 */
/* RsRTxTerm(); /* 中断指示 */
/* RsChRxBuf(); /* 受信バッファの変更 */
/* RsChTxTim(); /* 送信タイムアウト時間の変更 */
/* RsChRxTim(); /* 受信タイムアウト時間の変更 */
/* RsChRxCall(); /* 受信通知アドレスの変更 */
/* RsChBps(); /* ボーレートの変更 */
/* RsChFlow(); /* フロー制御の変更 */
/* RsChSPC(); /* ストップビット、パリティ、キャラクタ長の変更 */
RsClose(); /* 回線クローズ */
/* RsInit(); /* BIOSの無条件初期化 */
}
}
}
/****************************************************************/
/* BIOSの組み込みチェック */
/* */
/* */
/* */
/* */
/****************************************************************/
int BiosCheck() {
static char buf[8+1]="RSABIOS.";
char *cp;
cp=*(char **)(FNCINT*4)-16;
if(strncmp(cp,buf,8)) {
printf("BIOSが組み込まれていません\n");
return(0);
}
else {
printf("BIOSのバージョンは %c.%c%c です\n",*(cp+8),*(cp+9),*(cp+10));
return(1);
}
}
/****************************************************************/
/* 回線オープン */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsOpen() {
union REGS inregs,outregs;
struct SREGS segregs;
unsigned long li;
PP.baseadr=0x50e1; /* ボードベースポートアドレス */
PP.reserve1=0; /* 9032B 互換のためのリザーブ1 */
PP.reserve2=0; /* 9032B 互換のためのリザーブ2 */
PP.mode=0x4d; /* 通信モード */
PP.bps=0x01; /* ボーレート */
*PP.rxbuf=RsRxBuf; /* 受信バッファアドレス */
PP.rxbuflen=RX_BUF_CNT; /* 受信バッファ長 */
PP.txtim=6000; /* 送信タイムアウト時間 */
PP.rxtim=6000; /* 受信タイムアウト時間 */
PP.rxcall=0L; /* 受信通知アドレス */
PP.intno=0; /* INT割り込み番号 0~6 */
PP.timercount=4; /* タイマカウントの設定 1~0ffh (1=1.25ms) */
inregs.h.ah=0;
inregs.h.al=CHANNEL;
li=(unsigned long)&PP;
inregs.x.si=li;
segregs.ds=li>>16;
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("回線オープンエラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
return(1);
}
/****************************************************************/
/* 回線クローズ */
/* */
/* */
/* */
/* */
/****************************************************************/
RsClose() {
union REGS inregs,outregs;
struct SREGS segregs;
inregs.h.ah=1;
inregs.h.al=CHANNEL;
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah)
printf("回線クローズエラー:%d(10)\n",outregs.h.ah-256);
}
/****************************************************************/
/* データ受信 */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsIn() {
union REGS inregs,outregs;
struct SREGS segregs;
for(;;) {
inregs.h.ah=2;
inregs.h.al=CHANNEL;
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("データ受信エラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
else {
printf("受信ステータス:%02x(16) 受信データ:%02x(16)\n",outregs.h.dh,outregs.h.dl);
if(outregs.h.dh & 0x7c)
return(0);
if(outregs.h.dl==0x1a)
return(1);
}
}
}
/****************************************************************/
/* データ送信 */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsOut() {
static char buf[10+1]="RSA-98....";
union REGS inregs,outregs;
struct SREGS segregs;
int i;
for(i=0;buf[i];i++) {
inregs.h.ah=3;
inregs.h.al=CHANNEL;
inregs.h.dl=buf[i];
int86x(FNCINT,&inregs,&outregs,&segregs);
printf("送信ステータス:%02x(16)\n",outregs.h.dh);
if(outregs.h.ah) {
printf("データ送信エラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
}
return(1);
}
/****************************************************************/
/* 受信バッファの初期化 */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsRxBufInit() {
union REGS inregs,outregs;
struct SREGS segregs;
inregs.h.ah=5;
inregs.h.al=CHANNEL;
inregs.h.dl=0;
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("受信バッファの初期化エラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
return(1);
}
/****************************************************************/
/* 回線ステータスの読み取り */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsSts() {
union REGS inregs,outregs;
struct SREGS segregs;
inregs.h.ah=6;
inregs.h.al=CHANNEL;
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("回線ステータスの読み取りエラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
printf("モデム制御の状態:%02x(16)\n",outregs.h.dl);
printf("Xon/Xoff 制御の状態:%02x(16)\n",outregs.h.dh);
printf("ラインステータス:%02x(16)\n",outregs.h.cl);
printf("モデムステータス:%02x(16)\n",outregs.h.ch);
return(1);
}
/****************************************************************/
/* 受信データ数の読み取り */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsRxCnt() {
union REGS inregs,outregs;
struct SREGS segregs;
for(;;) {
inregs.h.ah=7;
inregs.h.al=CHANNEL;
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("受信データ数の読み取りエラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
printf("受信データ数:%d(10)\r",outregs.x.cx);
if(outregs.x.cx > 10) break;
}
return(1);
}
/****************************************************************/
/* モデム制御 */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsModem() {
union REGS inregs,outregs;
struct SREGS segregs;
inregs.h.ah=8;
inregs.h.al=CHANNEL;
inregs.h.dl=0x22; /* RTS=1、DTR=1 */
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("モデム制御エラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
return(1);
}
/****************************************************************/
/* ブレーク信号の送信 */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsBreak() {
union REGS inregs,outregs;
struct SREGS segregs;
inregs.h.ah=9;
inregs.h.al=CHANNEL;
inregs.x.cx=30; /* 300m秒 */
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("ブレーク信号の送信エラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
return(1);
}
/****************************************************************/
/* 中断指示 */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsRTxTerm() {
union REGS inregs,outregs;
struct SREGS segregs;
inregs.h.ah=10;
inregs.h.al=CHANNEL;
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("中断指示エラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
return(1);
}
/****************************************************************/
/* 受信バッファの変更 */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsChRxBuf() {
union REGS inregs,outregs;
struct SREGS segregs;
unsigned long li;
inregs.h.ah=11;
inregs.h.al=CHANNEL;
li=(unsigned long)RsRxBuf;
inregs.x.di=li;
segregs.es=li>>16;
inregs.x.cx=RX_BUF_CNT;
inregs.h.dl=0;
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("受信バッファの変更エラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
return(1);
}
/****************************************************************/
/* 送信タイムアウト時間の変更 */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsChTxTim() {
union REGS inregs,outregs;
struct SREGS segregs;
inregs.h.ah=12;
inregs.h.al=CHANNEL;
inregs.x.cx=6000;
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("送信タイムアウト時間の変更エラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
return(1);
}
/****************************************************************/
/* 受信タイムアウト時間の変更 */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsChRxTim() {
union REGS inregs,outregs;
struct SREGS segregs;
inregs.h.ah=13;
inregs.h.al=CHANNEL;
inregs.x.cx=6000;
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("受信タイムアウト時間の変更エラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
return(1);
}
/****************************************************************/
/* 受信通知アドレスの変更 */
/* */
/* */
/* */
/* */
/****************************************************************/
void RxCall() { }
int RsChRxCall() {
union REGS inregs,outregs;
struct SREGS segregs;
unsigned long li;
inregs.h.ah=14;
inregs.h.al=CHANNEL;
li=(unsigned long)RxCall;
inregs.x.di=li;
segregs.es=li>>16;
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("受信通知アドレスの変更エラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
return(1);
}
/****************************************************************/
/* ボーレートの変更 */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsChBps() {
union REGS inregs,outregs;
struct SREGS segregs;
inregs.h.ah=15;
inregs.h.al=CHANNEL;
inregs.h.dl=0x03;
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("ボーレートの変更エラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
return(1);
}
/****************************************************************/
/* フロー制御の変更 */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsChFlow() {
union REGS inregs,outregs;
struct SREGS segregs;
inregs.h.ah=16;
inregs.h.al=CHANNEL;
inregs.h.dl=1;
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("フロー制御の変更エラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
return(1);
}
/****************************************************************/
/* ストップビット、パリティ、キャラクタ長の変更 */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsChSPC() {
union REGS inregs,outregs;
struct SREGS segregs;
inregs.h.ah=17;
inregs.h.al=CHANNEL;
inregs.h.dl=0x4c;
int86x(FNCINT,&inregs,&outregs,&segregs);
if(outregs.h.ah) {
printf("ストップビット、パリティ、キャラクタ長の変更エラー:%d(10)\n",outregs.h.ah-256);
return(0);
}
return(1);
}
/****************************************************************/
/* BIOSの無条件初期化 */
/* */
/* */
/* */
/* */
/****************************************************************/
int RsInit() {
union REGS inregs,outregs;
struct SREGS segregs;
inregs.h.ah=18;
int86x(FNCINT,&inregs,&outregs,&segregs);
return(1);
}