home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 324_01 / wgconio.c < prev    next >
C/C++ Source or Header  |  1990-07-17  |  19KB  |  832 lines

  1. /*
  2.    HEADER:       ;
  3.    TITLE:        Text Window Support Functions;
  4.    DATE:         07/17/1990;
  5.    DESCRIPTION: "Emulates most text windowing functions of Turbo C 2.0
  6.          with a few additions. With exception of make_window()
  7.          functions can all be used in TSR's. Make_window() could
  8.          be modified not to call malloc() and thus also be used
  9.          in a TSR.";
  10.    SYSTEM:       MS-DOS;
  11.    FILENAME:     WGCONIO.C;
  12.    WARNINGS:    "Uses int86(), if not supported replace with equivalent.";
  13.    SEE-ALSO:     wgconio.h, wgconio.lib, sample.c, sample.exe;
  14.    AUTHORS:      Bill Giel;
  15.    COMPILERS:    TC;
  16. */
  17.  
  18. #include<stdlib.h>
  19. #include<dos.h>
  20. #include<stdarg.h>
  21. #include<process.h>
  22.  
  23. #define WINLEFT 1
  24. #define WINTOP 1
  25. #define WINBOTTOM 25
  26. #define WINRIGHT 80
  27. #define SCREENHEIGHT 25
  28. #define SCREENWIDTH 80
  29. #define MAX_TEXTBUF 4000
  30. #define TXTLINE_BYTES 160
  31. #define TXTCHAR_BYTES 2
  32.  
  33.  
  34. /* Macros for scroll_window and wg_scroll functions*/
  35.  
  36. #define UP 6
  37. #define DOWN 7
  38.  
  39.  
  40. /* Macro to create a far pointer from a segment,offset*/
  41.  
  42. #define MFP(seg,off) ((void far *)\
  43.         (((unsigned long)(seg) << 16) + (unsigned)(off)))
  44.  
  45.  
  46. /*Structure to hold textscreen info*/
  47.  
  48. struct wgtext_info{
  49.        unsigned char winleft, wintop, winright, winbottom, attribute,
  50.         currmode, screenheight, screenwidth, curx,
  51.         cury, foreground, background;
  52. }WGW;
  53.  
  54.  
  55. /*Structure to hold video mode parameters used by the system*/
  56.  
  57. struct wgvid_parameters{
  58.     unsigned char textline,textchar;
  59.     char far *vid_mem;
  60. }WGV;
  61.  
  62.  
  63. /*Union to hold 16-bit keycode*/
  64.  
  65. union keycode{
  66.     char ch[2];
  67.     int i;
  68. }WGC;
  69.  
  70.  
  71. /*Structure for Current Widow Parameters*/
  72.  
  73. struct wgwind{
  74.     unsigned char foreborder,backborder,foretitle,backtitle,
  75.         foreground,background,leftlim,toplim,rightlim,bottomlim;
  76. };
  77.  
  78.  
  79.  
  80. /*Prototypes*/
  81.  
  82. void wgwindow        (int left,int top,int right,int bottom);
  83. void wgtextcolor    (int color);
  84. void wgtextbackground    (int color);
  85. void wgtextattr        (int attribute);
  86. void goto_xy        (int x,int y);
  87. void wggotoxy        (int x,int y);
  88. void wgclrscr        (void);
  89. void wgclreol        (void);
  90. int  wggettext        (int left,int top,int right,int bottom,char *buf);
  91. int  wgputtext        (int left,int top,int right,int bottom,char *buf);
  92. int  wgcputs        (char *string);
  93. int  wgputch        (int c);
  94. int  wgwherex        (void);
  95. int  wgwherey        (void);
  96. void wggettextinfo    (struct wgtext_info *inforec);
  97. void initiallize_WGW    (void);
  98. int  get_video_mode    (void);
  99. void get_cursor_pos    (unsigned char *x,unsigned char *y);
  100. int  get_keycode    (void);
  101. int  wggetch        (void);
  102. int  wggetche        (void);
  103. void get_cursor_size    (unsigned char *ch,unsigned char *cl);
  104. int  wgmovetext        (int left,int top,int right,int bottom,
  105.                 int newleft,int newtop);
  106. void scroll_window    (unsigned char direct,unsigned char lines,
  107.                 unsigned char top,unsigned char left,
  108.                 unsigned char bottom,unsigned char right,
  109.                 unsigned char attribute);
  110. void wg_scroll        (unsigned char direction);
  111. void box        (int width,int height);
  112. void box2        (int width,int height);
  113. char *make_window    (char *title,struct wgwind w,
  114.                 struct wgtext_info *t,int shadow_flag);
  115. void restore_screen    (struct wgwind w, char *text_buf,
  116.                 struct wgtext_info t, int shadow_flag);
  117. void cursor_off        (void);
  118. void size_cursor    (unsigned char start,unsigned char end);
  119. int  cdecl wgcprintf    (char *format, ...);
  120. void get_attrib        (unsigned char *attribute,unsigned char *foreground,
  121.                         unsigned char *background);
  122. void wgdelline        (void);
  123. void wginsline        (void);
  124. int  make_shadow    (int left,int top,int right,int bottom);
  125. char *make_tsr_window    (char *title,struct wgwind w,
  126.                     struct wgtext_info *t,char *buf);
  127. void restore_tsr_screen(struct wgwind w, char *text_buf,
  128.                     struct wgtext_info t);
  129.  
  130. int get_video_mode(void)
  131. {
  132.     union REGS r;
  133.  
  134.     r.x.ax=0x0F00;
  135.     int86(0x10,&r,&r);
  136.     return(r.x.ax & 0xFF);
  137. }
  138.  
  139. void get_cursor_pos(unsigned char *x,unsigned char *y)
  140. {
  141.     union REGS r;
  142.  
  143.     r.h.bh=0;
  144.     r.h.ah=3;
  145.     int86(0x10,&r,&r);
  146.     *y=r.h.dh+1;
  147.     *x=r.h.dl+1;
  148. }
  149.  
  150. void get_attrib(unsigned char *attribute,unsigned char *foreground,
  151.         unsigned char *background)
  152. {
  153.     union REGS r;
  154.     unsigned char dummy;
  155.  
  156.     r.h.ah=8;
  157.     r.h.bh=0;
  158.     int86(0x10,&r,&r);
  159.  
  160.     dummy=r.h.ah;
  161.     *attribute=r.h.ah;
  162.     *background=r.h.ah>>4;
  163.     *foreground=dummy<<4>>4;
  164. }
  165.  
  166. void initiallize_WGW(void)
  167. {
  168.  
  169.     WGW.winleft=WINLEFT;
  170.     WGW.wintop=WINTOP;
  171.     WGW.winright=WINRIGHT;
  172.     WGW.winbottom=WINBOTTOM;
  173.     WGW.screenheight=SCREENHEIGHT;
  174.     WGW.screenwidth=SCREENWIDTH;
  175.     WGW.currmode=get_video_mode();
  176.     get_cursor_pos(&WGW.curx,&WGW.cury);
  177.     get_attrib(&WGW.attribute,&WGW.foreground,&WGW.background);
  178.  
  179.     WGV.textline=TXTLINE_BYTES;
  180.     WGV.textchar=TXTCHAR_BYTES;
  181.  
  182.  
  183.     if(WGW.currmode==7)WGV.vid_mem=(char far *)MFP(0xB000,0000);
  184.     else WGV.vid_mem=(char far *)MFP(0xB800,0000);
  185.  
  186.     if(WGW.currmode<=1){
  187.         WGW.screenwidth=40;
  188.         WGW.winright=40;
  189.         WGV.textchar=2;
  190.         WGV.textline=80;
  191.  
  192.     }
  193.  
  194.     WGC.ch[0]=1;
  195. }
  196.  
  197. void goto_xy(int x,int y)
  198. {
  199.     union REGS r;
  200.  
  201.     r.h.dh=y-1;
  202.     r.h.dl=x-1;
  203.     r.h.ah=2;
  204.     r.h.bh=0;
  205.     int86(0x10,&r,&r);
  206. }
  207.  
  208.  
  209. void wggotoxy(int x,int y)
  210. {
  211.     union REGS r;
  212.  
  213.     if(y>WGW.winbottom-WGW.wintop+1||y<1)return;
  214.     if(x>WGW.winright-WGW.winleft+1||x<1)return;
  215.  
  216.     WGW.curx=x;WGW.cury=y;
  217.  
  218.     r.h.dh=WGW.wintop+WGW.cury-2;
  219.     r.h.dl=WGW.winleft+WGW.curx-2;
  220.     r.h.ah=2;
  221.     r.h.bh=0;
  222.     int86(0x10,&r,&r);
  223. }
  224.  
  225. void wgwindow(int left,int top,int right,int bottom)
  226. {
  227.  
  228.     if(left<1||right>WGW.screenwidth||left>right)return;
  229.     if(top<1||bottom>WGW.screenheight||top>bottom)return;
  230.  
  231.     WGW.winleft=left;
  232.     WGW.wintop=top;
  233.     WGW.winright=right;
  234.     WGW.winbottom=bottom;
  235.     wggotoxy(1,1);
  236. }
  237.  
  238. void wgclrscr(void)
  239. {
  240.     register i,j;
  241.     char far *v;
  242.     union REGS r;
  243.     extern wg_directvideo;
  244.  
  245.     if(wg_directvideo==1)
  246.         for(i=WGW.wintop-1;i<WGW.winbottom;i++)
  247.         for(j=WGW.winleft-1;j<WGW.winright;j++){
  248.             v=WGV.vid_mem+i*WGV.textline+j*WGV.textchar;
  249.             *v++=' ';
  250.             *v=WGW.attribute;
  251.         }
  252.     else{
  253.             r.h.ah=6;
  254.             r.h.al=0;
  255.             r.h.ch=WGW.wintop-1;
  256.             r.h.cl=WGW.winleft-1;
  257.             r.h.dh=WGW.winbottom-1;
  258.             r.h.dl=WGW.winright-1;
  259.             r.h.bh=WGW.attribute;
  260.             int86(0x10,&r,&r);
  261.     }
  262.  
  263.     wggotoxy(1,1);
  264. }
  265.  
  266. void wgtextcolor(int color)
  267. {
  268.     WGW.attribute=(color+(WGW.background<<4));
  269.     WGW.foreground=color;
  270. }
  271.  
  272. void wgtextbackground(int color)
  273. {
  274.     if(color>7)color-=8;
  275.     WGW.attribute=(WGW.foreground+(color<<4));
  276.     WGW.background=color;
  277. }
  278.  
  279. void wgtextattr(int attribute)
  280. {
  281.     int dummy;
  282.  
  283.     dummy=attribute;
  284.     WGW.attribute=attribute;
  285.     WGW.background=dummy>>4;
  286.     WGW.foreground=attribute<<4>>4;
  287. }
  288.  
  289. void wgclreol(void)
  290. {
  291.     register j;
  292.     int y;
  293.     char far *v;
  294.     union REGS r;
  295.     extern wg_directvideo;
  296.  
  297.     y=WGW.wintop+WGW.cury-2;
  298.  
  299.     if(wg_directvideo==1)
  300.         for(j=WGW.winleft+WGW.curx-2;j<WGW.winright;j++){
  301.             v=WGV.vid_mem+y*WGV.textline+j*WGV.textchar;
  302.             *v++=' ';
  303.             *v=WGW.attribute;
  304.         }
  305.     else for(j=WGW.winleft;j<=WGW.winright;j++){
  306.             goto_xy(j,WGW.cury);
  307.             r.h.ah=9;
  308.             r.h.bh=0;
  309.             r.x.cx=1;
  310.             r.h.al=' ';
  311.             r.h.bl=WGW.attribute;
  312.             int86(0x10,&r,&r);
  313.     }
  314. }
  315.  
  316. int wggettext(int left,int top,int right,int bottom,char *buf)
  317. {
  318.     register i,j;
  319.     char far *v;
  320.     char *buf_ptr;
  321.     union REGS r;
  322.     extern wg_directvideo;
  323.  
  324.     if(left<1||right>WGW.screenwidth||left>right)return 0;
  325.     if(top<1||bottom>WGW.screenheight||top>bottom)return 0;
  326.  
  327.     buf_ptr=buf;
  328.  
  329.     if(wg_directvideo==1)
  330.         for(i=top-1;i<bottom;i++)
  331.             for(j=left-1;j<right;j++){
  332.                 v=WGV.vid_mem+i*WGV.textline+j*WGV.textchar;
  333.                 *buf_ptr++=*v++;
  334.                 *buf_ptr++=*v;
  335.             }
  336.     else for(i=top;i<=bottom;i++)
  337.             for(j=left;j<=right;j++){
  338.                 goto_xy(j,i);
  339.                 r.h.ah=8;
  340.                 r.h.bh=0;
  341.                 *buf_ptr++=int86(0x10,&r,&r);
  342.                 *buf_ptr++=r.h.ah;
  343.     }
  344.     return 1;
  345. }
  346.  
  347. int wgputtext(int left,int top,int right,int bottom,char *buf)
  348. {
  349.     register i,j;
  350.     char far *v;
  351.     char *buf_ptr;
  352.     union REGS r;
  353.     extern wg_directvideo;
  354.  
  355.     if(left<1||right>WGW.screenwidth||left>right)return 0;
  356.     if(top<1||bottom>WGW.screenheight||top>bottom)return 0;
  357.  
  358.     buf_ptr=buf;
  359.  
  360.     if(wg_directvideo==1)
  361.         for(i=top-1;i<bottom;i++)
  362.             for(j=left-1;j<right;j++){
  363.                 v=WGV.vid_mem+i*WGV.textline+j*WGV.textchar;
  364.                 *v++=*buf_ptr++;
  365.                 *v=*buf_ptr++;
  366.             }
  367.     else for(i=top;i<=bottom;i++)
  368.             for(j=left;j<=right;j++){
  369.                 goto_xy(j,i);
  370.                 r.h.ah=9;
  371.                 r.h.bh=0;
  372.                 r.x.cx=1;
  373.                 r.h.al=*buf_ptr++;
  374.                 r.h.bl=*buf_ptr++;
  375.                 int86(0x10,&r,&r);
  376.     }
  377.     return 1;
  378. }
  379.  
  380. int wgmovetext(int left,int top,int right,int bottom,int newleft,int newtop)
  381. {
  382.     char far *v,*p;
  383.     char buf[MAX_TEXTBUF];
  384.     register i,j;
  385.     int max_i,max_j;
  386.     union REGS r;
  387.     unsigned char attribute,foreground,background;
  388.     extern wg_directvideo;
  389.  
  390.     if(left<1||right>WGW.screenwidth||left>right)return 0;
  391.     if(top<1||bottom>WGW.screenheight||top>bottom)return 0;
  392.     if(newleft<1||newleft+right-left>WGW.screenwidth)return 0;
  393.     if(newtop<1||newtop+bottom-top>WGW.screenheight)return 0;
  394.  
  395.     p=buf;
  396.  
  397.     if(wg_directvideo==1)
  398.         for(i=top-1;i<bottom;i++)
  399.            for(j=left-1;j<right;j++){
  400.             v=WGV.vid_mem+i*WGV.textline+j*WGV.textchar;
  401.             *p++=*v++;
  402.             *p++=*v;
  403.            }
  404.     else for(i=top;i<=bottom;i++)
  405.             for(j=left;j<=right;j++){
  406.                 goto_xy(j,i);
  407.                 get_attrib(&attribute,&foreground,&background);
  408.                 r.h.ah=8;
  409.                 r.h.bh=0;
  410.                 *p++=int86(0x10,&r,&r);
  411.                 *p++=attribute;
  412.     }
  413.  
  414.     p=buf;
  415.     max_i=newtop+bottom-top;
  416.     max_j=newleft+right-left;
  417.  
  418.     if(wg_directvideo==1)
  419.         for(i=newtop-1;i<max_i;i++)
  420.            for(j=newleft-1;j<max_j;j++){
  421.             v=WGV.vid_mem+i*WGV.textline+j*WGV.textchar;
  422.             *v++=*p++;
  423.             *v=*p++;
  424.            }
  425.     else for(i=newtop;i<=max_i;i++)
  426.             for(j=newleft;j<=max_j;j++){
  427.                 goto_xy(j,i);
  428.                 r.h.ah=9;
  429.                 r.h.bh=0;
  430.                 r.x.cx=1;
  431.                 r.h.al=*p++;
  432.                 r.h.bl=*p++;
  433.                 int86(0x10,&r,&r);
  434.     }
  435.     return 1;
  436. }
  437.  
  438.  
  439. void scroll_window(unsigned char direct,unsigned char lines,
  440.     unsigned char top,unsigned char left,unsigned char bottom,
  441.     unsigned char right,unsigned char attribute)
  442. {
  443.     union REGS r;
  444.  
  445.     r.h.ah=direct;   /* Direction of Scroll     */
  446.     r.h.al=lines;    /* No. of Lines To Scroll  */
  447.     r.h.ch=top-1;    /* Absolute Window top     */
  448.     r.h.cl=left-1;   /*    "   Window left      */
  449.     r.h.dh=bottom-1; /*    "   Window bottom    */
  450.     r.h.dl=right-1;  /*    "   Window right     */
  451.     r.h.bh=attribute;/* Color for blank line(s) */
  452.     int86(0x10,&r,&r);
  453. }
  454.  
  455. void wg_scroll(unsigned char direct)
  456. {
  457.     scroll_window(direct,1,WGW.wintop,WGW.winleft,
  458.         WGW.winbottom,WGW.winright,WGW.attribute);
  459. }
  460.  
  461. int wgcputs(char *string)
  462. {
  463.     int startx,endx,y;
  464.     char far *v;
  465.     char *p;
  466.     union REGS r;
  467.     extern wg_directvideo;
  468.  
  469.     p=string;
  470.     y=WGW.wintop+WGW.cury-2;
  471.     startx=WGW.winleft+WGW.curx-2;
  472.     endx=WGW.winright;
  473.     while(*p){
  474.         if(*p!=10&&*p!=13){
  475.             if(wg_directvideo==1){
  476.                  v=WGV.vid_mem+y*WGV.textline+(startx++)*WGV.textchar;
  477.                  *v++=*p++;
  478.                  *v=WGW.attribute;
  479.             }
  480.             else{
  481.                  goto_xy((startx++)+1,y+1);
  482.                  r.h.ah=9;
  483.                  r.h.bh=0;
  484.                  r.x.cx=1;
  485.                  r.h.al=*p++;
  486.                  r.h.bl=WGW.attribute;
  487.                  int86(0x10,&r,&r);
  488.             }
  489.         }
  490.         if(startx==endx||*p==10||*p==13){
  491.             if(*p==10||startx==endx)y++;
  492.             if(y==WGW.winbottom){
  493.                 wg_scroll(UP);
  494.                 y--;
  495.             }
  496.             if(*p==13||startx==endx)startx=WGW.winleft-1;
  497.             if(*p==10||*p==13)p++;
  498.         }
  499.     }
  500.     WGW.cury=y-WGW.wintop+2;WGW.curx=startx-WGW.winleft+2;
  501.     wggotoxy(WGW.curx,WGW.cury);
  502.     --p;
  503.     return(*p);
  504. }
  505.  
  506. int wgputch(int c)
  507. {
  508.     int startx,endx,y;
  509.     char far *v;
  510.     union REGS r;
  511.     extern wg_directvideo;
  512.  
  513.     y=WGW.wintop+WGW.cury-2;
  514.     startx=WGW.winleft+WGW.curx-2;
  515.     endx=WGW.winright;
  516.  
  517.     if(c!=10&&c!=13){
  518.         if(wg_directvideo==1){
  519.              v=WGV.vid_mem+y*WGV.textline+(startx++)*WGV.textchar;
  520.              *v++=c;
  521.              *v=WGW.attribute;
  522.         }
  523.         else{
  524.              goto_xy((startx++)+1,y+1);
  525.              r.h.ah=9;
  526.              r.h.bh=0;
  527.              r.x.cx=1;
  528.              r.h.al=c;
  529.              r.h.bl=WGW.attribute;
  530.              int86(0x10,&r,&r);
  531.         }
  532.     }
  533.     if(startx==endx||c==10||c==13){
  534.         if(c==10||startx==endx)y++;
  535.         if(y==WGW.winbottom){
  536.             wg_scroll(UP);
  537.             y--;
  538.         }
  539.         if(c==13||startx==endx)startx=WGW.winleft-1;
  540.     }
  541.     WGW.cury=y-WGW.wintop+2;WGW.curx=startx-WGW.winleft+2;
  542.     wggotoxy(WGW.curx,WGW.cury);
  543.     return c;
  544. }
  545.  
  546. int wgwherex(void)
  547. {
  548.     return(WGW.curx);
  549. }
  550.  
  551. int wgwherey(void)
  552. {
  553.     return(WGW.cury);
  554. }
  555.  
  556. void wggettextinfo(struct wgtext_info *textinfo)
  557. {
  558.     *textinfo=WGW;
  559. }
  560.  
  561. int get_keycode(void)
  562. {
  563.     union REGS r;
  564.  
  565.     r.h.ah=0;
  566.     int86(0x16,&r,&r);
  567.     return r.x.ax;
  568.  
  569. }
  570.  
  571. int wggetch(void)
  572. {
  573.     if(WGC.ch[0]==0){
  574.         WGC.ch[0]=1;
  575.         return(WGC.ch[1]);
  576.     }
  577.     WGC.i=get_keycode();
  578.     return(WGC.i & 255);
  579. }
  580.  
  581. int wggetche(void)
  582. {
  583.     char ch;
  584.     if((ch=wggetch())!=0)wgputch(ch);
  585.     return ch;
  586. }
  587.  
  588. void get_cursor_size(unsigned char *ch,unsigned char *cl)
  589. {
  590.     union REGS r;
  591.  
  592.     r.h.ah=3;
  593.     r.h.bh=0;
  594.     int86(0x10,&r,&r);
  595.  
  596.     *ch=r.h.ch;
  597.     *cl=r.h.cl;
  598. }
  599.  
  600. void box(int width,int height)
  601. {
  602.         register i;
  603.                 int upperleftx=wgwherex();
  604.                 int upperlefty=wgwherey();
  605.  
  606.         wgputch(201);
  607.         for(i=1;i<width-1;++i)wgputch(205);
  608.         wgputch(187);
  609.                 for(i=upperlefty+1;i<upperlefty+height-1;++i){
  610.                         wggotoxy(upperleftx,i);
  611.             wgputch(186);
  612.                         wggotoxy(upperleftx+width-1,i);
  613.             wgputch(186);
  614.         }
  615.                 wggotoxy(upperleftx,i);
  616.         wgputch(200);
  617.         for(i=1;i<width-1;++i)wgputch(205);
  618.         wgputch(188);
  619. }
  620.  
  621. void box2(int width,int height)
  622. {
  623.         register i;
  624.                 int upperleftx=wgwherex();
  625.                 int upperlefty=wgwherey();
  626.  
  627.         wgputch(218);
  628.         for(i=1;i<width-1;++i)wgputch(196);
  629.         wgputch(191);
  630.                 for(i=upperlefty+1;i<upperlefty+height-1;++i){
  631.                         wggotoxy(upperleftx,i);
  632.             wgputch(179);
  633.                         wggotoxy(upperleftx+width-1,i);
  634.             wgputch(179);
  635.         }
  636.                 wggotoxy(upperleftx,i);
  637.         wgputch(192);
  638.         for(i=1;i<width-1;++i)wgputch(196);
  639.         wgputch(217);
  640. }
  641.  
  642. char *make_window(char *title,struct wgwind w,
  643.             struct wgtext_info *t,int shadow_flag)
  644. {
  645.     char *buf_ptr;
  646.     int v_offset=0,h_offset=0,v2=0,h2=0;
  647.  
  648.     if(w.leftlim<1||w.rightlim>WGW.screenwidth||w.leftlim>w.rightlim)
  649.                                 return 0;
  650.     if(w.toplim<1||w.bottomlim>WGW.screenheight||w.toplim>w.bottomlim)
  651.                                 return 0;
  652.  
  653.     if(shadow_flag){
  654.         v_offset=v2=1;
  655.         h_offset=h2=2;
  656.         while(w.rightlim+h_offset>WGW.screenwidth)h_offset--;
  657.         while(w.bottomlim+v_offset>WGW.screenheight)v_offset--;
  658.     }
  659.     wggettextinfo(t);
  660.     buf_ptr=(char *)malloc((w.rightlim-w.leftlim+1+h_offset)
  661.                 *(w.bottomlim-w.toplim+1+v_offset)*2);
  662.     if(!buf_ptr)return(0);
  663.     wggettext(w.leftlim,w.toplim,
  664.         w.rightlim+h_offset,w.bottomlim+v_offset,buf_ptr);
  665.     if(shadow_flag)make_shadow(w.leftlim+h2,w.toplim+v2,
  666.             w.rightlim+h_offset,w.bottomlim+v_offset);
  667.     wgwindow(w.leftlim,w.toplim,w.rightlim,w.bottomlim);
  668.     wgtextbackground(w.backborder);wgtextcolor(w.foreborder);
  669.     wgclrscr();wggotoxy(2,1);
  670.     box(w.rightlim-w.leftlim-1,w.bottomlim-w.toplim+1);
  671.     if(*title){
  672.         wggotoxy((w.rightlim-w.leftlim-strlen(title)-2)/2+3,1);
  673.         wgtextcolor(w.foretitle);wgtextbackground(w.backtitle);
  674.         wgcputs(title);
  675.     }
  676.     wgwindow(w.leftlim+2,w.toplim+1,w.rightlim-2,w.bottomlim-1);
  677.     wgtextcolor(w.foreground);wgtextbackground(w.background);wgclrscr();
  678.     return(buf_ptr);
  679. }
  680.  
  681.  
  682. void restore_screen(struct wgwind w, char *text_buf,struct wgtext_info t,
  683.             int shadow_flag)
  684. {
  685.     int v_offset=0,h_offset=0;
  686.  
  687.     if(shadow_flag){
  688.         v_offset=1;
  689.         h_offset=2;
  690.         while(w.rightlim+h_offset>WGW.screenwidth)h_offset--;
  691.         while(w.bottomlim+v_offset>WGW.screenheight)v_offset--;
  692.     }
  693.  
  694.     if(text_buf==NULL)return;
  695.     wgputtext(w.leftlim,w.toplim,w.rightlim+h_offset,
  696.                     w.bottomlim+v_offset,text_buf);
  697.     free(text_buf);
  698.     wgwindow(t.winleft,t.wintop,t.winright,t.winbottom);
  699.     wgtextcolor(t.foreground);wgtextbackground(t.background);
  700.     wggotoxy(t.curx,t.cury);
  701. }
  702.  
  703. void cursor_off(void)
  704. {
  705.     union REGS r;
  706.     r.h.ah=1;
  707.     r.h.ch=0x20;
  708.     int86(0x10,&r,&r);
  709. }
  710.  
  711.  
  712. void size_cursor(unsigned char start,unsigned char end)
  713. {
  714.     union REGS r;
  715.     r.h.ah=1;
  716.     r.h.ch=start;
  717.     r.h.cl=end;
  718.     int86(0x10,&r,&r);
  719. }
  720.  
  721. int cdecl wgcprintf(char *format, ...)
  722. {
  723.     char dummy_str[255];
  724.     int rtn_val;
  725.     va_list aptr;
  726.  
  727.     va_start(aptr,format);
  728.     rtn_val=vsprintf(dummy_str,format,aptr);
  729.     va_end(aptr);
  730.     wgcputs(dummy_str);
  731.     return(rtn_val);
  732. }
  733.  
  734. void wgdelline(void)
  735. {
  736.     scroll_window(UP,1,wgwherey()+WGW.wintop-1,WGW.winleft,
  737.         WGW.winbottom,WGW.winright,WGW.attribute);
  738.     wggotoxy(1,wgwherey());
  739. }
  740.  
  741. void wginsline(void)
  742. {
  743.     scroll_window(DOWN,1,wgwherey()+WGW.wintop-1,WGW.winleft,
  744.         WGW.winbottom,WGW.winright,WGW.attribute);
  745.     wggotoxy(1,wgwherey());
  746. }
  747.  
  748. int make_shadow(int left,int top,int right,int bottom)
  749. {
  750.     register i,j;
  751.     char far *v;
  752.     union REGS r;
  753.     extern wg_directvideo;
  754.  
  755.     if(left<1||right>WGW.screenwidth||left>right)return 0;
  756.     if(top<1||bottom>WGW.screenheight||top>bottom)return 0;
  757.  
  758.  
  759.     if(wg_directvideo==1){
  760.         for(i=top-1;i<bottom-1;i++)
  761.             for(j=right-2;j<right;j++){
  762.                 v=WGV.vid_mem+i*WGV.textline+j*WGV.textchar;
  763.                 v++;*v=8;
  764.             }
  765.  
  766.             for(j=left-1;j<right;j++){
  767.                 v=WGV.vid_mem+i*WGV.textline+j*WGV.textchar;
  768.                 v++;*v=8;
  769.             }
  770.     }
  771.     else{
  772.          for(i=top;i<=bottom-1;i++)
  773.             for(j=right-1;j<=right;j++){
  774.                 goto_xy(j,i);
  775.                 r.h.ah=8;
  776.                 r.h.bh=0;
  777.                 r.h.al=int86(0x10,&r,&r);
  778.                 r.h.ah=9;
  779.                 r.h.bh=0;
  780.                 r.x.cx=1;
  781.                 r.h.bl=8;
  782.                 int86(0x10,&r,&r);
  783.             }
  784.             for(j=left;j<=right;j++){
  785.                 goto_xy(j,i);
  786.                 r.h.ah=8;
  787.                 r.h.bh=0;
  788.                 r.h.al=int86(0x10,&r,&r);
  789.                 r.h.ah=9;
  790.                 r.h.bh=0;
  791.                 r.x.cx=1;
  792.                 r.h.bl=8;
  793.                 int86(0x10,&r,&r);
  794.             }
  795.     }
  796.     return 1;
  797. }
  798.  
  799. char *make_tsr_window(char *title,struct wgwind w,
  800.             struct wgtext_info *t,char *buf)
  801. {
  802.  
  803.     if(w.leftlim<1||w.rightlim>WGW.screenwidth||w.leftlim>w.rightlim)
  804.                                 return 0;
  805.     if(w.toplim<1||w.bottomlim>WGW.screenheight||w.toplim>w.bottomlim)
  806.                                 return 0;
  807.  
  808.     wggettextinfo(t);
  809.     wggettext(w.leftlim,w.toplim,w.rightlim,w.bottomlim,buf);
  810.     wgwindow(w.leftlim,w.toplim,w.rightlim,w.bottomlim);
  811.     wgtextbackground(w.backborder);wgtextcolor(w.foreborder);
  812.     wgclrscr();wggotoxy(2,1);
  813.     box(w.rightlim-w.leftlim-1,w.bottomlim-w.toplim+1);
  814.     if(*title){
  815.         wggotoxy((w.rightlim-w.leftlim-strlen(title)-2)/2+2,1);
  816.         wgtextcolor(w.foretitle);wgtextbackground(w.backtitle);
  817.         wgcputs(title);
  818.     }
  819.     wgwindow(w.leftlim+2,w.toplim+1,w.rightlim-2,w.bottomlim-1);
  820.     wgtextcolor(w.foreground);wgtextbackground(w.background);wgclrscr();
  821.     return(buf);
  822. }
  823.  
  824. void restore_tsr_screen(struct wgwind w, char *text_buf,struct wgtext_info t)
  825. {
  826.  
  827.     if(text_buf==NULL)return;
  828.     wgputtext(w.leftlim,w.toplim,w.rightlim,w.bottomlim,text_buf);
  829.     wgwindow(t.winleft,t.wintop,t.winright,t.winbottom);
  830.     wgtextcolor(t.foreground);wgtextbackground(t.background);
  831.     wggotoxy(t.curx,t.cury);
  832. }