home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / PCTEXT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-29  |  7.0 KB  |  276 lines

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