home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / OS2OPEN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-05  |  6.5 KB  |  237 lines

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