	PAGE 66, 132
	TITLE C TO BIOS SCREEN INTERFACE
;------------------------------------------------------------------*
;  SCREEN CONTROL INTERFACE BETWEEN C PROGRAM AND PC BIOS.
;
;   Copyright 1985,86 by Turning Point Logic Corporation.
;   Permission granted for personal, non-commercial use.
;
;	This module is a simple interface between 'C' programs and
;	the BIOS interrupt which controls screen scrolling, cursor
;	addressing and etc.
;
;
;	ENTRY:  SS:SP points to a control block:
;		SP+0  - Return address.
;		SP+2  - Command code:
;			 0 - Set cursor position                SCP
;		 	 1 - Return cursor position             RCP
;			 2 - Read char/attr at cursor position  RDC
;			 3 - Write char/attr at cursor position WTC
;			 4 - Scroll window up                   SWU
;			 5 - Scroll window down                 SWD
;			 6 - Return current screen mode         RSM
;		SP+4 - SP+19  Variables for the above commands.
;			       Refer to the structures listed
;			       for the assignments.
;
;	EXIT:   The operation has been performed and if specified,
;		 the return values have been written to locations
;		 pointed to on entry.
;
; ----- STRUCTURES.
;
SCP	STRUC;		Set Cursor Position
;
SCP_RNM DB;		Row number for cursor.
	DB;
SCP_CNM DB;		Column number for cursor.
	DB;
;
SCP	ENDS
;
;
RCP	STRUC;		Retrieve Cursor Position
;
RCP_RPT DW;		Offset from DS to store row number of cursor
;			 position.  A word is stored at that loc.
RCP_CPT DW;		Offset from DS to store column number of cur-
;			 sor position.  A word is stored at that
;			 location.
;
RCP	ENDS
;
;
RDC	STRUC;		Read Character/Attribute at Cursor Position
;
RDC_RDP DW;		Offset from DS to store character read.  A
;			 word is written at that location.
RDC_ATP	DW;		Offset from DS to store attribute of char-
;			 acter read.  A word is stored at that
;			 location.
;
RDC	ENDS
;
;
WTC	STRUC;		Write Character/Attribute at Cursor Position
;
WTC_WCH	DB;		Character to be written.
	DB;
WTC_ATP DB;		Attribute for character(s).
	DB;
WTC_CNT DW;		Number of characters to write.
;
WTC	ENDS
;
;
SWD	STRUC;		Scroll Window (Up or Down)
;                                                                       
SWD_ULRNM DB;		Row number of upper left hand corner of the     
	  DB;		 window to be scrolled.                         
SWD_ULCNM DB;		Column number of upper left hand corner of      
	  DB;		 the window to be scrolled.                     
SWD_LRRNM DB;		Row number of lower right hand corner of the    
	  DB;		 window to be scrolled.                         
SWD_LRCNM DB;		Column number of lower right hand corner of     
	  DB;		 the window to be scrolled.                     
SWD_CAT   DB;		Attribute to be stored into the new line(s)     
	  DB;		 created by the scroll.                         
SWD_CNT	  DB;		Number of lines to scroll (0 implies clear      
	  DB;		 the screen).					
;
SWD	ENDS
;
;
RSM	STRUC;		Return Current Screen Mode
;
RSM_MPT	DW;		Offset from DS to store the current screen
;			 mode value.  A word is written at that 
;			 location.
;
RSM	ENDS
;
;
; ----- EQUATES.
;
VIDINT	EQU	10H;	IBM BIOS Video interrupt number.
PG_NUM	EQU	  0;	Default display page number.
;
PROG	SEGMENT	BYTE	PUBLIC	'PROG'
	ASSUME  CS:PROG,DS:NOTHING,SS:NOTHING,ES:NOTHING
PUBLIC	SCINTF
;
CJTAB	DW SETCS;			Set cursor position.
	DW RETCS;			Return cursor position.
	DW RCHAR;			Read char/attribute.
	DW WCHAR;			Write char/attribute.
	DW SCRLUP;			Scroll window up.
	DW SCRLDN;			Scroll window down.
	DW RETMD;			Return screen mode value.
;
; ----- ENTRY POINT.
;
SCINTF	PROC  	NEAR
;
	PUSH BP;			Set pointer to variables.
	MOV BP, SP;
	ADD BP, 4;
;
	PUSH DI;			Save work registers.
	PUSH SI;
	PUSH DS;
	PUSH ES;
;
	MOV BX, [BP];			Load command code, use as
	ADD BP, 2;			 word index into jump table
	SHL BX, 1;			 and execute specified 
	JMP CJTAB[BX];			 command.
