/*=================================================== CONS98.C =========*/ /* PC98用コンソールライブラリー */ /* ver 1.2 H4/07/01 by S.F */ /*----------------------------------------------------------------------*/ #include #include #include #include #include #include "CONS98.H" #define uchar unsigned char #define uint unsigned int #define TGCMD 0x62 /* テキストGDCコマンドポート */ #define TGPRA 0x60 /* テキストGDCパラメータポート */ #define TGSTS 0x60 /* テキストGDCステータスポート */ #define CRSFORM 0x4b /* GDCのCRSFORMコマンド */ #define CRSRATE 10 /* カーソルのブリンクレート */ #define ABS(c) ( (c)<0 ? -(c) : (c) ) /*---------- BIOSによる1文字入力 ----------*/ int cgetch( void ) /* 上位8ビットはスキャンコード */ { /* 下位8ビットは内部コード */ union REGS inregs,outregs; inregs.h.ah = 0; int86( 0x18, &inregs, &outregs ); return( outregs.x.ax ); } /*---------- BIOSによるキー入力チェック ----------*/ int cinkey( void ) /* キーが押されていなければ 0 を返す */ { /* キーが押されていれば cgetch() と同じ */ union REGS inregs,outregs; inregs.h.ah = 1; int86( 0x18, &inregs, &outregs ); if(outregs.h.bh) return( cgetch() ); return(0); } /*---------- DOSによるリアルタイムキー入力 ----------*/ int inkey() { int c; if((c=kbhit()) != 0){ c = getch(); if(c==27 && kbhit()) c = 256+getch(); } return(c); } /*---------- キーバッファを空にする -------------*/ void kb_flash() { while(kbhit()) getch(); } /*---------- テキストカラー設定関数 ----------*/ void txt_color( int col ) /* 標準テキストカラーの指定 */ { /* -7〜7 負の数は反転カラー */ static char cc[]="\x1b[37m"; static char cp[]="04152637"; cc[2] = (col<0) ? '4' : '3' ; cc[3] = cp[( ABS(col) & 7 )]; printf(cc); } /*---------- 現在のモードを調べます ----------*/ int txt_mode_ck( void ) { union REGS inregs,outregs; inregs.h.ah = 0x0b; int86( 0x18, &inregs, &outregs ); return( outregs.h.al & 0xff ); } /*---------- テキスト画面表示を開始します ----------*/ void txt_disp_on( void ) { union REGS inregs,outregs; inregs.h.ah = 0x0c; int86( 0x18, &inregs, &outregs ); } /*---------- テキスト画面を非表示にします ----------*/ void txt_disp_off( void ) { union REGS inregs,outregs; inregs.h.ah = 0x0d; int86( 0x18, &inregs, &outregs ); } /*----- カーソル形状の設定 -----*/ crsform( int cstart, /* カーソル開始ライン (0-31) */ int cend, /* カーソル終了ライン (0-31) */ int crate, /* カーソルブリンクレート(1-31) */ int cdsp ) /* カーソル表示フラグ */ { int p[3]; cstart &= 0x1f; cend &= 0x1f; crate &= 0x1f; if(cstart>cend) cstart = cend; p[0] = (cdsp << 7) + 15; p[1] = (cstart & 0x1f) + (crate << 6); p[2] = (crate >> 2) + (cend << 3); if(crate==0) p[1] |= 0x20; while(inportb(TGSTS) & 2); outportb(TGCMD, CRSFORM); while(inportb(TGSTS) & 2); outportb(TGPRA, p[0]); while(inportb(TGSTS) & 2); outportb(TGPRA, p[1]); while(inportb(TGSTS) & 2); outportb(TGPRA, p[2]); } /*----- 文字列の移動(同じ文字列内で)-----*/ strmov( char *str, /* 対象となる文字列 */ int d, /* 文字列の移動先の位置 */ int s) /* 移動文字列の開始位置 */ { int ls,i,j; ls = strlen(str); if(d>s) /* 後ろのデータから移動 */ for(i=ls-d+s-1,j=ls-1;j>=d;j--,i--) str[j] = str[i]; else /* 前のデータから移動 */ for(i=s;i>8)&0xff)); } /*----- 整数型の漢字を画面に出力する -----*/ kputch(int x) { if(x<0) putch(x>>8); putch(x); } /*---- 文字列のコピー(漢字対応)-----*/ strkcpy(char *dst, char *src, char n) /* add H4/8/10 */ { int i,sn; char *dp; sn = strlen(src); dp = dst; if(sn>=n){ for(i=0;ibl-1) px = bl-1; /* pxの範囲チェック */ else if(px<0) px = 0; crsform(ins,15,CRSRATE,1); /* ブロックカーソルに */ do{ gotoxy(lx+px,ly); /* カーソル表示と位置の設定 */ while(!kbhit()); /* 何か押されるまで待つ */ k = getch(); /* リアルタイムキー入力 */ if(iskanji(k)){ /* 漢字が入力されたなら mod H41215 */ a.w = (k<<8) | getch(); /* 次のバイトと合成する */ } else if((k==27)&&(kbhit())){ /* escに続く拡張キーなら */ k = getch(); a.w = 0x100 + k; /* 次のバイトに100Hを加える */ }else{ a.w = k; /* その他のキー入力はそのまま */ } sc = ktype(bf,px); /* 現在カーソル位置の文字の種類は? */ switch(a.w){ case 0x1a: /* - HOMEキーの処理 */ strnset(bf,' ',bl); /* 文字列バッファ内を消去 */ px = 0; /* 先頭から再入力 */ break; case 0x08: /* - 左矢印カーソルキー処理 */ if(px>0) px--; else{ /* -- 文字列の先頭より左の指示は */ strcpy(rts,bf); /* 変更データを有効にして */ return(a.w); /* 呼出ルーチンへ戻る */ } break; case 0x0c: /* - 右矢印カーソルキー処理 */ if(px512){ /* 入力文字が漢字 */ if(px==bl-1){ /* -- 行の最後にカーソルがある場合 */ bf[px] = ' '; /* 入力漢字ではなく空白1文字 */ strcpy(rts,bf); /* 変更データを有効にして */ gotoxy(lx,ly); /* 変更データを再表示 */ cputs(bf); return(a.w); /* はみ出し文字はシフトJISで */ } else{ if(ins==0){ /* -- 置換モード */ sc2=ktype(bf,px+1); /* --- 次文字の種類は? */ bf[px] = a.b[1]; bf[px+1] = a.b[0]; if(sc==2) /* --- 現在文字が漢字2バイト目 */ bf[px-1]= ' '; if(sc2==2) /* --- 次文字が漢字2バイト目なら */ bf[px+2]= ' '; }else{ /* -- 挿入モード */ if(sc==2) px--; /* --- 現在文字が漢字2バイト目 */ ec=ktype(bf,bl-2); /* --- 行末の2バイト目チェック */ strmov(bf,px+2,px); bf[px] = a.b[1]; bf[px+1] = a.b[0]; if(ec==2) /* --- 2バイト目が漢字の後半 */ bf[bl]=' '; } if(px+2 255 ){ /* - 入力文字がesc2バイト文字 */ strcpy(rts,bf); /* 変更データを有効にして */ return(a.w); /* 呼出ルーチンへ戻る */ } else if( a.w > 31 ){ /* - 入力文字がアスキーコード */ if(ins==0){ /* -- 置換モード */ bf[px] = a.b[0]; if(sc==2){ /* --- 現在文字が漢字2バイト目 */ bf[px-1] = ' '; }else if(sc==1){ /* --- 現在文字が漢字1バイト目 */ bf[px+1] = ' '; } } else{ /* -- 挿入モード */ if(sc==2) px--; /* --- 現在文字が漢字2バイト目 */ ec = ktype(bf,bl-1); /* --- 行末のバイトをチェック */ strmov(bf,px+1,px); bf[px] = a.b[0]; if(ec==2) /* --- 行末が漢字の後半の場合 */ bf[bl-1]=' '; } if(px=0;i--){ if(str[i]==0x20) str[i]='\0'; else return(i); } } /*====================== e n d ========================( CONS98.C )======*/