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

  1. /*
  2.     pcmcga.c
  3.  
  4.     %  PC MCGA support
  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.      4/14/89 ted     Added palette poking function.
  15.      5/06/89 ted    Added colormap initialization.
  16.      6/15/89 Ted    Added PlotText func.
  17.      7/10/89 ted    Installed new text-plotting approach.
  18.      7/12/89 ted    Added OSTATIC's and '_func' macros.
  19.      8/22/89 ted    Added fontdesc_struct elements to def_font initialization.
  20.      3/04/90 ted    Added support for DC_PV messages.
  21.      3/28/90 jmd    ansi-fied
  22. */
  23.  
  24. #define DEFDEFCMAPS        /* Define default pc cmap declarations in this file */
  25.  
  26. #include "pcpriv.h"
  27.  
  28. /* Declare and initialize default 256 color color map */
  29. /* Note: initializers are broken up so as not to choke the M5.1 compiler */
  30.  
  31. OGLOBAL ocolmap_struct(256) pcdefmcgamap =    PC_DEF_MCGAMAPINIT0
  32.                                     PC_DEF_MCGAMAPINIT2
  33.                                     PC_DEF_MCGAMAPINIT4
  34.                                     PC_DEF_MCGAMAPINIT6
  35.                                     PC_DEF_MCGAMAPINIT8
  36.                                     PC_DEF_MCGAMAPINITA
  37.                                     PC_DEF_MCGAMAPINITC
  38.                                     PC_DEF_MCGAMAPINITE;
  39.  
  40. OSTATIC pc_setinfo_func        (mcga_setinfo);
  41. OSTATIC attrcols_func        (mcga_attrcols);
  42. OSTATIC dig_dControl_func    (mcga_dControl);
  43.  
  44. OSTATIC void DIGPRIV mcga_setfuncs(dig_struct *digp);
  45. OSTATIC void DIGPRIV mcga_setcolmap(ocolmap_type cmap);
  46.  
  47. /* -------------------------------------------------------------------------- */
  48.  
  49. boolean pc_Mode13(dig_struct *digp)
  50. {
  51.     return(pc_OpenMCGA(digp, 0x13));
  52. }
  53. /* -------------------------------------------------------------------------- */
  54.  
  55. boolean DIGPRIV pc_OpenMCGA(dig_struct *digp, int mode)
  56. {
  57.     if (!pc_OpenDIG(digp, mode, mcga_setinfo)) {
  58.         return(FALSE);
  59.     }
  60.     mcga_setfuncs(digp);
  61.     return(TRUE);
  62. }
  63. /* -------------------------------------------------------------------------- */
  64.  
  65. static void DIGPRIV mcga_setfuncs(dig_struct *digp)
  66. {
  67.     pc_setgfuncs(digp);        /* Set the standard ptrs & vars for pc graphics */
  68.  
  69.     digp->dControl      = mcga_dControl;
  70. }
  71. /* -------------------------------------------------------------------------- */
  72.  
  73. static dispinfo_struct mcgainfo = {
  74.     {'I','B','M',' ', 'P','C',' ','M', 'C','G','A',' ',
  75.      'G','R','A','P', 'H','I','C','S', 0,0},            /* devname */
  76.     0x13,            /* mode */
  77.     0, 0,            /* xpixperm, ypixperm */
  78.     &pcdatastruc.dmspace, /* dispmap */
  79.     VID_EVGAADDR,    /* dispaddr */
  80.     320,            /* bytewidth */
  81.     0,                /* ileave */
  82.     0,                /* ilsize */
  83.     1,                /* nplanes */
  84.     8,                /* pixbits */
  85.  
  86.     256L,            /* ncolors */
  87.     DTYPE_MAPCOLOR,    /* color type */
  88.     (ocolmap_type) &pcdefmcgamap,    /* defcolmap */
  89.  
  90.     FALSE,            /* hardcursor */
  91.     BO_LSBYTFIRST,    /* byteorder */
  92.     {                /* def_font */
  93.         0,                /* fontid */
  94.         { 8, 8, 0, 0,0,0, 0 },         /* real: width, height, style, etc. */
  95.         { 8, 8, 0, 0,0,0, 0 }         /* req:  width, height, style, etc. */
  96.     }
  97. };
  98. /* -------------------------------------------------------------------------- */
  99.  
  100. static boolean DIGPRIV mcga_setinfo(int mode)
  101. {
  102.     int i;
  103.  
  104.     /* Set up the device info structure */
  105.     memmove(&pcdata->info, &mcgainfo, sizeof(dispinfo_struct));
  106.     pc_initdispmap(320, 200);
  107.  
  108.     pcdata->info.mode = mode;
  109.  
  110.     /* Set up attrmap */
  111.     pcdata->attrsize = 8;    /* 8 bit attrmap elements */
  112.     pcdata->xattrmap = (byte *) omalloc(OA_DIGATTRMAP, 256 * sizeof(byte));
  113.     if (pcdata->xattrmap == NULL) {
  114.         return(FALSE);
  115.     }
  116.     /* Set up stuff for font plotter */
  117.     pcdata->attrcols = mcga_attrcols;
  118.     pcdata->plotchar = pc_8bitplotchar;
  119.  
  120.     for (i = 0; i < 256; i++) {
  121.         pcdata->attrmap[i]  = (byte) (i & 0x0F);
  122.         pcdata->xattrmap[i] = (byte) (i >> 4);
  123.     }
  124.     pchdata->xmouscale = 2;
  125.     pchdata->ymouscale = 1;
  126.  
  127.     return(TRUE);
  128. }
  129. /* -------------------------------------------------------------------------- */
  130.  
  131. static int mcga_dControl(dig_dcmsg msg, VOID *indata, VOID *outdata)
  132. {
  133.     setattr_struct *pvs;
  134.  
  135.     switch (msg) {
  136.     case DC_SETATTRCOLS:
  137.         pvs = (setattr_struct *)indata;
  138.  
  139.         pcdata->attrmap[pvs->attr]  = ((byte) (pvs->fg));
  140.         pcdata->xattrmap[pvs->attr] = ((byte) (pvs->bg));
  141.         break;
  142.     case DC_GETATTRFG:
  143.         *((opixval *) outdata) = (opixval)
  144.             pcdata->attrmap[*((byte *)indata)];
  145.         break;
  146.     case DC_GETATTRBG:
  147.         *((opixval *) outdata) = (opixval)
  148.             pcdata->xattrmap[*((byte *)indata)];
  149.         break;
  150.     case DC_SETCOLMAP:
  151.         mcga_setcolmap((ocolmap_type) indata);
  152.         break;
  153.     case DC_GETCOLMAP:
  154.         ocolmap_set((ocolmap_type) outdata, pcdata->colmap);
  155.         break;
  156.     case DC_PVFINDRGB:    /* indata is (findcol_struct *), outdata is (opixval *), ret is int dist or -1 for failure */
  157.     case DC_PVALLOC:    /* indata is void, outdata is (opixval *), ret is TRUE/FALSE */
  158.     case DC_PVMAKERO:    /* indata is (opixval *), outdata is void, ret is void */
  159.     case DC_PVFREE:        /* indata is (opixval *), outdata is void, ret is void */
  160.  
  161.     default:
  162.         return(pc_dControl(msg, indata, outdata));
  163.     }
  164.     return(TRUE);
  165. }
  166. /* -------------------------------------------------------------------------- */
  167.  
  168. static unsigned DIGPRIV mcga_attrcols(byte rattr)
  169. /*
  170.     Return a word with foreground pixval in the low byte and background
  171.     pixval in the high byte.
  172. */
  173. {
  174.     union {
  175.         struct { byte bot, top; } dblcol;
  176.         unsigned short x;
  177.     } splitcol;
  178.  
  179.     splitcol.dblcol.bot = pcdata->attrmap[rattr];
  180.     splitcol.dblcol.top = pcdata->xattrmap[rattr];
  181.  
  182.     return((unsigned) splitcol.x);
  183. }
  184. /* -------------------------------------------------------------------------- */
  185.  
  186. static void DIGPRIV mcga_setcolmap(ocolmap_type cmap)
  187. {
  188.     OREGS regs;
  189.     byte *rgbarray, *p, *endp;
  190.  
  191.     if (cmap == NULL) {
  192.         return;
  193.     }
  194. /* Write new vals */
  195.     regs.x.ax = 0x1012;            /* int 10h, funtion 10.12: set block of regs */
  196.     regs.x.bx = (int) cmap->firstpix;        /* start */
  197.     regs.x.cx = (int) cmap->nentries;        /* count */
  198.  
  199.     rgbarray = (byte *)ocolmap_entry(cmap, cmap->firstpix);
  200.     endp = rgbarray + cmap->nentries * 3;
  201.     for (p = rgbarray; p < endp; p++) *p = *p >> 2; /* Scale rgb values for bios */
  202.  
  203.     /* put table address in es:dx */
  204.     regs.a.esdx = rgbarray;        /* dest. table address */
  205.     oakint86es(BIOS_VIDINT, ®s, cmap->nentries * 3);
  206.     for (p = rgbarray; p < endp; p++) *p = (*p << 2)+3; /* Un-scale rgb values again */
  207.  
  208.     /* Copy the info into our colmap copy */
  209.     ocolmap_set(pcdata->colmap, cmap);
  210. }
  211. /* -------------------------------------------------------------------------- */
  212.  
  213.