home *** CD-ROM | disk | FTP | other *** search
- /*
- os2open.c
-
- % OS/2 device interface initialization
-
- 11/11/88 by Ted.
-
- OWL
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 4/09/89 ted converted for static digdata.
- 4/22/89 ted added digpriv's.
- 8/08/89 ted removed dispid and changed mmwidth/height to x/ypixperm
- 9/11/89 gam added some casts for Version 1.1
- */
-
- #include "os2priv.h"
-
- #ifdef OAK_OS2 /* Only compile this for OS2 */
-
- os2data_struct os2datastruc;
-
- static void DIGPRIV os2_initdata(_arg1(void));
- static boolean DIGPRIV os2_setinfo(_arg1(VIOMODEINFO *));
-
- /* -------------------------------------------------------------------------- */
-
- boolean DIGPRIV os2_OpenDIG(digp, mode)
- dig_struct *digp;
- VIOMODEINFO *mode;
- {
- byte os2mode;
-
- /* Don't allow the same os2data to be initted twice */
- if (os2_inuse()) { /* (see if os2data struct has already been initted) */
- return(FALSE); /* (Note: depends on static struct initted to NULL's */
- }
- /* Point the DIG struct's DIG-specific data pointer to os2data */
- /* Note: os2/pc_hdata is not included */
- digp->data = (VOID *) &os2datastruc;
- digp->datasize = sizeof(os2datastruc);
-
- /* Set up the generic information in os2data */
- os2_initdata();
-
- /* Set up the mode-specific information in os2data */
- if (!os2_setinfo(mode)) {
- return(FALSE);
- }
-
- #ifdef OAK_FAMILYAPI
- /* Set up the hardware-related part of the DIG structure and its data */
- DosGetMachineMode(&os2mode);
-
- /* Use the regular PC hardware interface in OS/2 dos box */
- if (!os2mode) {
- os2data->h = pchdata;
-
- /* For use in dosbox mouse handler */
- pchdata->ymouscale = 8;
- pchdata->xmouscale = 8;
-
- pc_hOpen(digp); /* init hardware pointers */
- }
- else {
- os2data->h = os2hdata;
- os2_hOpen(digp); /* init hardware pointers */
- }
- #else
- oak_notused(os2mode);
- os2data->h = os2hdata;
- os2_hOpen(digp); /* init hardware pointers */
- #endif
-
- /* Init hardware */
- if (!(*digp->hControl)(HC_OPEN, NULL, NULL)) {
- os2_CloseDIG(digp);
- return(FALSE);
- }
- /* Initialize display mode to the one this DIG represents */
- os2_initmode();
-
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
-
- void os2_CloseDIG(digp)
- dig_struct *digp;
- /*
- Close a DIG and free any data it might have allocated.
- */
- {
- /* Close down hardware funcs as well */
- (*digp->hControl)(HC_CLOSE, NULL, NULL);
-
- /* Wipe the dig data structure clean again */
- memset(os2data, 0, sizeof(os2data_struct));
- }
- /* -------------------------------------------------------------------------- */
-
- static void DIGPRIV os2_initdata()
- /*
- Set up the generic information in os2data.
- */
- {
- int i;
- /* info struct will be initted later */
-
- os2data->hvio = 0;
-
- os2data->oldmode.cb = sizeof(os2data->oldmode);
- VioGetMode(&os2data->oldmode, os2data->hvio);
- VioGetCurPos((PUSHORT)&os2data->oldcursy, (PUSHORT)&os2data->oldcursx, os2data->hvio);
- os2data->curctype = CURSOR_NONE;
-
- /* Init this now; HC_OPEN in os2_hOpen will fix it if it should be FALSE */
- os2data->dosbox = TRUE;
-
- /* Set up attrmap */
- for (i = 0; i < 256; i++) {
- os2data->attrmap[i] = (byte) i;
- }
- /* def_font struct should be filled in later */
- /* hardware vars handled in HC_OPEN method */
- }
- /* -------------------------------------------------------------------------- */
-
- void DIGPRIV os2_vsetcursortype(ctype)
- cursortype ctype;
- {
- opcoord start, end;
- VIOCURSORINFO viociCursor;
-
- os2data->curctype = ctype;
-
- if (ctype == CURSOR_NONE) {
- viociCursor.attr = -1;
- viociCursor.yStart = 0;
- viociCursor.cEnd = 0;
- }
- else {
- viociCursor.attr = 0;
- dig_getcurslines(ctype, os2data->fontlines, &start, &end);
- viociCursor.yStart = start;
- viociCursor.cEnd = end-1;
- }
- viociCursor.cx = 0;
-
- VioSetCurType(&viociCursor, os2data->hvio);
- }
- /* -------------------------------------------------------------------------- */
- /* Display width & height in mm - take a guess since we don't know */
- #define DISPWIDTH 230
- #define DISPHEIGHT 160
-
- static boolean DIGPRIV os2_setinfo(mode)
- VIOMODEINFO *mode;
- {
- VIOPHYSBUF viopbuf;
-
- /* mode not used here */ oak_notused(mode);
-
- /* Set up the device info structure */
- os2data->info.mode = 0; /* Not applicable */
- strncpy(os2data->info.devname, "OS/2 VIO VIRTUAL DEV.", DEVNAMELEN-1);
- os2data->info.devname[DEVNAMELEN-1] = '\0';
-
- os2data->info.dispmap = &os2data->dmspace;
-
- os2data->info.dispmap->width = os2data->oldmode.col;
- os2data->info.dispmap->height = os2data->oldmode.row;
- os2data->info.dispmap->onboard = TRUE; /* onboard */
- os2data->info.dispmap->onscreen = TRUE;
- /* xpos, ypos stay 0 */
- /* xdata stays NULL */
-
- /* Set up display resolution numbers */
- os2data->info.xpixperm = (unsigned)
- ((long) os2data->info.dispmap->width * 1000 / DISPWIDTH);
- os2data->info.ypixperm = (unsigned)
- ((long) os2data->info.dispmap->height* 1000 / DISPHEIGHT);
-
- switch(os2data->oldmode.fbType) {
- case 0:
- viopbuf.pBuf = (byte *) VIO_MONOADDR;
- viopbuf.cb = 4000;
- os2data->info.colortype = DTYPE_MONOCHROME;
- break;
- case VGMT_OTHER:
- viopbuf.pBuf = (byte *) VIO_CGAADDR;
- viopbuf.cb = 4000;
- os2data->info.colortype = DTYPE_MAPCOLOR;
- break;
- default:
- return(FALSE);
- }
- VioGetPhysBuf(&viopbuf, os2data->hvio);
-
- os2data->info.dispaddr = viopbuf.asel[0];
- os2data->info.bytewidth = 2 * os2data->oldmode.col;
- /* ileave, ilsize stay 0 */
- os2data->info.nplanes = 1;
- os2data->info.pixbits = 16;
-
- os2data->info.ncolors = dig_powof2(os2data->oldmode.color);
- /* colortype set in above switch */
- /* colmap and defcolmap stay NULL */
-
- os2data->info.hardcursor = TRUE;
- os2data->info.byteorder = BO_LSBYTFIRST;
-
- /* Set up font */
- os2data->info.def_font.fontid = 0;
- os2data->info.def_font.real.width = 1;
- os2data->info.def_font.real.height = 1;
- os2data->info.def_font.req.width = 1;
- os2data->info.def_font.req.height = 1;
- /* All other def_font real & req elements stay 0 */
-
- os2data->fontlines = os2data->oldmode.vres / os2data->oldmode.row;
-
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
-
- #else /* ifndef OAK_OS2 */
- /* A dummy so compilers won't freak if everything else is ifdef'ed out. */
- int os2funcsdummy(void);
- int os2funcsdummy() { return(0); }
- #endif
-
-