/* ansi.c functions to check for ansi.c and to clear the screen with an ansi attribute written by Ben Fasenfest on: 11/27/96 */ /* monochrome card macro - 1 if card is monochrome, 0 if color */ #define MONOCHROME (biosequip() & 0x30) == 0x30 /* monochrome card attributes */ #define ANSI_M_OFF 0 #define ANSI_M_BOLD 1 #define ANSI_M_UNDERLINE 4 #define ANSI_M_BLINK 5 #define ANSI_M_REVERSE 7 /* color card forground colors (text colors) */ #define ANSI_FG_BLACK 30 #define ANSI_FG_RED 31 #define ANSI_FG_GREEN 32 #define ANSI_FG_YELLOW 33 #define ANSI_FG_BLUE 34 #define ANSI_FG_MAGENTA 35 #define ANSI_FG_CYAN 36 #define ANSI_FG_WHITE 37 /* color card background colors */ #define ANSI_BG_BLACK 40 #define ANSI_BG_RED 41 #define ANSI_BG_GREEN 42 #define ANSI_BG_YELLOW 43 #define ANSI_BG_BLUE 44 #define ANSI_BG_MAGENTA 45 #define ANSI_BG_CYAN 46 #define ANSI_BG_WHITE 47 /* function definitions */ int isansi(void); /* tests to see if ansi.sys is loaded returns 1 if it is */ int ansi_clrscrn2(int bg, int fg); /* clears the screen with the background color bg and the foregrund color fg. for monochrome cards, put the attribute as bg and use -1 for fg. The -1 causes ansi_clrscrn2 to ignore fg. */ int ansi_clrscrn(); /* clears the screen and restores the normal text attributes */ int isansi(void) /* tests to see if ansi.sys is loaded */ { /* returns a 1 if ansi.sys is loaded */ printf("\n\n\x1B[2J"); if(cursrow()!=0) { clrscrn(); return 0; } return 1; } int ansi_clrscrn2(int bg, int fg) { if(isansi()==0) return -1; if(fg!=0) printf("\x1B[%d;%dm \x1B[2J",bg,fg); else printf("\x1B[%dm \x1B[2J",bg); return 0; } int ansi_clrscrn() { if(isansi()==0) return -1; if((biosequip() & 0x30) ==0x30) /*detect card type */ { /* monochrome */ printf("\x1B[%dm \x1B[2J", ANSI_M_OFF); } else printf("\x1B[%d;%dm \x1B[2J",ANSI_BG_BLACK,ANSI_FG_WHITE); return 0; } void aclrscrn2(int bg, int fg) { int attr; if(isansi()) { if(fg!=-1) printf("\x1B[%d;%dm \x1B[2J",bg,fg); else printf("\x1B[%dm \x1B[2J",bg); } else { switch(bg) { case ANSI_M_OFF : bg=0x07; break; case ANSI_M_BOLD : bg=0x0E; break; case ANSI_M_UNDERLINE : bg=0x01; break; case ANSI_M_BLINK : bg=0x87; break; case ANSI_M_REVERSE : bg=0x70; break; case ANSI_BG_BLACK : bg=0x0; break; case ANSI_BG_RED : bg=0x4; break; case ANSI_BG_GREEN : bg=0x2; break; case ANSI_BG_YELLOW : bg=0xE; break; case ANSI_BG_BLUE : bg=0x1; break; case ANSI_BG_MAGENTA : bg=0x5; break; case ANSI_BG_CYAN : bg=0x3; break; case ANSI_BG_WHITE : bg=0x7; break; } switch(fg) { case ANSI_FG_BLACK : fg=0x00; break; case ANSI_FG_RED : fg=0x04; break; case ANSI_FG_GREEN : fg=0x02; break; case ANSI_FG_YELLOW : fg=0x0E; break; case ANSI_FG_BLUE : fg=0x01; break; case ANSI_FG_MAGENTA : fg=0x05; break; case ANSI_FG_CYAN : fg=0x03; break; case ANSI_FG_WHITE : fg=0x07; break; } if(fg!=-1) attr=fg | bg; else attr=bg; clrscrn2(attr); } }