home *** CD-ROM | disk | FTP | other *** search
- /*
- os2disp.c
-
- % OS/2 VIO text mode device interface functions.
-
- 11/11/88 by Ted.
-
- OWL 1.2
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 1/14/89 ted Removed redundant disp clips.
- 1/18/89 Ted changed call to PlotText for simplified interface.
- 4/09/89 ted converted for static digdata.
- 4/22/89 ted added digpriv's.
- 9/11/89 gam added some casts for Version 1.1
-
- 2/28/90 ted fixed invalid os2data->h references in CACHE/FLUSH methods.
- 3/29/90 ted added DC_HIDE/SHOWMOUSE msgs.
- 3/29/90 ted added vio_readattr to tweak clear color for scrolling.
- 4/05/90 jmd ansi-fied
- 9/15/90 ted added DC_PV... cases to Control function.
- 10/04/90 ted added casts to eliminate MC6.0 signed/unsigned warnings.
- */
-
- #include "os2priv.h"
-
- #ifdef OAK_OS2 /* Only compile this for OS2 */
-
- #define MAXPLOTLEN 132 /* the maximum length string PlotText can do */
-
- OSTATIC void DIGPRIV vio_setfuncs(dig_struct *digp);
- OSTATIC void DIGPRIV vio_cellcolor(opixval color, byte *cell);
-
- OSTATIC dig_dControl_func (vio_dControl);
- OSTATIC dig_pPlotText_func (vio_PlotText);
- OSTATIC dig_pDrawCursor_func (vio_DrawCursor);
- OSTATIC dig_pClear_func (vio_Clear);
- OSTATIC dig_pScrollBoxVt_func (vio_ScrollBoxVt);
- OSTATIC dig_pScrollBoxHz_func (vio_ScrollBoxHz);
-
- OSTATIC void DIGPRIV vio_ReadCharAttrbuf(ptd_struct *ptd, opcoord x, opcoord y, char *charbuf, byte *attrbuf, int slen);
- OSTATIC byte DIGPRIV vio_readattr(opcoord x, opcoord y);
- OSTATIC unsigned os2_dDummy(void);
-
- /* -------------------------------------------------------------------------- */
-
- boolean os2_ModeText(dig_struct *digp)
- {
- if (!os2_OpenDIG(digp, NULL)) {
- return(FALSE);
- }
- vio_setfuncs(digp);
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
-
- static void DIGPRIV vio_setfuncs(dig_struct *digp)
- {
- digp->CloseDIG = os2_CloseDIG;
- digp->dControl = vio_dControl;
-
- digp->pPlotText = vio_PlotText;
- digp->pDrawCursor = vio_DrawCursor;
- digp->pClear = vio_Clear;
- digp->pScrollBoxVt = vio_ScrollBoxVt;
- digp->pScrollBoxHz = vio_ScrollBoxHz;
-
- /* in hardware cursor text modes, no pixmap funcs are needed */
- digp->pDrawPixmap = (dig_pDrawPixmap_func ((*))) os2_dDummy;
- digp->pReadPixmap = (dig_pReadPixmap_func ((*))) os2_dDummy;
- digp->pControl = (dig_pControl_func ((*))) os2_dDummy;
-
- digp->vtscroll = TRUE;
- digp->hzscroll = TRUE;
- digp->textfree = FALSE;
- digp->evcheck = TRUE;
- digp->type = 0;
- digp->version = 0;
- }
- /* -------------------------------------------------------------------------- */
-
- static void DIGPRIV vio_cellcolor(opixval color, byte *cell)
- /*
- Return a 16 bit value which can be repeated to clear a region to the
- given color.
- */
- {
- cell[0] = ' ';
- /* put color val in bgcolor slot, and invert it for fgcolor slot */
- cell[1] = (byte) color & (byte) 0x07;
- cell[1] = (cell[1] ^ (byte) 0x07) | (byte)(cell[1] << 4);
- }
- /* -------------------------------------------------------------------------- */
-
- static int vio_dControl(dig_dcmsg msg, VOID *indata, VOID *outdata)
- {
- setattr_struct *pvs;
-
- switch (msg) {
- case DC_GETINFO:
- *((dispinfo_struct **)(outdata)) = &os2data->info;
- break;
- case DC_INITMODE:
- os2_initmode();
- break;
- case DC_RESTOREMODE:
- VioSetCurPos(os2data->oldcursy, os2data->oldcursx, os2data->hvio);
- os2_vsetcursortype(CURSOR_NORMAL);
- break;
- case DC_SETATTRCOLS:
- pvs = (setattr_struct *)indata;
-
- os2data->attrmap[pvs->attr] = (byte) pvs->fg & (byte) 0x0F;
- os2data->attrmap[pvs->attr] |= (byte) pvs->bg << 4;
- break;
- case DC_GETATTRFG:
- *((opixval *) outdata) = (opixval)
- (os2data->attrmap[*((byte *)indata)] & 0x0F);
- break;
- case DC_GETATTRBG:
- *((opixval *) outdata) = (opixval)
- (os2data->attrmap[*((byte *)indata)] >> 4);
- break;
- case DC_SETCOLMAP:
- case DC_GETCOLMAP:
- break;
-
- case DC_PVFINDRGB: /* indata is (findcol_struct *), outdata is (opixval *), ret is int dist or -1 for failure */
- return(-1);
- case DC_PVALLOC: /* indata is void, outdata is (opixval *), ret is TRUE/FALSE */
- case DC_PVMAKERO: /* indata is (opixval *), outdata is void, ret is void */
- case DC_PVFREE: /* indata is (opixval *), outdata is void, ret is void */
- return(FALSE);
-
- case DC_OPENFONT:
- memmove((VOID *)(ofont_type)outdata, (VOID *)&os2data->info.def_font,
- sizeof(struct ofont_struct));
- memmove((VOID *)(&((ofont_type)outdata)->req), (VOID *)indata,
- sizeof(fontdesc_struct));
- break;
- case DC_READCHARATTR:
- { ptarg_struct *pta = (ptarg_struct *)indata;
- vio_ReadCharAttrbuf(pta->ptd, pta->x, pta->y,
- pta->charbuf, pta->attrbuf, pta->slen);
- }
- break;
- #ifdef OAK_OS2FAPI
- case DC_HIDEMOUSE:
- case DC_CACHE:
- if (os2data->dosbox) {
- if (pchdata->ismouse) {
- OREGS regs;
- regs.x.ax = BMOU_HIDE;
- oakint86(BIOS_MOUSEINT, ®s);
- }
- }
- else {
- if (os2hdata->ismouse) {
- os2_dohide();
- }
- }
- break;
- case DC_SHOWMOUSE:
- case DC_FLUSH:
- if (os2data->dosbox) {
- if (pchdata->ismouse) {
- OREGS regs;
- regs.x.ax = BMOU_SHOW;
- oakint86(BIOS_MOUSEINT, ®s);
- }
- }
- else {
- if (os2hdata->ismouse) {
- os2_doshow();
- }
- }
- break;
- #else
- case DC_HIDEMOUSE:
- case DC_CACHE:
- if (os2hdata->ismouse) {
- os2_dohide();
- }
- break;
- case DC_SHOWMOUSE:
- case DC_FLUSH:
- if (os2hdata->ismouse) {
- os2_doshow();
- }
- break;
- #endif
- }
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
-
- static void vio_PlotText(ptd_struct *ptd, opcoord x, opcoord y, char *charbuf, char rchar, byte rattr, int slen)
- {
- win_type win;
- opbox clipbox;
- int delta;
- byte tbuf[2*MAXPLOTLEN];
-
- win = ptd->win;
-
- opbox_copy(&clipbox, ptd->relboxp);
- opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
- x += win_GetXmin(win);
- y += win_GetYmin(win);
-
- delta = opbox_clipstring(&clipbox, &x, &y, &slen, win_GetFont(win));
- if (slen <= 0) {
- return;
- }
- if (charbuf != NULL) charbuf += delta;
-
- y -= 1; /* Move y up to top of char box for vio cell address */
-
- rattr = os2data->attrmap[rattr];
-
- /* Index into buf for clipping. */
- if (charbuf != NULL) {
- /* Draw the string, interleaving chars with rattr */
- VioWrtCharStrAtt(charbuf, slen, y, x, &rattr, os2data->hvio);
- }
- else { /* no charbuf */
- /* Draw a string of rchar/rattr pairs */
- tbuf[0] = rchar;
- tbuf[1] = rattr;
- VioWrtNCell(tbuf, slen, y, x, os2data->hvio);
- }
- }
- /* -------------------------------------------------------------------------- */
-
- static void vio_DrawCursor(ptd_struct *ptd, cursortype ctype)
- {
- win_type win;
- opbox clipbox;
- int row, col;
- ofont_type font;
- opcoord x;
- opcoord y;
- int slen;
-
- win = ptd->win;
- font = win_GetFont(win);
-
- opbox_copy(&clipbox, ptd->relboxp);
- opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
- x = win_GetXmin(win) + win_GetCursx(win);
- y = win_GetYmin(win) + win_GetCursy(win);
-
- col = opcoord_GetXCol(x + ofont_GetWidth(font) - 1, font); /* round in */
- row = opcoord_GetYRow(y - 1, font);
- x = col * ofont_GetWidth(font);
- y = (row + 1) * ofont_GetHeight(font);
-
- slen = 1;
- opbox_clipstring(&clipbox, &x, &y, &slen, font);
- if (slen <= 0) {
- return;
- }
- if (ctype != CURSOR_NONE) {
- VioSetCurPos(row, col, os2data->hvio);
- }
- if (os2data->curctype != ctype) {
- os2_vsetcursortype(ctype);
- }
- }
- /* -------------------------------------------------------------------------- */
-
- static void vio_Clear(ptd_struct *ptd, opixval color)
- {
- win_type win;
- opbox scrbox;
- byte cell[2];
-
- win = ptd->win;
-
- opbox_copy(&scrbox, ptd->relboxp);
- opbox_trans(&scrbox, win_GetXmin(win), win_GetYmin(win));
-
- vio_cellcolor(color, cell);
-
- VioScrollUp(scrbox.ymin, scrbox.xmin,
- scrbox.ymax-1, scrbox.xmax-1,
- opbox_GetHeight(&scrbox), cell, os2data->hvio);
- }
- /* -------------------------------------------------------------------------- */
- static byte blank[2] = {0x20, 0x07};
- /* -------------------------------------------------------------------------- */
-
- static void vio_ScrollBoxVt(ptd_struct *ptd, opcoord nrows)
- {
- win_type win;
- opbox scrbox;
-
- if (nrows == 0) return;
-
- win = ptd->win;
-
- opbox_copy(&scrbox, ptd->relboxp);
- opbox_trans(&scrbox, win_GetXmin(win), win_GetYmin(win));
-
- if (nrows > 0) {
- if ((odim) nrows >= opbox_GetHeight(&scrbox)) return; /* quit if scroll all */
-
- blank[1] = vio_readattr(scrbox.xmin, scrbox.ymax - 1);
- VioScrollUp(scrbox.ymin, scrbox.xmin,
- scrbox.ymax-1, scrbox.xmax-1,
- nrows, blank, os2data->hvio);
- }
- else if (nrows < 0) {
- nrows = -nrows;
- if ((odim) nrows >= opbox_GetHeight(&scrbox)) return; /* quit if scroll all */
-
- blank[1] = vio_readattr(scrbox.xmin, scrbox.ymin);
- VioScrollDn(scrbox.ymin, scrbox.xmin,
- scrbox.ymax-1, scrbox.xmax-1,
- nrows, blank, os2data->hvio);
- }
- }
- /* -------------------------------------------------------------------------- */
-
- static void vio_ScrollBoxHz(ptd_struct *ptd, opcoord ncols)
- {
- win_type win;
- opbox scrbox;
-
- if (ncols == 0) return;
-
- win = ptd->win;
-
- opbox_copy(&scrbox, ptd->relboxp);
- opbox_trans(&scrbox, win_GetXmin(win), win_GetYmin(win));
-
- if (ncols > 0) {
- if ((odim) ncols >= opbox_GetWidth(&scrbox)) return; /* quit if scroll all */
-
- blank[1] = vio_readattr(scrbox.xmax - 1, scrbox.ymin);
- VioScrollLf(scrbox.ymin, scrbox.xmin,
- scrbox.ymax-1, scrbox.xmax-1,
- ncols, blank, os2data->hvio);
- }
- else if (ncols < 0) {
- ncols = -ncols;
- if ((odim) ncols >= opbox_GetWidth(&scrbox)) return; /* quit if scroll all */
-
- blank[1] = vio_readattr(scrbox.xmin, scrbox.ymin);
- VioScrollRt(scrbox.ymin, scrbox.xmin,
- scrbox.ymax-1, scrbox.xmax-1,
- ncols, blank, os2data->hvio);
- }
- }
- /* -------------------------------------------------------------------------- */
-
- static void DIGPRIV vio_ReadCharAttrbuf(ptd_struct *ptd, opcoord x, opcoord y, char *charbuf, byte *attrbuf, int slen)
- {
- win_type win;
- opbox clipbox;
- int delta;
- byte tbuf[2*MAXPLOTLEN];
-
- win = ptd->win;
-
- opbox_copy(&clipbox, ptd->relboxp);
- opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
- x += win_GetXmin(win);
- y += win_GetYmin(win);
-
- delta = opbox_clipstring(&clipbox, &x, &y, &slen, win_GetFont(win));
- if (slen <= 0) {
- return;
- }
- if (charbuf != NULL) charbuf += delta;
- if (attrbuf != NULL) attrbuf += delta;
-
- if (attrbuf == NULL || charbuf == NULL) {
- return;
- }
-
- /* Read the string in from display in char/attr form */
- if (slen > MAXPLOTLEN) slen = MAXPLOTLEN;
- slen *= 2;
- VioReadCellStr(tbuf, (PUSHORT)&slen, (USHORT)y-1, (USHORT)x, os2data->hvio);
- slen /= 2;
-
- /* Separate chars and attrs */
- for (delta = 0; slen > 0; slen--) {
- *charbuf++ = (char)tbuf[delta++];
- *attrbuf++ = tbuf[delta++];
- }
- }
- /* -------------------------------------------------------------------------- */
-
- static byte DIGPRIV vio_readattr(opcoord x, opcoord y)
- /* Return the text attribute found at the screen character position x,y. */
- {
- byte cell[2];
- unsigned slen;
-
- slen = 1;
- VioReadCellStr(cell, (PUSHORT)&slen, (USHORT)y, (USHORT)x, os2data->hvio);
- return(cell[1]);
- }
- /* -------------------------------------------------------------------------- */
-
- static unsigned os2_dDummy()
- {
- return(0);
- }
- /* -------------------------------------------------------------------------- */
-
- #else /* ifndef OAK_OS2 */
- /* A dummy so compilers won't freak if everything else is ifdef'ed out. */
- int os2textdummy(void);
- int os2textdummy() { return(0); }
- #endif
-