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

  1. /*
  2.     os2open.c
  3.  
  4.     % OS/2 device interface initialization
  5.  
  6.     11/11/88  by Ted.
  7.  
  8.     OWL
  9.     Copyright (c) 1988, by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      4/09/89 ted    converted for static digdata.
  15.      4/22/89 ted    added digpriv's.
  16.      8/08/89 ted    removed dispid and changed mmwidth/height to x/ypixperm
  17.      9/11/89 gam    added some casts for Version 1.1
  18. */
  19.  
  20. #include "os2priv.h"
  21.  
  22. #ifdef OAK_OS2            /* Only compile this for OS2 */
  23.  
  24. os2data_struct os2datastruc;
  25.  
  26. static void        DIGPRIV os2_initdata(_arg1(void));
  27. static boolean    DIGPRIV os2_setinfo(_arg1(VIOMODEINFO *));
  28.  
  29. /* -------------------------------------------------------------------------- */
  30.  
  31. boolean DIGPRIV os2_OpenDIG(digp, mode)
  32.     dig_struct *digp;
  33.     VIOMODEINFO *mode;
  34. {
  35.     byte os2mode;
  36.  
  37.     /* Don't allow the same os2data to be initted twice */
  38.     if (os2_inuse()) {    /* (see if os2data struct has already been initted) */
  39.         return(FALSE);    /* (Note: depends on static struct initted to NULL's */
  40.     }
  41.     /* Point the DIG struct's DIG-specific data pointer to os2data */
  42.     /* Note: os2/pc_hdata is not included */
  43.     digp->data = (VOID *) &os2datastruc;
  44.     digp->datasize = sizeof(os2datastruc);
  45.  
  46.     /* Set up the generic information in os2data */
  47.     os2_initdata();
  48.  
  49.     /* Set up the mode-specific information in os2data */
  50.     if (!os2_setinfo(mode)) {
  51.         return(FALSE);
  52.     }
  53.  
  54. #ifdef OAK_FAMILYAPI
  55.     /* Set up the hardware-related part of the DIG structure and its data */
  56.     DosGetMachineMode(&os2mode);
  57.  
  58.     /* Use the regular PC hardware interface in OS/2 dos box */
  59.     if (!os2mode) {
  60.         os2data->h = pchdata;
  61.  
  62.         /* For use in dosbox mouse handler */
  63.         pchdata->ymouscale = 8;
  64.         pchdata->xmouscale = 8;
  65.  
  66.         pc_hOpen(digp);        /* init hardware pointers */
  67.     }
  68.     else {
  69.         os2data->h = os2hdata;
  70.         os2_hOpen(digp);    /* init hardware pointers */
  71.     }
  72. #else
  73.     oak_notused(os2mode);
  74.     os2data->h = os2hdata;
  75.     os2_hOpen(digp);    /* init hardware pointers */
  76. #endif
  77.  
  78.     /* Init hardware */
  79.     if (!(*digp->hControl)(HC_OPEN, NULL, NULL)) {
  80.         os2_CloseDIG(digp);
  81.         return(FALSE);
  82.     }
  83.     /* Initialize display mode to the one this DIG represents */
  84.     os2_initmode();
  85.  
  86.     return(TRUE);
  87. }
  88. /* -------------------------------------------------------------------------- */
  89.  
  90. void os2_CloseDIG(digp)
  91.     dig_struct *digp;
  92. /*
  93.     Close a DIG and free any data it might have allocated.
  94. */
  95. {
  96.     /* Close down hardware funcs as well */
  97.     (*digp->hControl)(HC_CLOSE, NULL, NULL);
  98.  
  99.     /* Wipe the dig data structure clean again */
  100.     memset(os2data, 0, sizeof(os2data_struct));
  101. }
  102. /* -------------------------------------------------------------------------- */
  103.  
  104. static void DIGPRIV os2_initdata()
  105. /*
  106.     Set up the generic information in os2data.
  107. */
  108. {
  109.     int i;
  110. /* info struct will be initted later */
  111.  
  112.     os2data->hvio = 0;
  113.  
  114.     os2data->oldmode.cb = sizeof(os2data->oldmode);
  115.     VioGetMode(&os2data->oldmode, os2data->hvio);
  116.     VioGetCurPos((PUSHORT)&os2data->oldcursy, (PUSHORT)&os2data->oldcursx, os2data->hvio);
  117.     os2data->curctype = CURSOR_NONE;
  118.  
  119.     /* Init this now; HC_OPEN in os2_hOpen will fix it if it should be FALSE */
  120.     os2data->dosbox = TRUE;
  121.  
  122.     /* Set up attrmap */
  123.     for (i = 0; i < 256; i++) {
  124.         os2data->attrmap[i] = (byte) i;
  125.     }
  126.     /* def_font struct should be filled in later */
  127.     /* hardware vars handled in HC_OPEN method */
  128. }
  129. /* -------------------------------------------------------------------------- */
  130.  
  131. void DIGPRIV os2_vsetcursortype(ctype)
  132.     cursortype ctype;
  133. {
  134.     opcoord start, end;
  135.     VIOCURSORINFO viociCursor;
  136.  
  137.     os2data->curctype = ctype;
  138.  
  139.     if (ctype == CURSOR_NONE) {
  140.         viociCursor.attr = -1;
  141.         viociCursor.yStart = 0;
  142.         viociCursor.cEnd = 0;
  143.     }
  144.     else {
  145.         viociCursor.attr = 0;
  146.         dig_getcurslines(ctype, os2data->fontlines, &start, &end);
  147.         viociCursor.yStart = start;
  148.         viociCursor.cEnd = end-1;
  149.     }
  150.     viociCursor.cx = 0;
  151.  
  152.     VioSetCurType(&viociCursor, os2data->hvio);
  153. }
  154. /* -------------------------------------------------------------------------- */
  155. /* Display width & height in mm - take a guess since we don't know */
  156. #define DISPWIDTH    230
  157. #define DISPHEIGHT    160
  158.  
  159. static boolean DIGPRIV os2_setinfo(mode)
  160.     VIOMODEINFO *mode;
  161. {
  162.     VIOPHYSBUF viopbuf;
  163.  
  164.     /* mode not used here */ oak_notused(mode);
  165.  
  166. /* Set up the device info structure */
  167.     os2data->info.mode = 0;                    /* Not applicable */
  168.     strncpy(os2data->info.devname, "OS/2 VIO VIRTUAL DEV.", DEVNAMELEN-1);
  169.     os2data->info.devname[DEVNAMELEN-1] = '\0';
  170.  
  171.     os2data->info.dispmap =  &os2data->dmspace;
  172.  
  173.     os2data->info.dispmap->width = os2data->oldmode.col;
  174.     os2data->info.dispmap->height = os2data->oldmode.row;
  175.     os2data->info.dispmap->onboard  = TRUE;            /* onboard */
  176.     os2data->info.dispmap->onscreen = TRUE;
  177.     /* xpos, ypos stay 0 */
  178.     /* xdata stays NULL */
  179.  
  180.     /* Set up display resolution numbers */
  181.     os2data->info.xpixperm = (unsigned)
  182.         ((long) os2data->info.dispmap->width * 1000 / DISPWIDTH);
  183.     os2data->info.ypixperm = (unsigned)
  184.         ((long) os2data->info.dispmap->height* 1000 / DISPHEIGHT);
  185.  
  186.     switch(os2data->oldmode.fbType) {
  187.     case 0:
  188.         viopbuf.pBuf = (byte *) VIO_MONOADDR;
  189.         viopbuf.cb = 4000;
  190.         os2data->info.colortype = DTYPE_MONOCHROME;
  191.         break;
  192.     case VGMT_OTHER:
  193.         viopbuf.pBuf = (byte *) VIO_CGAADDR;
  194.         viopbuf.cb = 4000;
  195.         os2data->info.colortype = DTYPE_MAPCOLOR;
  196.         break;
  197.     default:
  198.         return(FALSE);
  199.     }
  200.     VioGetPhysBuf(&viopbuf, os2data->hvio);
  201.  
  202.     os2data->info.dispaddr = viopbuf.asel[0];
  203.     os2data->info.bytewidth = 2 * os2data->oldmode.col;
  204.     /* ileave, ilsize stay 0 */
  205.     os2data->info.nplanes = 1;
  206.     os2data->info.pixbits = 16;
  207.  
  208.     os2data->info.ncolors = dig_powof2(os2data->oldmode.color);
  209.     /* colortype set in above switch */
  210.     /* colmap and defcolmap stay NULL */
  211.  
  212.     os2data->info.hardcursor = TRUE;
  213.     os2data->info.byteorder = BO_LSBYTFIRST;
  214.  
  215.     /* Set up font */
  216.     os2data->info.def_font.fontid = 0;
  217.     os2data->info.def_font.real.width = 1;
  218.     os2data->info.def_font.real.height = 1;
  219.     os2data->info.def_font.req.width = 1;
  220.     os2data->info.def_font.req.height = 1;
  221.     /* All other def_font real & req elements stay 0 */
  222.  
  223.     os2data->fontlines = os2data->oldmode.vres / os2data->oldmode.row;
  224.  
  225.     return(TRUE);
  226. }
  227. /* -------------------------------------------------------------------------- */
  228.  
  229. #else    /* ifndef OAK_OS2 */
  230. /* A dummy so compilers won't freak if everything else is ifdef'ed out. */
  231.     int os2funcsdummy(void);
  232.     int os2funcsdummy() { return(0); }
  233. #endif
  234.  
  235.