home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / UE311C.ZIP / IBMPC.C < prev    next >
C/C++ Source or Header  |  1991-10-22  |  18KB  |  750 lines

  1. /*
  2.  * The routines in this file provide support for the IBM-PC and other
  3.  * compatible terminals. It goes directly to the graphics RAM to do
  4.  * screen output. It compiles into nothing if not an IBM-PC driver
  5.  * Supported monitor cards include CGA, MONO and EGA.
  6.  */
  7.  
  8. #define    termdef    1            /* don't define "term" external */
  9.  
  10. #include        <stdio.h>
  11. #include    "estruct.h"
  12. #include    "eproto.h"
  13. #include        "edef.h"
  14. #include    "elang.h"
  15.  
  16. #if     IBMPC
  17. #define NROW    50            /* Max Screen size.        */
  18. #define NCOL    80                      /* Edit if you want to.         */
  19. #define    MARGIN    8            /* size of minimim margin and    */
  20. #define    SCRSIZ    64            /* scroll size for extended lines */
  21. #define    NPAUSE    200            /* # times thru update to pause */
  22. #define BEL     0x07                    /* BEL character.               */
  23. #define ESC     0x1B                    /* ESC character.               */
  24. #define    SPACE    32            /* space character        */
  25.  
  26. #define    SCADC    0xb8000000L        /* CGA address of screen RAM    */
  27. #define    SCADM    0xb0000000L        /* MONO address of screen RAM    */
  28. #define SCADE    0xb8000000L        /* EGA/VGA address of screen RAM*/
  29.  
  30. #define MONOCRSR 0x0B0D            /* monochrome cursor        */
  31. #define CGACRSR 0x0607            /* CGA cursor            */
  32. #define EGACRSR 0x0709            /* EGA/VGA cursor        */
  33.  
  34. #define    CDCGA    0            /* color graphics card        */
  35. #define    CDMONO    1            /* monochrome text card        */
  36. #define    CDEGA    2            /* EGA color adapter        */
  37. #define    CDVGA    3            /* VGA color adapter        */
  38. #define    CDVGA12    4            /* VGA 12 line mode        */
  39. #define    CDCGA40    5            /* CGA 40 wide mode        */
  40. #define    CDSENSE    9            /* detect the card type        */
  41.  
  42. #define NDRIVE    6            /* number of screen drivers    */
  43.  
  44. typedef struct sdrive {
  45.     char drv_name[8];        /* screen driver name    */
  46.     long drv_scradd;        /* address of segment of screen ram */
  47.     int drv_rows;            /* # of rows for screen driver */
  48.     int drv_cols;            /* # of columns for screen driver */
  49. } SDRIVE;
  50.  
  51. SDRIVE scr_drive[] = {
  52.     "CGA",   SCADC, 25, 80,        /* standard color card        */
  53.     "MONO",  SCADM, 25, 80,        /* momochrome graphics adapter    */
  54.     "EGA",   SCADE, 43, 80,        /* Enhanced graphics adapter    */
  55.     "VGA",   SCADE, 50, 80,        /* Very Enhanced graphics adapter*/
  56.     "VGA12", SCADE, 12, 80,        /* 12 lines x 80 cols        */
  57.     "CGA40", SCADC, 25, 40,        /* low resolution CGA        */
  58. };
  59.  
  60. int dtype = -1;                /* current display type        */
  61.  
  62. long scadd;                /* address of screen ram    */
  63. int *scptr[NROW];            /* pointer to screen lines    */
  64. unsigned int sline[NCOL];        /* screen line image        */
  65. int num_cols;                /* current number of columns    */
  66. int orig_mode;                /* screen mode on entry        */
  67. int egaexist = FALSE;            /* is an EGA card available?    */
  68. int vgaexist = FALSE;            /* is video graphics array available? */
  69. extern union REGS rg;            /* cpu register for use of DOS calls */
  70. int revflag = FALSE;            /* are we currently in rev video? */
  71. int desk_rows;                /* number of rows on current desktop */
  72. int desk_cols;                /* number of cols on current desktop */
  73.  
  74.  
  75. PASCAL NEAR ibmmove();
  76. PASCAL NEAR ibmeeol();
  77. PASCAL NEAR ibmputc();
  78. PASCAL NEAR ibmeeop();
  79. PASCAL NEAR ibmclrdesk();
  80. PASCAL NEAR ibmrev();
  81. PASCAL NEAR ibmcres();
  82. PASCAL NEAR spal();
  83. PASCAL NEAR ibmbeep();
  84. PASCAL NEAR ibmopen();
  85. PASCAL NEAR ibmclose();
  86. PASCAL NEAR ibmkopen();
  87. PASCAL NEAR ibmkclose();
  88. PASCAL NEAR scinit();
  89. PASCAL NEAR screen_init();
  90. int PASCAL NEAR getboard();
  91. PASCAL NEAR egaopen();
  92. PASCAL NEAR egaclose();
  93. PASCAL NEAR cga40_open();
  94. PASCAL NEAR cga40_close();
  95. PASCAL NEAR change_width();
  96. PASCAL NEAR fnclabel();
  97.  
  98. #if    COLOR
  99. PASCAL NEAR ibmfcol();
  100. PASCAL NEAR ibmbcol();
  101. int    cfcolor = -1;        /* current forground color */
  102. int    cbcolor = -1;        /* current background color */
  103. int    ctrans[] =        /* ansi to ibm color translation table */
  104.     {0, 4, 2, 6, 1, 5, 3, 7,
  105.      8, 12, 10, 14, 9, 13, 11, 15};
  106. #endif
  107.  
  108. /*
  109.  * Standard terminal interface dispatch table. Most of the fields point into
  110.  * "termio" code.
  111.  */
  112. TERM    term    = {
  113.     NROW-1,
  114.         NROW-1,
  115.         NCOL,
  116.         NCOL,
  117.     0, 0,
  118.     MARGIN,
  119.     SCRSIZ,
  120.     NPAUSE,
  121.         ibmopen,
  122.         ibmclose,
  123.     ibmkopen,
  124.     ibmkclose,
  125.         ttgetc,
  126.     ibmputc,
  127.         ttflush,
  128.         ibmmove,
  129.         ibmeeol,
  130.         ibmeeop,
  131.         ibmclrdesk,
  132.         ibmbeep,
  133.     ibmrev,
  134.     ibmcres
  135. #if    COLOR
  136.     , ibmfcol,
  137.     ibmbcol
  138. #endif
  139. };
  140.  
  141. #if    COLOR
  142. PASCAL NEAR ibmfcol(color)    /* set the current output color */
  143.  
  144. int color;    /* color to set */
  145.  
  146. {
  147.     cfcolor = ctrans[color];
  148. }
  149.  
  150. PASCAL NEAR ibmbcol(color)    /* set the current background color */
  151.  
  152. int color;    /* color to set */
  153.  
  154. {
  155.         cbcolor = ctrans[color];
  156. }
  157. #endif
  158.  
  159. PASCAL NEAR ibmmove(row, col)
  160. {
  161.     rg.h.ah = 2;        /* set cursor position function code */
  162.     rg.h.dl = col + term.t_colorg;
  163.     rg.h.dh = row + term.t_roworg;
  164.     rg.h.bh = 0;        /* set screen page number */
  165.     int86(0x10, &rg, &rg);
  166. }
  167.  
  168. PASCAL NEAR ibmeeol()    /* erase to the end of the line */
  169.  
  170. {
  171.     unsigned int attr;    /* attribute byte mask to place in RAM */
  172.     unsigned int *lnptr;    /* pointer to the destination line */
  173.     int i;
  174.     int ccol;    /* current column cursor lives */
  175.     int crow;    /*       row    */
  176.  
  177.     /* find the current cursor position */
  178.     rg.h.ah = 3;        /* read cursor position function code */
  179.     rg.h.bh = 0;        /* current video page */
  180.     int86(0x10, &rg, &rg);
  181.     ccol = rg.h.dl - term.t_colorg;    /* record current column */
  182.     crow = rg.h.dh - term.t_roworg;    /* and row */
  183.  
  184.     /* build the attribute byte and setup the screen pointer */
  185. #if    COLOR
  186.     if (dtype != CDMONO)
  187.         if (revflag)
  188.             attr = (((cfcolor & 15) << 4) | (cbcolor & 15)) << 8;
  189.         else
  190.             attr = (((cbcolor & 15) << 4) | (cfcolor & 15)) << 8;
  191.     else
  192.         if (revflag)
  193.             attr = 0x7000;
  194.         else
  195.             attr = 0x0700;
  196. #else
  197.     attr = 0x0700;
  198. #endif
  199.     lnptr = &sline[0];
  200.     for (i=0; i < term.t_ncol; i++)
  201.         *lnptr++ = SPACE | attr;
  202.  
  203.     if (flickcode && (dtype == CDCGA || dtype == CDCGA40)) {
  204.         /* wait for vertical retrace to be off */
  205.         while ((inp(0x3da) & 8))
  206.             ;
  207.     
  208.         /* and to be back on */
  209.         while ((inp(0x3da) & 8) == 0)
  210.             ;
  211.     }            
  212.  
  213.     /* and send the string out */
  214.     movmem(&sline[0], scptr[crow+term.t_roworg]+ccol+term.t_colorg, (term.t_ncol-ccol)*2);
  215.  
  216. }
  217.  
  218. PASCAL NEAR ibmputc(ch) /* put a character at the current position in the
  219.            current colors */
  220.  
  221. int ch;
  222.  
  223. {
  224.     /* if its a newline, we have to move the cursor */
  225.     if (ch == '\n' || ch == '\r') {
  226.         rg.h.ah = 3;
  227.         int86(0x10, &rg, &rg);
  228.         if (rg.h.dh == 24) {
  229.             ibmmove(20, 0);
  230.             /* we must scroll the screen */
  231.             rg.h.ah = 6;    /* scroll up */
  232.             rg.h.al = 1;    /* # of lines to scroll by */
  233. #if    COLOR
  234.             rg.h.bh = cfcolor; /* attribute for blank line */
  235. #else
  236.             rg.h.bh = 0; /* attribute for blank line */
  237. #endif
  238.             rg.x.cx = 0;    /* upper left corner of scroll */
  239.             rg.x.dx = 0x184f;/* lower right */
  240.             int86(0x10, &rg, &rg);
  241.             rg.h.dh = 23;
  242.         }
  243.         ibmmove(rg.h.dh + 1, 0);
  244.         return;
  245.     }
  246.  
  247. #if    1
  248.     if (ch == '\b') {
  249.  
  250.         /* backup the cursor by 1 position */
  251.         rg.h.ah = 3;        /* read current position */
  252.         int86(0x10, &rg, &rg);
  253.         rg.h.dl--;        /* move it forward one */
  254.         rg.h.ah = 2;        /* set its new position */
  255.         int86(0x10, &rg, &rg);
  256.     
  257.         rg.h.ah = 9;        /* write char with attributes to cursor position */
  258.         rg.h.bh = 0;        /* display page zero */
  259.         rg.x.cx = 1;        /* only one please! */
  260.         rg.h.al = ' ';        /* character to write */
  261.         rg.h.bl = ((ctrans[gbcolor] << 4) | ctrans[gfcolor]);/* attribute */
  262.         int86(0x10, &rg, &rg);
  263.         return;
  264.     }
  265.  
  266.     if (ch == 7) {
  267.         TTbeep();
  268.         return;
  269.     }
  270.  
  271.     rg.h.ah = 9;        /* write char with attributes to cursor position */
  272.     rg.h.bh = 0;        /* display page zero */
  273.     rg.x.cx = 1;        /* only one please! */
  274.     rg.h.al = ch;        /* character to write */
  275.     rg.h.bl = ((ctrans[gbcolor] << 4) | ctrans[gfcolor]);    /* attribute */
  276.     int86(0x10, &rg, &rg);
  277.  
  278.     /* advance the cursor by 1 position */
  279.     rg.h.ah = 3;        /* read current position */
  280.     int86(0x10, &rg, &rg);
  281.     rg.h.dl++;        /* move it forward one */
  282.     rg.h.ah = 2;        /* set its new position */
  283.     int86(0x10, &rg, &rg);
  284. #else
  285.     rg.h.ah = 14;        /* write char to screen with current attrs */
  286.     rg.h.al = ch;
  287. #if    COLOR
  288.     if (dtype != CDMONO)
  289.         rg.h.bl = cfcolor;
  290.     else
  291.         rg.h.bl = 0x07;
  292. #else
  293.     rg.h.bl = 0x07;
  294. #endif
  295.     int86(0x10, &rg, &rg);
  296. #endif
  297. }
  298.  
  299. PASCAL NEAR ibmeeop()
  300.  
  301. {
  302.     rg.h.ah = 6;        /* scroll page up function code */
  303.     rg.h.al = 0;        /* # lines to scroll (clear it) */
  304.     rg.x.cx = (term.t_roworg << 8) | (term.t_colorg);
  305.                 /* upper left corner of scroll */
  306.     rg.x.dx = ((term.t_nrow + term.t_roworg) << 8) |
  307.             (term.t_ncol + term.t_colorg - 1);
  308.                 /* lower right corner of scroll */
  309. #if    COLOR
  310.     if (dtype != CDMONO)
  311.         if (revflag)
  312.             rg.h.bh = ((ctrans[gfcolor] & 15) << 4) | (ctrans[gbcolor] & 15);
  313.         else
  314.             rg.h.bh = ((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
  315.     else
  316.         if (revflag)
  317.             rg.h.bh = 70;
  318.         else
  319.             rg.h.bh = 07;
  320. #else
  321.     rg.h.bh = 07;
  322. #endif
  323.     int86(0x10, &rg, &rg);
  324. }
  325.  
  326. PASCAL NEAR ibmclrdesk()
  327.  
  328. {
  329.     int attr;        /* attribute to fill screen with */
  330.  
  331.     rg.h.ah = 6;        /* scroll page up function code */
  332.     rg.h.al = 0;        /* # lines to scroll (clear it) */
  333.     rg.x.cx = 0;        /* upper left corner of scroll */
  334.     rg.x.dx = (desk_rows << 8) | desk_cols;
  335.                 /* lower right corner of scroll */
  336. #if    COLOR
  337.     if (dtype != CDMONO)
  338.         if (revflag)
  339.             attr = ((ctrans[gfcolor] & 15) << 4) | (ctrans[deskcolor] & 15);
  340.         else
  341.             attr = ((ctrans[deskcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
  342.     else
  343.         if (revflag)
  344.             attr = 70;
  345.         else
  346.             attr = 07;
  347. #else
  348.     attr = 07;
  349. #endif
  350.     rg.h.bh = attr;
  351.     int86(0x10, &rg, &rg);
  352. }
  353.  
  354. PASCAL NEAR ibmrev(state)    /* change reverse video state */
  355.  
  356. int state;    /* TRUE = reverse, FALSE = normal */
  357.  
  358. {
  359.     revflag = state;
  360. }
  361.  
  362. extern dumpscreens();
  363.  
  364. PASCAL NEAR ibmcres(res) /* change screen resolution */
  365.  
  366. char *res;    /* resolution to change to */
  367.  
  368. {
  369.     int i;        /* index */
  370.  
  371.     for (i = 0; i < NDRIVE; i++)
  372.         if (strcmp(res, scr_drive[i].drv_name) == 0) {
  373.             scinit(i);
  374.             return(TRUE);
  375.         }
  376.     return(FALSE);
  377. }
  378.  
  379. PASCAL NEAR spal(mode)    /* reset the pallette registers */
  380.  
  381. char *mode;
  382.  
  383. {
  384.     /* nothin here now..... */
  385. }
  386.  
  387. PASCAL NEAR ibmbeep()
  388. {
  389. #if    MWC
  390.     ttputc(BEL);
  391. #else
  392.     bdos(6, BEL, 0);
  393. #endif
  394. }
  395.  
  396. PASCAL NEAR ibmopen()
  397. {
  398.     scinit(CDSENSE);
  399.     revexist = TRUE;
  400.     revflag = FALSE;
  401.         ttopen();
  402. }
  403.  
  404. PASCAL NEAR ibmclose()
  405.  
  406. {
  407. #if    COLOR
  408.     ibmfcol(7);
  409.     ibmbcol(0);
  410. #endif
  411.  
  412.     /* exit in the same mode that we entered */
  413.     if (dtype != orig_mode) {
  414.         scinit(orig_mode);
  415.         movecursor(term.t_nrow, 0);
  416.         TTflush();
  417.     }
  418.     dtype = -1;
  419.     ttclose();
  420. }
  421.  
  422. PASCAL NEAR ibmkopen()    /* open the keyboard */
  423.  
  424. {
  425. }
  426.  
  427. PASCAL NEAR ibmkclose() /* close the keyboard */
  428.  
  429. {
  430. }
  431.  
  432. PASCAL NEAR scinit(type) /* initialize the screen head pointers */
  433.  
  434. int type;    /* type of adapter to init for */
  435.  
  436. {
  437.     /* if asked...find out what display is connected */
  438.     if (type == CDSENSE)
  439.         type = getboard();
  440.  
  441.     /* if we have nothing to do....don't do it */
  442.     if (dtype == type)
  443.         return(TRUE);
  444.  
  445.     /* if we try to switch to EGA and there is none, don't */
  446.     if (type == CDEGA && !egaexist)
  447.         return(FALSE);
  448.  
  449.     /* if we try to switch to VGA and there is none, don't */
  450.     if (type == CDVGA && !vgaexist )
  451.         return(FALSE);
  452.  
  453.     /* if we had the EGA or VGA open... close it */
  454.     if (dtype == CDEGA || dtype == CDVGA || dtype == CDVGA12)
  455.         egaclose();
  456.  
  457.     /* if we had the CGA40 open... close it */
  458.     if (dtype == CDCGA40)
  459.         cga40_close();
  460.  
  461.     /* and set up the various parameters as needed */
  462.     scadd = scr_drive[type].drv_scradd;
  463.     switch (type) {
  464.         case CDMONO:    /* Monochrome adapter */
  465.         case CDCGA:    /* Color graphics adapter */
  466.                 break;
  467.  
  468.         case CDCGA40:    /* Color graphics adapter */
  469.                 cga40_open();
  470.                 break;
  471.  
  472.         case CDEGA:    /* Enhanced graphics adapter */
  473.                 egaopen(CDEGA);
  474.                 break;
  475.  
  476.         case CDVGA:    /* video graphics array - acts as EGA but more lines */
  477.                 egaopen(CDVGA);
  478.                 break;
  479.  
  480.         case CDVGA12:    /* Video Graphics Array 12 line mode */
  481.                 egaopen(CDVGA12);
  482.                 break;
  483.  
  484.     }
  485.     maxlines(scr_drive[type].drv_rows);
  486.  
  487.     /* reset the $sres environment variable */
  488.     strcpy(sres, scr_drive[type].drv_name);
  489.  
  490.     /* resize any screens that need it! */
  491.     screen_init(dtype, type);
  492.     dtype = type;
  493.  
  494.     return(TRUE);
  495. }
  496.  
  497. PASCAL NEAR screen_init(dtype, type) /* initialize the screen head pointers */
  498.  
  499. int dtype;    /* original screen type (-1 if first time!) */
  500. int type;    /* new type of adapter to adjust screens for */
  501.  
  502. {
  503.     int full_screen;    /* is the active screen full size */
  504.  
  505.     /* is the front screen full size? */
  506.     if ((dtype != -1) &&
  507.        (scr_drive[dtype].drv_rows == (term.t_nrow + 1)) &&
  508.         (scr_drive[dtype].drv_cols == term.t_ncol))
  509.         full_screen = TRUE;
  510.     else
  511.         full_screen = FALSE;
  512.  
  513.     /* set up the new desktop size */
  514.     desk_rows = scr_drive[type].drv_rows;
  515.     desk_cols = scr_drive[type].drv_cols;
  516.  
  517.     /* recalculate the screen line pointer array */
  518.     change_width(desk_cols);
  519.  
  520.     /* first time, or if we are full screen */
  521.     if ((dtype == -1) || full_screen) {
  522.         newsize(TRUE, desk_rows);
  523.         newwidth(TRUE, desk_cols);
  524.     }
  525.  
  526. #if    WINDOW_TEXT
  527.     refresh_screen(first_screen);
  528. #endif
  529.     return(TRUE);
  530. }
  531.  
  532. int PASCAL NEAR change_width(ncols)
  533.  
  534. int ncols;    /* number of columns across */
  535.  
  536. {
  537.     union {
  538.         long laddr;    /* long form of address */
  539.         int *paddr;    /* pointer form of address */
  540.     } addr;
  541.     int i;
  542.  
  543.     /* re-initialize the screen pointer array */
  544.     for (i = 0; i < NROW; i++) {
  545.         addr.laddr = scadd + (long)(ncols * i * 2);
  546.         scptr[i] = addr.paddr;
  547.     }
  548. }
  549.  
  550. /* getboard:    Determine which type of display board is attached.
  551.         Current known types include:
  552.  
  553.         CDMONO    Monochrome graphics adapter
  554.         CDCGA    Color Graphics Adapter
  555.         CDEGA    Extended graphics Adapter
  556.         CDVGA    Vidio Graphics Array
  557.  
  558.         if MONO    set to MONO
  559.            CGA40 set to CGA40    test as appropriate
  560.            CGA    set to CGA    EGAexist = FALSE VGAexist = FALSE
  561.            EGA    set to CGA    EGAexist = TRUE  VGAexist = FALSE
  562.            VGA    set to CGA    EGAexist = TRUE  VGAexist = TRUE
  563. */
  564.  
  565. int PASCAL NEAR getboard()
  566.  
  567. {
  568.     int type;    /* board type to return */
  569.  
  570.     type = CDCGA;
  571.     int86(0x11, &rg, &rg);
  572.     if ((((rg.x.ax >> 4) & 3) == 3))
  573.         type = CDMONO;
  574.  
  575.     /* test for 40 col mode */
  576.     rg.h.ah = 15;
  577.     int86(0x10, &rg, &rg);
  578.     if (rg.h.al == 1)
  579.         type = CDCGA40;
  580.  
  581.     /* save the original video mode */
  582.     orig_mode = type;
  583.  
  584.     /* test if EGA present */
  585.     rg.x.ax = 0x1200;
  586.     rg.x.bx = 0xff10;
  587.     int86(0x10,&rg, &rg);        /* If EGA, bh=0-1 and bl=0-3 */
  588.     egaexist = !(rg.x.bx & 0xfefc);    /* Yes, it's EGA */
  589.     if (egaexist) {
  590.         /* Adapter says it's an EGA. We'll get the same response
  591.            from a VGA, so try to tell the two apart */
  592.         rg.x.ax = 0x1a00;    /* read display combination */
  593.         int86(0x10,&rg,&rg);
  594.         if (rg.h.al == 0x1a && (rg.h.bl == 7 || rg.h.bl == 8)) {
  595.             /* Function is supported and it's a PS/2 50,60,80 with
  596.                analog display, so it's VGA (I hope!) */
  597.             vgaexist = TRUE;
  598.         } else {
  599.             /* Either BIOS function not supported or something
  600.                other then VGA so set it to be EGA */
  601.             vgaexist = FALSE;
  602.         }
  603.     }
  604.     return(type);
  605. }
  606.  
  607. PASCAL NEAR egaopen(mode) /* init the computer to work with the EGA or VGA */
  608.  
  609. int mode;    /* mode to select [CDEGA/CDVGA] */
  610.  
  611. {
  612.     /* set the proper number of scan lines */
  613.     rg.h.ah = 18;
  614.     switch (mode) {
  615.  
  616.         case CDEGA:    rg.h.al = 1;
  617.                 break;
  618.  
  619.         case CDVGA:    rg.h.al = 2;
  620.                 break;
  621.  
  622.         case CDVGA12:    rg.h.al = 0;
  623.                 break;
  624.  
  625.     }
  626.     rg.h.bl = 48;
  627.     int86(16, &rg, &rg);
  628.  
  629.     /* put the beast into EGA 43/VGA 50/VGA 12 line mode */
  630.     rg.x.ax = 3;
  631.     int86(16, &rg, &rg);
  632.  
  633.     /* set the proper character set */
  634.     if (mode == CDVGA12) {
  635.         rg.h.al = 20;    /*  to 8 by 16 double dot ROM         */
  636.     } else {
  637.         rg.h.al = 18;    /*  to 8 by 8 double dot ROM         */
  638.     }
  639.     rg.h.ah = 17;        /* set char. generator function code */
  640.     rg.h.bl = 0;        /* block 0                           */
  641.     int86(16, &rg, &rg);
  642.  
  643.     /* select the alternative Print Screen function */
  644.     rg.h.ah = 18;        /* alternate select function code    */
  645.     rg.h.al = 0;        /* clear AL for no good reason       */
  646.     rg.h.bl = 32;        /* alt. print screen routine         */
  647.     int86(16, &rg, &rg);
  648.  
  649.     /* resize the cursor */
  650.     rg.h.ah = 1;        /* set cursor size function code */
  651.     rg.x.cx = 0x0607;    /* turn cursor on code */
  652.     int86(0x10, &rg, &rg);
  653.  
  654.     /* video bios bug patch */
  655.     outp(0x3d4, 10);
  656.     outp(0x3d5, 6);
  657. }
  658.  
  659. PASCAL NEAR egaclose()
  660.  
  661. {
  662.     /* set the proper number of scan lines for CGA */
  663.     rg.h.ah = 18;
  664.     rg.h.al = 2;
  665.     rg.h.bl = 48;
  666.     int86(16, &rg, &rg);
  667.  
  668.     /* put the beast into 80 column mode */
  669.     rg.x.ax = 3;
  670.     int86(16, &rg, &rg);
  671. }
  672.  
  673. PASCAL NEAR cga40_open()
  674.  
  675. {
  676.     /* put the beast into 40 column mode */
  677.     rg.x.ax = 1;
  678.     int86(16, &rg, &rg);
  679. }
  680.  
  681. PASCAL NEAR cga40_close()
  682.  
  683. {
  684.     /* put the beast into 80 column mode */
  685.     rg.x.ax = 3;
  686.     int86(16, &rg, &rg);
  687. }
  688.  
  689. PASCAL NEAR scwrite(row, outstr, forg, bacg)    /* write a line out*/
  690.  
  691. int row;    /* row of screen to place outstr on */
  692. char *outstr;    /* string to write out (must be term.t_ncol long) */
  693. int forg;    /* forground color of string to write */
  694. int bacg;    /* background color */
  695.  
  696. {
  697.     unsigned int attr;    /* attribute byte mask to place in RAM */
  698.     unsigned int *lnptr;    /* pointer to the destination line */
  699.     int i;
  700.  
  701.     /* build the attribute byte and setup the screen pointer */
  702. #if    COLOR
  703.     if (dtype != CDMONO)
  704.         if (revflag)
  705.             attr = (ctrans[forg] << 12) | (ctrans[bacg] << 8);
  706.         else
  707.             attr = (ctrans[bacg] << 12) | (ctrans[forg] << 8);
  708.     else
  709.         if ((bacg || revflag) && !(bacg && revflag))
  710.             attr = 0x7000;
  711.         else
  712.             attr = 0x0700;
  713. #else
  714.     attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  715. #endif
  716.     lnptr = &sline[0];
  717.     for (i=0; i<term.t_ncol; i++)
  718.         *lnptr++ = (outstr[i] & 255) | attr;
  719.  
  720.     if (flickcode && (dtype == CDCGA)) {
  721.         /* wait for vertical retrace to be off */
  722.         while ((inp(0x3da) & 8))
  723.             ;
  724.     
  725.         /* and to be back on */
  726.         while ((inp(0x3da) & 8) == 0)
  727.             ;
  728.     }
  729.  
  730.     /* and send the string out */
  731.     movmem(&sline[0], scptr[row+term.t_roworg]+term.t_colorg,term.t_ncol*2);
  732. }
  733.  
  734. #if    FLABEL
  735. PASCAL NEAR fnclabel(f, n)    /* label a function key */
  736.  
  737. int f,n;    /* default flag, numeric argument [unused] */
  738.  
  739. {
  740.     /* on machines with no function keys...don't bother */
  741.     return(TRUE);
  742. }
  743. #endif
  744. #else
  745. ibmhello()
  746. {
  747. }
  748. #endif
  749.  
  750.