home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / PCDISP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-06  |  6.3 KB  |  229 lines

  1. /*
  2.     pcdisp.c
  3.  
  4.     % PC device interface display functions common to all modes.
  5.  
  6.     4/24/89  by Ted.
  7.  
  8.     OWL-PC 1.2
  9.     Copyright (c) 1989 by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      4/26/89 ted    Moved attrmap out of info struct into pcdata.
  15.      8/01/89 ted    Moved pc_init/restoremode from pcmode.c.
  16.  
  17.     11/03/89 ted    Allowed blinking text wordcolor values.
  18.     11/07/89 ted    Changed reference to pcdata->oldmode to pc_GetMode in
  19.                     pc_initmode to facilitate curr_dmgr swapping.
  20.  
  21.      1/08/90 ted    Made GETATTRFG/BG msgs return all 8 bits to fix ptd_Clear
  22.                     problem, and made pc_wordcolor use all 8 bits for text mode.
  23.     
  24.      2/14/90 ted    Got rid of fontreq_struct. Just use fontdesc_struct.
  25.      3/04/90 ted    Added non-functional support for DC_PV messages.
  26.      3/21/90 ted    Added DC_HIDEMOUSE, DC_SHOWMOUSE cases to pc_dControl
  27.      3/28/90 jmd    ansi-fied
  28.      6/22/90 ted    added "void"s to no-parameter functions per ansii.
  29.     12/05/90 ted    tweaked wordcolor text-mode same-color case to intensify fg.
  30. */
  31.  
  32. #include "pcpriv.h"
  33.  
  34. OSTATIC void DIGPRIV pc_restoremode(void);
  35.  
  36. /* -------------------------------------------------------------------------- */
  37.  
  38. int pc_dControl(dig_dcmsg msg, VOID *indata, VOID *outdata)
  39. {
  40.     setattr_struct *pvs;
  41.     ptarg_struct *pta;
  42.     OREGS regs;
  43.  
  44.     switch (msg) {
  45.     case DC_GETINFO:
  46.         *((dispinfo_struct **)(outdata)) = &pcdata->info;
  47.         break;
  48.     case DC_INITMODE:
  49.         pc_initmode();
  50.         break;
  51.     case DC_RESTOREMODE:
  52.         pc_restoremode();
  53.         break;
  54.     case DC_SETATTRCOLS:
  55.         pvs = (setattr_struct *)indata;
  56.  
  57.         pcdata->attrmap[pvs->attr] =  ((byte) (pvs->fg)) & 0x0F;
  58.         pcdata->attrmap[pvs->attr] |= ((byte) (pvs->bg)) << 4;
  59.         break;
  60.     case DC_GETATTRFG:
  61.         *((opixval *) outdata) = (opixval) pcdata->attrmap[*((byte *)indata)];
  62.         break;
  63.     case DC_GETATTRBG:
  64.         *((opixval *) outdata) =
  65.             (opixval) ( (pcdata->attrmap[*((byte *)indata)] >> 4) |
  66.                         (pcdata->attrmap[*((byte *)indata)] << 4) );
  67.         break;
  68.     case DC_SETCOLMAP:
  69.     case DC_GETCOLMAP:
  70.         break;
  71.  
  72.     case DC_PVFINDRGB:    /* indata is (findcol_struct *), outdata is (opixval *), ret is int dist or -1 for failure */
  73.         return(-1);
  74.     case DC_PVALLOC:    /* indata is void, outdata is (opixval *), ret is TRUE/FALSE */
  75.     case DC_PVMAKERO:    /* indata is (opixval *), outdata is void, ret is void */
  76.     case DC_PVFREE:        /* indata is (opixval *), outdata is void, ret is void */
  77.         return(FALSE);
  78.  
  79.     case DC_OPENFONT:
  80.           memmove((VOID *)(ofont_type)outdata, (VOID *)&pcdata->info.def_font,
  81.                 sizeof(struct ofont_struct));
  82.           memmove((VOID *)(&((ofont_type)outdata)->req), (VOID *)indata,
  83.                 sizeof(fontdesc_struct));
  84.         break;
  85.     case DC_READCHARATTR:
  86.         pta = (ptarg_struct *)indata;
  87.         memset(pta->charbuf, ' ',  pta->slen);
  88.         memset(pta->attrbuf, 0x07, pta->slen);
  89.         break;
  90.     case DC_HIDEMOUSE:
  91.     case DC_CACHE:
  92.         if (pchdata->ismouse) {
  93.             regs.x.ax = BMOU_HIDE;
  94.             oakint86(BIOS_MOUSEINT, ®s);
  95.         }
  96.         break;
  97.     case DC_SHOWMOUSE:
  98.     case DC_FLUSH:
  99.         if (pchdata->ismouse) {
  100.             regs.x.ax = BMOU_SHOW;
  101.             oakint86(BIOS_MOUSEINT, ®s);
  102.         }
  103.         break;
  104.     }
  105.     return(TRUE);
  106. }
  107. /* -------------------------------------------------------------------------- */
  108.  
  109. unsigned short DIGPRIV pc_wordcolor(opixval color)
  110. /*
  111.     Return a 16 bit value which can be repeated to clear a region to the
  112.     given color. (Only used for one-plane pixmaps.)
  113. */
  114. {
  115.     unsigned short colword;
  116.     struct { byte bot, top; } dblcol;
  117.     static unsigned short cols4[4] = { 0x0000, 0x5555, 0xAAAA, 0xFFFF };
  118.     byte fgnib;
  119.  
  120.     switch (pc_pixbits()) {
  121.     case 16:    /* text mode */
  122.         dblcol.bot = ' ';
  123.         /* Put color val in bg slot, and take next 4 bits for fg slot, or
  124.             itensify bg for fg slot if next 4 are same as bg.
  125.             (We do this so that the DOS prompt will be visible in case program
  126.             exits w/ screen this color.)
  127.         */
  128.         dblcol.top = ((byte) color) << 4;
  129.  
  130.         fgnib = (((byte) color) >> 4) & 0x0F;
  131.         /* Ignore blink bit; don't take intensity bit; don't take MDA underline
  132.             fg attribute */
  133.         if (fgnib == (((byte) color) & 0x07) && fgnib != 1) {
  134.             fgnib |= 0x08;    /* Poke in the intensity bit to guarantee visibility */
  135.         }
  136.         dblcol.top |= fgnib;
  137.  
  138.         return(*((unsigned short *)&dblcol));
  139.     case 2:
  140.         colword = cols4[(byte)color & 0x03];
  141.         return(colword);
  142.     case 1:
  143.         if (pc_nplanes() <= 1) {    /* one-plane / 2-color display mode */
  144.             if ((byte)color & 1) {
  145.                 colword = 0xFFFF;
  146.             }
  147.             else {
  148.                 colword = 0x0000;
  149.             }
  150.             return(colword);
  151.         }
  152.         /* else no break; EGA/VGA clear requires the real color to write thru */
  153.     default:
  154.     case 8:
  155.         dblcol.bot = (byte)color;
  156.         dblcol.top = dblcol.bot;
  157.         return(*((unsigned short *)&dblcol));
  158.     }
  159. }
  160. /* -------------------------------------------------------------------------- */
  161.  
  162. void DIGPRIV pc_bgetcursorpos(int *rowp, int *colp)
  163. {
  164.     OREGS regs;
  165.     
  166.     regs.h.ah = VIDINT_GETC;
  167.     regs.h.bh = TEXT_RPAGE;
  168.     oakint86(BIOS_VIDINT, ®s);
  169.  
  170.     *colp = (int)regs.h.dl;        /* get global cursor col */
  171.     *rowp = (int)regs.h.dh;        /* get global cursor row */
  172. }
  173. /* -------------------------------------------------------------------------- */
  174.  
  175. unsigned pc_dDummy(void)
  176. {
  177.     return(0);
  178. }
  179. /* -------------------------------------------------------------------------- */
  180.  
  181. void DIGPRIV pc_initmode(void)
  182. /*
  183.     Init the display video mode.
  184. */
  185. {
  186.     if (pc_GetMode() != pcdata->info.mode) {
  187.         pc_SetMode(pcdata->info.mode);
  188.     }
  189.     /* Make sure cursor gets turned off if necessary */
  190.     switch (pcdata->info.mode) {
  191.     case 0x00:
  192.     case 0x01:
  193.     case 0x02:
  194.     case 0x03:
  195.     case 0x07:
  196.     case PCMODE_EGA43:
  197.     case PCMODE_VGA50:
  198.         pcdata->curctype = CURSOR_NONE;
  199.         pc_bsetcursortype(CURSOR_NONE, pcdata->fontlines);
  200.         break;
  201.     }
  202. }
  203. /* -------------------------------------------------------------------------- */
  204.  
  205. static void DIGPRIV pc_restoremode(void)
  206. {
  207.     if (pcdata->oldmode != pcdata->info.mode) {
  208.         pc_SetMode(pcdata->oldmode);
  209.         pc_bsetcursorpos(0, 0);
  210.     }
  211.     else {    /* If not changing modes or clearing screen, restore cursor pos */
  212.         pc_bsetcursorpos(pcdata->oldcursx, pcdata->oldcursy);
  213.     }
  214.     switch (pcdata->oldmode) {
  215.     case 0x00:
  216.     case 0x01:
  217.     case 0x02:
  218.     case 0x03:
  219.     case 0x07:
  220.     case PCMODE_EGA43:
  221.     case PCMODE_VGA50:
  222.         pc_bsetcursortype(CURSOR_NORMAL,
  223.                             (opcoord)((pcdata->oldmode == 0x07) ? 14 : 8));
  224.         break;
  225.     }
  226. }
  227. /* -------------------------------------------------------------------------- */
  228.  
  229.