home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / MSGDP206.SZH / SCREEN.C < prev    next >
Text File  |  1990-11-20  |  15KB  |  829 lines

  1. /*
  2.  
  3. Title:  MsgEd
  4.  
  5. File:   Screen.c
  6.  
  7. Author: Jim Nutt
  8.  
  9. Copr:    released into the PUBLIC DOMAIN 30 jul 1990 by jim nutt
  10.  
  11. Description:
  12.  
  13.     Screen handling functions for MsgEd.
  14.  
  15.     if you need to port this... remember, msged uses a 1 based coordinate
  16.     system (i.e. top left is (1,1) NOT (0,0)).
  17.  
  18. */
  19.  
  20. #include "pascal.h"
  21.  
  22. #include <dos.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <stdio.h>
  26. #include <stdarg.h>
  27. #if !defined(__TURBOC__)
  28. #include <conio.h>
  29. #else
  30. int kbhit(void);
  31. int getch(void);
  32. #endif
  33. #ifndef MK_FP
  34. #include "mkfp.h"
  35. #endif
  36. #include "screen.h"
  37. #include "vfossil.h"
  38.  
  39. #ifndef _MSC_VER
  40. #include "screen2.h"
  41. #endif
  42.  
  43. static void pascal vfossil_cursor (int st);
  44. static void pascal vfossil_init (void);
  45. static void pascal vfossil_open (void);
  46. static void pascal vfossil_close (void);
  47.  
  48. void pascal strins(char *l, char c, int x);
  49. void pascal strdel(char *l, int x);
  50.  
  51. #define FALSE 0
  52. #define TRUE !FALSE
  53. #define TEXTLEN 256
  54.  
  55. int int86(int intnum,union REGS *i, union REGS *o);
  56. int int86x(int intnum,union REGS *i, union REGS *o,struct SREGS *s);
  57.  
  58. unsigned int *macros[41];     /* function key macros + 1 for autostart */
  59.  
  60. int maxx;               /* maximum screen columns */
  61. int maxy;               /* maximum screen rows */
  62. int videomethod;        /* how to write to the screen */
  63. unsigned int vbase;     /* where screen memory is located */
  64. unsigned char current_color;    /* current screen attribute */
  65.  
  66. /* keyboard control values */
  67.  
  68. static int autostart = 0;
  69. static unsigned int * macro = (void *) NULL;
  70.  
  71. static char s[TEXTLEN];
  72.  
  73. static unsigned int *screen = NULL;
  74. static unsigned int cx = 1;
  75. static unsigned int cy = 1;
  76. static int desqview = 0;
  77.  
  78. static unsigned char scroll_fill [2];
  79. static VIOMODEINFO fossil_data;
  80.  
  81.  
  82. void pascal video_init()
  83. {
  84.     union REGS r;
  85.     struct SREGS sr;
  86.     int vmode = 0;
  87.  
  88.     if (videomethod == ANSI) {
  89.         maxx = 80;
  90.         maxy = 25;
  91.         desqview = 0;
  92.         return;
  93.     }
  94.  
  95.     if (videomethod == FOSSIL) {
  96.         vfossil_init ();                /* Start Video FOSSIL */
  97.         fossil_data.cb = 2 * sizeof (VIOMODEINFO);
  98.         VioGetMode ((PVIOMODEINFO) &fossil_data,0);    /* Get mode info      */
  99.         maxx = fossil_data.col;        /* Maximum 'X' value  */
  100.         maxy = fossil_data.row;        /* Maximum 'Y' value  */
  101.     }
  102.     else {
  103.         r.h.ah = 0x0f;
  104.         int86(0x10,&r,&r);
  105.         vmode = r.h.al;
  106.         if (maxx == 0)
  107.             maxx = (int) r.h.ah;
  108.  
  109.         if (maxy == 0) {
  110.             r.x.ax = 0x1130;
  111.             r.x.dx = maxy;
  112.             int86(0x10,&r,&r);
  113.             maxy = (r.x.dx == 0) ? 25 : (r.x.dx + 1);
  114.         }
  115.  
  116.         if (videomethod == DIRECT) {
  117.             if (vbase == 0)
  118.                 if (vmode == 0x07)
  119.                     vbase = 0xb000;
  120.                 else
  121.                     vbase = 0xb800;
  122.  
  123.             r.h.ah = 0xfe;
  124.             sr.es = vbase;
  125.             r.x.di = 0;
  126.             int86x(0x10,&r,&r,&sr);
  127.             desqview = (vbase != sr.es);
  128.             vbase = sr.es;
  129.             screen = (unsigned int *) MK_FP(vbase,r.x.di);
  130.         }
  131.     }
  132. }
  133.  
  134. int  *getrgn(int x1,int y1,int x2,int y2)
  135.  
  136. {
  137.     if ((x1 < 0) || (x2 > maxx) || (y1 < 0) || (y2 > maxy))
  138.         return(NULL);
  139.  
  140.     return(NULL);
  141. }
  142.  
  143. void putrgn(int x1,int y1,int x2,int y2,int *rgn)
  144.  
  145. {
  146.     if ((x1 < 0) || (x2 > maxx) || (y1 < 0) || (y2 > maxy))
  147.         return;
  148.  
  149.     if (!rgn)
  150.         return;
  151. }
  152.  
  153.  
  154. void pascal video_end()
  155. {
  156.     if (videomethod == FOSSIL)
  157.         vfossil_close ();
  158. }
  159.  
  160. void pascal video_update()
  161. {
  162.     if (videomethod == ANSI) {
  163.         printf("\033[%d;%dH",cy,cx);
  164.     }
  165.     else if (videomethod == FOSSIL)
  166.         VioSetCurPos (cy - 1, cx - 1, 0);
  167.     else {
  168.         union REGS r;
  169.  
  170.         r.h.ah = 2;
  171.         r.h.bh = 0;
  172.         r.h.dh = (char) (cy - 1);
  173.         r.h.dl = (char) (cx - 1);
  174.         int86(0x10, &r, &r);
  175.     }
  176. }
  177.  
  178. void pascal scrollup(int x1, int y1, int x2, int y2, int lines)
  179.  
  180. {
  181.     if (videomethod == ANSI) {
  182.         printf("\033[%d;%dH\033F",y1,x1);
  183.         printf("\033[%d;%dH\033G",y2,x2);
  184.         printf("\033[%dS",lines);
  185.         printf("\033[%d;%dH\033F",1,1);
  186.         printf("\033[%d;%dH\033G",maxy,maxx);
  187.         return;
  188.     }
  189.  
  190.     y2 = min(y2,maxy);
  191.     y1 = min(y1,maxy);
  192.     x1 = min(x1,maxx);
  193.     x2 = min(x2,maxx);
  194.  
  195.     if (videomethod == FOSSIL) {
  196.         scroll_fill [0] = ' ';
  197.         scroll_fill [1] = current_color;
  198.         if (lines == 0)
  199.             lines = -1;
  200.  
  201.         VioScrollUp (y1-1,x1-1,y2-1,x2-1,lines,(unsigned char *) scroll_fill,0);
  202.     }
  203.     else if (videomethod == BIOS) {
  204.         union REGS      r;
  205.  
  206.         r.h.ah = 6;
  207.         r.h.al = (char) lines;
  208.         r.h.ch = (char) (y1-1);
  209.         r.h.cl = (char) (x1-1);
  210.         r.h.dh = (char) (y2-1);
  211.         r.h.dl = (char) (x2-1);
  212.         r.h.bh = current_color;
  213.         int86(0x10, &r, &r);
  214.     }
  215.     else {
  216.         while (lines--) {
  217. #ifndef ASM
  218.             int *scrptr = MK_FP(vbase,((y1-1) * maxx + (x1-1)) << 1);
  219.             int ny = y1-1;
  220.             int l = ((x2 - x1) + 1);
  221.  
  222.             while (ny++ < y2) {
  223.                 memcpy(scrptr,scrptr + maxx,l<<1);
  224.                 scrptr += maxx;
  225.             }
  226.             while (l)
  227.                 *(scrptr + --l) = 0x20 | (current_color << 8);
  228. #else
  229.             if (y1 != y2)
  230.                 dscrollup(x1,y1,x2,y2);
  231.             else
  232.                 dclrwnd(min(x1,x2),min(y1,y2),max(x1,x2),max(y1,y2));
  233. #endif
  234.         }
  235.     }
  236. }
  237.  
  238. void pascal scrolldown(int x1, int y1, int x2, int y2, int lines)
  239.  
  240. {
  241.     if (videomethod == ANSI) {
  242.         printf("\033[%d;%dH\033F",y1,x1);
  243.         printf("\033[%d;%dH\033G",y2,x2);
  244.         printf("\033[%dT",lines);
  245.         printf("\033[%d;%dH\033F",1,1);
  246.         printf("\033[%d;%dH\033G",maxy,maxx);
  247.         return;
  248.     }
  249.  
  250.     y2 = min(y2,maxy);
  251.     y1 = min(y1,maxy);
  252.     x1 = min(x1,maxx);
  253.     x2 = min(x2,maxx);
  254.  
  255.     if (videomethod == FOSSIL) {
  256.         scroll_fill [0] = ' ';
  257.         scroll_fill [1] = current_color;
  258.         VioScrollDn (y1-1,x1-1,y2-1,x2-1,lines,(unsigned char *) scroll_fill,0);
  259.     }
  260.     else if (videomethod == BIOS) {
  261.         union REGS      r;
  262.  
  263.         r.h.ah = 7;
  264.         r.h.al = (char) lines;
  265.         r.h.ch = (char) (y1-1);
  266.         r.h.cl = (char) (x1-1);
  267.         r.h.dh = (char) (y2-1);
  268.         r.h.dl = (char) (x2-1);
  269.         r.h.bh = current_color;
  270.         int86(0x10, &r, &r);
  271.     }
  272.     else {
  273.         while (lines--) {
  274. #ifndef ASM
  275.             int ny = y2-1;
  276.             int l = ((x2 - x1) + 1);
  277.             int *scrptr = MK_FP(vbase,((y2-1) * maxx + (x1-1)) << 1);
  278.             while (ny-- >= y1) {
  279.                 memcpy(scrptr,scrptr - maxx,l<<1);
  280.                 scrptr -= maxx;
  281.             }
  282.             while (l)
  283.                 *(scrptr + --l) = 0x20 | (current_color << 8);
  284. #else
  285.             if (y1 != y2)
  286.                 dscrolldn(x1,y1,x2,y2);
  287.             else
  288.                 dclrwnd(min(x1,x2),min(y1,y2),max(x1,x2),max(y1,y2));
  289. #endif
  290.         }
  291.     }
  292. }
  293.  
  294. void pascal bputc(int c)
  295.  
  296. {
  297. #ifndef ASM
  298.     union REGS r;
  299. #endif
  300.  
  301.     unsigned int d = 0;
  302.  
  303.     if (videomethod == ANSI) {
  304.         printf("\033[%d;%dH\033[%d;%dm%c",cy,cx,
  305.             30+(current_color & 0x7),
  306.             40+(current_color>>4),c&0x7f);
  307.         return;
  308.     }
  309.  
  310. #ifndef ASM
  311.     if (videomethod == DIRECT) {
  312.         *(screen + ((((cy - 1) * maxx) + (cx - 1)))) = d;
  313. #else
  314.     if ((videomethod == DIRECT) || (videomethod == BIOS)) {
  315.         dputc(cx,cy,c);
  316. #endif
  317.     }
  318.     else if (videomethod == FOSSIL) {
  319.         d = ((unsigned) c & 0xff) | (current_color << 8);
  320.         VioWrtCellStr ((unsigned int *) &d, 2, cy - 1, cx - 1, 0);
  321.     }
  322. #ifndef ASM
  323.     else {
  324.         video_update();
  325.         r.h.ah = 0x9;
  326.         r.h.bh = 0;
  327.         r.h.al = (unsigned char) c;
  328.         r.h.bl = current_color;
  329.         r.x.cx = 1;
  330.         int86(0x10,&r,&r);
  331.     }
  332. #endif
  333.     if (++cx > (unsigned) maxx) {
  334.         cx = 1;
  335.         if (++cy > (unsigned) maxy)
  336.             cy = 1;
  337.     }
  338. }
  339.  
  340. void pascal gotoxy(int x, int y)
  341.  
  342. {
  343.     cx = min(x,maxx);
  344.     cy = min(y,maxy);
  345. }
  346.  
  347. int pascal wherex()
  348.  
  349. {
  350.     return (cx);
  351. }
  352.  
  353. int pascal wherey()
  354.  
  355. {
  356.     return(cy);
  357. }
  358.  
  359. unsigned int pascal keyhit()
  360.  
  361. {
  362.     union REGS r;
  363.  
  364.     if (macro)      /* always return no keypress during macros */
  365.         return(0);
  366.  
  367.     if (videomethod == FOSSIL) {
  368.         r.x.ax = 0x0d00;
  369.         int86(0x14,&r,&r);
  370.         if (r.x.ax == 0xffff)
  371.             return(0);
  372.     }
  373.     else {
  374.         r.h.ah = 1;
  375.         int86(0x16,&r,&r);
  376. #if defined(_MSC_VER)
  377.         if (r.x.cflag)
  378. #else
  379.         if (r.x.flags & 64)
  380. #endif
  381.             return(0);
  382.     }
  383.  
  384.     if (r.h.al)                     /* Must use FOSSIL keymap,   */
  385.         r.h.ah = 0;             /* No scan code if have char */
  386.  
  387.     return r.x.ax;
  388. }
  389.  
  390. unsigned int pascal getkey()
  391.  
  392. {
  393.     union REGS r;
  394.  
  395.     if ((macros[0] != (void *) NULL) && !autostart) {
  396.         autostart = 1;
  397.         macro = macros[0];
  398.     }
  399.  
  400.     if (macro != (void *) NULL) {
  401.         if (*(++macro))
  402.             return(*macro);
  403.  
  404.         macro = (void *) NULL;
  405.     }
  406.  
  407.     if (videomethod == FOSSIL) {
  408.         r.h.ah = 0x0e;
  409.         int86 (0x14,&r,&r);
  410.     }
  411.     else {
  412.         r.h.ah = 0;
  413.         int86(0x16,&r,&r);
  414.     }
  415.  
  416.     if (r.h.al) {                    /* Must use FOSSIL keymap,   */
  417.         r.h.ah = 0;             /* No scan code if have char */
  418.         return(r.x.ax);
  419.     }
  420.  
  421.     if ((r.h.ah >= 0x3b) && (r.h.ah <= 0x44))
  422.         macro = macros[r.h.ah - 0x3a];
  423.     else if ((r.h.ah >= 0x54) && (r.h.ah <= 0x71))
  424.         macro = macros[r.h.ah - 0x49];
  425.  
  426.     if (macro != (void *) NULL) {
  427.         if (*macro)
  428.             return(*macro);
  429.  
  430.         macro = (void *) NULL;
  431.     }
  432.  
  433.     return(r.x.ax);
  434. }
  435.  
  436. void pascal bputs(char *s)
  437.  
  438. {
  439. #ifndef ASM
  440.     unsigned int *linebase = screen + ((((cy - 1) * maxx) + (cx - 1)));
  441.     unsigned int d;
  442. #endif
  443.     char *t = s;
  444.     char ch = '\0';
  445.     unsigned int a = current_color;
  446.     unsigned int l = 0,l1 = 0;
  447.  
  448.     if (s == NULL)
  449.         return;
  450.  
  451.     if (videomethod == ANSI) {
  452.         printf("\033[%d;%dH\033[%d;%dm%0.79s",cy,cx,
  453.             30+(current_color & 0x7),
  454.             40+(current_color>>4),s);
  455.             return;
  456.     }
  457.  
  458.     if ((t = strchr(s,'\n')) != NULL) {
  459.         ch = *t;
  460.         *t = '\0';
  461.     }
  462.  
  463.     if ((strlen(s) + cx) > (size_t) maxx) {
  464.         if (t) *t = ch;
  465.         ch = *(t = s + maxx - cx + 1);
  466.         *t = '\0';
  467.     }
  468.  
  469. #ifdef ASM
  470.     if ((videomethod == DIRECT) || (videomethod == BIOS)) {
  471.         cx += dputs(cx,cy,s);
  472.         if (t) *t = ch;
  473.         return;
  474.     }
  475. #endif
  476.  
  477.     if (strlen(s)) {
  478.         l1 = l = (((strlen(s) + cx) < (size_t) maxx)?strlen(s):maxx - cx + 1);
  479.  
  480.         if (videomethod == FOSSIL)
  481.             VioWrtCharStrAtt((char *) s,l,cy - 1,cx - 1, (unsigned char *) &a,0);
  482. #ifndef ASM
  483.         else
  484.             if (videomethod == DIRECT) {
  485.                 d = current_color << 8;
  486.                 while (l--)
  487.                     *linebase++ = (unsigned int) (*s++ & 0xff) | d;
  488.             }
  489.             else
  490.                 while (l--)
  491.                     bputc(*s++);
  492. #endif
  493.     }
  494.  
  495.     if (t) *t = ch;
  496.     if (videomethod != BIOS)
  497.         cx += l1;
  498. }
  499.  
  500. void pascal cls()
  501.  
  502. {
  503.     if (videomethod == ANSI) {
  504.         fputs("\033[2J",stdout);
  505.         return;
  506.     }
  507.  
  508.     if (videomethod == DIRECT) {
  509.  
  510. #ifndef ASM
  511.         int ny = 0;
  512.         int *scrptr = MK_FP(vbase,0);
  513.         while (ny++ < maxy) {
  514.             int l = maxx;
  515.             while (l)
  516.                 *(scrptr + --l) = 0x20 | (current_color << 8);
  517.             scrptr += maxx;
  518.         }
  519. #else
  520.         dcls();
  521. #endif
  522.     }
  523.     else {
  524.         scrollup(1, 1, maxx, maxy, 0);
  525.         gotoxy(1, 1);
  526.     }
  527. }
  528.  
  529. void pascal clrwnd(int x1, int y1, int x2, int y2)
  530.  
  531. {
  532.     if (x1 > x2) return;
  533.     if (y1 > y2) return;
  534.  
  535.     if (videomethod == ANSI) {
  536.         printf("\033[%d;%dH\033F",y1,x1);
  537.         printf("\033[%d;%dH\033G",y2,x2);
  538.         printf("\033[O");
  539.         printf("\033[%d;%dH\033F",1,1);
  540.         printf("\033[%d;%dH\033G",maxy,maxx);
  541.         return;
  542.     }
  543.     if (videomethod == DIRECT) {
  544. #ifndef ASM
  545.         int ny = y1-1;
  546.         int *scrptr = MK_FP(vbase,((y1-1) * maxx + (x1-1)) * 2);
  547.  
  548.         while (ny++ <= (y2-1)) {
  549.             int l = (((x2-1) - (x1-1)) + 1);
  550.             while (l)
  551.                 *(scrptr + --l) = 0x20 | (current_color << 8);
  552.             scrptr += maxx;
  553.         }
  554. #else
  555.         dclrwnd(min(x1,x2),min(y1,y2),max(x1,x2),max(y1,y2));
  556. #endif
  557.     }
  558.     else {
  559.         scrollup(x1, y1, x2, y2, 0);
  560.         gotoxy(x1,y1);
  561.     }
  562. }
  563.  
  564. void pascal clreol()
  565. {
  566.     int x = cx;
  567.  
  568.     if (videomethod == ANSI) {
  569.         fputs("\033[K",stdout);
  570.     }
  571.     else if (videomethod == BIOS) {
  572.         union REGS r;
  573.  
  574.         video_update();
  575.         r.h.ah = 0x9;
  576.         r.h.bh = 0;
  577.         r.h.al = 0x20;
  578.         r.h.bl = current_color;
  579.         r.x.cx = (maxx - cx + 1);
  580.         int86(0x10,&r,&r);
  581.     }
  582.     else
  583.         clrwnd(x,cy,maxx,cy);
  584.     cx = x;
  585. }
  586.  
  587. int pascal bgets(char *s, int c, int w)
  588.  
  589. {
  590.     int x1,x2,y,ch,tx,m=1;
  591.     char *o,fmt[10],*p;
  592.     static ins = 1;
  593.     
  594.     w = min(c,w);
  595.     x1 = max(0,cx); y = min(maxy,max(0,cy)); x2 = min(cx + w,(unsigned) maxx);
  596.     o = strdup(s);
  597.     p = s;
  598.     sprintf(fmt,"%%-%d.%ds",w,w);
  599.     cx = x1 + strlen(s);
  600.     if (cx > (unsigned) x2) {
  601.         p = s + (cx - x2);
  602.         cx = x2;
  603.     }
  604.  
  605.     for (;;) {
  606.         if (m) {
  607.             tx = cx;
  608.             clrwnd(x1,y,x2,y);
  609.             cx = x1; bprintf(fmt,p); 
  610.             cx = tx; m = 0;
  611.         }
  612.  
  613.         video_update();
  614.         switch (ch = getkey()) {
  615.             case UP:
  616.             case DOWN:
  617.             case ENTER:
  618.                 free(o);
  619.                 return(ch);
  620.  
  621.             case GOBOL:
  622.                 cx = x1;
  623.                 p = s;
  624.                 m = 1;
  625.                 break;
  626.     
  627.  
  628.             case GOEOL:
  629.                 cx = x1 + strlen(p);
  630.                 if (cx > (unsigned) x2) {
  631.                     p += cx - x2;
  632.                     cx = x2 - 1;
  633.                 }
  634.                 m = 1;
  635.                 break;
  636.  
  637.             case ABORT:
  638.                 strcpy(s,o);
  639.                 free(o);
  640.                 return(ch);
  641.  
  642.             case INSERT:
  643.                 ins = !ins;
  644.                 break;
  645.  
  646.             case BKSPC:
  647.                 if (cx > (unsigned) x1) {
  648.                     cx--;
  649.                     strdel(p,cx - x1 + 1);            
  650.                     m = 1;
  651.                 }
  652.                 else if (p > s) {
  653.                     p--;
  654.                     strdel(p,1);
  655.                     m = 1;
  656.                 }
  657.                 break;
  658.  
  659.             case WORDLT:
  660.                 break;
  661.  
  662.             case WORDRT:
  663.                 break;
  664.  
  665.             case LEFT:
  666.                 if (cx > (unsigned) x1) cx--;
  667.                 else if (p > s) { p--; m = 1; }
  668.                 break;
  669.  
  670.             case RIGHT:
  671.                 if (cx < (unsigned) (x2-1)) {
  672.                     if ((cx-x1) < strlen(p)) cx++;
  673.                 }
  674.                 else if ((unsigned) w < strlen(p)) { p++; m = 1; }
  675.                 break;
  676.  
  677.             case DELCHR:
  678.                 strdel(p,cx - x1 + 1);
  679.                 m = 1;
  680.                 break;
  681.  
  682.             case CANCEL:
  683.                 p = s; m = 1; cx = x1;
  684.                 strset(s,0);
  685.                 break;
  686.  
  687.             default:
  688.                 if (!(ch & 0xff))
  689.                     break;
  690.  
  691.                 if (ins)
  692.                     if (strlen(s) >= (unsigned) c) break;
  693.                     else strins(p,(char) (ch & 0xff), (int) cx - x1 + 1);
  694.                 else
  695.                     *(p + cx - x1) = (char) (ch & 0xff);
  696.                 
  697.                 if (cx < (unsigned) x2)
  698.                     cx++;
  699.                 else if ((unsigned) w < strlen(p)) p++;
  700.  
  701.                 m = 1;
  702.  
  703.                 break;
  704.             }
  705.     }
  706. }
  707.  
  708. int pascal getnum(int l, int h, int value)
  709.  
  710. {
  711.     int     i, x;
  712.     char    s[TEXTLEN];
  713.  
  714.     i = value;
  715.     x = wherex();
  716.  
  717.     do {
  718.         memset(s, 0, sizeof(s));
  719.         itoa(i, s, 10);
  720.         gotoxy(x, wherey());
  721.         bgets(s, sizeof s << 1,min(maxx - x, sizeof s << 1));
  722.         i = atoi(s);
  723.  
  724.     } while ((i < l) || (i > h));
  725.  
  726.     return (i);
  727. }
  728.  
  729. void pascal set_color(unsigned int attr)
  730.  
  731. {
  732.     current_color = (unsigned char) attr;
  733. }
  734.  
  735. unsigned pascal get_color()
  736.  
  737. {
  738.     return(current_color);
  739. }
  740.  
  741. int cdecl bprintf(char *f,...)
  742.  
  743. {
  744.     va_list params;
  745.     int     i;
  746.  
  747.     va_start(params, f);
  748.     i = vsprintf(s, f, params);
  749.     bputs(s);
  750.     return (i);
  751. }
  752.  
  753. VFOSSIL v;
  754.  
  755. static void pascal vfossil_init ()
  756.  
  757. {
  758.     char *q;
  759.     union REGS r;
  760.     struct SREGS s;
  761.  
  762.     v.vfossil_size = sizeof (VFOSSIL);
  763.     q = (char *) &v;
  764.  
  765.     r.h.ah = 0x81;
  766.     r.h.al = 0;
  767.  
  768.     segread (&s);
  769.     s.es = FP_SEG (q);
  770.     r.x.di = FP_OFF (q);
  771.     int86x (0x14, &r, &r, &s);
  772.  
  773.     if (r.x.ax == 0x1954)
  774.     /* There is a VFOSSIL out there, so set it up for use */
  775.         vfossil_open ();
  776.     else {
  777.         fputs ("No Video FOSSIL installed, aborting....\n\n",stderr);
  778.         exit (255);
  779.     }
  780. }
  781.  
  782. CURSOR _cursor;
  783.  
  784. static void pascal vfossil_cursor (int st)
  785.  
  786. {
  787.     CURSOR *q;
  788.  
  789.     q = (CURSOR *) &_cursor;
  790.     /* We can make the cursor go away */
  791.     VioGetCurType (q, 0);
  792.     _cursor.cur_attr = st ? 0 : -1;
  793.     VioSetCurType (q, 0);
  794. }
  795.  
  796. static void pascal vfossil_open ()
  797.  
  798. {
  799.     char *q;
  800.     union REGS r;
  801.     struct SREGS s;
  802.  
  803.     segread (&s);
  804.     r.h.ah = 0x81;
  805.     r.h.al = 1;
  806.     r.x.cx = 80;
  807.     q = (char *) &vfossil_funcs;
  808.     r.x.di = FP_OFF (q);
  809.     s.es = FP_SEG (q);
  810.     int86x (0x14, &r, &r, &s);
  811.     if ((r.x.ax != 0x1954) || (r.x.bx < 14)) {
  812.         fputs ("Unable to initialize Video FOSSIL, aborting....\n\n",stderr);
  813.         exit (255);
  814.     }
  815. }
  816.  
  817. static void pascal vfossil_close ()
  818.  
  819. {
  820.    union REGS r;
  821.  
  822.    vfossil_cursor (1);
  823.  
  824.    r.h.ah = 0x81;
  825.    r.h.al = 2;
  826.  
  827.    int86 (0x14, &r, &r);
  828. }
  829.