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