/* * tsrs.h * ***************************************************************************** * * Console functions for TSRs * ~~~~~~~~~~~~~~~~~~~~~~~~~~ ***************************************************************************** * * Author : Rajesh _ThE gReAt * Built on : forgotten! (some time in 2k) * Last Modified on : Friday, February 08, 2002, 3:55:44 PM * * Known errors : Almost all functions access memory directly . * Do not try to compile in any OS other than DOS. * ***************************************************************************** * DISCLAIMER: ***************************************************************************** * * Programmers may incorporate any or all code into their programs, * giving proper credit within the source. Publication of the * source routines is permitted so long as proper credit is given * to Rajesh _ThE gReAt. * * Copyright (C) 2002, 2003 by Rajesh _ThE gReAt. You may use this program, or * code or tables extracted from it, as desired without restriction. * I can not and will not be held responsible for any damage caused from * the use of this software. * * Read license.txt from http://www.rajeshgoli.com/license.txt * or http://www.rajeshgoli.com/license.htm * before using / distributing / or any sort of use of my source * Also read my disclaimer http://www.rajeshgoli.com/disclaimer.htm * * YOU AGREE TO BE BOUND BY MY DISCLAIMER AND LICENSE BY IN ANY WAY * USING THIS FILE . * ***************************************************************************** * This source works with Turbo C 2.0 and Turbo C++ 3.0 and above. ***************************************************************************** * Rajesh _ThE gReAt is a synonym of Rajesh Goli * Source freely distributable *****************************************************************************/ #ifndef __DOS_H #include #endif #ifdef __TSR_H #error Cant include both tsr.h and tsrs.h #endif #ifndef __TSRS_H #define __TSRS_H #else #undef __TSRS_H #define __TSRS_H #endif #define MALLOC_ERROR -5 #define DEFAULT_BKCOLOR 84 #define _BOX_ #ifndef NULL #define NULL (void *)0 #endif typedef unsigned char byte; union REGS input,output; struct SREGS sregisters; int r,c,k; byte far *scr = (byte far *)0xB8000000L; byte *savedwin; int destroy_buffer = 0; /* Function Prototypes */ void writestring (char * ,unsigned short ,unsigned short ,byte ,byte ); void writechar (char ,unsigned short ,unsigned short ,byte ,byte ); void _clrwin (unsigned short ,unsigned short ,unsigned short ,unsigned short ,byte ); void _savewin (unsigned short ,unsigned short ,unsigned short ,unsigned short ); void _restorewin (unsigned short ,unsigned short ,unsigned short ,unsigned short ); void _box (unsigned short ,unsigned short ,unsigned short ,unsigned short ,byte ,byte ,signed short ,unsigned short ); void writecolor (unsigned short ,unsigned short ,byte ); void box (unsigned short ,unsigned short ,unsigned short ,unsigned short ,byte ,byte ,signed short ,int ); void clrwin (unsigned short ,unsigned short ,unsigned short ,unsigned short ,byte ); void savewin_here (byte *,unsigned short ,unsigned short ,unsigned short ,unsigned short ); void restorewin_here (byte *,unsigned short ,unsigned short ,unsigned short ,unsigned short ); int savewin (byte *,unsigned short ,unsigned short ,unsigned short ,unsigned short ); void restorewin (byte *,unsigned short ,unsigned short ,unsigned short ,unsigned short ); int destroybuf (byte *); unsigned attrbconv (byte *,byte ,byte ,short ); void writestring(char *str,unsigned short row,unsigned short col,byte attrb,byte battrb) { unsigned nowcolor; while(*str) { if( battrb != DEFAULT_BKCOLOR ) writechar(*str,row,col,attrb,battrb); else { nowcolor = *( scr + col*160 + row*2 + 1); nowcolor = (nowcolor >> 4); nowcolor = (nowcolor & (~0x8)); writechar(*str,row,col,attrb,nowcolor); } str++; col++; } return; } void writechar(char ch,unsigned short row,unsigned short col,byte attrb,byte battrb) { byte atr; *(scr+(row*160)+(col*2)) = ch; attrbconv(&atr,attrb,battrb,0); *(scr+(row*160)+(col*2)+1) = atr; return; } /* Clears window */ void _clrwin(unsigned short sr,unsigned short sc,unsigned short er,unsigned short ec,byte attrb) { input.h.ah = 6; input.h.al = 0; input.h.ch = sr; input.h.cl = sc; input.h.dh = er; input.h.dl = ec; input.h.bh = attrb; int86(0x10,&input,&output); return; } void _savewin(unsigned short sr,unsigned short sc,unsigned short er,unsigned short ec) { for(k=0,r=sr;r<=er;r++) { for(c=sc;c<=ec;c++) { savedwin[k]=*(scr+(r*160)+(c*2)); savedwin[k+1]=*(scr+(r*160)+(c*2)+1); k += 2; } } return; } void _restorewin(unsigned short sr,unsigned short sc,unsigned short er,unsigned short ec) { for(k=0,r=sr;r<=er;r++) { for(c=sc;c<=ec;c++) { *(scr+(r*160)+(c*2)) = savedwin[k]; *(scr+(r*160)+(c*2)+1) = savedwin[k+1]; k += 2; } } return; } void _box(unsigned short r1,unsigned short c1,unsigned short r2,unsigned short c2,byte attrb,byte battrb,signed short shadow,unsigned short clwin_or_not) { int rr,cc; if(clwin_or_not) _clrwin(r1,c1,r2,c2,attrb); writechar(201,r1,c1,attrb,battrb); writechar(187,r1,c2,attrb,battrb); writechar(200,r2,c1,attrb,battrb); writechar(188,r2,c2,attrb,battrb); for(rr=r1+1;rr> 4) & 0x07); *(scr+(r1*160)+(c1*2)+1) &= ~8; if(clwin_or_not) clrwin(r1,c1,r2,c2,bk); textbackground(bk); textcolor(attrb); gotoxy(c1+1,r1+1); cprintf("%c",201); gotoxy(c2+1,r1+1); cprintf("%c",187); gotoxy(c1+1,r2+1); cprintf("%c",200); gotoxy(c2+1,r2+1); cprintf("%c",188); for(rr=r1+1;rr 15) return_value += PFORE; if(bak_color > 7) return_value += PBAK; return return_value; }