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

  1. /*
  2.     pcopen.c
  3.  
  4.     % PC device interface initialization
  5.  
  6.     5/16/88  by Ted.
  7.  
  8.     OWL-PC 1.2
  9.     Copyright (c) 1988, 1989 by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      8/17/88 jmd      removed  eNOMEM
  15.      1/14/89 ted    extracted pc_getcurslines to pcgcursl.c for better shareability.
  16.      2/05/89 ted    moved pc_wordcolor in from its own file.
  17.      3/19/89 ted    made pcdata static.
  18.      4/04/89 ted    Added FreeFont function.
  19.      4/24/89 ted    Renamed from pcfuncs.c, moved dig funcs to pcdisp.c.
  20.      4/26/89 ted    Moved attrmap out of info struct into pcdata.
  21.      5/06/89 ted    Added colormap initialization.
  22.      7/05/89 ted    Changed the display mode initialization sequence, added
  23.                         fontseg, fontoffs, dispseg initialization.
  24.      7/12/89 ted    Added OSTATIC's and '_func' macros.
  25.      7/14/89 ted    Added more video initialization (ilmask, ilsize, vbincr).
  26.  
  27.     11/05/89 ted    Added DOS_ZEROSEG macro.
  28.     11/08/89 ted    Added pcdata->brmask initialization for pc_roundbyte macros.
  29.      3/28/90 jmd    ansi-fied
  30.      6/22/90 ted    added "void"s to no-parameter functions per ansii.
  31. */
  32.  
  33. #include "pcpriv.h"
  34.  
  35. OGLOBAL pcdata_struct pcdatastruc;
  36.  
  37. OSTATIC boolean DIGPRIV pc_initdata(void);
  38. OSTATIC boolean DIGPRIV pc_initdata2(void);
  39. /* -------------------------------------------------------------------------- */
  40.  
  41. boolean DIGPRIV pc_OpenDIG(dig_struct *digp, int mode, pc_setinfo_fptr setinfo)
  42. /*
  43.     Perform the initial set-up operations on the DIG structure which are common
  44.     to all pc mode DIGs.
  45. */
  46. {
  47.     /* Fail if the current hardware cannot support the mode requested */
  48.     if (!pc_ModeSupport(mode)) {
  49.         return(FALSE);
  50.     }
  51.     /* Don't allow the same pcdata to be initted twice */
  52.     if (pc_inuse()) {    /* (see if pcdata has already been initialized) */
  53.         return(FALSE);    /* (Note: depends on static struct initted to NULL's */
  54.     }
  55.     /* Point the DIG struct's DIG-specific data pointer to pcdata so it can */
  56.     /* be saved and swapped later on. */
  57.     digp->data = (VOID *) &pcdatastruc;
  58.     digp->datasize = sizeof(pcdatastruc);
  59.  
  60.     /* Set up the generic information in pcdata */
  61.     if (!pc_initdata()) {
  62.         return(FALSE);
  63.     }
  64.     /* Set up the mode-specific information in pcdata */
  65.     if (!(*setinfo)(mode)) {
  66.         return(FALSE);
  67.     }
  68.  
  69.     /* Finish initting data, init display mode */
  70.     if (!pc_initdata2()) {
  71.         pc_CloseDIG(digp);
  72.         return(FALSE);
  73.     }
  74.     /* Set up the hardware-related part of the DIG structure and its data */
  75.     pc_hOpen(digp);
  76.  
  77.     /* Init hardware */
  78.     if (!(*digp->hControl)(HC_OPEN, NULL, NULL)) {
  79.         pc_CloseDIG(digp);
  80.         return(FALSE);
  81.     }
  82.     return(TRUE);
  83. }
  84. /* -------------------------------------------------------------------------- */
  85.  
  86. void pc_CloseDIG(dig_struct *digp)
  87. /*
  88.     Close a DIG and free any data it might have allocated.
  89. */
  90. {
  91.     /* Free xattrmap if present */
  92.     if (pcdata->xattrmap != NULL) {
  93.         ofree(OA_DIGATTRMAP, (VOID *) pcdata->xattrmap);
  94.     }
  95.     /* Free colormap copy if any was allocated */
  96.     if (pcdata->colmap != NULL) {
  97.         ofree(OA_DIGCOLMAP, (VOID *) pcdata->colmap);
  98.     }
  99.     /* Close down hardware funcs as well */
  100.     (*digp->hControl)(HC_CLOSE, NULL, NULL);
  101.  
  102.     /* Wipe the dig data structure clean again */
  103.     memset(pcdata, 0, sizeof(pcdata_struct));
  104. }
  105. /* -------------------------------------------------------------------------- */
  106.  
  107. static boolean DIGPRIV pc_initdata(void)
  108. /*
  109.     General initialization of the pcdata structure.
  110.     (The info struct will be initted later - in setinfo).
  111. */
  112. {
  113.     int i;
  114.  
  115.     pcdata->oldmode = pc_GetMode();
  116.     pc_bgetcursorpos(&pcdata->oldcursx, &pcdata->oldcursy);
  117.     pcdata->curctype = CURSOR_NONE;
  118.  
  119.     /* Start with fontseg, fontoffs clear so we'll know if it's set in setinfo */
  120.     /* Start with retrace flag off. It may be set on later in the init process */
  121.     /* (pcdata struct is guaranteed to start out cleared to 0's) */
  122. /*    pcdata->fontseg  = pcdata->fontoffs = 0; */
  123. /*    pc_setretrace(FALSE); */
  124.  
  125.     /* init static dispmap space structure */
  126.     /* width & height stay 0 for now - initted later (in setinfo) */
  127.     pcdata->dmspace.onboard  = TRUE;            /* onboard */
  128.     pcdata->dmspace.onscreen = TRUE;
  129.     /* xpos, ypos stay 0 */
  130.     /* xdata stays NULL */
  131.  
  132.     /* init attrmap assuming 4-bit color values */
  133.     /* (this effort will be duplicated in mode 13) */
  134.     pcdata->attrsize = 4;    /* 4 bit attrmap elements */
  135.     for (i = 0; i < 256; i++) {
  136.         pcdata->attrmap[i] = (byte) i;
  137.     }
  138.     /* def_font struct should be filled in later */
  139.     /* hardware vars handled in HC_OPEN method */
  140.  
  141.     /* Chain pcdata to pchdata so it can be saved and swapped later on. */
  142.     pcdata->h = (VOID *) pchdata;
  143.     pcdata->hdatasize = sizeof(pchdata_struct);
  144.  
  145.     return(TRUE);
  146. }
  147. /* -------------------------------------------------------------------------- */
  148. #define DISPWIDTH    230
  149. #define DISPHEIGHT    160
  150.  
  151. static boolean DIGPRIV pc_initdata2(void)
  152. /*
  153.     General initialization performed based on contents of info structure.
  154.     Allocates system colormap copy and copies default colormap into it.
  155. */
  156. {
  157.     /* interleave factor table: (2 ** factor) - 1 */
  158.     static byte ilmasktab[3] = { 0, 1, 3 };
  159.  
  160.     unsigned short fontvec[2];
  161.  
  162.     /* Don't really know display size; use a guess */
  163.     pcdata->info.xpixperm = (unsigned)
  164.         ((long) pcdata->info.dispmap->width * 1000 / DISPWIDTH);
  165.     pcdata->info.ypixperm = (unsigned)
  166.         ((long) pcdata->info.dispmap->height* 1000 / DISPHEIGHT);
  167.  
  168.     if (pcdata->info.defcolmap != NULL) {
  169.         /* Allocate system color map the right size.  */
  170.         /* Note: can't call ocolmap_Open because it refers to the system colmap */
  171.         pcdata->colmap = (ocolmap_type) omalloc(OA_DIGCOLMAP,
  172.                 (SIZE_T) ocolmap_GetSize((unsigned) pcdata->info.ncolors));
  173.         if (pcdata->colmap != NULL) {
  174.             pcdata->colmap->firstpix = 0;
  175.             pcdata->colmap->nentries = (unsigned) pcdata->info.ncolors;
  176.             ocolmap_set(pcdata->colmap, pcdata->info.defcolmap);
  177.         }
  178.         else return(FALSE);
  179.     }
  180.     /* Initialize display mode to the one this DIG represents */
  181.     pc_initmode();
  182.  
  183.     /* Make def_font.req = def_font.real */
  184.       pcdata->info.def_font.req.height = pcdata->info.def_font.real.height;
  185.  
  186.     /* Initialize pcdata struct elements looked at in font plotting */
  187.     pcdata->dispseg = (unsigned short) pcdata->info.dispaddr;
  188.     pcdata->nplanes = pcdata->info.nplanes;
  189.  
  190.     pcdata->ilmask = ilmasktab[pc_ileave()];
  191.     pcdata->ilsize = pc_ilsize();
  192.     pcdata->vbincr = pc_bwidth() - pcdata->ilmask * pcdata->ilsize;
  193.  
  194.     /* set the byte rounding mask */
  195.     pcdata->brmask = 8 / pc_pixbits();
  196.     if (pcdata->brmask > 0) pcdata->brmask -= 1;
  197.  
  198.     /* If the setinfo func didn't set fontlines, make it the font height */
  199.     if (pcdata->fontlines == 0) {
  200.         pcdata->fontlines = pcdata->info.def_font.real.height;
  201.     }
  202.     /* If the setinfo func didn't set font addr, make it the curr. BIOS font. */
  203.     if (pcdata->fontseg0 == 0) {
  204.     /* Get the font address from int 43 */
  205.         ram_segtomem(DOS_ZEROSEG, 4 * BIOS_FONTVEC, (byte *) fontvec, 4);
  206.         pcdata->fontseg0  = fontvec[1];
  207.         pcdata->fontoffs0 = fontvec[0];
  208.     }
  209.     /* Extended ASCII font pointer points to second half of font table */
  210.     /* (Assumes 1-byte wide font characters) */
  211.     if (pcdata->fontseg1 == 0) {
  212.         pcdata->fontseg1  = pcdata->fontseg0;
  213.         pcdata->fontoffs1 = pcdata->fontoffs0 + 128 * pcdata->fontlines;
  214.     }
  215.     return(TRUE);
  216. }
  217. /* -------------------------------------------------------------------------- */
  218.  
  219.