home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / pine3.07 / pico / ibmpc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-18  |  5.9 KB  |  284 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.  */
  6.  
  7. #include        <stdio.h>
  8. #include    "osdep.h"
  9. #if     IBMPC
  10. #define    termdef    1            /* don't define "term" external */
  11. #include    "pico.h"
  12. #include    "estruct.h"
  13. #include        "edef.h"
  14.  
  15. #define NROW    25                      /* Screen size.                 */
  16. #define NCOL    80                      /* Edit if you want to.         */
  17. #define    MARGIN    8            /* size of minimim margin and    */
  18. #define    SCRSIZ    64            /* scroll size for extended lines */
  19. #define    NPAUSE    200            /* # times thru update to pause */
  20. #define BEL     0x07                    /* BEL character.               */
  21. #define ESC     0x1B                    /* ESC character.               */
  22. #define    SPACE    32            /* space character        */
  23. #define    SCADD    0xb8000000L        /* address of screen RAM    */
  24.  
  25. int *scptr[NROW];            /* pointer to screen lines    */
  26. int sline[NCOL];            /* screen line image        */
  27.  
  28. extern  int     ttopen();               /* Forward references.          */
  29. extern  int     ttgetc();
  30. extern  int     ttputc();
  31. extern  int     ttflush();
  32. extern  int     ttclose();
  33. extern  int     ibmmove();
  34. extern  int     ibmeeol();
  35. extern  int     ibmeeop();
  36. extern  int     ibmbeep();
  37. extern  int     ibmopen();
  38. extern    int    ibmrev();
  39. extern    int    ibmclose();
  40. extern    int    ibmputc();
  41.  
  42. int    cattr    = 0x07;        /* gray by default */
  43.  
  44. #if    COLOR
  45. extern    int    ibmfcol();
  46. extern    int    ibmbcol();
  47.  
  48. int    cfcolor = -1;        /* current forground color */
  49. int    cbcolor = -1;        /* current background color */
  50. int    ctrans[] =        /* ansi to ibm color translation table */
  51.     {0, 4, 2, 6, 1, 5, 3, 7};
  52. #endif
  53.  
  54. /*
  55.  * Standard terminal interface dispatch table. Most of the fields point into
  56.  * "termio" code.
  57.  */
  58. TERM    term    = {
  59.         NROW-1,
  60.         NCOL,
  61.     MARGIN,
  62.     SCRSIZ,
  63.         ibmopen,
  64.         ibmclose,
  65.         ttgetc,
  66.     ibmputc,
  67.         ttflush,
  68.         ibmmove,
  69.         ibmeeol,
  70.         ibmeeop,
  71.         ibmbeep,
  72.     ibmrev
  73. #if    COLOR
  74.     , ibmfcol,
  75.     ibmbcol
  76. #endif
  77. };
  78.  
  79. extern union REGS rg;
  80.  
  81. #if    COLOR
  82. ibmfcol(color)        /* set the current output color */
  83.  
  84. int color;    /* color to set */
  85.  
  86. {
  87.     cfcolor = ctrans[color];
  88. }
  89.  
  90. ibmbcol(color)        /* set the current background color */
  91.  
  92. int color;    /* color to set */
  93.  
  94. {
  95.         cbcolor = ctrans[color];
  96. }
  97. #endif    /* COLOR */
  98.  
  99.  
  100. ibmmove(row, col)
  101. {
  102.     rg.h.ah = 2;        /* set cursor position function code */
  103.     rg.h.dl = col;
  104.     rg.h.dh = row;
  105.     rg.h.bh = 0;        /* set screen page number */
  106.     int86(0x10, &rg, &rg);
  107. }
  108.  
  109. ibmeeol()    /* erase to the end of the line */
  110.  
  111. {
  112.     int attr;    /* attribute byte mask to place in RAM */
  113.     int *lnptr;    /* pointer to the destination line */
  114.     int i;
  115.     int ccol;    /* current column cursor lives */
  116.     int crow;    /*       row    */
  117.  
  118.     /* find the current cursor position */
  119.     rg.h.ah = 3;        /* read cursor position function code */
  120.     rg.h.bh = 0;        /* current video page */
  121.     int86(0x10, &rg, &rg);
  122.     ccol = rg.h.dl;        /* record current column */
  123.     crow = rg.h.dh;        /* and row */
  124.  
  125.     /* build the attribute byte and setup the screen pointer */
  126. #if    COLOR
  127.     attr = (((cbcolor & 15) << 4) | (cfcolor & 15)) << 8;
  128. #else
  129.     attr = 0x0700;
  130. #endif
  131.     lnptr = &sline[0];
  132.     for (i=0; i < NCOL; i++)
  133.         *lnptr++ = SPACE | attr;
  134.  
  135.     /* wait for vertical retrace to be off */
  136.     while ((inp(0x3da) & 8))
  137.         ;
  138.  
  139.     /* and to be back on */
  140.     while ((inp(0x3da) & 8) == 0)
  141.         ;
  142.  
  143.     /* and send the string out */
  144.     memmove(scptr[crow]+ccol, &sline[0], (NCOL-ccol)*2);
  145.  
  146. }
  147.  
  148.  
  149. /* ibmputc - put a character at the current position in the
  150.  *         current colors
  151.  */
  152. ibmputc(ch)
  153. int ch;
  154. {
  155.     int col, row, page;
  156.  
  157.     /* advance the cursor */
  158.     rg.h.ah = 0x03;            /* first, get current position */
  159.     int86(0x10, &rg, &rg);
  160.     page = rg.h.bh;
  161.     row = rg.h.dh;
  162.     col = rg.h.dl;
  163.  
  164.     rg.h.ah = 0x09;        /* write char to screen with new attrs */
  165.     rg.h.al = ch;
  166.     rg.h.bl = cattr;        /* inverting if needed */
  167.     rg.h.bh = page;
  168.     rg.x.cx = 1;        /* only once */
  169.     int86(0x10, &rg, &rg);
  170.  
  171.     /* write the char with attribute */
  172.     if(col < 80)
  173.         ibmmove(row, ++col);
  174. }
  175.  
  176. ibmeeop()
  177. {
  178.     int attr;        /* attribute to fill screen with */
  179.  
  180.     rg.h.ah = 6;        /* scroll page up function code */
  181.     rg.h.al = 0;        /* # lines to scroll (clear it) */
  182.     rg.x.cx = 0;        /* upper left corner of scroll */
  183.     rg.x.dx = 0x174f;    /* lower right corner of scroll */
  184. #if    COLOR
  185.     attr = ((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
  186. #else
  187.     attr = 0;
  188. #endif
  189.     rg.h.bh = attr;
  190.     int86(0x10, &rg, &rg);
  191. }
  192.  
  193. ibmrev(state)        /* change reverse video state */
  194. int state;    /* TRUE = reverse, FALSE = normal */
  195. {
  196.     if(state){
  197.         cattr = 0x70;
  198.     }
  199.     else{
  200.         cattr = 0x07;
  201.     }
  202. }
  203.  
  204.  
  205. ibmbeep()
  206. {
  207.     bdos(6, BEL, 0);
  208. }
  209.  
  210. ibmopen()
  211. {
  212.     scinit();
  213.     revexist = TRUE;
  214.     HelpKeyNames = justnames;
  215.         ttopen();
  216. }
  217.  
  218. ibmclose()
  219.  
  220. {
  221. #if    COLOR
  222.     ibmfcol(7);
  223.     ibmbcol(0);
  224. #endif
  225.     ttclose();
  226. }
  227.  
  228. /*
  229.  *
  230.  */
  231. scinit()    /* initialize the screen head pointers */
  232. {
  233.     union {
  234.         long laddr;    /* long form of address */
  235.         int *paddr;    /* pointer form of address */
  236.     } addr;
  237.     int i;
  238.  
  239.     /* initialize the screen pointer array */
  240.     for (i = 0; i < NROW; i++) {
  241.         addr.laddr = SCADD + (long)(NCOL * i * 2);
  242.         scptr[i] = addr.paddr;
  243.     }
  244. }
  245.  
  246. scwrite(row, outstr, forg, bacg)    /* write a line out*/
  247.  
  248. int row;    /* row of screen to place outstr on */
  249. char *outstr;    /* string to write out (must be NCOL long) */
  250. int forg;    /* forground color of string to write */
  251. int bacg;    /* background color */
  252.  
  253. {
  254.     int attr;    /* attribute byte mask to place in RAM */
  255.     int *lnptr;    /* pointer to the destination line */
  256.     int i;
  257.  
  258.     /* build the attribute byte and setup the screen pointer */
  259. #if    COLOR
  260.     attr = (((ctrans[bacg] & 15) << 4) | (ctrans[forg] & 15)) << 8;
  261. #else
  262.     attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  263. #endif
  264.     lnptr = &sline[0];
  265.     for (i=0; i<NCOL; i++)
  266.         *lnptr++ = (outstr[i] & 255) | attr;
  267.  
  268.     /* wait for vertical retrace to be off */
  269.     while ((inp(0x3da) & 8))
  270.         ;
  271.  
  272.     /* and to be back on */
  273.     while ((inp(0x3da) & 8) == 0)
  274.         ;
  275.  
  276.     /* and send the string out */
  277.     memmove(scptr[row], &sline[0], NCOL*2);
  278. }
  279. #else
  280. ibmhello()
  281. {
  282. }
  283. #endif
  284.