home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / PCTEXT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-07  |  6.8 KB  |  284 lines

  1. /*
  2.     pctext.c
  3.  
  4.     % PC text drawing routines
  5.  
  6.     5/16/88  by Ted.
  7.  
  8.     OWL 1.1
  9.     Copyright (c) 1988, by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      1/10/89 ted    Removed redundant disp clip.
  15.      1/10/89 ted    Made ModeText stay in mode 7 if already in mode 7.
  16.      1/18/89 Ted    changed call to PlotText for simplified interface.
  17.      2/04/89 Ted    removed Read and Draw Pixmap functions.
  18.      7/12/89 ted    Added OSTATIC's and '_func' macros.
  19.      7/21/89 ted    Made retrace wait for modes 0, 1, and 2 as well as 3.
  20. */
  21.  
  22. #include "pcpriv.h"
  23.  
  24. OSTATIC void                DIGPRIV text_setfuncs(_arg1(dig_struct *digp));
  25.  
  26. OSTATIC dig_dControl_func     (text_dControl);
  27. OSTATIC dig_pPlotText_func     (text_rPlotText);
  28.  
  29. OSTATIC void                DIGPRIV text_rReadCharAttrbuf(
  30.                     _arg6(ptd_struct *, opcoord, opcoord, char *, byte *, int));
  31. /* -------------------------------------------------------------------------- */
  32.  
  33. boolean pc_ModeText(digp)
  34.     dig_struct *digp;
  35. {
  36.     boolean rval;
  37.  
  38.     if (pc_GetMode() != 0x07) {
  39.         if ((rval = pc_OpenText(digp, 0x03)) != 0) {
  40.             return(rval);
  41.         }
  42.     }
  43.     return(pc_OpenText(digp, 0x07));
  44. }
  45.  
  46. boolean pc_Mode0(digp)
  47.     dig_struct *digp;
  48. {
  49.     return(pc_OpenText(digp, 0x00));
  50. }
  51.  
  52. boolean pc_Mode1(digp)
  53.     dig_struct *digp;
  54. {
  55.     return(pc_OpenText(digp, 0x01));
  56. }
  57.  
  58. boolean pc_Mode2(digp)
  59.     dig_struct *digp;
  60. {
  61.     return(pc_OpenText(digp, 0x02));
  62. }
  63.  
  64. boolean pc_Mode3(digp)
  65.     dig_struct *digp;
  66. {
  67.     return(pc_OpenText(digp, 0x03));
  68. }
  69.  
  70. boolean pc_ModeEGA43(digp)
  71.     dig_struct *digp;
  72. {
  73.     return(pc_OpenText(digp, PCMODE_EGA43));
  74. }
  75.  
  76. boolean pc_ModeVGA50(digp)
  77.     dig_struct *digp;
  78. {
  79.     return(pc_OpenText(digp, PCMODE_VGA50));
  80. }
  81.  
  82. boolean pc_Mode7(digp)
  83.     dig_struct *digp;
  84. {
  85.     return(pc_OpenText(digp, 0x07));
  86. }
  87. /* -------------------------------------------------------------------------- */
  88.  
  89. boolean DIGPRIV pc_OpenText(digp, mode)
  90.     dig_struct *digp;
  91.     int mode;
  92. {
  93.     if (!pc_OpenDIG(digp, mode, text_setinfo)) {
  94.         return(FALSE);
  95.     }
  96.     /* If setting color text mode on a CGA, set retrace flag */
  97.     if ((mode >= 0 && mode <= 0x03) && !pc_IsEGA() && !pc_IsCompaq()) {
  98.         text_setretracefuncs(digp);
  99.     }
  100.     else {
  101.         text_setnormfuncs(digp);
  102.     }
  103.     return(TRUE);
  104. }
  105. /* -------------------------------------------------------------------------- */
  106.  
  107. void text_setnormfuncs(digp)
  108.     dig_struct *digp;
  109. /*
  110.     Set up the dig function ptrs for no-wait text mode RAM operation.
  111. */
  112. {
  113.     pc_setretrace(FALSE);
  114.     text_setfuncs(digp);
  115. }
  116. /* -------------------------------------------------------------------------- */
  117.  
  118. void text_setretracefuncs(digp)
  119.     dig_struct *digp;
  120. /*
  121.     Set up the dig function ptrs for wait-for-retrace text mode RAM operation.
  122. */
  123. {
  124.     pc_setretrace(TRUE);
  125.     text_setfuncs(digp);
  126.  
  127. /* use BIOS Vt scroll function - it's faster than ram w/retrace */
  128.     digp->pScrollBoxVt  = text_bScrollBoxVt;
  129. }
  130. /* -------------------------------------------------------------------------- */
  131.  
  132. static void DIGPRIV text_setfuncs(digp)
  133.     dig_struct *digp;
  134. {
  135.     digp->CloseDIG = pc_CloseDIG;
  136.     digp->dControl      = text_dControl;
  137.  
  138.     digp->pPlotText     = text_rPlotText;
  139.     digp->pDrawCursor   = pc_bDrawCursor;
  140.     digp->pClear        = ram_Clear;
  141.     digp->pScrollBoxVt  = ram_ScrollBoxVt;
  142.     digp->pScrollBoxHz  = ram_ScrollBoxHz;
  143.  
  144.     /* in hardware cursor text modes, no pixmap funcs are needed */
  145.     digp->pDrawPixmap   = (dig_pDrawPixmap_func ((*)))pc_dDummy;
  146.     digp->pReadPixmap   = (dig_pReadPixmap_func ((*)))pc_dDummy;
  147.     digp->pControl      = (dig_pControl_func ((*)))pc_dDummy;
  148.  
  149.     digp->vtscroll = TRUE;
  150.     digp->hzscroll = TRUE;
  151.     digp->textfree = FALSE;
  152.     digp->evcheck  = TRUE;
  153.     digp->type = 0;
  154.     digp->version = 0;
  155. }
  156. /* -------------------------------------------------------------------------- */
  157.  
  158. static int text_dControl(msg, indata, outdata)
  159.     dig_dcmsg msg;
  160.     VOID *indata;
  161.     VOID *outdata;
  162. {
  163.     switch (msg) {
  164.     case DC_READCHARATTR:
  165.         {    ptarg_struct *pta = (ptarg_struct *)indata;
  166.             text_rReadCharAttrbuf(pta->ptd, pta->x, pta->y,
  167.                                     pta->charbuf, pta->attrbuf, pta->slen);
  168.         }
  169.         break;
  170.     default:
  171.         return(pc_dControl(msg, indata, outdata));
  172.     }
  173.     return(TRUE);
  174. }
  175. /* -------------------------------------------------------------------------- */
  176.  
  177. static void text_rPlotText(ptd, x, y, charbuf, rchar, rattr, slen)
  178.     ptd_struct *ptd;
  179.     opcoord x;
  180.     opcoord y;
  181.     char *charbuf;
  182.     char rchar;
  183.     byte rattr;
  184.     int slen;
  185. {
  186.     win_type win;
  187.     opbox clipbox;
  188.     int delta;
  189.  
  190.     unsigned vidoffs;
  191.  
  192.     win = ptd->win;
  193.  
  194.     opbox_copy(&clipbox, ptd->relboxp);
  195.     opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
  196.     x += win_GetXmin(win);
  197.     y += win_GetYmin(win);
  198.  
  199.     delta = opbox_clipstring(&clipbox, &x, &y, &slen, win_GetFont(win));
  200.     if (slen <= 0) {
  201.         return;
  202.     }
  203.     if (charbuf != NULL) charbuf += delta;
  204.     rattr = pcdata->attrmap[rattr];
  205.  
  206.     vidoffs = ((y-1)*pc_bwidth())+(x*2);
  207.  
  208.     /* Index into buf for clipping. */
  209.     if (charbuf != NULL) {
  210.     /* Draw the string, interleaving chars with rattr */
  211.         if (!pc_retrace()) {
  212.             ram_mem1toseg(pc_vidseg(), vidoffs, (byte *) charbuf,
  213.                             (unsigned) rattr, (unsigned) slen);
  214.         }
  215.         else {
  216.             ram_wmem1toseg(pc_vidseg(), vidoffs, (byte *) charbuf,
  217.                             (unsigned) rattr, (unsigned) slen);
  218.         }
  219.     }
  220.     else {    /* no charbuf */
  221.     /* Draw a string of rchar/rattr pairs */
  222.         if (!pc_retrace()) {
  223.             ram_segwordset(pc_vidseg(),
  224.                             vidoffs, (unsigned)slen * 2,
  225.                             (unsigned)((byte)rchar) | ((unsigned)rattr << 8) );
  226.         }
  227.         else {
  228.             ram_wsegwordset(pc_vidseg(),
  229.                             vidoffs, (unsigned)slen * 2,
  230.                             (unsigned)((byte)rchar) | ((unsigned)rattr << 8) );
  231.         }
  232.     }
  233. }
  234. /* -------------------------------------------------------------------------- */
  235. #define BUFLEN    132
  236.  
  237. static void DIGPRIV text_rReadCharAttrbuf(ptd, x, y, charbuf, attrbuf, slen)
  238.     ptd_struct *ptd;
  239.     opcoord x;
  240.     opcoord y;
  241.     char *charbuf;
  242.     byte *attrbuf;
  243.     int slen;
  244. {
  245.     win_type win;
  246.     opbox clipbox;
  247.     int delta;
  248.  
  249.     unsigned vidoffs;
  250.     byte tbuf[2*BUFLEN];
  251.  
  252.     win = ptd->win;
  253.  
  254.     opbox_copy(&clipbox, ptd->relboxp);
  255.     opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
  256.     x += win_GetXmin(win);
  257.     y += win_GetYmin(win);
  258.  
  259.     delta = opbox_clipstring(&clipbox, &x, &y, &slen, win_GetFont(win));
  260.     if (slen <= 0) {
  261.         return;
  262.     }
  263.     if (charbuf != NULL) charbuf += delta;
  264.     if (attrbuf != NULL) attrbuf += delta;
  265.  
  266.     if (attrbuf == NULL || charbuf == NULL) {
  267.         return;
  268.     }
  269.     vidoffs = ((y-1)*pc_bwidth())+(x*2);
  270.  
  271.     /* Read the string in from display in char/attr form */
  272.     if (slen > BUFLEN) slen = BUFLEN;
  273.     /* This will Snow on a CGA. Oh Well...It's only at disp_Init time. */
  274.     ram_segtomem(pc_vidseg(), vidoffs, tbuf, (unsigned)(slen * 2));
  275.  
  276.     /* Separate chars and attrs */
  277.     for (delta = 0; slen > 0; slen--) {
  278.         *charbuf++ = (char)tbuf[delta++];
  279.         *attrbuf++ = tbuf[delta++];
  280.     }
  281. }
  282. /* -------------------------------------------------------------------------- */
  283.  
  284.