home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 198_02 / z309.c < prev   
C/C++ Source or Header  |  1990-01-23  |  8KB  |  364 lines

  1. /*
  2.  * The routines in this file provide support for the Zenith Z-100 PC
  3.  * family.  It goes directly to the graphics RAM to do screen output. 
  4.  * It compiles into nothing if not a Zenith driver.
  5.  */
  6.  
  7. #define    termdef    1            /* don't define "term" external */
  8.  
  9. #include        <stdio.h>
  10. #include    "estruct.h"
  11. #include        "edef.h"
  12.  
  13. #if     Z309
  14.  
  15. /* set NROW to 25 for 25-line interlaced mode */
  16. #define NROW    50                      /* Screen size.                 */
  17. #define NCOL    80                      /* Edit if you want to.         */
  18. #define    MARGIN    8            /* size of minimim margin and    */
  19. #define    SCRSIZ    64            /* scroll size for extended lines */
  20. #define    NPAUSE    200            /* # times thru update to pause */
  21. #define BEL     0x07                    /* BEL character.               */
  22. #define ESC     0x1B                    /* ESC character.               */
  23. #define    SPACE    32            /* space character        */
  24.  
  25. #define    SCADC    0xb8000000L        /* CGA address of screen RAM    */
  26. #define    SCADM    0xb0000000L        /* MONO address of screen RAM    */
  27.  
  28. #define    CDMONO    0            /* monochrome text card        */
  29. #define    CDCGA50    1            /* 50-line color graphics card    */
  30. #define CDCGI25 2            /* 25-line interlaced CGA text    */
  31. #define CDCGA25 3            /* 25-line color graphics card    */
  32. #define    CDSENSE    9            /* detect the card type        */
  33.  
  34. int dtype = CDCGA50;            /* current display type        */
  35. long scadd;                /* address of screen ram    */
  36. int *scptr[NROW];            /* pointer to screen lines    */
  37. int sline[NCOL];            /* screen line image        */
  38. extern union REGS rg;            /* cpu register for use of DOS calls */
  39.  
  40. extern  int     ttopen();               /* Forward references.          */
  41. extern  int     ttgetc();
  42. extern  int     ttputc();
  43. extern  int     ttflush();
  44. extern  int     ttclose();
  45. extern  int     z309move();
  46. extern  int     z309eeol();
  47. extern  int     z309eeop();
  48. extern  int     z309beep();
  49. extern  int     z309open();
  50. extern    int    z309rev();
  51. extern    int    z309cres();
  52. extern    int    z309close();
  53. extern    int    z309putc();
  54. extern    int    z309kopen();
  55. extern    int    z309kclose();
  56.  
  57. #if    COLOR
  58. extern    int    z309fcol();
  59. extern    int    z309bcol();
  60.  
  61. int    cfcolor = -1;        /* current forground color */
  62. int    cbcolor = -1;        /* current background color */
  63. int    ctrans[] =        /* ansi to z309 color translation table */
  64.     {0, 4, 2, 6, 1, 5, 3, 7};
  65. #endif
  66.  
  67. /*
  68.  * Standard terminal interface dispatch table. Most of the fields point into
  69.  * "termio" code.
  70.  */
  71. TERM    term    = {
  72.     NROW-1,
  73.         NROW-1,
  74.         NCOL,
  75.         NCOL,
  76.     MARGIN,
  77.     SCRSIZ,
  78.     NPAUSE,
  79.         z309open,
  80.         z309close,
  81.     z309kopen,
  82.     z309kclose,
  83.         ttgetc,
  84.     z309putc,
  85.         ttflush,
  86.         z309move,
  87.         z309eeol,
  88.         z309eeop,
  89.         z309beep,
  90.     z309rev,
  91.     z309cres
  92. #if    COLOR
  93.     , z309fcol,
  94.     z309bcol
  95. #endif
  96. };
  97.  
  98. extern union REGS rg;
  99.  
  100. #if    COLOR
  101. z309fcol(color)        /* set the current output color */
  102.  
  103. int color;    /* color to set */
  104.  
  105. {
  106.     cfcolor = ctrans[color];
  107. }
  108.  
  109. z309bcol(color)        /* set the current background color */
  110.  
  111. int color;    /* color to set */
  112.  
  113. {
  114.         cbcolor = ctrans[color];
  115. }
  116. #endif
  117. z309move(row, col)
  118. {
  119.     rg.h.ah = 2;        /* set cursor position function code */
  120.     rg.h.dl = col;
  121.     rg.h.dh = row;
  122.     rg.h.bh = 0;        /* set screen page number */
  123.     int86(0x10, &rg, &rg);
  124. }
  125.  
  126. z309eeol()    /* erase to the end of the line */
  127.  
  128. {
  129.     int attr;    /* attribute byte mask to place in RAM */
  130.     int *lnptr;    /* pointer to the destination line */
  131.     int i;
  132.     int ccol;    /* current column cursor lives */
  133.     int crow;    /*       row    */
  134.  
  135.     /* find the current cursor position */
  136.     rg.h.ah = 3;        /* read cursor position function code */
  137.     rg.h.bh = 0;        /* current video page */
  138.     int86(0x10, &rg, &rg);
  139.     ccol = rg.h.dl;        /* record current column */
  140.     crow = rg.h.dh;        /* and row */
  141.  
  142.     /* build the attribute byte and setup the screen pointer */
  143. #if    COLOR
  144.     if (dtype != CDMONO)
  145.         attr = (((cbcolor & 15) << 4) | (cfcolor & 15)) << 8;
  146.     else
  147.         attr = 0x0700;
  148. #else
  149.     attr = 0x0700;
  150. #endif
  151.     lnptr = &sline[0];
  152.     for (i=0; i < term.t_ncol; i++)
  153.         *lnptr++ = SPACE | attr;
  154.  
  155. #if 0    /* Heath/Zenith builds flicker-less CGAs */
  156.     if (flickcode) {
  157.         /* wait for vertical retrace to be off */
  158.         while ((inp(0x3da) & 8))
  159.             ;
  160.     
  161.         /* and to be back on */
  162.         while ((inp(0x3da) & 8) == 0)
  163.             ;
  164.     }
  165. #endif
  166.  
  167.     /* and send the string out */
  168.     movmem(&sline[0], scptr[crow]+ccol, (term.t_ncol-ccol)*2);
  169.  
  170. }
  171.  
  172. z309putc(ch)    /* put a character at the current position in the
  173.            current colors */
  174.  
  175. int ch;
  176.  
  177. {
  178.     rg.h.ah = 14;        /* write char to screen with current attrs */
  179.     rg.h.al = ch;
  180. #if    COLOR
  181.     if (dtype != CDMONO)
  182.         rg.h.bl = cfcolor;
  183.     else
  184.         rg.h.bl = 0x07;
  185. #else
  186.     rg.h.bl = 0x07;
  187. #endif
  188.     int86(0x10, &rg, &rg);
  189. }
  190.  
  191. z309eeop()
  192. {
  193.     int attr;        /* attribute to fill screen with */
  194.  
  195.     rg.h.ah = 6;        /* scroll page up function code */
  196.     rg.h.al = 0;        /* # lines to scroll (clear it) */
  197.     rg.x.cx = 0;        /* upper left corner of scroll */
  198. /*HERE*/    rg.x.dx = 0x184f;    /* lower right corner of scroll */
  199. #if    COLOR
  200.     if (dtype != CDMONO)
  201.         attr = ((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
  202.     else
  203.         attr = 0;
  204. #else
  205.     attr = 0;
  206. #endif
  207.     rg.h.bh = attr;
  208.     int86(0x10, &rg, &rg);
  209. }
  210.  
  211. z309rev(state)        /* change reverse video state */
  212.  
  213. int state;    /* TRUE = reverse, FALSE = normal */
  214.  
  215. {
  216.     /* This never gets used under the z309-PC driver */
  217. }
  218.  
  219. z309cres(res)    /* change screen resolution */
  220.  
  221. char *res;    /* resolution to change to */
  222.  
  223. {
  224.     if (strcmp(res, "CGA50") == 0) {
  225.         scinit(CDCGA50);
  226.         return(TRUE);
  227.     } else if (strcmp(res, "MONO") == 0) {
  228.         scinit(CDMONO);
  229.         return(TRUE);
  230.     } else
  231.         return(FALSE);
  232. }
  233.  
  234. z309beep()
  235. {
  236. #if    MWC86
  237.     putcnb(BEL);
  238. #else
  239.     bdos(6, BEL, 0);
  240. #endif
  241. }
  242.  
  243. z309open()
  244. {
  245.     scinit(CDSENSE);
  246.     revexist = TRUE;
  247.         ttopen();
  248. }
  249.  
  250. z309close()
  251.  
  252. {
  253.     rg.h.ah = 101;
  254.     rg.h.al = 1;    /* 25-line interlace mode */
  255.     int86(0x10, &rg, &rg); 
  256. #if    COLOR
  257.     z309fcol(7);
  258.     z309bcol(0);
  259. #endif
  260.     ttclose();
  261. }
  262.  
  263. z309kopen()    /* open the keyboard */
  264.  
  265. {
  266. }
  267.  
  268. z309kclose()    /* close the keyboard */
  269.  
  270. {
  271. }
  272.  
  273. scinit(type)    /* initialize the screen head pointers */
  274.  
  275. int type;    /* type of adapter to init for */
  276.  
  277. {
  278.     union {
  279.         long laddr;    /* long form of address */
  280.         int *paddr;    /* pointer form of address */
  281.     } addr;
  282.     int i;
  283.  
  284.     /* if asked...find out what display is connected */
  285.     int86(0x11, &rg, &rg);
  286.     dtype = CDCGA50;
  287.     scadd = SCADC;
  288.     strcpy(sres, "CGA50");
  289.     if ((((rg.x.ax >> 4) & 11) == 3) || type == CDMONO) {
  290.         strcpy(sres, "MONO");
  291.         dtype = CDMONO;
  292.         scadd = SCADM;
  293.     }
  294.     else {
  295.         rg.h.ah = 101;
  296. /* set al = 1 for 25-line interlace mode */        
  297.         rg.h.al = 2;    /* 50-line interlace mode */
  298.         int86(0x10, &rg, &rg); 
  299.     }
  300.  
  301.     /* initialize the screen pointer array */
  302.     for (i = 0; i < NROW; i++) {
  303.         addr.laddr = scadd + (long)(NCOL * i * 2);
  304.         scptr[i] = addr.paddr;
  305.     }
  306. }
  307.  
  308. scwrite(row, outstr, forg, bacg)    /* write a line out*/
  309.  
  310. int row;    /* row of screen to place outstr on */
  311. char *outstr;    /* string to write out (must be term.t_ncol long) */
  312. int forg;    /* forground color of string to write */
  313. int bacg;    /* background color */
  314.  
  315. {
  316.     int attr;    /* attribute byte mask to place in RAM */
  317.     int *lnptr;    /* pointer to the destination line */
  318.     int i;
  319.  
  320.     /* build the attribute byte and setup the screen pointer */
  321. #if    COLOR
  322.     if (dtype != CDMONO)
  323.         attr = (((ctrans[bacg] & 15) << 4) | (ctrans[forg] & 15)) << 8;
  324.     else
  325.         attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  326. #else
  327.     attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  328. #endif
  329.     lnptr = &sline[0];
  330.     for (i=0; i<term.t_ncol; i++)
  331.         *lnptr++ = (outstr[i] & 255) | attr;
  332.  
  333. #if 0    /* Heath/Zenith builds flicker-less CGAs */
  334.     if (flickcode) {
  335.         /* wait for vertical retrace to be off */
  336.         while ((inp(0x3da) & 8))
  337.             ;
  338.     
  339.         /* and to be back on */
  340.         while ((inp(0x3da) & 8) == 0)
  341.             ;
  342.     }
  343. #endif    
  344.  
  345.     /* and send the string out */
  346.     movmem(&sline[0], scptr[row],term.t_ncol*2);
  347. }
  348.  
  349. #if    FLABEL
  350. fnclabel(f, n)        /* label a function key */
  351.  
  352. int f,n;    /* default flag, numeric argument [unused] */
  353.  
  354. {
  355.     /* on machines with no function keys...don't bother */
  356.     return(TRUE);
  357. }
  358. #endif
  359. #else
  360. z309hello()
  361. {
  362. }
  363. #endif
  364.