home *** CD-ROM | disk | FTP | other *** search
- #include <conio.h>
- #include "cursor.h"
-
- /*************************************************************************\
- | |
- | Programmer : Omer YALHI |
- | CompuServe : 71501,243 |
- | America OnLine : Falcon Men |
- | Internet : camel@acs.bu.edu |
- | Type : Freeware |
- | Purpose : Some cursor routines |
- | Version : 1.0 |
- | Last Modified : March 18'94 |
- | Compiler Used : Microsoft Visual C++ 1.0 |
- | |
- \*************************************************************************/
-
- /*************************************************************************\
- | FUNCTIONS |
- \*************************************************************************/
-
- /*************************************************************************\
- | |
- | void eeol(); |
- |___________________________________________________________________________|
- | |
- | Erases the line from current cursor position to the end of line |
- | Uses whatever the current attribute is. Doesn't change the |
- | cursor position. |
- |___________________________________________________________________________|
- | |
- | Inputs : None |
- | Returns : None |
- | |
- \*************************************************************************/
- void eeol()
- {
- int x = wherex(); /* get current col */
- int y = wherey(); /* get current row */
- int xOld = x; /* save current col */
- int yOld = y; /* save current row */
- int styleOld = getcursor(); /* save cursor style */
-
- showcursor(NOCURSOR); /* hide cursor */
- for(; x < 80; x++) { /* start from current location */
- gotoxy(x, y); /* till the end of line */
- _cprintf(" "); /* and erase the character */
- }
- showcursor(styleOld); /* show cursor as it was before */
- gotoxy(xOld, yOld); /* place cursor where it was before */
- }
-
- /*************************************************************************\
- | |
- | void gotoxy(int x, int y); |
- |___________________________________________________________________________|
- | |
- | Places cursor to the specified postion. Uses page 0. |
- |___________________________________________________________________________|
- | |
- | Inputs : int x -> column for cursor (lowest = 1) |
- | Returns : int y -> row for cursor (lowest = 1) |
- | |
- \*************************************************************************/
- void gotoxy(int x, int y)
- {
- x--; /* service uses base 0 so decrement */
- y--; /* service uses base 0 so decrement */
- __asm {
- mov ah, 2 /* service no 2 */
- mov bh, 0 /* use page number 0 */
- mov cx, y /* y is in cl now, don't care what ch is */
- mov dx, x /* put col info in dx. x is in dl now */
- mov dh, cl /* put row info in dh. dx has row and col info */
- int 10h /* invoke interrupt routine */
- }
- }
-
- /*************************************************************************\
- | |
- | int wherey(); |
- |___________________________________________________________________________|
- | |
- | Returns the current row position of the cursor. Uses page number 0. |
- |___________________________________________________________________________|
- | |
- | Inputs : None |
- | Returns : current row postion of the cursor |
- | |
- \*************************************************************************/
- int wherey()
- {
- int y; /* value to be returned */
-
- __asm {
- mov ah, 3 /* service no 3 */
- mov bh, 0 /* use page number 0 */
- int 10h /* invoke interrupt routine */
- mov dl, dh /* dh has row information, so put in loe byte */
- xor dh, dh /* we don't need dh */
- inc dl /* service uses base 0, so increment */
- mov y, dx /* save row information y */
- }
- return y; /* return row number */
- }
-
- /*************************************************************************\
- | |
- | int wherex(); |
- |___________________________________________________________________________|
- | |
- | Returns the current column position of the cursor. Uses page number 0. |
- |___________________________________________________________________________|
- | |
- | Inputs : None |
- | Returns : current column postion of the cursor |
- | |
- \*************************************************************************/
- int wherex()
- {
- int x; /* value to be returned */
-
- __asm {
- mov ah, 3 /* service no 3 */
- mov bh, 0 /* use page number 0 */
- int 10h /* invoke interrupt routine */
- xor dh, dh /* col info is in dl, we don't need dh */
- inc dl /* service uses base 0, so increment */
- mov x, dx /* save col information in x */
- }
- return x; /* return column number */
- }
-
- /*************************************************************************\
- | |
- | void showcursor(int style); |
- |___________________________________________________________________________|
- | |
- | Changes the shape of the cursor according to the style. |
- |___________________________________________________________________________|
- | |
- | Inputs : int style -> style to be used. Available styles defined in |
- | cursor.h are : |
- | |
- | NOCURSOR |
- | NORMALCURSOR |
- | BLOCKCURSOR |
- | |
- | Returns : None |
- | |
- \*************************************************************************/
- void showcursor(int style)
- {
- __asm {
- mov ah, 1 /* service no 1 */
- mov cx, style /* put style in cx */
- int 10h /* invoke interrupt routine */
- }
- }
-
- /*************************************************************************\
- | |
- | int getcursor(); |
- |___________________________________________________________________________|
- | |
- | Returns the style of the cursor. |
- |___________________________________________________________________________|
- | |
- | Inputs : None |
- | |
- | Returns : style -> Available styles defined in cursor.h are : |
- | |
- | NOCURSOR |
- | NORMALCURSOR |
- | BLOCKCURSOR |
- | |
- | Note that the returned value might not be one of the |
- | defined styles. |
- | |
- \*************************************************************************/
- int getcursor()
- {
- int style; /* value to be returned */
-
- __asm {
- mov ah, 3 /* service no 3 */
- mov bh, 0 /* use page number 0 */
- int 10h /* invoke interrupt routine */
- mov style, cx /* put info in style */
- }
- return style; /* return style */
- }
-
-