home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / DOANSI_2.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  5KB  |  237 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  DOANSI_2.C - OS-Specific ANSI screen code interpreter functions
  5. **
  6. **  From DRSK_105.LZH (ansi.c), hereby declared free for use for whatever
  7. **  purposes by author: Mark Kimes
  8. */
  9.  
  10. #include "doansi.h"
  11. #include "mk_fp.h"
  12.  
  13. int   realmaxy, realmaxx;
  14. int   maxx, maxy;
  15.  
  16. #ifdef OS2
  17.  
  18. #define INCL_DOS
  19. #define INCL_VIO
  20.  
  21. #include <os2.h>
  22.  
  23. int vidhandle = 0;  /* can be changed for AVIO */
  24.  
  25. void set_screensize (int reservedlines)
  26. {
  27.       VIOMODEINFO vm;
  28.  
  29.       vm.cb = sizeof(VIOMODEINFO);
  30.       VioGetMode(&vm, vidhandle);
  31.       maxx = vm.col;
  32.       maxy = vm.row - reservedlines;
  33.       realmaxx = maxx;
  34.       realmaxy = vm.row;
  35. }
  36.  
  37. void pos_hardcursor (int x,int y)
  38. {
  39.       VioSetCurPos(y,x,vidhandle);
  40. }
  41.  
  42. void hardcursor_off (void)
  43. {
  44.       VIOCURSORINFO vc;
  45.  
  46.       VioGetCurType(&vc,vidhandle);
  47.       vc.attr = -1;
  48.       VioSetCurType(&vc,vidhandle);
  49. }
  50.  
  51. void hardcursor_on (int x,int y)
  52. {
  53.       VIOCURSORINFO vc;
  54.  
  55.       VioGetCurType(&vc,vidhandle);
  56.       vc.attr = 0;
  57.       VioSetCurType(&vc,vidhandle);
  58.       VioSetCurPos(y,x,vidhandle);
  59. }
  60.  
  61. void put_char (char c, char attr, int x, int y)
  62. {
  63.       VioWrtCharStrAtt(&c,1,y,x,&attr,vidhandle);
  64. }
  65.  
  66. void scroll_up (int tx,int ty,int bx,int by,char attr)
  67. {
  68.       int attrib = ' ' | (attr << 8);
  69.  
  70.       VioScrollUp(ty,tx,by,bx,1,(char *)&attrib,vidhandle);
  71. }
  72.  
  73. void clearwindow (int tx,int ty,int bx,int by,char attr)
  74. {
  75.       int attrib = ' ' | (attr << 8);
  76.  
  77.       VioScrollUp(ty,tx,by,bx,-1,(char *)&attrib,vidhandle);
  78. }
  79.  
  80. void cleartoeol (int x,int y,int ex,char attr)
  81. {
  82.       int attrib = ' ' | (attr << 8);
  83.  
  84.       VioScrollUp(y,x,y,ex,-1,(char *)&attrib,vidhandle);
  85. }
  86.  
  87. #else
  88.  
  89. /* MS-DOS -- (urp) */
  90.  
  91. #include <dos.h>
  92.  
  93. #if !defined(MK_FP)
  94.  #define MK_FP(seg,off) ((void far *)(((long)(seg) << 16)|(unsigned)(off)))
  95. #endif
  96.  
  97. static int far *vseg;
  98. char           usebios = 0; /* if true, output through BIOS */
  99.  
  100. int vmode (void)
  101. {
  102.       union REGS r;
  103.  
  104.       r.h.ah = 15;
  105.       r.x.bx = 0;
  106.       int86(0x10,&r,&r);
  107.       return r.h.al;
  108. }
  109.  
  110. void set_screensize (int reservedlines)
  111. {
  112.       union REGS   r;
  113.       unsigned int vbase;
  114.  
  115.       r.h.ah = 0x0f;
  116.       r.x.bx = 0;
  117.       int86 (0x10, &r, &r);
  118.       maxx = (int) r.h.ah;
  119.       if (maxx < 80)                                  /* gimme a break! */
  120.       {
  121.             r.x.ax = 0x0003;
  122.             int86(0x10,&r,&r);
  123.             maxx = 80;
  124.       }
  125.       realmaxx = maxx;
  126.       r.x.ax = 0x1130;
  127.       r.x.dx = maxy;
  128.       int86 (0x10, &r, &r);
  129.       realmaxy = maxy = (r.x.dx == 0) ? 25 : (r.x.dx + 1);
  130.       maxy -= reservedlines;
  131.       vbase = (vmode () == 7 ? 0xb000 : 0xb800);
  132.       vseg = MK_FP(vbase,0);        /* address of video ram as pointer */
  133. }
  134.  
  135. void pos_hardcursor (int x,int y)
  136. {
  137.       union REGS r;
  138.  
  139.       r.x.ax = 0x0200;
  140.       r.x.bx = 0;
  141.       r.x.dx = ((y << 8) & 0xff00) + x;
  142.       int86(0x10,&r,&r);
  143. }
  144.  
  145. void hardcursor_off (void)
  146. {
  147.       union REGS r;
  148.  
  149.       r.x.ax = 0x0200;
  150.       r.x.bx = 0;
  151.       r.x.dx = ((realmaxy << 8) & 0xff00);
  152.       int86(0x10,&r,&r);
  153. }
  154.  
  155. void hardcursor_on (int x,int y)
  156. {
  157.       union REGS r;
  158.  
  159.       r.x.ax = 0x0200;
  160.       r.x.bx = 0;
  161.       r.x.dx = ((y << 8) & 0xff00) + x;
  162.       int86(0x10,&r,&r);
  163. }
  164.  
  165. void put_char (char c, char attr, int x, int y)
  166. {
  167.       if(!usebios)
  168.       {
  169.             register int far *v;
  170.  
  171.              /* point v to right spot in vid RAM */
  172.  
  173.             v = vseg + ((y * realmaxx) + x);
  174.             *v = (c | (attr << 8));                   /* display */
  175.       }
  176.       else
  177.       {
  178.  
  179.             union REGS r;
  180.  
  181.             r.x.ax = 0x0200;
  182.             r.x.bx = 0;
  183.             r.x.dx = ((y << 8) & 0xff00) + x;
  184.             int86(0x10,&r,&r);
  185.             r.h.ah = 0x09;
  186.             r.h.bh = 0;
  187.             r.h.bl = attr;
  188.             r.x.cx = 1;
  189.             r.h.al = c;
  190.             int86(0x10,&r,&r);
  191.       }
  192. }
  193.  
  194. void scroll_up (int tx,int ty,int bx,int by,char attr)
  195. {
  196.       union REGS r;
  197.  
  198.       r.h.ah = 6;
  199.       r.h.al = 1;
  200.       r.h.bh = attr;
  201.       r.h.cl = tx;
  202.       r.h.ch = ty;
  203.       r.h.dl = bx;
  204.       r.h.dh = by;
  205.       int86(0x10,&r,&r);
  206. }
  207.  
  208. void clearwindow (int tx,int ty,int bx,int by,char attr)
  209. {
  210.       union REGS r;
  211.  
  212.       r.h.ah = 6;
  213.       r.h.al = 0;
  214.       r.h.bh = attr;
  215.       r.h.cl = tx;
  216.       r.h.ch = ty;
  217.       r.h.dl = bx;
  218.       r.h.dh = by;
  219.       int86(0x10,&r,&r);
  220. }
  221.  
  222. void cleartoeol (int x,int y,int ex,char attr)
  223. {
  224.       union REGS r;
  225.  
  226.       r.h.ah = 6;
  227.       r.h.al = 0;
  228.       r.h.bh = attr;
  229.       r.h.cl = x;
  230.       r.h.ch = y;
  231.       r.h.dl = ex;
  232.       r.h.dh = y;
  233.       int86(0x10,&r,&r);
  234. }
  235.  
  236. #endif
  237.