home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / VILE327.ZIP / VILE327.TAR / vile3.27 / z_ibmpc.c < prev    next >
C/C++ Source or Header  |  1992-12-14  |  9KB  |  430 lines

  1. /*
  2.  * The routines in this file provide support for the IBM-PC and other
  3.  * compatible terminals. The routines access graphics RAM directly to do
  4.  * screen output. They utilise the zortech 'disp' package and make no attempt
  5.  * to be portable between compilers.
  6.  * Supported monitor cards include CGA, MONO, EGA and VGA.
  7.  *
  8.  *    Differs from standard "ibmpc.c" in that the Zortech display library
  9.  *  is called whenever possible.
  10.  *  Modifications by Pete Ruczynski (pjr).
  11.  * $Log: z_ibmpc.c,v $
  12.  * Revision 1.2  1992/08/20  23:40:48  foxharp
  13.  * typo fixes -- thanks, eric
  14.  *
  15.  * Revision 1.1  1992/07/01  16:57:45  foxharp
  16.  * Initial revision
  17.  *
  18.  *
  19.  */
  20.  
  21. #define    termdef    1            /* don't define "term" external */
  22.  
  23. #include    <stdio.h>
  24. #include    "estruct.h"
  25. #include    "edef.h"
  26.  
  27. #if ZIBMPC
  28.  
  29. #include    <disp.h>
  30.  
  31. #define NROW    50            /* Max Screen size.        */
  32. #define NCOL    80                      /* Edit if you want to.         */
  33. #define    MARGIN    8            /* size of minimim margin and    */
  34. #define    SCRSIZ    64            /* scroll size for extended lines */
  35. #define    NPAUSE    200            /* # times thru update to pause */
  36. #define    SPACE    32            /* space character        */
  37.  
  38. #define    SCADC    0xb8000000L        /* CGA address of screen RAM    */
  39. #define    SCADM    0xb0000000L        /* MONO address of screen RAM    */
  40. #define SCADE    0xb8000000L        /* EGA address of screen RAM    */
  41.  
  42. #define MONOCRSR 0x0B0D            /* monochrome cursor        */
  43. #define CGACRSR 0x0607            /* CGA cursor            */
  44. #define EGACRSR 0x0709            /* EGA cursor            */
  45.  
  46. #define    CDCGA    0            /* color graphics card        */
  47. #define    CDMONO    1            /* monochrome text card        */
  48. #define    CDEGA    2            /* EGA color adapter        */
  49. #define    CDVGA    3            /* VGA color adapter        */
  50. #define    CDSENSE    9            /* detect the card type        */
  51.  
  52. #define NDRIVE    4            /* number of screen drivers    upped to 4 (vga) */
  53.  
  54. extern int zibmtype;        /* pjr - what to do about screen resolution */
  55.  
  56.  
  57. int dtype = -1;                /* current display type        */
  58. long scadd;                    /* address of screen ram    */
  59. int *scptr[NROW];            /* pointer to screen lines    */
  60. unsigned int sline[NCOL];    /* screen line image        */
  61. extern union REGS rg;        /* cpu register for use of DOS calls */
  62.  
  63. extern  void    ttopen();       /* Forward references.          */
  64. extern  int        ttgetc();
  65. extern  void    ttputc();
  66. extern  void    ttflush();
  67. extern  void    ttclose();
  68.  
  69. extern  int    zibmmove();
  70. extern  int    zibmeeol();
  71. extern  int    zibmeeop();
  72. extern  int    zibmbeep();
  73. extern  int    zibmopen();
  74. extern    int    zibmrev();
  75. extern    int    zibmcres();
  76. extern    int    zibmclose();
  77. extern    int    zibmputc();
  78. extern    int    zibmkopen();
  79. extern    int    zibmkclose();
  80.  
  81. #if    COLOR
  82. extern    int    zibmfcol();
  83. extern    int    zibmbcol();
  84.  
  85. int    cfcolor = -1;        /* current forground color */
  86. int    cbcolor = -1;        /* current background color */
  87. int    ctrans[] =        /* ansi to zibm color translation table */
  88.     {0, 4, 2, 6, 1, 5, 3, 7};
  89. #endif
  90.  
  91. /*
  92.  * Standard terminal interface dispatch table. Most of the fields point into
  93.  * "termio" code.
  94.  */
  95. TERM    term    = {
  96.     NROW-1,
  97.     NROW-1,
  98.     NCOL,
  99.     NCOL,
  100.     MARGIN,
  101.     SCRSIZ,
  102.     NPAUSE,
  103.     zibmopen,
  104.     zibmclose,
  105.     zibmkopen,
  106.     zibmkclose,
  107.     ttgetc,
  108.     zibmputc,
  109.     ttflush,
  110.     zibmmove,
  111.     zibmeeol,
  112.     zibmeeop,
  113.     zibmbeep,
  114.     zibmrev,
  115.     zibmcres
  116. #if    COLOR
  117.     , zibmfcol,
  118.     zibmbcol
  119. #endif
  120. };
  121.  
  122. #if    COLOR
  123. zibmfcol(color)        /* set the current output color */
  124.  
  125. int color;    /* color to set */
  126.  
  127. {
  128.     cfcolor = ctrans[color];
  129. }
  130.  
  131. zibmbcol(color)        /* set the current background color */
  132.  
  133. int color;    /* color to set */
  134.  
  135. {
  136.     cbcolor = ctrans[color];
  137. }
  138. #endif
  139.  
  140.  
  141. /*
  142.  * zibmmove
  143.  *
  144.  * set cursor position
  145.  */
  146. /*****************************************************************************/
  147. int
  148. zibmmove(row, col)
  149. /*****************************************************************************/
  150. {
  151.     disp_move(row, col);
  152.     disp_flush();
  153. } /* end of zibmmove */
  154.  
  155.  
  156. /*
  157.  * zibmeeol
  158.  *
  159.  * erase to the end of the line
  160.  */
  161. /*****************************************************************************/
  162. int
  163. zibmeeol(void)
  164. /*****************************************************************************/
  165. {
  166.     disp_eeol();
  167. } /* end of zibmeeol */
  168.  
  169.  
  170. /*
  171.  * zibmputc
  172.  *
  173.  * put a character at the current cursor position in the current colors
  174.  */
  175. /*****************************************************************************/
  176. int
  177. zibmputc(ch)
  178. /*****************************************************************************/
  179. int ch;
  180. {
  181.     disp_putc(ch);
  182.     disp_flush();
  183. } /* end of zibmputc */
  184.  
  185.  
  186. /*
  187.  * zibmeeop
  188.  *
  189.  * erase from the current position to the end of the screen
  190.  */
  191. /*****************************************************************************/
  192. int
  193. zibmeeop(void)
  194. /*****************************************************************************/
  195. {
  196.     disp_eeop();
  197. } /* end of zibmeeop */
  198.  
  199.  
  200. /*
  201.  * zibmrev
  202.  *
  203.  * change reverse video state
  204.  */
  205. /*****************************************************************************/
  206. int
  207. zibmrev()
  208. /*****************************************************************************/
  209. {
  210.     /* This never gets used under the IBM-PC driver */
  211. } /* end of zibmrev */
  212.  
  213.  
  214. int set43 = TRUE;        /* pjr - try and force 43/50 line mode first */
  215.  
  216. /*
  217.  * zibmcres
  218.  *
  219.  * change screen resolution
  220.  */
  221. /*****************************************************************************/
  222. int
  223. zibmcres(type)
  224. /*****************************************************************************/
  225. {
  226.     union {
  227.         long laddr;    /* long form of address */
  228.         short *paddr;    /* pointer form of address */
  229.     } addr;
  230.     int i;
  231.  
  232.     disp_close();
  233.  
  234.     if (set43)
  235.     {
  236.         disp_set43();
  237.         disp_setcursortype(DISP_CURSORUL);
  238.     }
  239.  
  240.     disp_open();
  241.  
  242.     /*
  243.      * this bit is all about getting the base address for the scwrite
  244.      * routine, needed because its faster than disp_puts()!
  245.      */
  246.     scadd = (long)disp_base;
  247.     scadd = scadd << 16;
  248.  
  249.     /* initialize the screen pointer array */
  250.     addr.laddr = scadd;
  251.     for (i = 0; i < NROW; i++) {
  252.         scptr[i] = addr.paddr + NCOL * i;
  253.     }
  254.  
  255.     /* set screen size */
  256.     newscreensize(disp_numrows, term.t_ncol);
  257.     disp_move(disp_numrows-1, 0);
  258.     disp_flush();
  259.  
  260.     dtype = type;    /* history */
  261.  
  262. } /* end of zibmcres */
  263.  
  264.  
  265. /*
  266.  * spal
  267.  *
  268.  * reset the palette registers
  269.  */
  270. /*****************************************************************************/
  271. int
  272. spal()
  273. /*****************************************************************************/
  274. {
  275.     /* nothing here now..... */
  276. } /* end of spal */
  277.  
  278.  
  279. /*
  280.  * zibmbeep
  281.  *
  282.  * make a beep noise, disabled because its annoying!
  283.  */
  284. /*****************************************************************************/
  285. int
  286. zibmbeep()
  287. /*****************************************************************************/
  288. {
  289. #if    MWC86
  290.     putcnb(BEL);
  291. #else
  292.     bdos(6, BEL, 0);    /* annoying!! */
  293. #endif
  294. } /* end of zibmbeep */
  295.  
  296.  
  297. int zibmtype;        /* pjr - what to do about screen resolution */
  298. /*
  299.  * zibmopen
  300.  *
  301.  * open the screen
  302.  */
  303. /*****************************************************************************/
  304. int
  305. zibmopen()
  306. /*****************************************************************************/
  307. {
  308.     revexist = TRUE;
  309.     ttopen();
  310.     disp_open();
  311. } /* end of zibmopen */
  312.  
  313.  
  314. /*
  315.  * zibmclose
  316.  *
  317.  * close the display
  318.  */
  319. /*****************************************************************************/
  320. int
  321. zibmclose()
  322. /*****************************************************************************/
  323. {
  324.     disp_close();
  325.     if (set43)
  326.     {
  327.         disp_reset43();
  328.     }
  329. } /* end of zibmclose */
  330.  
  331.  
  332. extern int displaying;
  333.  
  334.  
  335. /*
  336.  * scwrite
  337.  *
  338.  * write a line out
  339.  * Note that this is the original code as its faster than the disp package
  340.  * equivalents!!
  341.  */
  342. /*****************************************************************************/
  343. void
  344. scwrite(row, col, nchar, outstr, forg, bacg)
  345. /*****************************************************************************/
  346. int row, col, nchar;        /* row,col of screen to place nchars of outstr on */
  347. char *outstr;    /* string to write out (must be term.t_ncol long) */
  348. int forg;        /* forground color of string to write */
  349. int bacg;        /* background color */
  350. {
  351.     unsigned int attr;    /* attribute byte mask to place in RAM */
  352.     unsigned int *lnptr;    /* pointer to the destination line */
  353.     int i;
  354.  
  355.     /* build the attribute byte and setup the screen pointer */
  356. #if    COLOR
  357.     if (dtype != CDMONO)
  358.         attr = ((ctrans[bacg] & 15) << 4) | (ctrans[forg] & 15);
  359.     else
  360. #endif
  361.      attr = ((bacg & 15) << 4) | (forg & 15);
  362.     attr <<= 8;
  363.     lnptr = &sline[0];
  364.     for (i=0; i<nchar; i++)
  365.         *lnptr++ = (outstr[i] & 255) | attr;
  366.  
  367.     if (flickcode && (dtype == CDCGA)) {
  368.         /* wait for vertical retrace to be off */
  369.         while ((inp(0x3da) & 8))
  370.             ;
  371.     
  372.         /* and to be back on */
  373.         while ((inp(0x3da) & 8) == 0)
  374.             ;
  375.     }
  376.  
  377.     /* and send the string out */
  378.     movmem(&sline[0], scptr[row]+col, nchar*2);
  379. } /* end of scwrite */
  380.  
  381.  
  382. /*
  383.  * zibmsetcur
  384.  *
  385.  * change cursor
  386.  * can be either underline param == TRUE
  387.  * or half block param == FALSE
  388.  * used to indicate mode we are in
  389.  */
  390. /*****************************************************************************/
  391. void
  392. zibmsetcur(param)
  393. /*****************************************************************************/
  394. int param;
  395. {
  396.     if (param)
  397.         disp_setcursortype(DISP_CURSORUL);
  398.     else
  399.         disp_setcursortype(DISP_CURSORHALF);
  400.  
  401. } /* end of zibmsetcur */
  402.  
  403.  
  404. #if    FLABEL
  405. fnclabel(f, n)        /* label a function key */
  406.  
  407. int f,n;    /* default flag, numeric argument [unused] */
  408.  
  409. {
  410.     /* on machines with no function keys...don't bother */
  411.     return(TRUE);
  412. }
  413. #endif
  414.  
  415. zibmkopen()    /* open the keyboard */
  416.  
  417. {
  418. }
  419.  
  420. zibmkclose()    /* close the keyboard */
  421.  
  422. {
  423. }
  424.  
  425. #else
  426. zibmhello()
  427. {
  428. }
  429. #endif
  430.