;
;
; ----- SET CURSOR POSITION.
;
SETCS:	MOV DH, [BP].SCP_RNM;		Load row address,
	MOV DL, [BP].SCP_CNM;		 column address and set
	MOV BH, PG_NUM;			 default page number.
;
	MOV AH, 2;			Set function number,
	INT VIDINT;			 call BIOS to set cursor
	JMP SCRTN;			 position and exit.
;
; ----- RETURN CURSOR POSITION.
;
RETCS:	PUSH BP;			Save variable pointer.
;
	MOV BH, PG_NUM;			Set default page number,
	MOV AH, 3;			 function code, and perform
	INT VIDINT;			 BIOS screen interrupt.
;
	POP BP;				Restore varible pointer.

	XOR AH, AH;			Load pointer to row address
	MOV BX, [BP].RCP_RPT;		 variable and store value.
	MOV AL, DH;
	MOV [BX], AX;
;
	MOV BX, [BP].RCP_CPT;		Load pointer to column 
	MOV AL, DL;			 address variable and store
	MOV [BX], AX;			 value.
;
	JMP SCRTN;			Exit.
;
; ----- READ CHARACTER/ATTRIBUTE AT CURSOR POSITION.
;
RCHAR:	PUSH BP;			Save variables pointer.
;
	MOV BH, PG_NUM;			Set default page number,
	MOV AH, 8;			 function code and call
	INT VIDINT;			 BIOS interrupt.
;
	POP BP;				Restore variables pointer.
;
	XOR CH, CH;			Load pointer to character
	MOV BX, [BP].RDC_RDP;		 location and store char-
	MOV CL, AL;			 acter value.
	MOV [BX], CX;
;
	MOV BX, [BP].RDC_ATP;		Load pointer to attribute
	MOV CL, AH;			 location and store 
	MOV [BX], CX;			 attribute value.
;
	JMP SCRTN;			Exit.
;
; ----- WRITE CHARACTER AT CURSOR POSITION.
;
WCHAR:  MOV CX, [BP].WTC_CNT;		Load character count,
	MOV AL, [BP].WTC_WCH;		 the character,
	MOV BL, [BP].WTC_ATP;		 the attribute, and set
	MOV BH, PG_NUM;			 the default page number.
;
	MOV AH, 9;			Load function code,
	INT VIDINT;			 call BIOS interrupt,
	JMP SCRTN;			 and exit.
;
; ----- SCROLL WINDOW UP.
;
SCRLUP: MOV AL, [BP].SWD_CNT;		Load number of lines,
	MOV CH, [BP].SWD_ULRNM;		 upper left row address,
	MOV CL, [BP].SWD_ULCNM;		 upper left column address,
	MOV DH, [BP].SWD_LRRNM;		 lower right row address,
	MOV DL, [BP].SWD_LRCNM;		 lower right column address,
	MOV BH, [BP].SWD_CAT;		 and new attribute.
;
	MOV AH, 6;			Load function code,
	INT VIDINT;			 call BIOS interrupt,
	JMP SCRTN;			 and exit.	
;
; ----- SCROLL WINDOW DOWN.
;
SCRLDN: MOV AL, [BP].SWD_CNT;		Load number of lines,
	MOV CH, [BP].SWD_ULRNM;		 upper left row address,
	MOV CL, [BP].SWD_ULCNM;		 upper left column address,
	MOV DH, [BP].SWD_LRRNM;		 lower right row address,
	MOV DL, [BP].SWD_LRCNM;		 lower right column address,
	MOV BH, [BP].SWD_CAT;		 and new attribute.
;
	MOV AH, 7;			Load function code,
	INT VIDINT;			 call BIOS interrupt,
	JMP SCRTN;			 and exit.
;
; ----- RETURN DISPLAY MODE.
;
RETMD:	PUSH BP;			Save variables pointer.
;
	MOV AH, 15;			Set function number and
	INT VIDINT;			 perform BIOS interrupt.
;
	POP BP;				Restore variables pointer.
;
	XOR AH, AH;			Load pointer for mode value
	MOV BX, [BP].RSM_MPT;		 and store value.
	MOV [BX], AX;
;
; ----- RETURN.
;
SCRTN:	POP ES;				Restore work registers and
	POP DS;				 return.
	POP SI;
	POP DI;
	POP BP;
	RET;
;
;
SCINTF	ENDP
;
PROG	ENDS
;
; ----- MODULE REVISION HISTORY. ----------------------------------*
;
;	ORIGINAL: December 20, 1985  Mike Dougherty
;
	END
