Close Back

      1  /*
      2  *	tsr.h
      3  *
      4  *****************************************************************************
      5  *
      6  *	Memory only - Console functions for TSRs
      7  *     	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      8  *****************************************************************************
      9  *
     10  *     	Author           :  Rajesh _ThE gReAt
     11  *	Built on         :  forgotten! (some time in 2k)
     12  *	Last Modified on :  Friday, February 08, 2002, 3:55:16 PM
     13  *
     14  *	Known errors : Almost all functions access memory directly .
     15  *		       Do not try to compile in any OS other than DOS.
     16  *
     17  *****************************************************************************
     18  *	DISCLAIMER:
     19  *****************************************************************************
     20  *
     21  *	Programmers may incorporate any or all code into their programs,
     22  *	giving proper credit within the source. Publication of the
     23  *	source routines is permitted so long as proper credit is given
     24  *	to Rajesh _ThE gReAt.
     25  *
     26  *	Copyright (C) 2002, 2003 by Rajesh _ThE gReAt.  You may use this program, or
     27  *	code or tables extracted from it, as desired without restriction.
     28  *	I can not and will not be held responsible for any damage caused from
     29  *	the use of this software.
     30  *
     31  *	Read license.txt from http://www.rajeshgoli.com/license.txt
     32  *	                   or http://www.rajeshgoli.com/license.htm
     33  *	before using / distributing / or any sort of use of my source
     34  *	Also read my disclaimer http://www.rajeshgoli.com/disclaimer.htm
     35  *	
     36  *	YOU AGREE TO BE BOUND BY MY DISCLAIMER AND LICENSE BY IN ANY WAY
     37  *	USING THIS FILE .
     38  *
     39  *****************************************************************************
     40  * This source works with Turbo C 2.0 and Turbo C++ 3.0 and above.
     41  *****************************************************************************
     42  *	Rajesh _ThE gReAt is a synonym of Rajesh Goli
     43  *	Source freely distributable
     44  *****************************************************************************/
     45  
     46  #ifndef __DOS_H
     47  #include<dos.h>
     48  #endif
     49  
     50  #ifdef __TSRS_H
     51  #error Cant include both tsr.h and tsrs.h
     52  #endif
     53  
     54  #ifndef __TSR_H
     55  #define __TSR_H
     56  #endif
     57  
     58  #define _BOX_
     59  
     60  typedef unsigned char byte;
     61  
     62  union REGS input,output;
     63  struct SREGS sregisters;
     64  
     65  unsigned short r,c,k;
     66  byte far *scr = (byte far *)0xB8000000L;
     67  byte *buffer;
     68  
     69  
     70  void writestring	(char *,unsigned short ,unsigned short ,byte );
     71  void writechar		(char  ,unsigned short ,unsigned short ,byte );
     72  void clrwin		(unsigned short ,unsigned short ,unsigned short ,unsigned short ,byte );
     73  void savewin		(unsigned short ,unsigned short ,unsigned short ,unsigned short );
     74  void restorewin		(unsigned short ,unsigned short ,unsigned short ,unsigned short );
     75  void box		(unsigned short ,unsigned short ,unsigned short ,unsigned short ,byte ,byte );
     76  void writecolor		(unsigned short ,unsigned short ,byte );
     77  
     78  /************************************************/
     79  /* Fuction 2 write a string to VDU memory       */
     80  /************************************************/
     81  
     82  void writestring(char *str,unsigned short row,unsigned short col,byte attrb)
     83  {
     84  	while(*str)
     85  	{
     86  		writechar(*str,row,col,attrb);
     87  		str++;
     88  		col++;
     89  	}
     90  	return;
     91  }
     92  /************************************************/
     93  
     94  
     95  
     96  /**********************************************/
     97  /* Function 2 write a charecter to VDU memory */
     98  /**********************************************/
     99  
    100  void writechar(char ch,unsigned short row,unsigned short col,byte attrb)
    101  {
    102  	*(scr+(row*160)+(col*2)) = ch;
    103  	*(scr+(row*160)+(col*2)+1) = attrb;
    104  	return;
    105  }
    106  
    107  /***********************************************/
    108  
    109  
    110  
    111  /**********************************/
    112  /* Clears window                  */
    113  /**********************************/
    114  void clrwin(unsigned short sr,unsigned short sc,unsigned short er,unsigned short ec,byte attrb)
    115  {
    116  	input.h.ah = 6;
    117  	input.h.al = 0;
    118  	input.h.ch = sr;
    119  	input.h.cl = sc;
    120  	input.h.dh = er;
    121  	input.h.dl = ec;
    122  	input.h.bh = attrb;
    123  	
    124  	int86(0x10,&input,&output);
    125  	return;
    126  }
    127  /**********************************/
    128  
    129  
    130  /***********************************************************/
    131  /* Function 2 save charecters in VDU memory                */
    132  /***********************************************************/
    133  void savewin(unsigned short sr,unsigned short sc,unsigned short er,unsigned short ec)
    134  {
    135  	for(k=0,r=sr;r<=er;r++)
    136  	{
    137  		for(c=sc;c<=ec;c++)
    138  		{
    139  			buffer[k]=*(scr+(r*160)+(c*2));
    140  			buffer[k+1]=*(scr+(r*160)+(c*2)+1);
    141  	
    142  			k += 2;
    143  		}
    144  	}
    145  	return;
    146  }
    147  /***********************************************************/
    148  
    149  
    150  /***********************************************************/
    151  /* Function 2 save charecters to VDU memory                */
    152  /***********************************************************/
    153  void restorewin(unsigned short sr,unsigned short sc,unsigned short er,unsigned short ec)
    154  {
    155  	for(k=0,r=sr;r<=er;r++)
    156  	{
    157  		for(c=sc;c<=ec;c++)
    158  		{
    159  			*(scr+(r*160)+(c*2)) = buffer[k];
    160  			*(scr+(r*160)+(c*2)+1) = buffer[k+1];
    161  	
    162  			k += 2;
    163  		}
    164  	}
    165  	return;
    166  }
    167  /***********************************************************/
    168  
    169  
    170  
    171  unsigned short rr,cc;
    172  
    173  void box(unsigned short r1,unsigned short c1,unsigned short r2,unsigned short c2,byte attrb,byte shadow)
    174  {
    175  
    176  	clrwin(r1,c1,r2,c2,attrb);
    177  	writechar(201,r1,c1,attrb);
    178  	writechar(187,r1,c2,attrb);
    179  	writechar(200,r2,c1,attrb);
    180  	writechar(188,r2,c2,attrb);
    181  
    182  	for(rr=r1+1;rr<r2;rr++)
    183  	{
    184  		writechar(186,rr,c1,attrb);
    185  		writechar(186,rr,c2,attrb);
    186  	}
    187  
    188  	for(cc=c1+1;cc<c2;cc++)
    189  	{
    190  		writechar(205,r1,cc,attrb);
    191  		writechar(205,r2,cc,attrb);
    192  	}
    193  
    194  	for(rr=r1+1;rr<=r2;rr++)
    195  		writecolor(rr,c2+1,shadow);
    196  
    197  	for(cc=c1+1;cc<=c2;cc++)
    198  		writecolor(r2+1,cc,shadow);
    199  	return;
    200  }
    201  
    202  
    203  void writecolor(unsigned short row,unsigned short col,byte attrb)
    204  {
    205  	*(scr+(row*160)+(col*2)+1) = attrb;
    206  	return;
    207  }
    208