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

  1. /*
  2.     pcgfuncs.c
  3.  
  4.     % pc_setgfuncs
  5.  
  6.     OWL 1.1
  7.     Copyright (c) 1988, by Oakland Group, Inc.
  8.     ALL RIGHTS RESERVED.
  9.  
  10.     Revision History:
  11.     -----------------
  12.     10/19/88 ted    Extracted from pcdisp.c
  13.     01/10/89 ted    Removed redundant disp clip.
  14.      1/18/89 Ted    changed call to PlotText for simplified interface.
  15.      3/02/89 Ted    restored ah in bios plot calls because of clone bios bug.
  16.      6/15/89 Ted    got rid of BLOCKCHAR plotting, used _Clear funcs instead.
  17.      6/17/89 Ted    split pc_bgPlotText into evga_Plot-, mcga_Plot-, pc_bgPlot-.
  18.      7/12/89 ted    Added OSTATIC's and '_func' macros.
  19.      7/14/89 ted    Installed no-bios graphics char plotter.
  20. */
  21.  
  22. #define DEFDEFCMAPS        /* allow pcdef cmap declarations in this file */
  23.  
  24. #include "pcpriv.h"
  25.  
  26. OGLOBAL ocolmap_struct(2) pcdefmcmap = PC_DEF_MCMAPINIT;
  27. OGLOBAL ocolmap_struct(16) pcdefcmap = PC_DEF_CMAPINIT;
  28.  
  29. OSTATIC dig_pPlotText_func        (pc_gPlotText);
  30. OSTATIC dig_pDrawCursor_func    (pc_gDrawCursor);
  31. /* -------------------------------------------------------------------------- */
  32.  
  33. void DIGPRIV pc_setgfuncs(digp)
  34.     dig_struct *digp;
  35. {
  36.     digp->CloseDIG        = pc_CloseDIG;
  37.     digp->dControl        = pc_dControl;
  38.  
  39.     digp->pPlotText        = pc_gPlotText;
  40.     digp->pDrawCursor    = pc_gDrawCursor;
  41.     digp->pClear        = ram_Clear;
  42.     digp->pScrollBoxVt    = ram_ScrollBoxVt;
  43.     digp->pScrollBoxHz    = ram_ScrollBoxHz;
  44.  
  45.     digp->pDrawPixmap    = ram_DrawPixmap;
  46.     digp->pReadPixmap    = ram_ReadPixmap;
  47.     digp->pControl        = pc_pControl;
  48.  
  49.     digp->vtscroll = TRUE;
  50.     digp->hzscroll = TRUE;
  51.     digp->textfree = FALSE;
  52.     digp->evcheck  = TRUE;
  53.     digp->type = 0;
  54.     digp->version = 0;
  55. }
  56. /* -------------------------------------------------------------------------- */
  57.  
  58. unsigned DIGPRIV pc_attrcols(rattr)
  59.     byte rattr;
  60. /*
  61.     Return a word with foreground pixval in the low byte and background
  62.     pixval in the high byte.
  63. */
  64. {
  65.     union {
  66.         struct { byte bot, top; } dblcol;
  67.         unsigned short x;
  68.     } splitcol;
  69.  
  70.     rattr = pcdata->attrmap[rattr];
  71.  
  72.     splitcol.dblcol.bot = rattr & 0x0F;
  73.     splitcol.dblcol.top = rattr >> 4;
  74.  
  75.     return((unsigned) splitcol.x);
  76. }
  77. /* -------------------------------------------------------------------------- */
  78.  
  79. static void pc_gPlotText(ptd, x, y, charbuf, rchar, rattr, slen)
  80.     ptd_struct *ptd;
  81.     opcoord x;
  82.     opcoord y;
  83.     char *charbuf;
  84.     char rchar;
  85.     byte rattr;
  86.     int slen;
  87. /*
  88.     Plot text/attribute buffers to screen at (x,y), clipped into ptd->relboxp.
  89. */
  90. {
  91.     win_type win;
  92.     opbox clipbox;
  93.     int delta;
  94.     int ichar;
  95.  
  96.     win = ptd->win;
  97.  
  98.     /* Clip the string so that it doesn't overlap its box anywhere */
  99.  
  100.     opbox_copy(&clipbox, ptd->relboxp);
  101.     opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
  102.     x += win_GetXmin(win);
  103.     y += win_GetYmin(win);
  104.  
  105.     delta = opbox_clipstring(&clipbox, &x, &y, &slen, win_GetFont(win));
  106.     if (slen <= 0) {
  107.         return;
  108.     }
  109.     if (charbuf != NULL) charbuf += delta;
  110.  
  111.     /* Do the nitty gritty */
  112.  
  113.     /* Note: these parameters put in the pcdata structure for use by */
  114.     /*  the plotchar function to save argument passing overhead:   */
  115.     /*  dispaddr, nplanes, ilmask, ilsize, vbincr, vidaddr, nsame, splitcol */
  116.  
  117.     y -= pcdata->fontlines;
  118.     pcdata->vidaddr = (y & pcdata->ilmask) * pcdata->ilsize +
  119.                         (y >> pc_ileave()) * pc_bwidth() +
  120.                          x * pc_pixbits() / 8;
  121.  
  122.     pcdata->splitcol = (*pcdata->attrcols)(rattr);
  123.     pcdata->starty = y;
  124.  
  125.     for (ichar = 0; ichar < slen; ) {
  126.  
  127.         /* Get character and figure out repeat count */
  128.         if (charbuf == NULL) {
  129.             pcdata->nsame = slen;
  130.         }
  131.         else {
  132.             rchar = *charbuf++;
  133.             pcdata->nsame = 1;
  134.             while (*charbuf == rchar) {
  135.                 if (ichar + pcdata->nsame >= slen) break;
  136.                 pcdata->nsame++;
  137.                 charbuf++;
  138.             }
  139.         }
  140.         /* Compute address of character in font */
  141.         if ((byte) rchar < 128) {
  142.             pcdata->fontoffs = pcdata->fontoffs0 +
  143.                                 ((unsigned) rchar) * pcdata->fontlines;
  144.             pcdata->fontseg = pcdata->fontseg0;
  145.         }
  146.         else {
  147.             pcdata->fontoffs = pcdata->fontoffs1 +
  148.                                 ((unsigned)((byte) rchar - 128)) * pcdata->fontlines;
  149.             pcdata->fontseg = pcdata->fontseg1;
  150.         }
  151.         /* Plot string of identical chars using info set up in pcdata */ 
  152.         (*pcdata->plotchar)();
  153.  
  154.         ichar += pcdata->nsame;
  155.         if (ichar >= slen) {
  156.             break;
  157.         }
  158.         pcdata->vidaddr += pcdata->nsame * pc_pixbits(); /* /8 *(fontwidth = 8) */
  159.     }
  160. }
  161. /* -------------------------------------------------------------------------- */
  162.  
  163. static void pc_gDrawCursor(ptd, ctype)
  164.     ptd_struct *ptd;
  165.     cursortype ctype;
  166. {
  167.     win_type win;
  168.     opbox cursbox;
  169.     opbox *opboxp;
  170.  
  171.     if (ctype != CURSOR_NONE) {
  172.         win = ptd->win;
  173.         dig_getcursbox(win, ctype, &cursbox);
  174.         cursbox.xmax += 1;    /* Compensate for getcursb making 7 bit box. */
  175.         if (opbox_clipbox(ptd->relboxp, &cursbox)) {
  176.             opboxp = ptd->relboxp;
  177.             ptd->relboxp = &cursbox;
  178.             ram_Clear(ptd, win_GetFgColor(win));
  179.             ptd->relboxp = opboxp;
  180.         }
  181.     }
  182. }
  183. /* -------------------------------------------------------------------------- */
  184.  
  185.