home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2001 April / VPR0104A.BIN / DRIVER / IODATA / RSDV120 / rsdv120.exe / DISK.EXE / DOS / BIOSSAMP.C next >
Text File  |  1995-02-17  |  14KB  |  654 lines

  1. /*
  2. /*  BIOS使用サンプルプログラム
  3. /*  Copyright (C) 1995 I-O DATA DEVICE,INC
  4. /*
  5. /*    記述言語:Microsoft (R) C Compiler  Version 6.00
  6. /*
  7. /*
  8. /*    1995.02.17 Ver1.00
  9. /*
  10. /*
  11. /*    [注意]
  12. /*
  13. /*     ・BIOSを組み込んでください。
  14. /*     ・ラージメモリモデルでコンパイルしてください。
  15. /*        cl /AL /J biossamp.c
  16. /*
  17. /*/
  18. #include <stdio.h>
  19. #include <dos.h>
  20. #include <conio.h>
  21.  
  22.  
  23.  
  24.  
  25. typedef struct {
  26.     unsigned int baseadr;        /* ボードベースポートアドレス */
  27.     unsigned int reserve1;        /* 9032B 互換のためのリザーブ1 */
  28.     unsigned int reserve2;        /* 9032B 互換のためのリザーブ2 */
  29.     unsigned char mode;        /* 通信モード */
  30.     unsigned char bps;        /* ボーレート */
  31.     unsigned int (*rxbuf)[];    /* 受信バッファアドレス */
  32.     unsigned int rxbuflen;        /* 受信バッファ長 */
  33.     unsigned int txtim;        /* 送信タイムアウト時間 */
  34.     unsigned int rxtim;        /* 受信タイムアウト時間 */
  35.     void (*rxcall)();        /* 受信通知アドレス */
  36.  
  37.     unsigned char intno;        /* INT割り込み番号 0~6 */
  38.     unsigned char timercount;    /* タイマカウントの設定 1~0ffh (1=1.25ms) */
  39.  
  40.  
  41.     /***** BIOSのワーク *****/
  42.  
  43.     char bioswork[113];
  44.  
  45. } PPacket;
  46.  
  47. #define FNCINT 0x60            /* ソフトウェア割り込み番号 */
  48. #define CHANNEL 2            /* 回線番号 */
  49. #define RX_BUF_CNT 2048            /* 受信バッファカウント */
  50.  
  51.  
  52.  
  53.  
  54. static PPacket PP;            /* 通信パラメータパケット */
  55.  
  56. static unsigned int RsRxBuf[RX_BUF_CNT * 2];    /* 受信バッファ */
  57.                     /* 2048キャラクタ分(4096バイト) */
  58.  
  59.  
  60.  
  61.  
  62. main() {
  63.  
  64.     if(BiosCheck()) {            /* BIOSの組み込みチェック */
  65.         if(RsOpen()) {            /* 回線オープン */
  66.             /* RsIn();        /* データ受信 */
  67.             /* RsOut();        /* データ送信 */
  68.             /* RsRxBufInit();    /* 受信バッファの初期化 */
  69.             /* RsSts();        /* 回線ステータスの読み取り */
  70.             /* RsRxCnt();        /* 受信データ数の読み取り */
  71.             /* RsModem();        /* モデム制御 */
  72.             /* RsBreak();        /* ブレーク信号の送信 */
  73.             /* RsRTxTerm();        /* 中断指示 */
  74.             /* RsChRxBuf();        /* 受信バッファの変更 */
  75.             /* RsChTxTim();        /* 送信タイムアウト時間の変更 */
  76.             /* RsChRxTim();        /* 受信タイムアウト時間の変更 */
  77.             /* RsChRxCall();    /* 受信通知アドレスの変更 */
  78.             /* RsChBps();        /* ボーレートの変更 */
  79.             /* RsChFlow();        /* フロー制御の変更 */
  80.             /* RsChSPC();        /* ストップビット、パリティ、キャラクタ長の変更 */
  81.  
  82.             RsClose();        /* 回線クローズ */
  83.             /* RsInit();        /* BIOSの無条件初期化 */
  84.         }
  85.     }
  86. }
  87.  
  88.  
  89.  
  90.  
  91. /****************************************************************/
  92. /*  BIOSの組み込みチェック                    */
  93. /*                                */
  94. /*                                */
  95. /*                                */
  96. /*                                */
  97. /****************************************************************/
  98. int BiosCheck() {
  99.  
  100.     static char buf[8+1]="RSABIOS.";
  101.     char *cp;
  102.  
  103.     cp=*(char **)(FNCINT*4)-16;
  104.     if(strncmp(cp,buf,8)) {
  105.         printf("BIOSが組み込まれていません\n");
  106.         return(0);
  107.     }
  108.     else {
  109.         printf("BIOSのバージョンは %c.%c%c です\n",*(cp+8),*(cp+9),*(cp+10));
  110.         return(1);
  111.     }
  112. }
  113.  
  114.  
  115.  
  116.  
  117. /****************************************************************/
  118. /*  回線オープン                        */
  119. /*                                */
  120. /*                                */
  121. /*                                */
  122. /*                                */
  123. /****************************************************************/
  124. int RsOpen() {
  125.  
  126.     union REGS inregs,outregs;
  127.     struct SREGS segregs;
  128.     unsigned long li;
  129.  
  130.     PP.baseadr=0x50e1;    /* ボードベースポートアドレス */
  131.     PP.reserve1=0;        /* 9032B 互換のためのリザーブ1 */
  132.     PP.reserve2=0;        /* 9032B 互換のためのリザーブ2 */
  133.     PP.mode=0x4d;        /* 通信モード */
  134.     PP.bps=0x01;        /* ボーレート */
  135.     *PP.rxbuf=RsRxBuf;    /* 受信バッファアドレス */
  136.     PP.rxbuflen=RX_BUF_CNT;    /* 受信バッファ長 */
  137.     PP.txtim=6000;        /* 送信タイムアウト時間 */
  138.     PP.rxtim=6000;        /* 受信タイムアウト時間 */
  139.     PP.rxcall=0L;        /* 受信通知アドレス */
  140.     PP.intno=0;        /* INT割り込み番号 0~6 */
  141.     PP.timercount=4;    /* タイマカウントの設定 1~0ffh (1=1.25ms) */
  142.  
  143.     inregs.h.ah=0;
  144.     inregs.h.al=CHANNEL;
  145.  
  146.     li=(unsigned long)&PP;
  147.     inregs.x.si=li;
  148.     segregs.ds=li>>16;
  149.     int86x(FNCINT,&inregs,&outregs,&segregs);
  150.  
  151.     if(outregs.h.ah) {
  152.         printf("回線オープンエラー:%d(10)\n",outregs.h.ah-256);
  153.         return(0);
  154.     }
  155.     return(1);
  156. }
  157.  
  158.  
  159.  
  160.  
  161. /****************************************************************/
  162. /*  回線クローズ                        */
  163. /*                                */
  164. /*                                */
  165. /*                                */
  166. /*                                */
  167. /****************************************************************/
  168. RsClose() {
  169.  
  170.     union REGS inregs,outregs;
  171.     struct SREGS segregs;
  172.  
  173.     inregs.h.ah=1;
  174.     inregs.h.al=CHANNEL;
  175.  
  176.     int86x(FNCINT,&inregs,&outregs,&segregs);
  177.  
  178.     if(outregs.h.ah)
  179.         printf("回線クローズエラー:%d(10)\n",outregs.h.ah-256);
  180. }
  181.  
  182.  
  183.  
  184.  
  185. /****************************************************************/
  186. /*  データ受信                            */
  187. /*                                */
  188. /*                                */
  189. /*                                */
  190. /*                                */
  191. /****************************************************************/
  192. int RsIn() {
  193.  
  194.     union REGS inregs,outregs;
  195.     struct SREGS segregs;
  196.  
  197.     for(;;) {
  198.         inregs.h.ah=2;
  199.         inregs.h.al=CHANNEL;
  200.  
  201.         int86x(FNCINT,&inregs,&outregs,&segregs);
  202.  
  203.         if(outregs.h.ah) {
  204.             printf("データ受信エラー:%d(10)\n",outregs.h.ah-256);
  205.             return(0);
  206.         }
  207.         else {
  208.             printf("受信ステータス:%02x(16)    受信データ:%02x(16)\n",outregs.h.dh,outregs.h.dl);
  209.             if(outregs.h.dh & 0x7c)
  210.                 return(0);
  211.             if(outregs.h.dl==0x1a)
  212.                 return(1);
  213.         }
  214.     }
  215. }
  216.  
  217.  
  218.  
  219.  
  220. /****************************************************************/
  221. /*  データ送信                            */
  222. /*                                */
  223. /*                                */
  224. /*                                */
  225. /*                                */
  226. /****************************************************************/
  227. int RsOut() {
  228.  
  229.     static char buf[10+1]="RSA-98....";
  230.     union REGS inregs,outregs;
  231.     struct SREGS segregs;
  232.     int i;
  233.  
  234.     for(i=0;buf[i];i++) {
  235.         inregs.h.ah=3;
  236.         inregs.h.al=CHANNEL;
  237.         inregs.h.dl=buf[i];
  238.  
  239.         int86x(FNCINT,&inregs,&outregs,&segregs);
  240.  
  241.         printf("送信ステータス:%02x(16)\n",outregs.h.dh);
  242.         if(outregs.h.ah) {
  243.             printf("データ送信エラー:%d(10)\n",outregs.h.ah-256);
  244.             return(0);
  245.         }
  246.     }
  247.     return(1);
  248. }
  249.  
  250.  
  251.  
  252.  
  253. /****************************************************************/
  254. /*  受信バッファの初期化                    */
  255. /*                                */
  256. /*                                */
  257. /*                                */
  258. /*                                */
  259. /****************************************************************/
  260. int RsRxBufInit() {
  261.  
  262.     union REGS inregs,outregs;
  263.     struct SREGS segregs;
  264.  
  265.     inregs.h.ah=5;
  266.     inregs.h.al=CHANNEL;
  267.     inregs.h.dl=0;
  268.  
  269.     int86x(FNCINT,&inregs,&outregs,&segregs);
  270.  
  271.     if(outregs.h.ah) {
  272.         printf("受信バッファの初期化エラー:%d(10)\n",outregs.h.ah-256);
  273.         return(0);
  274.     }
  275.     return(1);
  276. }
  277.  
  278.  
  279.  
  280.  
  281. /****************************************************************/
  282. /*  回線ステータスの読み取り                    */
  283. /*                                */
  284. /*                                */
  285. /*                                */
  286. /*                                */
  287. /****************************************************************/
  288. int RsSts() {
  289.  
  290.     union REGS inregs,outregs;
  291.     struct SREGS segregs;
  292.  
  293.     inregs.h.ah=6;
  294.     inregs.h.al=CHANNEL;
  295.  
  296.     int86x(FNCINT,&inregs,&outregs,&segregs);
  297.  
  298.     if(outregs.h.ah) {
  299.         printf("回線ステータスの読み取りエラー:%d(10)\n",outregs.h.ah-256);
  300.         return(0);
  301.     }
  302.     printf("モデム制御の状態:%02x(16)\n",outregs.h.dl);
  303.     printf("Xon/Xoff 制御の状態:%02x(16)\n",outregs.h.dh);
  304.     printf("ラインステータス:%02x(16)\n",outregs.h.cl);
  305.     printf("モデムステータス:%02x(16)\n",outregs.h.ch);
  306.     return(1);
  307. }
  308.  
  309.  
  310.  
  311.  
  312. /****************************************************************/
  313. /*  受信データ数の読み取り                    */
  314. /*                                */
  315. /*                                */
  316. /*                                */
  317. /*                                */
  318. /****************************************************************/
  319. int RsRxCnt() {
  320.  
  321.     union REGS inregs,outregs;
  322.     struct SREGS segregs;
  323.  
  324.     for(;;) {
  325.         inregs.h.ah=7;
  326.         inregs.h.al=CHANNEL;
  327.  
  328.         int86x(FNCINT,&inregs,&outregs,&segregs);
  329.  
  330.         if(outregs.h.ah) {
  331.             printf("受信データ数の読み取りエラー:%d(10)\n",outregs.h.ah-256);
  332.             return(0);
  333.         }
  334.         printf("受信データ数:%d(10)\r",outregs.x.cx);
  335.         if(outregs.x.cx > 10) break;
  336.     }
  337.     return(1);
  338. }
  339.  
  340.  
  341.  
  342.  
  343. /****************************************************************/
  344. /*  モデム制御                            */
  345. /*                                */
  346. /*                                */
  347. /*                                */
  348. /*                                */
  349. /****************************************************************/
  350. int RsModem() {
  351.  
  352.     union REGS inregs,outregs;
  353.     struct SREGS segregs;
  354.  
  355.     inregs.h.ah=8;
  356.     inregs.h.al=CHANNEL;
  357.     inregs.h.dl=0x22;    /* RTS=1、DTR=1 */
  358.  
  359.     int86x(FNCINT,&inregs,&outregs,&segregs);
  360.  
  361.     if(outregs.h.ah) {
  362.         printf("モデム制御エラー:%d(10)\n",outregs.h.ah-256);
  363.         return(0);
  364.     }
  365.     return(1);
  366. }
  367.  
  368.  
  369.  
  370.  
  371. /****************************************************************/
  372. /*  ブレーク信号の送信                        */
  373. /*                                */
  374. /*                                */
  375. /*                                */
  376. /*                                */
  377. /****************************************************************/
  378. int RsBreak() {
  379.  
  380.     union REGS inregs,outregs;
  381.     struct SREGS segregs;
  382.  
  383.     inregs.h.ah=9;
  384.     inregs.h.al=CHANNEL;
  385.     inregs.x.cx=30;        /* 300m秒 */
  386.  
  387.     int86x(FNCINT,&inregs,&outregs,&segregs);
  388.  
  389.     if(outregs.h.ah) {
  390.         printf("ブレーク信号の送信エラー:%d(10)\n",outregs.h.ah-256);
  391.         return(0);
  392.     }
  393.     return(1);
  394. }
  395.  
  396.  
  397.  
  398.  
  399. /****************************************************************/
  400. /*  中断指示                            */
  401. /*                                */
  402. /*                                */
  403. /*                                */
  404. /*                                */
  405. /****************************************************************/
  406. int RsRTxTerm() {
  407.  
  408.     union REGS inregs,outregs;
  409.     struct SREGS segregs;
  410.  
  411.     inregs.h.ah=10;
  412.     inregs.h.al=CHANNEL;
  413.  
  414.     int86x(FNCINT,&inregs,&outregs,&segregs);
  415.  
  416.     if(outregs.h.ah) {
  417.         printf("中断指示エラー:%d(10)\n",outregs.h.ah-256);
  418.         return(0);
  419.     }
  420.     return(1);
  421. }
  422.  
  423.  
  424.  
  425.  
  426. /****************************************************************/
  427. /*  受信バッファの変更                        */
  428. /*                                */
  429. /*                                */
  430. /*                                */
  431. /*                                */
  432. /****************************************************************/
  433. int RsChRxBuf() {
  434.  
  435.     union REGS inregs,outregs;
  436.     struct SREGS segregs;
  437.     unsigned long li;
  438.  
  439.     inregs.h.ah=11;
  440.     inregs.h.al=CHANNEL;
  441.  
  442.     li=(unsigned long)RsRxBuf;
  443.     inregs.x.di=li;
  444.     segregs.es=li>>16;
  445.  
  446.     inregs.x.cx=RX_BUF_CNT;
  447.     inregs.h.dl=0;
  448.  
  449.     int86x(FNCINT,&inregs,&outregs,&segregs);
  450.  
  451.     if(outregs.h.ah) {
  452.         printf("受信バッファの変更エラー:%d(10)\n",outregs.h.ah-256);
  453.         return(0);
  454.     }
  455.     return(1);
  456. }
  457.  
  458.  
  459.  
  460.  
  461. /****************************************************************/
  462. /*  送信タイムアウト時間の変更                    */
  463. /*                                */
  464. /*                                */
  465. /*                                */
  466. /*                                */
  467. /****************************************************************/
  468. int RsChTxTim() {
  469.  
  470.     union REGS inregs,outregs;
  471.     struct SREGS segregs;
  472.  
  473.     inregs.h.ah=12;
  474.     inregs.h.al=CHANNEL;
  475.     inregs.x.cx=6000;
  476.  
  477.     int86x(FNCINT,&inregs,&outregs,&segregs);
  478.  
  479.     if(outregs.h.ah) {
  480.         printf("送信タイムアウト時間の変更エラー:%d(10)\n",outregs.h.ah-256);
  481.         return(0);
  482.     }
  483.     return(1);
  484. }
  485.  
  486.  
  487.  
  488.  
  489. /****************************************************************/
  490. /*  受信タイムアウト時間の変更                    */
  491. /*                                */
  492. /*                                */
  493. /*                                */
  494. /*                                */
  495. /****************************************************************/
  496. int RsChRxTim() {
  497.  
  498.     union REGS inregs,outregs;
  499.     struct SREGS segregs;
  500.  
  501.     inregs.h.ah=13;
  502.     inregs.h.al=CHANNEL;
  503.     inregs.x.cx=6000;
  504.  
  505.     int86x(FNCINT,&inregs,&outregs,&segregs);
  506.  
  507.     if(outregs.h.ah) {
  508.         printf("受信タイムアウト時間の変更エラー:%d(10)\n",outregs.h.ah-256);
  509.         return(0);
  510.     }
  511.     return(1);
  512. }
  513.  
  514.  
  515.  
  516.  
  517. /****************************************************************/
  518. /*  受信通知アドレスの変更                    */
  519. /*                                */
  520. /*                                */
  521. /*                                */
  522. /*                                */
  523. /****************************************************************/
  524. void RxCall() { }
  525.  
  526. int RsChRxCall() {
  527.  
  528.     union REGS inregs,outregs;
  529.     struct SREGS segregs;
  530.     unsigned long li;
  531.  
  532.     inregs.h.ah=14;
  533.     inregs.h.al=CHANNEL;
  534.  
  535.     li=(unsigned long)RxCall;
  536.     inregs.x.di=li;
  537.     segregs.es=li>>16;
  538.  
  539.     int86x(FNCINT,&inregs,&outregs,&segregs);
  540.  
  541.     if(outregs.h.ah) {
  542.         printf("受信通知アドレスの変更エラー:%d(10)\n",outregs.h.ah-256);
  543.         return(0);
  544.     }
  545.     return(1);
  546. }
  547.  
  548.  
  549.  
  550.  
  551. /****************************************************************/
  552. /*  ボーレートの変更                        */
  553. /*                                */
  554. /*                                */
  555. /*                                */
  556. /*                                */
  557. /****************************************************************/
  558. int RsChBps() {
  559.  
  560.     union REGS inregs,outregs;
  561.     struct SREGS segregs;
  562.  
  563.     inregs.h.ah=15;
  564.     inregs.h.al=CHANNEL;
  565.     inregs.h.dl=0x03;
  566.  
  567.     int86x(FNCINT,&inregs,&outregs,&segregs);
  568.  
  569.     if(outregs.h.ah) {
  570.         printf("ボーレートの変更エラー:%d(10)\n",outregs.h.ah-256);
  571.         return(0);
  572.     }
  573.     return(1);
  574. }
  575.  
  576.  
  577.  
  578.  
  579. /****************************************************************/
  580. /*  フロー制御の変更                        */
  581. /*                                */
  582. /*                                */
  583. /*                                */
  584. /*                                */
  585. /****************************************************************/
  586. int RsChFlow() {
  587.  
  588.     union REGS inregs,outregs;
  589.     struct SREGS segregs;
  590.  
  591.     inregs.h.ah=16;
  592.     inregs.h.al=CHANNEL;
  593.     inregs.h.dl=1;
  594.  
  595.     int86x(FNCINT,&inregs,&outregs,&segregs);
  596.  
  597.     if(outregs.h.ah) {
  598.         printf("フロー制御の変更エラー:%d(10)\n",outregs.h.ah-256);
  599.         return(0);
  600.     }
  601.     return(1);
  602. }
  603.  
  604.  
  605.  
  606.  
  607. /****************************************************************/
  608. /*  ストップビット、パリティ、キャラクタ長の変更        */
  609. /*                                */
  610. /*                                */
  611. /*                                */
  612. /*                                */
  613. /****************************************************************/
  614. int RsChSPC() {
  615.  
  616.     union REGS inregs,outregs;
  617.     struct SREGS segregs;
  618.  
  619.     inregs.h.ah=17;
  620.     inregs.h.al=CHANNEL;
  621.     inregs.h.dl=0x4c;
  622.  
  623.     int86x(FNCINT,&inregs,&outregs,&segregs);
  624.  
  625.     if(outregs.h.ah) {
  626.         printf("ストップビット、パリティ、キャラクタ長の変更エラー:%d(10)\n",outregs.h.ah-256);
  627.         return(0);
  628.     }
  629.     return(1);
  630. }
  631.  
  632.  
  633.  
  634.  
  635. /****************************************************************/
  636. /*  BIOSの無条件初期化                    */
  637. /*                                */
  638. /*                                */
  639. /*                                */
  640. /*                                */
  641. /****************************************************************/
  642. int RsInit() {
  643.  
  644.     union REGS inregs,outregs;
  645.     struct SREGS segregs;
  646.  
  647.     inregs.h.ah=18;
  648.  
  649.     int86x(FNCINT,&inregs,&outregs,&segregs);
  650.  
  651.     return(1);
  652. }
  653.  
  654.