[net.sources] ibm compatible bios routines from c

geb@cadre.UUCP (07/12/84)

Here are some routines to let you use the video bios calls from c:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


/*****************************************************************************
*	video.h			12 Jul 84			G. Banks     *
*									     *
*	Header file for video.c defining the constants			     *
*									     *
*****************************************************************************/


#define BLANK 32

#define MONOCHROME 0x18
#define COLOR80 0x10
#define COLOR40 0x08

#define NORMAL	7
#define BLINK 0x80
#define UNDERLINE 1
#define INVERSE 0x70
#define HIGHLIGHT 0x0F
#define HIUNDER 9

/*****************************************************************************
 *	video.c			12 Jul 84			G. Banks     *
 *									     *
 *  set of video functions to control the screen on ibm/pc compatible using  *
 *  bios calls.  Must be linked to assembly of vidbios.asm		     *
 * 									     *
 *  includes:								     *
 * 									     *
 * 	clrtoeos(a)		Clears to end of screen with attribute a     *
 *	readc()			Returns the character at the cursor	     *
 *      read_attribute()	Returns the attribute at the cursor	     *
 *      clrtoeol(a)		Clears to end of line with attribute a	     *
 *	readrow()		Returns the row of the cursor		     *
 *      readcol()		Returns the column of the cursor	     *
 *	check_display()		Decides what kind of display is being used   *
 *									     *
 ****************************************************************************/


#include <video.h>

int clrtoeos(a)	/* clears to end of screen to attribute */
char a;
{
	int i;

	i = readrow();
	clrtoeol(a);
	while (i++ < 24) {
		gotoxy(0,i);
		clrtoeol(a);
	}		
}


char readc()	/* returns the char on screen at the current cursor position */
{
	return(vreadc()%256);
}

char read_attribute() /* returns attribute at the current cursor position */
{
	return(vreadc()/256);
}

int clrtoeol(a) /*clears to the end of the line to attribute */
char a;
{
	writenca(BLANK,a,80-readcol());
}

int readrow()	/* returns the row of the current cursor position */
{
	return(vreadcur()/256);
}

int readcol()	/* returns the column of the current cursor position */
{
	return(vreadcur()%256);
}
	
int check_display()	/* returns the number of the type of display */
{
	return(equip() & 0x18);
}	
	
int num_drives()	/* returns the number of drives of the system */
{
	int eq;
	
	eq = (equip() & 0x60);
	if (eq == 0x60) return(4);
	if (eq == 0x40) return(3);
	if (eq == 0x20) return(2);
	else return(0);
}

	
;  vidbios.asm				12 Jul 84	G. Banks
;
;  Set of routines for performing screen operations on ibm pc compatibles
;  Using BIOS functions.
;
;  Includes:
;
;	equip()  		Determines equipment (monochrome, etc.)
;	cls(a)   		Clears screen to (a = attribute)
;	gotoxy(col,row)		Cursor addressing
;	vreadcur()		Returns cursor position
;	vreadc()		Returns character at current cursor
;	writeca(c,a)		Writes char c with attrib a at cursor
;	writenca(c,a,n)	        Writes char with attr n times
;	writec(c)		Writes char with current attribute

INCLUDE	MODEL.H		; these are for c86
INCLUDE	PROLOGUE.H	; if you don't have them, e.g. lattice,
			; they simply define the segment registers, etc.
			; as shown in your manual



BDOSINT		EQU	21h
VBIOSINT	EQU	10h
EQUIPINT	EQU	11h
NUMROWS		EQU	25
NUMCOLS		EQU	80


		PUBLIC	EQUIP,CLS,GOTOXY,VREADCUR,VREADC,WRITECA,WRITENCA,WRITEC
		

;int equip()
;
;returns an integer which can be bitwise analysed to determine
;what equipment is being used with the computer.


EQUIP	PROC	NEAR
		int	EQUIPINT	;returns equipment attached in AX
		ret
EQUIP	ENDP		
		
;cls(a)
;char a;
;
;clears the display to blanks of attribute a

CLS	PROC	NEAR
		push	bp
		push	es
		mov	bp,sp
		cli			;don't bother me while I'm on the stack
		add 	sp,6		;get the argument pointer
		pop	bx		;get the attribute
		mov	sp,bp		
		sti
		mov 	ah,6		;scroll up
		mov	al,0		;blanks
		mov	ch,0		;top row
		mov	cl,0		;left column
		mov	dh,NUMROWS-1
		mov	dl,NUMCOLS-1
		mov	bh,bl		;blank	 line attribute
		int	VBIOSINT	;go do it
		pop 	es
		pop	bp
		ret
CLS		ENDP

;gotoxy(x,y)
;int x,y;
;
;cursor addressing through bios
;

GOTOXY	PROC	NEAR
		push	bp
		push	es
		mov	bp,sp
		cli			;don't bother me while I'm on the stack
		add 	sp,6		;get the argument pointer
		pop	dx		;column
		pop	cx		;row
		mov	sp,bp		
		sti
		mov	dh,cl		;get row into dh (column is already in dl)
		mov	bh,0		;zero page
		mov	ah,2		;setcursor function
		int	VBIOSINT	;go do it
		pop 	es
		pop	bp
		ret
GOTOXY	ENDP

;int vreadcur()
;
;reads the cursor position and returns:
;	row = vreadcur() / 256;
;	col = vreadcur() % 256;

VREADCUR	PROC	NEAR
		mov	bh,0		;zero page
		mov	ah,3		;readcursor function
		int	VBIOSINT	;go do it
		mov	ax,dx		;transfer returned row,column values to a reg
		ret
VREADCUR	ENDP

;int vreadc()
;
;reads the character and attribute at the current cursor position
;
;	char = vreadc() % 256;
;	attr = vreadc() / 256;

VREADC	PROC	NEAR
		mov 	bh,0		;zero page
		mov	ah,8		;read character
		int	VBIOSINT	;go do it
		ret
VREADC	ENDP

;writeca(a,c)
;char a,c;
;	
;writes a character	(c) with attribute (a) to the screen

WRITECA	PROC	NEAR
		push	bp
		push	es
		mov	bp,sp
		cli
		add	sp,6 		;get arguments
		pop	ax	    	;character in low byte
		pop	bx		;attribute in low byte
		mov	sp,bp
		sti
		mov	bh,0		;zero page
		mov	ah,9		;write character
		mov	cl,1		;write it only once
		int	VBIOSINT	;go do it
		pop	es
		pop	bp
		ret
WRITECA	ENDP


;writenca(a,c,n)
;char a,c,n;
;	
;writes a character	(c) with attribute (a) to the screen (n) times

WRITENCA	PROC	NEAR
		push	bp
		push	es
		mov	bp,sp
		cli
		add	sp,6 		;get arguments
		pop	ax	    	;character in low byte
		pop	bx		;attribute in low byte
		pop	cx		;number of times to write it
		mov	sp,bp
		sti
		mov	bh,0		;zero page
		mov	ah,9		;write character
		int	VBIOSINT	;go do it
		pop	es
		pop	bp
		ret
WRITENCA	ENDP

;writec(c)
;char c;
;
;write character at current cursor position

WRITEC	PROC	NEAR
		push	bp
		push	es
		mov	bp,sp
		cli
		add	sp,6
		pop	ax
		mov	sp,bp
		sti
		mov	ah,9		;write character
		mov	cx,1		;write it only once
		mov	bh,0		;zero page
		int	VBIOSINT	;go to it, boy
		pop	es
		pop	bp
		ret
WRITEC	ENDP

@CODE		ENDS

		END