#include #include #include "box.h" #include // Ascii box drawing subroutine. This uses the line-drawing character-set. // It reads the current screen, and attaches a new box to any old boxes // that might exist. // The algorithm uses two translation tables: // A2V converts an ascii character into a direction vector // V2A converts from direction vector to ascii. // A direction vector is a byte with each pair of bits representing a direction // WwSsEeNn (West, South, East, North). Within each pair, the even bit // represents a single line, the odd bit represents a double line. #define SINGLE 0x55 #define DOUBLE 0xaa // Single Line Box (Ascii) Vector #define Bx_H 0xc4 // Horizontal 44 #define Bx_V 0xb3 // Vertical 11 #define Bx_UL 0xda // Upper Left 14 #define Bx_UR 0xbf // Upper Right 50 #define Bx_BR 0xd9 // Bottom Right 41 #define Bx_BL 0xc0 // Bottom Left 05 #define Bx_LT 0xc3 // Left T 15 #define Bx_RT 0xb4 // Right T 51 #define Bx_UT 0xc2 // Upper T 54 #define Bx_BT 0xc1 // Bottom T 45 #define Bx_X 0xc5 // Cross 55 // Double Line Box #define Dx_H 0xcd // Horizontal 88 #define Dx_V 0xba // Vertical 22 #define Dx_UL 0xc9 // Upper Left 28 #define Dx_UR 0xbb // Upper Right a0 #define Dx_BR 0xbc // Bottom Right 82 #define Dx_BL 0xc8 // Bottom Left 0a #define Dx_LT 0xcc // Left T 2a #define Dx_RT 0xb9 // Right T a2 #define Dx_UT 0xcb // Upper T a8 #define Dx_BT 0xca // Bottom T 8a #define Dx_X 0xce // Cross aa // Horiz Double to Vertical Single #define DH_UL 0xd5 // Upper Left #define DH_UR 0xb8 // Upper Right #define DH_BR 0xbe // Bottom Right #define DH_BL 0xd4 // Bottom Left #define DH_LT 0xc6 // Left T #define DH_RT 0xb5 // Right T #define DH_UT 0xd1 // Upper T #define DH_BT 0xcf // Bottom T #define DH_X 0xd8 // Cross // Vert Double to Horiz Single #define DV_UL 0xd6 // Upper Left #define DV_UR 0xb7 // Upper Right #define DV_BR 0xbd // Bottom Right #define DV_BL 0xd3 // Bottom Left #define DV_LT 0xc7 // Left T #define DV_RT 0xb6 // Right T #define DV_UT 0xd2 // Upper T #define DV_BT 0xd0 // Bottom T #define DV_X 0xd7 // Cross unsigned char A2V[256]= { // Translate Ascii to Dir Vector 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0x11,0x51,0x91,0x62,0x24,0x90,0xa2,0x22,0xa0,0x82,0x42,0x81,0x50, 0x5,0x45,0x54,0x15,0x44,0x55,0x19,0x26,0xa,0x28,0x8a,0xa8,0x2a,0x88,0xaa,0x89, 0x46,0x98,0x64,0x6,0x9,0x18,0x60,0x66,0x99,0x41,0x14,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ; unsigned char V2A[256]= { // Translate Dir vector to ascii 0, Bx_H , Dx_H , 0,Bx_V , Bx_BL, DV_BL, 0,Dx_V , DH_BL, Dx_BL, 0,0,0,0,0, Bx_H , Bx_V , Bx_V , 0,Bx_UL, Bx_LT, Bx_LT, 0,DH_UL, DH_LT, Bx_LT, 0,0,0,0,0, Dx_H , Bx_V , Dx_V , 0,DV_UL, Bx_LT, DV_LT, 0,Dx_UL, Bx_LT, Dx_LT, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, Bx_V , Bx_BR, DV_BR, 0,Bx_H , Bx_BT, DV_BT, 0,Bx_H , Bx_BT, Bx_BT, 0,0,0,0,0, Bx_UR, Bx_RT, Bx_RT, 0,Bx_UT, Bx_X , Bx_X , 0,Bx_UT, Bx_X , Bx_X , 0,0,0,0,0, DV_UR, Bx_RT, DV_RT, 0,DV_UT, Bx_X , DV_X , 0,Bx_UT, Bx_X , DV_X , 0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, Dx_V , DH_BR, Dx_BR, 0,Bx_H , Bx_BT, Bx_BT, 0,Dx_H , DH_BT, Dx_BT, 0,0,0,0,0, DH_UR, DH_RT, Bx_RT, 0,Bx_UT, Bx_X , Bx_X , 0,DH_UT, DH_X , DH_X , 0,0,0,0,0, Dx_UR, Bx_RT, Dx_RT, 0,Bx_UT, Bx_X , DV_X , 0,Dx_UT, DH_X , Dx_X , 0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; #define Xlate(X,M) \ { L[X][0]= V2A[ (A2V[L[X][0]] & M) | (Type & ~M) ]; \ if (Attr) L[X][1]=Attr; } void ABox(int X1, int Y1, int X2, int Y2, int Type) { int S,I; // Type = DOUBLE or SINGLE int Attr= (Type >>8)&0xff; // Get attr from upper 8 bits of Type int ScrH,ScrW; unsigned char L[256][2]; { struct text_info Ti; // Find screen size gettextinfo(&Ti); ScrH= Ti.screenheight; ScrW= Ti.screenwidth; } Type &= 0xff; if (X1>X2) {I=X1; X1=X2; X2=I;} // Normalize box if (Y1>Y2) {I=Y1; Y1=Y2; Y2=I;} if (X1<1) X1=1; else if (X1>ScrW) X1=ScrW; // Check boundaries if (X2<1) X2=1; else if (X2>ScrW) X2=ScrW; if (Y1<1) Y1=1; else if (Y1>ScrH) Y1=ScrH; if (Y2<1) Y2=1; else if (Y2>ScrH) Y2=ScrH; S=X2-X1; // Get length of top/bottom gettext(X1,Y1,X2,Y1,L); // Draw top line Xlate(0,0xc3); Xlate(S,0x0f); // Get corners (UL, UR) for (I=S; --I;) Xlate(I,0x33); // Get the rest puttext(X1,Y1,X2,Y1,L); gettext(X1,Y2,X2,Y2,L); // Draw bottom line Xlate(0,0xf0); Xlate(S,0x3c); for (I=S; --I;) Xlate(I,0x33); puttext(X1,Y2,X2,Y2,L); S=Y2-Y1; // Get length of left/right side gettext(X1,Y1,X1,Y2,L); // Draw left side for (I=S; --I;) Xlate(I,0xcc); puttext(X1,Y1,X1,Y2,L); gettext(X2,Y1,X2,Y2,L); // Draw right side for (I=S; --I;) Xlate(I,0xcc); puttext(X2,Y1,X2,Y2,L); } void Test_ABox(void) { textmode(C4350); clrscr(); ABox(4,6,75,46,(MHILITE<<8)|SINGLE); ABox(6,42,70,8,(NORMAL<<8) |DOUBLE); ABox(8,3,78,40,(HILITE<<8) |SINGLE); ABox(9,4,77,39,(MNORMAL<<8)|DOUBLE); ABox(-30,-20,100,100,(OUTLINE<<8)|DOUBLE); window(30,20,69,38); textattr( NORMAL); cprintf(" NORMAL "); textattr( MNORMAL); cprintf(" MNORMAL \n\r"); textattr( H_HELP); cprintf(" H_HELP "); textattr( OUTLINE); cprintf(" OUTLINE \n\r"); textattr( TEXT); cprintf(" TEXT "); textattr( HILITE); cprintf(" HILITE \n\r"); textattr( HELP); cprintf(" HELP "); textattr( FLASH); cprintf(" FLASH \n\r"); textattr( MSELECT); cprintf(" MSELECT "); textattr( DIRECT); cprintf(" DIRECT \n\r"); textattr( H_DIRECT);cprintf(" H_DIRECT "); textattr( HIST_S); cprintf(" HIST_S \n\r"); textattr( HIST_E); cprintf(" HIST_E "); textattr( DIM); cprintf(" DIM \n\r"); } int Hilite(int X, int Y, int L, int Attr) { char Buf[256]; int I, Was; gettext(X,Y,X+L-1,Y,Buf); Was= Buf[1]; for (I= L+L-1; I>0; I-=2) Buf[I]=Attr; puttext(X,Y,X+L-1,Y,Buf); return Was; } #include void Print_Dir() { struct ffblk FB; int I; char Dir[40]; char Buf[20*24*2]; gettext(1,1,20,24,Buf); window(1,1,20,24); textattr(DIRECT); clrscr(); textattr(H_DIRECT); if (getcwd(Dir,40)!=0) cprintf("%-40s",Dir); textattr(DIRECT); cputs("------ *.bit -------"); if (findfirst("*.bit",&FB,0)==0) do { for (I=0; I<8; ++I) if (FB.ff_name[I]=='.') { FB.ff_name[I]= 0; break; } cprintf(" %-8s ",FB.ff_name); } while(findnext(&FB)==0); cputs("\n\r------ *.pat -------"); if (findfirst("*.pat",&FB,0)==0) do { for (I=0; I<8; ++I) if (FB.ff_name[I]=='.') { FB.ff_name[I]= 0; break; } cprintf(" %-8s ",FB.ff_name); } while(findnext(&FB)==0); Pause; puttext(1,1,20,24,Buf); } void More(char *File) { char *S; char L[80]; int C,I=45; FILE *F; if ((S= (char *)malloc(50*80*2)) == 0) { ERRBOX(FLASH); cprintf("Out of memory to display file."); Pause;} gettext(1,1,80,50,S); window(1,1,80,50); textattr(NORMAL); clrscr(); if ((F= fopen(File,"rt"))==NULL) { printf("Unable to open file %s\n",File); if (getch()==0) getch();} else while (feof(F) == 0) { while (I-- && (fgets(L,80,F) >0)) cprintf("%s\r",L); cprintf("--more--\r"); if ((C=getch()) == 0) getch(); if ((C|32) == 'q') break; if (C==32) I=45; else I=1; } puttext(1,1,80,50,S); free(S); }