home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / memacs / ue311c.arc / Z309.C < prev   
C/C++ Source or Header  |  1990-08-16  |  9KB  |  374 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.         z309beep,
  94.     z309rev,
  95.     z309cres
  96. #if    COLOR
  97.     , z309fcol,
  98.     z309bcol
  99. #endif
  100. };
  101.  
  102. extern union REGS rg;
  103.  
  104. #if    COLOR
  105. PASCAL NEAR z309fcol(color)        /* set the current output color */
  106.  
  107. int color;    /* color to set */
  108.  
  109. {
  110.     cfcolor = ctrans[color];
  111. }
  112.  
  113. PASCAL NEAR z309bcol(color)        /* set the current background color */
  114.  
  115. int color;    /* color to set */
  116.  
  117. {
  118.         cbcolor = ctrans[color];
  119. }
  120. #endif
  121. PASCAL NEAR z309move(row, col)
  122. {
  123.     rg.h.ah = 2;        /* set cursor position function code */
  124.     rg.h.dl = col;
  125.     rg.h.dh = row;
  126.     rg.h.bh = 0;        /* set screen page number */
  127.     int86(0x10, &rg, &rg);
  128. }
  129.  
  130. PASCAL NEAR z309eeol()    /* erase to the end of the line */
  131.  
  132. {
  133.     int attr;    /* attribute byte mask to place in RAM */
  134.     int *lnptr;    /* pointer to the destination line */
  135.     int i;
  136.     int ccol;    /* current column cursor lives */
  137.     int crow;    /*       row    */
  138.  
  139.     /* find the current cursor position */
  140.     rg.h.ah = 3;        /* read cursor position function code */
  141.     rg.h.bh = 0;        /* current video page */
  142.     int86(0x10, &rg, &rg);
  143.     ccol = rg.h.dl;        /* record current column */
  144.     crow = rg.h.dh;        /* and row */
  145.  
  146.     /* build the attribute byte and setup the screen pointer */
  147. #if    COLOR
  148.     if (dtype != CDMONO)
  149.         attr = (((cbcolor & 15) << 4) | (cfcolor & 15)) << 8;
  150.     else
  151.         attr = 0x0700;
  152. #else
  153.     attr = 0x0700;
  154. #endif
  155.     lnptr = &sline[0];
  156.     for (i=0; i < term.t_ncol; i++)
  157.         *lnptr++ = SPACE | attr;
  158.  
  159. #if 0    /* Heath/Zenith builds flicker-less CGAs */
  160.     if (flickcode) {
  161.         /* wait for vertical retrace to be off */
  162.         while ((inp(0x3da) & 8))
  163.             ;
  164.     
  165.         /* and to be back on */
  166.         while ((inp(0x3da) & 8) == 0)
  167.             ;
  168.     }
  169. #endif
  170.  
  171.     /* and send the string out */
  172.     movmem(&sline[0], scptr[crow]+ccol, (term.t_ncol-ccol)*2);
  173.  
  174. }
  175.  
  176. PASCAL NEAR z309putc(ch)    /* put a character at the current position in the
  177.            current colors */
  178.  
  179. int ch;
  180.  
  181. {
  182.     rg.h.ah = 14;        /* write char to screen with current attrs */
  183.     rg.h.al = ch;
  184. #if    COLOR
  185.     if (dtype != CDMONO)
  186.         rg.h.bl = cfcolor;
  187.     else
  188.         rg.h.bl = 0x07;
  189. #else
  190.     rg.h.bl = 0x07;
  191. #endif
  192.     int86(0x10, &rg, &rg);
  193. }
  194.  
  195. PASCAL NEAR z309eeop()
  196. {
  197.     int attr;        /* attribute to fill screen with */
  198.  
  199.     rg.h.ah = 6;        /* scroll page up function code */
  200.     rg.h.al = 0;        /* # lines to scroll (clear it) */
  201.     rg.x.cx = 0;        /* upper left corner of scroll */
  202. /*HERE*/    rg.x.dx = 0x184f;    /* lower right corner of scroll */
  203. #if    COLOR
  204.     if (dtype != CDMONO)
  205.         attr = ((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
  206.     else
  207.         attr = 0;
  208. #else
  209.     attr = 0;
  210. #endif
  211.     rg.h.bh = attr;
  212.     int86(0x10, &rg, &rg);
  213. }
  214.  
  215. PASCAL NEAR z309rev(state)        /* change reverse video state */
  216.  
  217. int state;    /* TRUE = reverse, FALSE = normal */
  218.  
  219. {
  220.     /* This never gets used under the z309-PC driver */
  221. }
  222.  
  223. PASCAL NEAR z309cres(res)    /* change screen resolution */ 
  224.  
  225. char *res;    /* resolution to change to */
  226.  
  227. {
  228.     if (strcmp(res, "CGA50") == 0) {
  229.         scinit(CDCGA50);
  230.         return(TRUE);
  231.     } else if (strcmp(res, "MONO") == 0) {
  232.         scinit(CDMONO);
  233.         return(TRUE);
  234.     } else
  235.         return(FALSE);
  236. }
  237.  
  238. PASCAL NEAR z309beep()
  239. {
  240. #if    MWC
  241.     putcnb(BEL);
  242. #else
  243.     bdos(6, BEL, 0);
  244. #endif
  245. }
  246.  
  247. PASCAL NEAR z309open()
  248. {
  249.     scinit(CDSENSE);
  250.     revexist = TRUE;
  251.         ttopen();
  252. }
  253.  
  254. PASCAL NEAR z309close()
  255.  
  256. {
  257.     rg.h.ah = 101;
  258.     rg.h.al = 1;    /* 25-line interlace mode */
  259.     int86(0x10, &rg, &rg); 
  260. #if    COLOR
  261.     z309fcol(7);
  262.     z309bcol(0);
  263. #endif
  264.     ttclose();
  265. }
  266.  
  267. PASCAL NEAR spal()    /* reset the pallette registers */
  268.  
  269. {
  270.     /* nothin here now..... */
  271. }
  272.  
  273. PASCAL NEAR z309kopen()    /* open the keyboard */
  274.  
  275. {
  276. }
  277.  
  278. PASCAL NEAR z309kclose()    /* close the keyboard */
  279.  
  280. {
  281. }
  282.  
  283. PASCAL NEAR scinit(type)    /* initialize the screen head pointers */
  284.  
  285. int type;    /* type of adapter to init for */
  286.  
  287. {
  288.     union {
  289.         long laddr;    /* long form of address */
  290.         int *paddr;    /* pointer form of address */
  291.     } addr;
  292.     int i;
  293.  
  294.     /* if asked...find out what display is connected */
  295.     int86(0x11, &rg, &rg);
  296.     dtype = CDCGA50;
  297.     scadd = SCADC;
  298.     strcpy(sres, "CGA50");
  299.     if ((((rg.x.ax >> 4) & 11) == 3) || type == CDMONO) {
  300.         strcpy(sres, "MONO");
  301.         dtype = CDMONO;
  302.         scadd = SCADM;
  303.     }
  304.     else {
  305.         rg.h.ah = 101;
  306. /* set al = 1 for 25-line interlace mode */        
  307.         rg.h.al = 2;    /* 50-line interlace mode */
  308.         int86(0x10, &rg, &rg); 
  309.     }
  310.  
  311.     /* initialize the screen pointer array */
  312.     for (i = 0; i < NROW; i++) {
  313.         addr.laddr = scadd + (long)(NCOL * i * 2);
  314.         scptr[i] = addr.paddr;
  315.     }
  316. }
  317.  
  318. PASCAL NEAR scwrite(row, outstr, forg, bacg)    /* write a line out*/
  319.  
  320. int row;    /* row of screen to place outstr on */
  321. char *outstr;    /* string to write out (must be term.t_ncol long) */
  322. int forg;    /* forground color of string to write */
  323. int bacg;    /* background color */
  324.  
  325. {
  326.     int attr;    /* attribute byte mask to place in RAM */
  327.     int *lnptr;    /* pointer to the destination line */
  328.     int i;
  329.  
  330.     /* build the attribute byte and setup the screen pointer */
  331. #if    COLOR
  332.     if (dtype != CDMONO)
  333.         attr = (((ctrans[bacg] & 15) << 4) | (ctrans[forg] & 15)) << 8;
  334.     else
  335.         attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  336. #else
  337.     attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  338. #endif
  339.     lnptr = &sline[0];
  340.     for (i=0; i<term.t_ncol; i++)
  341.         *lnptr++ = (outstr[i] & 255) | attr;
  342.  
  343. #if 0    /* Heath/Zenith builds flicker-less CGAs */
  344.     if (flickcode) {
  345.         /* wait for vertical retrace to be off */
  346.         while ((inp(0x3da) & 8))
  347.             ;
  348.     
  349.         /* and to be back on */
  350.         while ((inp(0x3da) & 8) == 0)
  351.             ;
  352.     }
  353. #endif    
  354.  
  355.     /* and send the string out */
  356.     movmem(&sline[0], scptr[row],term.t_ncol*2);
  357. }
  358.  
  359. #if    FLABEL
  360. PASCAL NEAR fnclabel(f, n)        /* label a function key */
  361.  
  362. int f,n;    /* default flag, numeric argument [unused] */
  363.  
  364. {
  365.     /* on machines with no function keys...don't bother */
  366.     return(TRUE);
  367. }
  368. #endif
  369. #else
  370. PASCAL NEAR z309hello()
  371. {
  372. }
  373. #endif
  374.