home *** CD-ROM | disk | FTP | other *** search
- /* (c) 1985, Phoenix Computer Products Corp. and Novum Organum, Inc. */
- /* (c) 1985, Phoenix Computer Products Corp. and Novum Organum, Inc. */
- /***
- * name:
- * get/set current state
- * vstsetcur - change to a different video state.
- * vstgetcur - return the number of the current video state.
- * get/set a state definition
- * vstsetdef - define the colors and attributes for a state.
- * vstgetdef - return the current definition of a state.
- * read/write the whole table
- * vstatgtable - return pointer to and size of state-table.
- * vsttbl - move an entire set of values into state-table.
- * change the current attributes of the current state
- * vstoffattr - turn off attributes.
- * vstonattr - turn on attributes.
- * vstsetattr - set attributes.
- * vsttogattr - complement (toggle) attributes.
- *
- * description: A table of video states is maintained. Each state has
- * a foreground, background, and alternate color, a base-case
- * attribute (reverse video etc.), and a current attribute.
- *
- * The background color is the color of the field on which the
- * character will be painted. The foreground color is the color
- * of the character itself.
- *
- * The underline attribute (VA_ULINE) causes the alternate color
- * to be used in place of the foreground color. The blink
- * attribute (VA_BLINK) makes the character blink. The high-
- * intensity attribute (VA_HIINT) makes the character brighter.
- * The reverse-video attribute (VA_REVVID) causes the background
- * and foreground colors to be traded.
- *
- * The functions vstoffattr(), vstonattr(), vstsetattr(), and vsttogattr()
- * have no effect on any state except the current state. E.g.,
- * oldstate = vstsetcur( newstate );
- * . . .
- * vsttogattr(VA_HIINT);
- * . . .
- * vstsetcur( oldstate );
- * has no effect on the old state. Moreover, these functions
- * have no effect on the base-case attributes. Therefore,
- * vstsetattr(VA_NORML) will always return you to the base state.
- * Finally, the current attribute settings are XOR'd with the
- * base-case settings, and thus always produce an effect.
- * If the base-case has VA_HIINT on, then turning VA_HIINT on via
- * a call to vstonattr(VA_HIINT), for example, will result in a
- * normal, low-intensity display! The other way of doing things
- * results in a lot of recoding if you ever need to change a
- * base-case attribute definition. This way, the effect of a call
- * may be exactly opposite to what its name suggests, but at least
- * it does something distinctive on screen, which is what you were
- * trying to do, anyway.
- *
- * (C) novum organum, inc. 1985
- *
- ***/
- #define GLOBAL /**/
-
- #include "pdefs.h"
- #include "psys.h"
-
- #define NSTATES 16 /* number of video state slots */
-
- typedef struct
- {
- int fgd, /* foreground color */
- bgd, /* background color */
- uln, /* alternate color (underline on IBM-PC) */
- battr, /* base-state attributes */
- cattr; /* current attributes */
- } STATE;
-
- /* Black, white, and blue are the only colors used with a monochrome */
- /* screen, and so these are used as default colors for all of the */
- /* states. The attributes are normal except for the field states */
- /* (states 1 and 2) which are set so as to be distinctive. */
- static STATE _state[NSTATES] =
- {
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_HIINTY,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_REVVID,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
- {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL}
- };
-
- #define TABBASE &_state[0]
- static STATE *_cstate = TABBASE;
-
-
- /* set the current state number */
- GLOBAL int vstsetcur(register int newstate)
- {
- int oldstate;
-
- oldstate = _cstate - TABBASE;
-
- if ( (newstate >= 0) && (newstate < NSTATES) )
- {
- _cstate = TABBASE + newstate; /* reset the active state. */
- _setattr();
- }
- return ( oldstate );
- }
-
-
- /* return the current state number */
- vstgetcur ()
- {
- return ((int)(_cstate-TABBASE));
- }
-
-
- /* define a video state */
- GLOBAL void vstsetdef(int state, int fgdcol, int bgdcol, int ulncol, int attr)
- {
- FAST STATE *p;
-
- if ( (state >= 0) && (state < NSTATES) )
- {
- p = TABBASE + state;
- p->fgd = fgdcol;
- p->bgd = bgdcol;
- p->uln = ulncol;
- p->battr = attr;
- p->cattr = VA_NORMAL;
- if ( _cstate == p )
- _setattr();
- }
- }
-
-
- /* return a video state definition */
- vstgetdef (state, pfgdcol, pbgdcol, pulncol, pattr)
- int state;
- int *pfgdcol, *pbgdcol, *pulncol, *pattr;
- {
- FAST STATE *p;
-
- if ( (state >= 0) && (state < NSTATES) )
- {
- p = TABBASE + state;
- *pfgdcol = p->fgd;
- *pbgdcol = p->bgd;
- *pulncol = p->uln;
- *pattr = p->battr;
- }
- }
-
-
- /* return the address and size of the state-table for external storage */
- char *vstatgtable (pn)
-
- int *pn;
- {
- *pn = sizeof(_state);
- return ( (char *)TABBASE );
- }
-
-
- /* fill the state table from external storage */
- GLOBAL void vsttbl(char *data, register int nbytes)
- {
- if (nbytes > 0)
- {
- if (nbytes > sizeof(_state)) /* trying to overrun table area? */
- nbytes = sizeof(_state); /* reset N so we won't overrun. */
- memcpy(data, (char *)_state, nbytes);
- _setattr();
- }
- }
-
-
- /* return current attribute settings */
- int vstattr()
- {
- return ( _cstate->battr ^ _cstate->cattr );
- }
-
-
- /* turn off current attributes */
- vstoffattr ( attr )
- int attr;
- {
- int old;
- old = _cstate->cattr;
- _cstate->cattr &= ~attr;
- _setattr();
- return (old);
- }
-
-
- /* turn on current attributes */
- GLOBAL int vstonattr(int attr)
- {
- register int old;
-
- old = _cstate->cattr;
- _cstate->cattr |= attr;
- _setattr();
- return (old);
- }
-
-
-
- GLOBAL int vstgetattr(void)
- {
- return(_cstate->cattr);
- }
-
-
-
- GLOBAL int vstsetattr(int attr) /* set the current attribute */
- {
- int old;
- old = _cstate->cattr;
- _cstate->cattr = attr;
- _setattr();
- return (old);
- }
-
-
- /* toggle the current attribute */
- vsttogattr ( attr )
- int attr;
- {
- int old;
- old = _cstate->cattr;
- _cstate->cattr ^= attr;
- _setattr();
- return (old);
- }
-
-
- static _setattr()
- {
- _videncode( _cstate->battr ^ _cstate->cattr,
- _cstate->fgd, _cstate->bgd, _cstate->uln );
- }
-
-
-
- GLOBAL void vstibm(int state, int ibmattr)
- {
- register int attr;
- int fgdcol, bgdcol, ulncol;
-
- fgdcol = A_RGBBITS(ibmattr);
- bgdcol = A_RGBBITS(ibmattr >> 4);
- ulncol = VC_BLUE;
-
- attr = VA_NORMAL;
- if (ibmattr & A_BLINKBIT)
- attr |= VA_BLINK;
- if (ibmattr & A_HIINTYBIT)
- attr |= VA_HIINTY;
-
- vstsetdef(state, fgdcol, bgdcol, ulncol, attr);
- }
-
-
-
- /* end of VST.C */
-