home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / memacs32.zip / src / os2npm.c < prev    next >
C/C++ Source or Header  |  1994-03-17  |  22KB  |  826 lines

  1. /*
  2.  * OS2NONPM.C
  3.  *
  4.  * The routines in this file provide video and keyboard support using the
  5.  * OS/2 Vio and Kbd functions (not the presentation manager).
  6.  *
  7.  * The os2putc, os2eeol and os2eeop routines modify the logical video
  8.  * buffer.  Os2flush calls VioShowBuf to update the physical video buffer.
  9.  * An earlier version used VioWrtTTy with ANSI processing (easy to do, but
  10.  * sloooow).  A later version using VioWrtNCell was better, but not as
  11.  * good as manipulating the logical buffer.
  12.  */
  13.  
  14. #define INCL_BASE
  15. #define INCL_DOSDEVIOCTL
  16. #include    <os2.h>
  17.  
  18. #define    termdef    1            /* don't define "term" external */
  19.  
  20. #include    <stdio.h>
  21.  
  22. #undef    PASCAL
  23. #undef    NEAR
  24. #undef    HIBYTE
  25.  
  26. #include    "estruct.h"
  27. #include    "eproto.h"
  28. #include    "edef.h"
  29. #include    "elang.h"
  30.  
  31. #if     OS2NPM
  32. /*
  33.  * Os2def.h defines COLOR, but no MSC stuff needs it.
  34.  * We need COLOR as defined in estruct.h, so edit it out of os2def.h.
  35.  */
  36. #include    <conio.h>
  37.  
  38. #define    NROW    102        /* Screen size.                 */
  39. #define    NCOL    80        /* Edit if you want to.         */
  40. #define    MARGIN    8        /* size of minimim margin and    */
  41. #define    SCRSIZ    64        /* scroll size for extended lines */
  42. #define    NPAUSE    100        /* # times thru update to pause */
  43.  
  44. #define CDCGA    0        /* color graphics adapter    */
  45. #define CDMONO    1        /* monochrome display adapter    */
  46. #define CDEGA    2        /* EGA                */
  47. #define CDVGA    3        /* VGA                */
  48.  
  49. #define NDRIVE    4        /* number of video modes    */
  50.  
  51. int dtype = -1;                /* current video mode    */
  52. char drvname[][8] = {            /* names of video modes    */
  53.     "CGA", "MONO", "EGA", "VGA"
  54. };
  55.  
  56. /* Forward references.          */
  57.  
  58. int PASCAL NEAR os2move( int, int );
  59. int PASCAL NEAR os2eeol( void );
  60. int PASCAL NEAR os2eeop( void );
  61. int PASCAL NEAR os2beep( void );
  62. int PASCAL NEAR os2open( void );
  63. int PASCAL NEAR os2close( void );
  64. int PASCAL NEAR os2getc( void );
  65. int PASCAL NEAR os2putc( int );
  66. int PASCAL NEAR os2flush( void );
  67. int PASCAL NEAR os2rev( int );
  68. int PASCAL NEAR os2kclose( void );
  69. int PASCAL NEAR os2kopen( void );
  70. int PASCAL NEAR os2cres( char* );
  71. int PASCAL NEAR os2parm( void );
  72. #if    COLOR
  73. int PASCAL NEAR os2fcol( int );
  74. int PASCAL NEAR os2bcol( int );
  75. #endif
  76.  
  77. struct {         /* Current screen attribute for ORing    */
  78.     BYTE    filler;        /* with character to be displayed.    */
  79.     BYTE    attr;
  80. } os2cell = {0, 0x07};
  81.  
  82. struct {         /* Current reverse screen attribute for    */
  83.     BYTE    filler;        /* ORing with character to be displayed.*/
  84.     BYTE    attr;
  85. } os2rcell = {0, 0x07};
  86.  
  87. static struct {                        /* initial states     */
  88.     USHORT            ansiState;        /* ANSI translation        */
  89.     VIOCONFIGINFO    vioConfigInfo; /* video configuration        */
  90.     VIOMODEINFO     vioModeInfo;    /* video mode            */
  91.     KBDINFO            kbdInfo;         /* keyboard info        */
  92. } initial;
  93.  
  94. static int    cfcolor = -1;        /* current foreground color    */
  95. static int    cbcolor = -1;        /* current background color    */
  96. static int    ctrans[] =            /* ansi to ibm color translation table */
  97.     {0, 4, 2, 6, 1, 5, 3, 7,
  98.      8, 12, 10, 14, 9, 13, 11, 15};
  99.  
  100. static short     os2row;     /* current cursor row    */
  101. static short     os2col;     /* current cursor col    */
  102.  
  103. int revflag = FALSE;         /* are we currently in rev video? */
  104.  
  105. /*
  106.  * To minimize the amount of buffer that VioShowBuf has to update, we
  107.  * keep track of the lowest and highest bytes in the logical video
  108.  * buffer which have been modified.
  109.  */
  110. static USHORT    *lvb;         /* logical video buffer */
  111. static USHORT     lvbLen;     /* length of buffer    */
  112. static USHORT     lvbMin;     /* min index of modified byte */
  113. static USHORT     lvbMax;     /* max index of modified byte */
  114.  
  115. /*
  116.  * Standard terminal interface dispatch table.
  117.  */
  118. TERM      term     = {
  119.     NROW-1,
  120.     NROW-1,
  121.     NCOL,
  122.     NCOL,
  123.     0, 0,
  124.     MARGIN,
  125.     SCRSIZ,
  126.     NPAUSE,
  127.     os2open,
  128.     os2close,
  129.     os2kopen,
  130.     os2kclose,
  131.     os2getc,
  132.     os2putc,
  133.     os2flush,
  134.     os2move,
  135.     os2eeol,
  136.     os2eeop,
  137.     os2eeop,
  138.     os2beep,
  139.     os2rev,
  140.     os2cres
  141. #if    COLOR
  142.     , os2fcol,
  143.     os2bcol
  144. #endif
  145. };
  146.  
  147. static int mexist;    /* is the mouse driver installed? */
  148. #if    MOUSE
  149. /* Mousing global variable */
  150. static int nbuttons; /* number of buttons on the mouse */
  151. static int oldbut;    /* Previous state of mouse buttons */
  152. static int oldcol;    /* previous x position of mouse */
  153. static int oldrow;    /* previous y position of mouse */
  154. HMOU mouse_handle;    /* handle to opened mouse */
  155. #endif
  156.  
  157. /* input buffers and pointers */
  158.  
  159. #define    IBUFSIZE 64 /* this must be a power of 2 */
  160.  
  161. unsigned char in_buf[IBUFSIZE];    /* input character buffer */
  162. int in_next = 0;        /* pos to retrieve next input character */
  163. int in_last = 0;        /* pos to place most recent input character */
  164.  
  165. in_init()    /* initialize the input buffer */
  166.  
  167. {
  168.     in_next = in_last = 0;
  169. }
  170.  
  171. in_check()    /* is the input buffer non-empty? */
  172.  
  173. {
  174.     if (in_next == in_last)
  175.         return(FALSE);
  176.     else
  177.         return(TRUE);
  178. }
  179.  
  180. in_put(event)
  181.  
  182. int event;    /* event to enter into the input buffer */
  183.  
  184. {
  185.     in_buf[in_last++] = event;
  186.     in_last &= (IBUFSIZE - 1);
  187. }
  188.  
  189. int in_get()    /* get an event from the input buffer */
  190.  
  191. {
  192.     register int event;    /* event to return */
  193.  
  194.     event = in_buf[in_next++];
  195.     in_next &= (IBUFSIZE - 1);
  196.     return(event);
  197. }
  198.  
  199. #if    COLOR
  200. /*----------------------------------------------------------------------*/
  201. /* os2fcol()                            */
  202. /* Set the current foreground color.                    */
  203. /*----------------------------------------------------------------------*/
  204.  
  205. int PASCAL NEAR os2fcol( int color)            /* color to set */
  206. {
  207.     if (dtype != CDMONO)
  208.         cfcolor = ctrans[color];
  209.     else
  210.         cfcolor = 7;
  211.  
  212.     /* set the normal attribute */
  213.     os2cell.attr &= 0xF0;
  214.     os2cell.attr |= cfcolor;
  215.  
  216.     /* set the reverse attribute */
  217.     os2rcell.attr &= 0x07;
  218.     os2rcell.attr |= cfcolor << 4;   
  219. }
  220.  
  221. /*----------------------------------------------------------------------*/
  222. /* os2bcol()                            */
  223. /* Set the current background color.                    */
  224. /*----------------------------------------------------------------------*/
  225.  
  226. int PASCAL NEAR os2bcol( int color)        /* color to set */
  227. {
  228.     if (dtype != CDMONO)
  229.         cbcolor = ctrans[color];
  230.     else
  231.         cbcolor = 0;
  232.  
  233.     /* set normal background attribute */
  234.     os2cell.attr &= 0x0F;
  235.     os2cell.attr |= cbcolor << 4;
  236.  
  237.     /* set reverse background attribute */
  238.     os2rcell.attr &= 0x70;
  239.     os2rcell.attr |= cbcolor;
  240. }
  241. #endif
  242.  
  243.  
  244. /*----------------------------------------------------------------------*/
  245. /* os2move()                            */
  246. /* Move the cursor.                            */
  247. /*----------------------------------------------------------------------*/
  248.  
  249. int PASCAL NEAR os2move( int row, int col)
  250. {
  251.     os2row = row;
  252.     os2col = col;
  253.     VioSetCurPos(os2row, os2col, 0);
  254. }
  255.  
  256.  
  257. /*----------------------------------------------------------------------*/
  258. /* os2flush()                            */
  259. /* Update the physical video buffer from the logical video buffer.    */
  260. /*----------------------------------------------------------------------*/
  261.  
  262. int PASCAL NEAR os2flush()
  263. {
  264.     if (lvbMin <= lvbMax) {     /* did anything change? */
  265.         VioShowBuf(lvbMin * 2, (lvbMax - lvbMin + 1) * 2, 0);
  266.         VioSetCurPos(os2row, os2col, 0);
  267.     }
  268.     lvbMin = lvbLen;
  269.     lvbMax = 0;
  270. }
  271.  
  272.  
  273. /*----------------------------------------------------------------------*/
  274. /* os2char()                            */
  275. /* Get a character from the keyboard.                    */
  276. /* Function keys, editing keys and alt- keys queue extra bytes into        */
  277. /* input queue.
  278. /*----------------------------------------------------------------------*/
  279.  
  280. int PASCAL NEAR os2char()
  281. {
  282.     register c;     /* extended key code for special keys */
  283.     KBDKEYINFO keyInfo;
  284.  
  285.     KbdCharIn(&keyInfo, IO_WAIT, 0); /* get a character    */
  286.  
  287.     /* Function, edit or alt- key?    */
  288.     if (keyInfo.chChar == 0  ||  keyInfo.chChar == 0xE0) {
  289.         c = extcode(keyInfo.chScan); /* hold on to scan code */
  290.         in_put(c >> 8);        /* queue up prefix byte */
  291.         in_put(c & 0xFF); /* queue up event byte */
  292.         return(0);
  293.     }
  294.     return(keyInfo.chChar & 255);
  295. }
  296.  
  297. /*
  298.  * Read a character from the terminal, performing no editing and doing no echo
  299.  * at all. Also mouse events are forced into the input stream here.
  300.  */
  301. int PASCAL NEAR os2getc()
  302. {
  303.     register int c;        /* character read */
  304. #if    MOUSE
  305.     NOPTRRECT mouse_rect;
  306. #endif
  307.  
  308.     os2flush();
  309.  
  310. ttc:    /* return any keystrokes waiting in the
  311.         type ahead buffer */
  312.     if (in_check())
  313.         return(in_get());
  314.  
  315. #if    TYPEAH
  316.     if (typahead())
  317.         return(os2char());
  318.  
  319.     /* with no mouse, this is a simple get char routine */
  320.     if (mexist == FALSE || mouseflag == FALSE)
  321.         return(os2char());
  322.  
  323. #if    MOUSE
  324.     /* turn the mouse cursor on */
  325.     MouDrawPtr(mouse_handle);
  326.  
  327.     /* loop waiting for something to happen */
  328.     while (TRUE) {
  329.         if (typahead())
  330.             break;
  331.         if (checkmouse())
  332.             break;
  333.         DosSleep(10L); /* let others have some CPU! */
  334.     }
  335.  
  336.     /* turn the mouse cursor back off */
  337.     mouse_rect.row = 0;
  338.     mouse_rect.col = 0;
  339.     mouse_rect.cRow = 24;
  340.     mouse_rect.cCol = 79;
  341.     MouRemovePtr(&mouse_rect, mouse_handle);
  342.  
  343.     goto ttc;
  344. #endif    /* MOUSE */
  345. #else /* TYPEAH */
  346.     return(os2char());
  347. #endif    /* TYPEAH */
  348. }
  349.  
  350. #if    MOUSE
  351. checkmouse()
  352.  
  353. {
  354.     register int k;        /* current bit/button of mouse */
  355.     register int etype;    /* event type byte */
  356.     register int event;    /* encoded mouse event */
  357.     int mousecol;        /* current mouse column */
  358.     int mouserow;        /* current mouse row */
  359.     int sstate;     /* current shift key status */
  360.     int newbut;     /* new state of the mouse buttons */
  361.     MOUEVENTINFO mouse_event;    /* info about a mouse event */
  362.     MOUQUEINFO mouse_queue; /* holds info about the mouse queue */
  363.     USHORT wait_flag; /* wait flag for read mouse queue call */
  364.     KBDINFO kbd_info; /* keyboard information */
  365.  
  366.     /* is there a mouse event queued up? */
  367.     MouGetNumQueEl(&mouse_queue, mouse_handle);
  368.     if (mouse_queue.cEvents == 0)
  369.         return(FALSE); 
  370.  
  371.     /* get the current mouse event */
  372.     wait_flag = MOU_WAIT;
  373.     MouReadEventQue(&mouse_event, &wait_flag, mouse_handle);
  374.  
  375.     /* build a simple bit field out of OS/2's rather complex one */
  376.     newbut = 0;
  377.     if (mouse_event.fs & MOUSE_BN1_DOWN)
  378.         newbut |= 1;
  379.     if (mouse_event.fs & MOUSE_MOTION_WITH_BN1_DOWN)
  380.         newbut |= 1;
  381.     if (mouse_event.fs & MOUSE_BN2_DOWN)
  382.         newbut |= 2;
  383.     if (mouse_event.fs & MOUSE_MOTION_WITH_BN2_DOWN)
  384.         newbut |= 2;
  385.     if (mouse_event.fs & MOUSE_BN3_DOWN)
  386.         newbut |= 4;
  387.     if (mouse_event.fs & MOUSE_MOTION_WITH_BN3_DOWN)
  388.         newbut |= 4;
  389.  
  390.     /* check to see if any mouse buttons are different */
  391.     mousecol = mouse_event.col;
  392.     mouserow = mouse_event.row;
  393.  
  394.     /* only notice changes */
  395.     if ((oldbut == newbut) && (mousecol == oldcol)
  396.          && (mouserow == oldrow))
  397.         return(FALSE);
  398.  
  399.     /* get the shift key status as well */
  400.     KbdGetStatus(&kbd_info, 0);
  401.     etype = MOUS >> 8;
  402.     sstate = kbd_info.fsState;
  403.     if (sstate & (RIGHTSHIFT | LEFTSHIFT)) /* shifted */
  404.         etype |= (SHFT >> 8);
  405.     else if (sstate & CONTROL) /* controled? */
  406.         etype |= (CTRL >> 8);
  407.  
  408.     /* no buttons changes */
  409.     if (oldbut == newbut) {
  410.  
  411.         /* generate a mouse movement */
  412.         if (((mouse_move == 1) && (mmove_flag == TRUE)) ||
  413.              (mouse_move == 2)) {
  414.             in_put(0);
  415.             in_put(etype);
  416.             in_put(mousecol);
  417.             in_put(mouserow);
  418.             in_put('m');
  419.         }
  420.         oldcol = mousecol;
  421.         oldrow = mouserow;
  422.         return(TRUE);
  423.     }
  424.  
  425.     /* only on screen presses are legit! */
  426.     if (mousecol < 0)
  427.         mousecol = 0;
  428.     if (mouserow < 0)
  429.         mouserow = 0;
  430.  
  431.     for (k = 1; k != (1 << nbuttons); k = k << 1) {
  432.  
  433.         /* For each button on the mouse */
  434.         if ((oldbut&k) != (newbut&k)) {
  435.             /* This button changed, generate an event */
  436.             in_put(0);
  437.             in_put(etype);
  438.             in_put(mousecol);
  439.             in_put(mouserow);
  440.  
  441.             event = ((newbut&k) ? 0 : 1); /* up or down? */
  442.             if (k == 2)         /* center button? */
  443.                 event += 4;
  444.             if (k == 4)         /* right button? */
  445.                 event += 2;
  446.             event += 'a';        /* plain */
  447.             in_put(event);
  448.             oldbut = newbut;
  449.             oldcol = mousecol;
  450.             oldrow = mouserow;
  451.             return(TRUE);
  452.         }
  453.     }
  454.     return(TRUE);
  455. }
  456. #endif
  457.  
  458. #if    TYPEAH
  459. /*----------------------------------------------------------------------*/
  460. /* typahead()                            */
  461. /* Returns true if a key has been pressed.                */
  462. /*----------------------------------------------------------------------*/
  463.  
  464. int PASCAL NEAR typahead()
  465. {
  466.     KBDKEYINFO kbdinfo;
  467.  
  468.     KbdPeek(&kbdinfo, 0);
  469.     return(kbdinfo.fbStatus != 0);
  470. }
  471. #endif
  472.  
  473.  
  474. /*----------------------------------------------------------------------*/
  475. /* os2putc()                            */
  476. /* Put a character at the current position in the current colors. */
  477. /* Note that this does not behave the same as putc() or VioWrtTTy(). */
  478. /* This routine does nothing with returns and linefeeds.  For backspace */
  479. /* it puts a space in the previous column and moves the cursor to the    */
  480. /* previous column.    For all other characters, it will display the    */
  481. /* graphic representation of the character and put the cursor in the */
  482. /* next column (even if that is off the screen.  In practice this isn't */
  483. /* a problem.                                */
  484. /*----------------------------------------------------------------------*/
  485.  
  486. int PASCAL NEAR os2putc(int c)
  487. {
  488.     USHORT    cell;
  489.     USHORT    i;
  490.  
  491.     if (c == '\n' || c == '\r') {     /* returns and linefeeds */
  492.         return;
  493.     }
  494.     if (c == '\b') {            /* backspace        */
  495.         cell = ' ' | (revflag ? *(USHORT *)&os2rcell : *(USHORT *)&os2cell);
  496.         --os2col;            /* move cursor back    */
  497.         i = os2row * term.t_ncol + os2col;
  498.     }
  499.     else {
  500.         cell = (0x00ff & c) | (revflag ? *(USHORT *)&os2rcell : *(USHORT *)&os2cell);
  501.         i = os2row * term.t_ncol + os2col;
  502.         ++os2col;            /* move cursor forward    */
  503.     }
  504.     lvb[i] = cell;
  505.     if (i < lvbMin)
  506.         lvbMin = i;
  507.     if (i > lvbMax)
  508.         lvbMax = i;
  509. }
  510.  
  511.  
  512. /*----------------------------------------------------------------------*/
  513. /* os2eeol()                            */
  514. /* Erase to end of line.                        */
  515. /*----------------------------------------------------------------------*/
  516.  
  517. int PASCAL NEAR os2eeol()
  518. {
  519.     USHORT    cell = ' ';
  520.     USHORT  i;
  521.  
  522.     cell |= (revflag ? *(USHORT *)&os2rcell : *(USHORT *)&os2cell);
  523.    
  524.     i = os2row * term.t_ncol + os2col;    /* current cursor position */
  525.     if (i < lvbMin)
  526.         lvbMin = i;
  527.     while (i < os2row * term.t_ncol + term.t_ncol)
  528.         lvb[ i++] = cell;
  529.     if (--i > lvbMax)
  530.         lvbMax = i;
  531. }
  532.  
  533.  
  534. /*----------------------------------------------------------------------*/
  535. /* os2eeop()                            */
  536. /* Erase to end of page.                        */
  537. /*----------------------------------------------------------------------*/
  538.  
  539. int PASCAL NEAR os2eeop()
  540. {
  541.     USHORT    cell = ' ';
  542.     USHORT  i;
  543.  
  544. #if COLOR
  545.     if (dtype != CDMONO)
  546.         cell |= (ctrans[gbcolor] << 4 | ctrans[gfcolor]) << 8;
  547.     else
  548.         cell |= 0x0700;
  549. #else
  550.     cell |= 0x0700;
  551. #endif
  552.  
  553.     i = os2row * term.t_ncol + os2col;    /* current cursor position */
  554.     if (i < lvbMin)
  555.         lvbMin = i;
  556.     while (i < term.t_nrow * term.t_ncol + term.t_ncol)
  557.         lvb[ i++] = cell;
  558.     if (--i > lvbMax)
  559.         lvbMax = i;
  560. }
  561.  
  562. /*----------------------------------------------------------------------*/
  563. /* os2rev()                         */
  564. /* Change reverse video state.                    */
  565. /*----------------------------------------------------------------------*/
  566.  
  567. int PASCAL NEAR os2rev( int state) /* state: TRUE = reverse, FALSE = normal */
  568. {
  569.     revflag = state;
  570. }
  571.  
  572. /*----------------------------------------------------------------------*/
  573. /* os2cres()                            */
  574. /* Change the screen resolution.                 */
  575. /*----------------------------------------------------------------------*/
  576.  
  577. int PASCAL NEAR os2cres(char *res)     /* name of desired video mode */
  578. {
  579.     USHORT    err;
  580.     int    type;         /* video mode type    */
  581.     VIOMODEINFO vioModeInfo;
  582.  
  583.     vioModeInfo = initial.vioModeInfo;
  584.    
  585.     /* From the name, find the type of video mode.    */
  586.     for (type = 0; type < NDRIVE; type++) {
  587.         if (strcmp(res, drvname[type]) == 0)
  588.             break;
  589.     }
  590.     if (type == NDRIVE)
  591.         return(FALSE); /* not a mode we know about    */
  592.  
  593.        
  594.     switch (type) {
  595.         case CDMONO:
  596.         case CDCGA:
  597.             vioModeInfo.row = 25;
  598.             break;
  599.         case CDEGA:
  600.             vioModeInfo.row = 43;
  601.             break;
  602.         case CDVGA:
  603.             vioModeInfo.row = 50;
  604.             break;
  605.     }
  606.    
  607.     if (VioSetMode(&vioModeInfo, 0)) /* change modes    */
  608.         return(FALSE);         /* couldn't do it */
  609.  
  610.     newsize(TRUE, vioModeInfo.row);
  611.  
  612.     /* reset the $sres environment variable */
  613.     strcpy(sres, drvname[type]);
  614.     dtype = type;                /* set the current mode */
  615.    
  616.     return TRUE;
  617. }
  618.  
  619.  
  620. /*----------------------------------------------------------------------*/
  621. /* spal()                                */
  622. /* Change pallette settings.    (Does nothing.)                */
  623. /*----------------------------------------------------------------------*/
  624.  
  625. PASCAL NEAR spal(char *dummy)
  626. {
  627. }
  628.  
  629.  
  630. /*----------------------------------------------------------------------*/
  631. /* os2beep()                            */
  632. /*----------------------------------------------------------------------*/
  633.  
  634. int PASCAL NEAR os2beep()
  635. {
  636.     DosBeep(1200, 175);
  637. }
  638.  
  639.  
  640. /*----------------------------------------------------------------------*/
  641. /* os2open()                            */
  642. /* Find out what kind of video adapter we have and the current video */
  643. /* mode.  Even if the adapter supports a higher resolution mode than is */
  644. /* in use, we still use the current mode.             */
  645. /*----------------------------------------------------------------------*/
  646.  
  647. int PASCAL NEAR os2open()
  648. {
  649. #if    MOUSE
  650.     PTRLOC mouse_pos; /* position to place mouse */
  651.     USHORT event_mask;        /* event mask for mouse handling */
  652. #endif
  653.     USHORT rc;
  654.  
  655.     initial.vioConfigInfo.cb = 0x0A;
  656.     VioGetConfig(0, &initial.vioConfigInfo, 0);
  657.     switch (initial.vioConfigInfo.adapter) {
  658.         case DISPLAY_VGA:
  659.             dtype = CDVGA;
  660.             break;
  661.         case DISPLAY_EGA:
  662.             dtype = CDEGA;
  663.             break;
  664.         case DISPLAY_CGA:
  665.         case 8:    /* some new mode in OS/2 2.0 */
  666.             dtype = CDCGA;
  667.             break;
  668.         case DISPLAY_MONOCHROME:
  669.         default:
  670.             dtype = CDMONO;
  671.     }
  672.     strcpy(sres, drvname[dtype]);
  673.  
  674.     initial.vioModeInfo.cb = 0x0E;
  675.     rc = 
  676.     VioGetMode(&initial.vioModeInfo, 0);
  677.     if ( rc != 0) { perror("VioGetMode"); exit(1); }
  678.     newsize(TRUE, initial.vioModeInfo.row);
  679.            
  680.     rc = 
  681.     VioGetAnsi(&initial.ansiState, 0);
  682.     if ( rc != 0) { perror("VioGetAnsi"); exit(1); }
  683.     rc = 
  684.     VioGetBuf((PULONG)&lvb, &lvbLen, 0);
  685.     if ( rc != 0) { perror("VioGetBuf"); exit(1); }
  686. #if OS2 == 2
  687. #ifndef __EMX__
  688. #warning The last function returned a 16:16 ptr 
  689. #warning which has to be converted to a 32 bit 
  690. #warning flat pointer. If your compiler does not 
  691. #warning do this automaticly you have to insert 
  692. #warning some code here. Otherwise the programm 
  693. #warning will not run (starting produces an 
  694. #warning error).
  695. #else
  696.     /* Convert the return 16 bit far pointer to 32 bit flat pointer */
  697.     lvb = (USHORT*)_emx_16to32( (_far16ptr)lvb );
  698. #endif /* __EMX__ */ 
  699. #endif /* OS2 == 2 */
  700.     lvbMin = lvbLen;
  701.     lvbMax = 0;
  702.  
  703.     revexist = TRUE;
  704.     revflag = FALSE;
  705.  
  706.     /* initialize our character input queue */
  707.     in_init();
  708.     strcpy(os, "OS2");
  709.  
  710. #if    MOUSE
  711.     /* find out if we have a mouse */
  712.     if (MouOpen((PSZ)0, &mouse_handle) != 0) {
  713.         mexist = FALSE;
  714.         return;
  715.     }
  716.  
  717.     /* find out some info about the mouse */
  718.     mexist = TRUE;
  719.     MouGetNumButtons(&nbuttons, mouse_handle);
  720.  
  721.     /* tell it what events were interested in */
  722. /* event_mask = MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN;*/
  723.     event_mask = 0xff;
  724.     MouSetEventMask(&event_mask, mouse_handle);
  725.  
  726.     /* get the mouse in the upper right corner */
  727.     oldrow = mouse_pos.row = 0;    /* top row of display */
  728.     oldcol = mouse_pos.col = (term.t_ncol - 1); /* last col of display */
  729.     MouSetPtrPos(&mouse_pos, mouse_handle);
  730. #else
  731.     mexist = FALSE;
  732. #endif
  733. }
  734.  
  735. /*----------------------------------------------------------------------*/
  736. /* os2close()                            */
  737. /* Restore the original video settings.                    */
  738. /*----------------------------------------------------------------------*/
  739.  
  740. int PASCAL NEAR os2close()
  741. {
  742. #if    MOUSE
  743.     /* close our use of the mouse */
  744.     if (mexist)
  745.         MouClose(mouse_handle);
  746. #endif
  747.  
  748.     VioSetAnsi(initial.ansiState, 0);
  749.     VioSetMode(&initial.vioModeInfo, 0);
  750.     VioSetCurPos(initial.vioModeInfo.row - 1,
  751.              initial.vioModeInfo.col - 1, 0);
  752. }
  753.  
  754. /*----------------------------------------------------------------------*/
  755. /* os2kopen()                            */
  756. /* Open the keyboard.                            */
  757. /*----------------------------------------------------------------------*/
  758.  
  759. int PASCAL NEAR os2kopen()
  760. {
  761.     KBDINFO    kbdInfo;
  762.  
  763.     initial.kbdInfo.cb = 0x000A;
  764.     KbdGetStatus(&initial.kbdInfo, 0);  
  765.     kbdInfo = initial.kbdInfo;
  766.     kbdInfo.fsMask &= ~0x0001;     /* not echo on     */
  767.     kbdInfo.fsMask |= 0x0002;        /* echo off     */
  768.     kbdInfo.fsMask &= ~0x0008;     /* cooked mode off    */
  769.     kbdInfo.fsMask |= 0x0004;        /* raw mode     */
  770.     kbdInfo.fsMask &= ~0x0100;     /* shift report    off    */
  771.     KbdSetStatus(&kbdInfo, 0);
  772. }
  773.  
  774.  
  775. /*----------------------------------------------------------------------*/
  776. /* os2kclose()                         */
  777. /* Close the keyboard.                            */
  778. /*----------------------------------------------------------------------*/
  779.  
  780. int PASCAL NEAR os2kclose()
  781. {
  782.     KbdSetStatus(&initial.kbdInfo, 0); /* restore original state    */
  783. }
  784.  
  785. #if    FLABEL
  786. PASCAL NEAR fnclabel(f, n)    /* label a function key */
  787.  
  788. int f,n;    /* default flag, numeric argument [unused] */
  789.  
  790. {
  791.     /* on machines with no function keys...don't bother */
  792.     return(TRUE);
  793. }
  794. #endif
  795.  
  796. #if 0
  797. /*----------------------------------------------------------------------*/
  798. /*    scwrite()                            */
  799. /* Write a line to the screen.
  800. /* I tried using this routine with MEMMAP = 1, but there were too many    */
  801. /* problems with the cursor and flushing the buffer.            */
  802. /*----------------------------------------------------------------------*/
  803.  
  804. scwrite(
  805.     int     row,    /* row of screen to place outstr on */
  806.     char    *outstr,/* string to write out (must be term.t_ncol long) */
  807.     int     forg,    /* foreground color of string to write */
  808.     int     bacg,    /* background color */
  809. {
  810.     USHORT     attr;
  811.     int     i;
  812.  
  813.     attr = (((ctrans[bacg] & 15) << 4) | (forg & 15)) << 8;
  814.  
  815.     for (i = row * term.t_ncol;  i < (row + 1) * term.t_ncol;  i++)
  816.         lvb[i] = attr | *(outstr++);
  817.  
  818.     if (i < lvbMin)
  819.         lvbMin = i;
  820.     if (i > lvbMax)
  821.         lvbMax = i;
  822. }
  823. #endif
  824. #endif
  825.  
  826.