home *** CD-ROM | disk | FTP | other *** search
- /*
- pcbios.c
-
- % pc BIOS device interface
-
- 5/16/88 by Ted.
-
- OWL 1.1
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 8/31/88 Ted Added actual BIOS code.
- 01/10/89 ted Removed redundant disp clip.
- 1/18/89 Ted changed call to PlotText for simplified interface.
- 2/04/89 Ted removed Read and Draw Pixmap functions.
- 7/12/89 ted Added OSTATIC's and '_func' macros.
- */
-
- #include "pcpriv.h"
-
- OSTATIC boolean DIGPRIV pc_OpenBIOS(_arg2(dig_struct *, int));
- OSTATIC dig_dControl_func (text_bControl);
- OSTATIC dig_pPlotText_func (text_bPlotText);
- OSTATIC dig_pClear_func (text_bClear);
- OSTATIC dig_pScrollBoxHz_func (text_bScrollBoxHz);
-
- OSTATIC void DIGPRIV text_bReadCharAttrbuf(_arg6(ptd_struct *, opcoord, opcoord, char *, byte *, int));
-
- OSTATIC void DIGPRIV bios_clearbox(_arg2(opbox *, opixval));
- OSTATIC void DIGPRIV bios_scrollhz(_arg2(opbox *, opcoord));
- OSTATIC void DIGPRIV bios_movebuf(_arg5(opcoord, opcoord, opcoord, opcoord, int));
- /* -------------------------------------------------------------------------- */
-
- boolean pc_ModeBIOS(digp)
- dig_struct *digp;
- {
- boolean rval;
-
- if ((rval = pc_OpenBIOS(digp, 0x03)) != 0) {
- return(rval);
- }
- else {
- return(pc_OpenBIOS(digp, 0x07));
- }
- }
-
- boolean pc_ModeBIOS0(digp)
- dig_struct *digp;
- {
- return(pc_OpenBIOS(digp, 0x00));
- }
-
- boolean pc_ModeBIOS1(digp)
- dig_struct *digp;
- {
- return(pc_OpenBIOS(digp, 0x01));
- }
-
- boolean pc_ModeBIOS2(digp)
- dig_struct *digp;
- {
- return(pc_OpenBIOS(digp, 0x02));
- }
-
- boolean pc_ModeBIOS3(digp)
- dig_struct *digp;
- {
- return(pc_OpenBIOS(digp, 0x03));
- }
-
- boolean pc_ModeBIOS7(digp)
- dig_struct *digp;
- {
- return(pc_OpenBIOS(digp, 0x07));
- }
-
- boolean pc_ModeBIOSEGA43(digp)
- dig_struct *digp;
- {
- return(pc_OpenBIOS(digp, PCMODE_EGA43));
- }
-
- boolean pc_ModeBIOSVGA50(digp)
- dig_struct *digp;
- {
- return(pc_OpenBIOS(digp, PCMODE_VGA50));
- }
- /* -------------------------------------------------------------------------- */
-
- static boolean DIGPRIV pc_OpenBIOS(digp, mode)
- dig_struct *digp;
- int mode;
- {
- if (!pc_OpenDIG(digp, mode, text_setinfo)) {
- return(FALSE);
- }
- text_setbiosfuncs(digp);
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
-
- void text_setbiosfuncs(digp)
- dig_struct *digp;
- /*
- Set up the dig function ptrs for text mode BIOS operation.
- */
- {
- digp->CloseDIG = pc_CloseDIG;
- digp->dControl = text_bControl;
-
- digp->pPlotText = text_bPlotText;
- digp->pDrawCursor = pc_bDrawCursor;
- digp->pClear = text_bClear;
- digp->pScrollBoxVt = text_bScrollBoxVt;
- digp->pScrollBoxHz = text_bScrollBoxHz;
-
- /* in hardware cursor text modes, no pixmap funcs are needed */
- digp->pDrawPixmap = (dig_pDrawPixmap_func ((*)))pc_dDummy;
- digp->pReadPixmap = (dig_pReadPixmap_func ((*)))pc_dDummy;
- digp->pControl = (dig_pControl_func ((*)))pc_dDummy;
-
- digp->vtscroll = TRUE;
- digp->hzscroll = TRUE;
- digp->textfree = FALSE;
- digp->evcheck = TRUE;
- digp->type = 0;
- digp->version = 0;
- }
- /* -------------------------------------------------------------------------- */
-
- int text_bControl(msg, indata, outdata)
- dig_dcmsg msg;
- VOID *indata;
- VOID *outdata;
- {
- switch (msg) {
- case DC_READCHARATTR:
- { ptarg_struct *pta = (ptarg_struct *)indata;
- text_bReadCharAttrbuf(pta->ptd, pta->x, pta->y,
- pta->charbuf, pta->attrbuf, pta->slen);
- }
- break;
- default:
- return(pc_dControl(msg, indata, outdata));
- }
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
-
- static void text_bPlotText(ptd, x, y, charbuf, rchar, rattr, slen)
- ptd_struct *ptd;
- opcoord x;
- opcoord y;
- char *charbuf;
- char rchar;
- byte rattr;
- int slen;
- /*
- Plot text/attribute buffers to screen at (x,y), clipped into ptd->relboxp.
- */
- {
- win_type win;
- opbox clipbox;
- int delta;
-
- OREGS regs;
- int orow, ocol;
-
- 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;
- rattr = pcdata->attrmap[rattr];
-
- /* Draw the string, plotting chars and attrs */
- pc_bgetcursorpos(&orow, &ocol);
-
- for ( ; slen > 0; slen--) {
-
- /* pc_bsetcursorpos(row, x++); inline instead */
- regs.h.dl = ((byte) x++); /* set cursor xpos */
- regs.h.dh = ((byte) y-1); /* set cursor ypos */
- regs.h.ah = VIDINT_SETC;
- regs.h.bh = TEXT_RPAGE;
- oakint86(BIOS_VIDINT, ®s);
-
- if (charbuf != NULL) rchar = *charbuf++;
-
- regs.h.ah = VIDINT_WRTCHAR;
- regs.h.bh = TEXT_RPAGE;
- regs.x.cx = 1;
- regs.h.al = rchar;
- regs.h.bl = rattr;
- oakint86(BIOS_VIDINT, ®s);
- }
- pc_bsetcursorpos(orow, ocol);
- }
- /* -------------------------------------------------------------------------- */
-
- static void text_bClear(ptd, color)
- ptd_struct *ptd;
- opixval color;
- {
- win_type win;
- opbox scrbox;
-
- win = ptd->win;
-
- opbox_copy(&scrbox, ptd->relboxp);
- opbox_trans(&scrbox, win_GetXmin(win), win_GetYmin(win));
-
- bios_clearbox(&scrbox, color);
- }
- /* -------------------------------------------------------------------------- */
-
- static void text_bScrollBoxHz(ptd, ncols)
- ptd_struct *ptd;
- opcoord ncols;
- {
- win_type win;
- opbox scrbox;
-
- win = ptd->win;
-
- opbox_copy(&scrbox, ptd->relboxp);
- opbox_trans(&scrbox, win_GetXmin(win), win_GetYmin(win));
-
- bios_scrollhz(&scrbox, ncols);
- }
- /* -------------------------------------------------------------------------- */
-
- static void DIGPRIV text_bReadCharAttrbuf(ptd, x, y, charbuf, attrbuf, slen)
- ptd_struct *ptd;
- opcoord x;
- opcoord y;
- char *charbuf;
- byte *attrbuf;
- int slen;
- {
- win_type win;
- opbox clipbox;
- int delta;
- int orow, ocol;
- OREGS regs;
-
- 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, plotting chars and attrs */
- pc_bgetcursorpos(&orow, &ocol);
-
- for ( ; slen > 0; slen--) {
- regs.h.dl = ((byte) x++); /* set cursor xpos */
- regs.h.dh = ((byte) y-1); /* set cursor ypos */
- regs.h.ah = VIDINT_SETC;
- regs.h.bh = TEXT_RPAGE;
- oakint86(BIOS_VIDINT, ®s);
-
- regs.h.ah = VIDINT_RDCHAR;
- regs.h.bh = TEXT_RPAGE;
- oakint86(BIOS_VIDINT, ®s);
- *(charbuf++) = regs.h.al; /* char */
- *(attrbuf++) = regs.h.ah; /* attr */
- }
- pc_bsetcursorpos(orow, ocol);
- }
- /* -------------------------------------------------------------------------- */
- /* -------------------------------------------------------------------------- */
-
- static void DIGPRIV bios_clearbox(scrboxp, color)
- opbox *scrboxp;
- opixval color;
- {
- OREGS regs;
-
- regs.h.ah = VIDINT_SCRLDN;
- regs.h.al = 0;
- regs.x.bx = pc_wordcolor(color); /* bh gets attr */
-
- regs.h.cl = (byte)scrboxp->xmin;
- regs.h.ch = (byte)scrboxp->ymin;
- regs.h.dl = (byte)scrboxp->xmax-1;
- regs.h.dh = (byte)scrboxp->ymax-1;
- oakint86(BIOS_VIDINT, ®s);
- }
- /* -------------------------------------------------------------------------- */
-
- static void DIGPRIV bios_scrollhz(scrboxp, ncols)
- opbox *scrboxp;
- opcoord ncols;
- {
- int bwidth;
- opcoord x1, x2;
-
- if (ncols > 0) {
- x1 = scrboxp->xmin + ncols;
- x2 = scrboxp->xmin;
- }
- else if (ncols < 0) {
- ncols = -ncols;
- x1 = scrboxp->xmin;
- x2 = scrboxp->xmin + ncols;
- }
- else return; /* quit if no scroll */
-
- if (ncols >= opbox_GetWidth(scrboxp)) return; /* quit if scroll all */
-
- bwidth = (opbox_GetWidth(scrboxp) - ncols) * 2;
-
- for (;;) {
- bios_movebuf(x1, scrboxp->ymin, x2, scrboxp->ymin, bwidth);
-
- if (opbox_GetHeight(scrboxp) <= 1) {
- break;
- }
- scrboxp->ymin += 1;
- }
- }
- /* -------------------------------------------------------------------------- */
-
- static void DIGPRIV bios_movebuf(x1, y1, x2, y2, bwidth)
- opcoord x1;
- opcoord y1;
- opcoord x2;
- opcoord y2;
- int bwidth;
- {
- int orow, ocol;
- OREGS regs;
- byte tchar, tattr;
-
- /* Draw the string, plotting chars and attrs */
- pc_bgetcursorpos(&orow, &ocol);
-
- if (x1 < x2) {
- x1 += bwidth/2 - 1;
- x2 += bwidth/2 - 1;
- }
- for ( ; bwidth > 0; bwidth -= 2) {
- regs.h.dl = (byte) x1; /* set cursor xpos */
- regs.h.dh = (byte) y1; /* set cursor ypos */
- regs.h.ah = VIDINT_SETC;
- regs.h.bh = TEXT_RPAGE;
- oakint86(BIOS_VIDINT, ®s);
-
- regs.h.ah = VIDINT_RDCHAR;
- regs.h.bh = TEXT_RPAGE;
- oakint86(BIOS_VIDINT, ®s);
- tchar = regs.h.al; /* char */
- tattr = regs.h.ah; /* attr */
-
- regs.h.dl = (byte) x2; /* set cursor xpos */
- regs.h.dh = (byte) y2; /* set cursor ypos */
- regs.h.ah = VIDINT_SETC;
- regs.h.bh = TEXT_RPAGE;
- oakint86(BIOS_VIDINT, ®s);
-
- regs.h.ah = VIDINT_WRTCHAR;
- regs.h.bh = TEXT_RPAGE;
- regs.x.cx = 1;
- regs.h.al = tchar; /* char */
- regs.h.bl = tattr; /* attr */
- oakint86(BIOS_VIDINT, ®s);
-
- if (x1 < x2) {
- x1--;
- x2--;
- }
- else {
- x1++;
- x2++;
- }
- }
- pc_bsetcursorpos(orow, ocol);
- }
- /* -------------------------------------------------------------------------- */
-
-