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

  1. /*
  2.     pcgfuncs.c
  3.  
  4.     % pc_setgfuncs
  5.  
  6.     OWL-PC 1.2
  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.      3/28/90 jmd    ansi-fied
  21. */
  22.  
  23. #define DEFDEFCMAPS        /* allow pcdef cmap declarations in this file */
  24.  
  25. #include "pcpriv.h"
  26.  
  27. OGLOBAL ocolmap_struct(2) pcdefmcmap = PC_DEF_MCMAPINIT;
  28. OGLOBAL ocolmap_struct(16) pcdefcmap = PC_DEF_CMAPINIT;
  29.  
  30. OSTATIC dig_pPlotText_func        (pc_gPlotText);
  31. OSTATIC dig_pDrawCursor_func    (pc_gDrawCursor);
  32. /* -------------------------------------------------------------------------- */
  33.  
  34. void DIGPRIV pc_setgfuncs(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(byte rattr)
  59. /*
  60.     Return a word with foreground pixval in the low byte and background
  61.     pixval in the high byte.
  62. */
  63. {
  64.     union {
  65.         struct { byte bot, top; } dblcol;
  66.         unsigned short x;
  67.     } splitcol;
  68.  
  69.     rattr = pcdata->attrmap[rattr];
  70.  
  71.     splitcol.dblcol.bot = rattr & 0x0F;
  72.     splitcol.dblcol.top = rattr >> 4;
  73.  
  74.     return((unsigned) splitcol.x);
  75. }
  76. /* -------------------------------------------------------------------------- */
  77.  
  78. static void pc_gPlotText(ptd_struct *ptd, opcoord x, opcoord y, char *charbuf, char rchar, byte rattr, int slen)
  79. /*
  80.     Plot text/attribute buffers to screen at (x,y), clipped into ptd->relboxp.
  81. */
  82. {
  83.     win_type win;
  84.     opbox clipbox;
  85.     int delta;
  86.     int ichar;
  87.  
  88.     win = ptd->win;
  89.  
  90.     /* Clip the string so that it doesn't overlap its box anywhere */
  91.  
  92.     opbox_copy(&clipbox, ptd->relboxp);
  93.     opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
  94.     x += win_GetXmin(win);
  95.     y += win_GetYmin(win);
  96.  
  97.     delta = opbox_clipstring(&clipbox, &x, &y, &slen, win_GetFont(win));
  98.     if (slen <= 0) {
  99.         return;
  100.     }
  101.     if (charbuf != NULL) charbuf += delta;
  102.  
  103.     /* Do the nitty gritty */
  104.  
  105.     /* Note: these parameters put in the pcdata structure for use by */
  106.     /*  the plotchar function to save argument passing overhead:   */
  107.     /*  dispaddr, nplanes, ilmask, ilsize, vbincr, vidaddr, nsame, splitcol */
  108.  
  109.     y -= pcdata->fontlines;
  110.     pcdata->vidaddr = (y & pcdata->ilmask) * pcdata->ilsize +
  111.                         (y >> pc_ileave()) * pc_bwidth() +
  112.                          x * pc_pixbits() / 8;
  113.  
  114.     pcdata->splitcol = (*pcdata->attrcols)(rattr);
  115.     pcdata->starty = y;
  116.  
  117.     for (ichar = 0; ichar < slen; ) {
  118.  
  119.         /* Get character and figure out repeat count */
  120.         if (charbuf == NULL) {
  121.             pcdata->nsame = slen;
  122.         }
  123.         else {
  124.             rchar = *charbuf++;
  125.             pcdata->nsame = 1;
  126.             while (*charbuf == rchar) {
  127.                 if (ichar + pcdata->nsame >= slen) break;
  128.                 pcdata->nsame++;
  129.                 charbuf++;
  130.             }
  131.         }
  132.         /* Compute address of character in font */
  133.         if ((byte) rchar < 128) {
  134.             pcdata->fontoffs = pcdata->fontoffs0 +
  135.                                 ((unsigned) rchar) * pcdata->fontlines;
  136.             pcdata->fontseg = pcdata->fontseg0;
  137.         }
  138.         else {
  139.             pcdata->fontoffs = pcdata->fontoffs1 +
  140.                                 ((unsigned)((byte) rchar - 128)) * pcdata->fontlines;
  141.             pcdata->fontseg = pcdata->fontseg1;
  142.         }
  143.         /* Plot string of identical chars using info set up in pcdata */ 
  144.         (*pcdata->plotchar)();
  145.  
  146.         ichar += pcdata->nsame;
  147.         if (ichar >= slen) {
  148.             break;
  149.         }
  150.         pcdata->vidaddr += pcdata->nsame * pc_pixbits(); /* /8 *(fontwidth = 8) */
  151.     }
  152. }
  153. /* -------------------------------------------------------------------------- */
  154.  
  155. static void pc_gDrawCursor(ptd_struct *ptd, cursortype ctype)
  156. {
  157.     win_type win;
  158.     opbox cursbox;
  159.     opbox *opboxp;
  160.  
  161.     if (ctype != CURSOR_NONE) {
  162.         win = ptd->win;
  163.         dig_getcursbox(win, ctype, &cursbox);
  164.         cursbox.xmax += 1;    /* Compensate for getcursb making 7 bit box. */
  165.         if (opbox_clipbox(ptd->relboxp, &cursbox)) {
  166.             opboxp = ptd->relboxp;
  167.             ptd->relboxp = &cursbox;
  168.             ram_Clear(ptd, win_GetFgColor(win));
  169.             ptd->relboxp = opboxp;
  170.         }
  171.     }
  172. }
  173. /* -------------------------------------------------------------------------- */
  174.  
  175.