/*
	console.c
	tab=8
	コンソールBIOS
	int 91h
	1994/11/23 1994/11/26
	参考: list.asm
	      FreeSoftWaerCollection5 \ms_dos\r_gralib\r_gralib.asm
	      赤本に載ってない
	注意: エラー対策無し
*/

#include <dos.h>

#define ON 1
#define OFF 0


/*
	cur( OFF );		保存 & 消去
	cur( ON );		元に戻す
*/

int cur( unsigned char sw ){		/* カーソルのオンオフ */

	union REGS in,out;
	static char c=0; /* カーソル状態保存 */

	if( sw == OFF ){
		in.h.ah = 0x0c;
		int86( 0x91,&in,&out );
		c = out.h.al;
		in.h.al = 1;
	}else{
		in.h.al = c;
	}
	in.h.ah = 0x0b;
	int86( 0x91,&in,&out );
	return c;
}


/*
	width( [0|20|25] )	表示行数変更
	0:画面消去のみ
	戻り値は設定行数
	20行のときゴミが出ることがある
*/

#include <stdio.h>
#include <stdlib.h>
int width( unsigned char sw ){

	union REGS in,out;
	int r;
	
	if( sw != 0 && sw != 20 && sw != 25 ){
		fputs("\x1b[31;7m argument error. \x1b[m",stderr);
		exit(1);
	}

	/* 画面状態の取得 */
	in.h.ah = 0x04;
	int86(0x91,&in,&out);

	/* 画面状態の設定 */
	in.h.ah = 0x03;
	in.h.dl = out.h.dl;		/* 幅はそのまま */
	if( out.h.dh == 25 && sw == 20 ){
		in.h.dh = 20;		/* 20行 */
		int86(0x91,&in,&out);
	}
	if( out.h.dh == 20 && sw == 25 ){
		in.h.dh = 25;		/* 25行 */
		int86(0x91,&in,&out);
	}
	r = out.h.dh;
	/* 全画面消去 */
	if( sw == 0 ){
		in.h.ah = 0x02;
		int86(0x91,&in,&out);
	}
	return r;
}
