home *** CD-ROM | disk | FTP | other *** search
- /*
- pctext.c
-
- % PC text drawing routines
-
- 5/16/88 by Ted.
-
- OWL-PC 1.2
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 1/10/89 ted Removed redundant disp clip.
- 1/10/89 ted Made ModeText stay in mode 7 if already in mode 7.
- 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.
- 7/21/89 ted Made retrace wait for modes 0, 1, and 2 as well as 3.
- 2/28/90 ted Added DESQview screen buffer detect.
- 3/28/90 jmd ansi-fied
- */
-
- #include "pcpriv.h"
-
- OSTATIC void DIGPRIV text_setfuncs(dig_struct *digp);
- OSTATIC void DIGPRIV text_rReadCharAttrbuf(ptd_struct *ptd, opcoord x, opcoord y, char *charbuf, byte *attrbuf, int slen);
-
- OSTATIC dig_dControl_func (text_dControl);
- OSTATIC dig_pPlotText_func (text_rPlotText);
-
- /* -------------------------------------------------------------------------- */
-
- boolean pc_ModeText(dig_struct *digp)
- {
- boolean rval;
-
- if (pc_GetMode() != 0x07) {
- if ((rval = pc_OpenText(digp, 0x03)) != 0) {
- return(rval);
- }
- }
- return(pc_OpenText(digp, 0x07));
- }
-
- boolean pc_Mode0(dig_struct *digp)
- {
- return(pc_OpenText(digp, 0x00));
- }
-
- boolean pc_Mode1(dig_struct *digp)
- {
- return(pc_OpenText(digp, 0x01));
- }
-
- boolean pc_Mode2(dig_struct *digp)
- {
- return(pc_OpenText(digp, 0x02));
- }
-
- boolean pc_Mode3(dig_struct *digp)
- {
- return(pc_OpenText(digp, 0x03));
- }
-
- boolean pc_ModeEGA43(dig_struct *digp)
- {
- return(pc_OpenText(digp, PCMODE_EGA43));
- }
-
- boolean pc_ModeVGA50(dig_struct *digp)
- {
- return(pc_OpenText(digp, PCMODE_VGA50));
- }
-
- boolean pc_Mode7(dig_struct *digp)
- {
- return(pc_OpenText(digp, 0x07));
- }
- /* -------------------------------------------------------------------------- */
-
- boolean DIGPRIV pc_OpenText(dig_struct *digp, int mode)
- {
- boolean dv = FALSE;
-
- if (!pc_OpenDIG(digp, mode, text_setinfo)) {
- return(FALSE);
- }
- #ifdef OAK_DESQVIEW
- /* Allow DESQview to give us a new video buffer if it wants to */
- if (pch_IsDESQview()) {
- OREGS regs;
-
- regs.x.ax = VIDINT_DVSHADOW;
- regs.x.es = pcdata->info.dispaddr;
- regs.x.di = 0;
- oakint86es(BIOS_VIDINT, ®s, 0);
- if (regs.x.es != pcdata->info.dispaddr) {
- pcdata->info.dispaddr = regs.x.es;
- dv = TRUE;
- }
- }
- #endif
-
- /* If setting color text mode on a CGA, set retrace flag */
- if ((mode >= 0 && mode <= 0x03) && !pc_IsEGA() && !pc_IsCompaq() && !dv) {
- text_setretracefuncs(digp);
- }
- else {
- text_setnormfuncs(digp);
- }
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
-
- void text_setnormfuncs(dig_struct *digp)
- /*
- Set up the dig function ptrs for no-wait text mode RAM operation.
- */
- {
- pc_setretrace(FALSE);
- text_setfuncs(digp);
- }
- /* -------------------------------------------------------------------------- */
-
- void text_setretracefuncs(dig_struct *digp)
- /*
- Set up the dig function ptrs for wait-for-retrace text mode RAM operation.
- */
- {
- pc_setretrace(TRUE);
- text_setfuncs(digp);
-
- /* use BIOS Vt scroll function - it's faster than ram w/retrace */
- digp->pScrollBoxVt = text_bScrollBoxVt;
- }
- /* -------------------------------------------------------------------------- */
-
- static void DIGPRIV text_setfuncs(dig_struct *digp)
- {
- digp->CloseDIG = pc_CloseDIG;
- digp->dControl = text_dControl;
-
- digp->pPlotText = text_rPlotText;
- digp->pDrawCursor = pc_bDrawCursor;
- digp->pClear = ram_Clear;
- digp->pScrollBoxVt = ram_ScrollBoxVt;
- digp->pScrollBoxHz = ram_ScrollBoxHz;
-
- /* 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;
- }
- /* -------------------------------------------------------------------------- */
-
- static int text_dControl(dig_dcmsg msg, VOID *indata, VOID *outdata)
- {
- switch (msg) {
- case DC_READCHARATTR:
- { ptarg_struct *pta = (ptarg_struct *)indata;
- text_rReadCharAttrbuf(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_rPlotText(ptd_struct *ptd, opcoord x, opcoord y, char *charbuf, char rchar, byte rattr, int slen)
- {
- win_type win;
- opbox clipbox;
- int delta;
-
- unsigned vidoffs;
-
- 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];
-
- vidoffs = ((y-1)*pc_bwidth())+(x*2);
-
- /* Index into buf for clipping. */
- if (charbuf != NULL) {
- /* Draw the string, interleaving chars with rattr */
- if (!pc_retrace()) {
- ram_mem1toseg(pc_vidseg(), vidoffs, (byte *) charbuf,
- (unsigned) rattr, (unsigned) slen);
- }
- else {
- ram_wmem1toseg(pc_vidseg(), vidoffs, (byte *) charbuf,
- (unsigned) rattr, (unsigned) slen);
- }
- }
- else { /* no charbuf */
- /* Draw a string of rchar/rattr pairs */
- if (!pc_retrace()) {
- ram_segwordset(pc_vidseg(),
- vidoffs, (unsigned)slen * 2,
- (unsigned)((byte)rchar) | ((unsigned)rattr << 8) );
- }
- else {
- ram_wsegwordset(pc_vidseg(),
- vidoffs, (unsigned)slen * 2,
- (unsigned)((byte)rchar) | ((unsigned)rattr << 8) );
- }
- }
- }
- /* -------------------------------------------------------------------------- */
- #define BUFLEN 132
-
- static void DIGPRIV text_rReadCharAttrbuf(ptd_struct *ptd, opcoord x, opcoord y, char *charbuf, byte *attrbuf, int slen)
- {
- win_type win;
- opbox clipbox;
- int delta;
-
- unsigned vidoffs;
- byte tbuf[2*BUFLEN];
-
- 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;
- }
- vidoffs = ((y-1)*pc_bwidth())+(x*2);
-
- /* Read the string in from display in char/attr form */
- if (slen > BUFLEN) slen = BUFLEN;
- /* This will Snow on a CGA. Oh Well...It's only at disp_Init time. */
- ram_segtomem(pc_vidseg(), vidoffs, tbuf, (unsigned)(slen * 2));
-
- /* Separate chars and attrs */
- for (delta = 0; slen > 0; slen--) {
- *charbuf++ = (char)tbuf[delta++];
- *attrbuf++ = tbuf[delta++];
- }
- }
- /* -------------------------------------------------------------------------- */
-
-