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

  1. /*
  2.     pcopen.c
  3.  
  4.     % PC device interface initialization
  5.  
  6.     5/16/88  by Ted.
  7.  
  8.     OWL 1.1
  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.  
  28. #include "pcpriv.h"
  29.  
  30. OGLOBAL pcdata_struct pcdatastruc;
  31.  
  32. OSTATIC boolean        DIGPRIV pc_initdata(_arg1(void));
  33. OSTATIC boolean        DIGPRIV pc_initdata2(_arg1(void));
  34. /* -------------------------------------------------------------------------- */
  35.  
  36. boolean DIGPRIV pc_OpenDIG(digp, mode, setinfo)
  37.     dig_struct *digp;
  38.     int mode;
  39.     pc_setinfo_fptr setinfo;
  40. /*
  41.     Perform the initial set-up operations on the DIG structure which are common
  42.     to all pc mode DIGs.
  43. */
  44. {
  45.     /* Fail if the current hardware cannot support the mode requested */
  46.     if (!pc_ModeSupport(mode)) {
  47.         return(FALSE);
  48.     }
  49.     /* Don't allow the same pcdata to be initted twice */
  50.     if (pc_inuse()) {    /* (see if pcdata has already been initialized) */
  51.         return(FALSE);    /* (Note: depends on static struct initted to NULL's */
  52.     }
  53.     /* Point the DIG struct's DIG-specific data pointer to pcdata so it can */
  54.     /* be saved and swapped later on. Note: pchdata not included, so it won't */
  55.     /* be swapped. */
  56.     digp->data = (VOID *) &pcdatastruc;
  57.     digp->datasize = sizeof(pcdatastruc);
  58.  
  59.     /* Set up the generic information in pcdata */
  60.     if (!pc_initdata()) {
  61.         return(FALSE);
  62.     }
  63.     /* Set up the mode-specific information in pcdata */
  64.     if (!(*setinfo)(mode)) {
  65.         return(FALSE);
  66.     }
  67.  
  68.     /* Finish initting data, init display mode */
  69.     if (!pc_initdata2()) {
  70.         pc_CloseDIG(digp);
  71.         return(FALSE);
  72.     }
  73.     /* Set up the hardware-related part of the DIG structure and its data */
  74.     pc_hOpen(digp);
  75.  
  76.     /* Init hardware */
  77.     if (!(*digp->hControl)(HC_OPEN, NULL, NULL)) {
  78.         pc_CloseDIG(digp);
  79.         return(FALSE);
  80.     }
  81.     return(TRUE);
  82. }
  83. /* -------------------------------------------------------------------------- */
  84.  
  85. void pc_CloseDIG(digp)
  86.     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()
  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.     pcdata->h = pchdata;
  142.  
  143.     return(TRUE);
  144. }
  145. /* -------------------------------------------------------------------------- */
  146. #define DISPWIDTH    230
  147. #define DISPHEIGHT    160
  148.  
  149. static boolean DIGPRIV pc_initdata2()
  150. /*
  151.     General initialization performed based on contents of info structure.
  152.     Allocates system colormap copy and copies default colormap into it.
  153. */
  154. {
  155.     /* interleave factor table: (2 ** factor) - 1 */
  156.     static byte ilmasktab[3] = { 0, 1, 3 };
  157.  
  158.     unsigned short fontvec[2];
  159.  
  160.     /* Don't really know display size; use a guess */
  161.     pcdata->info.xpixperm = (unsigned)
  162.         ((long) pcdata->info.dispmap->width * 1000 / DISPWIDTH);
  163.     pcdata->info.ypixperm = (unsigned)
  164.         ((long) pcdata->info.dispmap->height* 1000 / DISPHEIGHT);
  165.  
  166.     if (pcdata->info.defcolmap != NULL) {
  167.         /* Allocate system color map the right size.  */
  168.         /* Note: can't call ocolmap_Open because it refers to the system colmap */
  169.         pcdata->colmap = (ocolmap_type) omalloc(OA_DIGCOLMAP,
  170.                 (SIZE_T) ocolmap_GetSize((unsigned) pcdata->info.ncolors));
  171.         if (pcdata->colmap != NULL) {
  172.             pcdata->colmap->firstpix = 0;
  173.             pcdata->colmap->nentries = (unsigned) pcdata->info.ncolors;
  174.             ocolmap_set(pcdata->colmap, pcdata->info.defcolmap);
  175.         }
  176.         else return(FALSE);
  177.     }
  178.     /* Initialize display mode to the one this DIG represents */
  179.     pc_initmode();
  180.  
  181.     /* Make def_font.req = def_font.real */
  182.       pcdata->info.def_font.req.height = pcdata->info.def_font.real.height;
  183.  
  184.     /* Initialize pcdata struct elements looked at in font plotting */
  185.     pcdata->dispseg = (unsigned short) pcdata->info.dispaddr;
  186.     pcdata->nplanes = pcdata->info.nplanes;
  187.  
  188.     pcdata->ilmask = ilmasktab[pc_ileave()];
  189.     pcdata->ilsize = pc_ilsize();
  190.     pcdata->vbincr = pc_bwidth() - pcdata->ilmask * pcdata->ilsize;
  191.  
  192.     /* If the setinfo func didn't set fontlines, make it the font height */
  193.     if (pcdata->fontlines == 0) {
  194.         pcdata->fontlines = pcdata->info.def_font.real.height;
  195.     }
  196.     /* If the setinfo func didn't set font addr, make it the curr. BIOS font. */
  197.     if (pcdata->fontseg0 == 0) {
  198.     /* Get the font address from int 43 */
  199.         ram_segtomem(0x00, 4 * BIOS_FONTVEC, (byte *) fontvec, 4);
  200.         pcdata->fontseg0  = fontvec[1];
  201.         pcdata->fontoffs0 = fontvec[0];
  202.     }
  203.     /* Extended ASCII font pointer points to second half of font table */
  204.     /* (Assumes 1-byte wide font characters) */
  205.     if (pcdata->fontseg1 == 0) {
  206.         pcdata->fontseg1  = pcdata->fontseg0;
  207.         pcdata->fontoffs1 = pcdata->fontoffs0 + 128 * pcdata->fontlines;
  208.     }
  209.     return(TRUE);
  210. }
  211. /* -------------------------------------------------------------------------- */
  212.  
  213.