home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / s / s001 / 1.ddi / PFC / SRC / VST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-04  |  7.2 KB  |  276 lines

  1. /* (c) 1985, Phoenix Computer Products Corp. and Novum Organum, Inc. */
  2. /* (c) 1985, Phoenix Computer Products Corp. and Novum Organum, Inc. */
  3. /***
  4. * name:
  5. *         get/set current state
  6. *        vstsetcur - change to a different video state.
  7. *        vstgetcur - return the number of the current video state.
  8. *         get/set a state definition
  9. *        vstsetdef - define the colors and attributes for a state.
  10. *        vstgetdef - return the current definition of a state.
  11. *         read/write the whole table
  12. *        vstatgtable - return pointer to and size of state-table.
  13. *        vsttbl  - move an entire set of values into state-table.
  14. *      change the current attributes of the current state
  15. *        vstoffattr - turn off attributes.
  16. *        vstonattr  - turn on attributes.
  17. *        vstsetattr - set attributes.
  18. *        vsttogattr - complement (toggle) attributes.
  19. *
  20. * description:    A table of video states is maintained.  Each state has
  21. *        a foreground, background, and alternate color, a base-case
  22. *        attribute (reverse video etc.), and a current attribute.
  23. *
  24. *        The background color is the color of the field on which the
  25. *        character will be painted.  The foreground color is the color
  26. *        of the character itself.
  27. *
  28. *        The underline attribute (VA_ULINE) causes the alternate color
  29. *        to be used in place of the foreground color.  The blink
  30. *        attribute (VA_BLINK) makes the character blink.  The high-
  31. *        intensity attribute (VA_HIINT) makes the character brighter.
  32. *        The reverse-video attribute (VA_REVVID) causes the background
  33. *        and foreground colors to be traded.
  34. *
  35. *        The functions vstoffattr(), vstonattr(), vstsetattr(), and vsttogattr()
  36. *        have no effect on any state except the current state.  E.g.,
  37. *            oldstate = vstsetcur( newstate );
  38. *            . . .
  39. *            vsttogattr(VA_HIINT);
  40. *            . . .
  41. *            vstsetcur( oldstate );
  42. *        has no effect on the old state.  Moreover, these functions
  43. *        have no effect on the base-case attributes.  Therefore,
  44. *        vstsetattr(VA_NORML) will always return you to the base state.
  45. *        Finally, the current attribute settings are XOR'd with the
  46. *        base-case settings, and thus always produce an effect.
  47. *        If the base-case has VA_HIINT on, then turning VA_HIINT on via
  48. *        a call to vstonattr(VA_HIINT), for example, will result in a
  49. *        normal, low-intensity display!  The other way of doing things
  50. *        results in a lot of recoding if you ever need to change a
  51. *        base-case attribute definition.  This way, the effect of a call
  52. *        may be exactly opposite to what its name suggests, but at least
  53. *        it does something distinctive on screen, which is what you were
  54. *        trying to do, anyway.
  55. *
  56. * (C) novum organum, inc. 1985
  57. *
  58. ***/
  59. #define GLOBAL    /**/
  60.  
  61. #include "pdefs.h"
  62. #include "psys.h"
  63.  
  64. #define    NSTATES    16        /* number of video state slots */
  65.  
  66. typedef struct    
  67.     {
  68.     int     fgd,        /* foreground color */
  69.         bgd,        /* background color */
  70.         uln,        /* alternate color (underline on IBM-PC) */
  71.         battr,        /* base-state attributes */
  72.         cattr;        /* current attributes */
  73.     } STATE;
  74.  
  75. /* Black, white, and blue are the only colors used with a monochrome    */
  76. /* screen, and so these are used as default colors for all of the     */
  77. /* states.  The attributes are normal except for the field states    */
  78. /* (states 1 and 2) which are set so as to be distinctive.        */
  79. static    STATE _state[NSTATES] =
  80.     {
  81.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
  82.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_HIINTY,VA_NORMAL},
  83.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_REVVID,VA_NORMAL},
  84.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
  85.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
  86.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
  87.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
  88.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
  89.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
  90.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
  91.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
  92.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
  93.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
  94.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
  95.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL},
  96.     {VC_WHITE,VC_BLACK,VC_BLUE,VA_NORMAL,VA_NORMAL}
  97.     };
  98.  
  99. #define    TABBASE    &_state[0]
  100. static    STATE    *_cstate = TABBASE;
  101.  
  102.  
  103. /* set the current state number */
  104. GLOBAL int vstsetcur(register int newstate)
  105. {
  106.    int    oldstate;
  107.  
  108.    oldstate = _cstate - TABBASE;
  109.  
  110.    if  ( (newstate >= 0) && (newstate < NSTATES) )
  111.     {
  112.         _cstate = TABBASE + newstate;    /* reset the active state. */
  113.     _setattr();
  114.     }
  115.    return ( oldstate );
  116. }
  117.  
  118.  
  119. /* return the current state number */
  120. vstgetcur ()
  121. {
  122.     return ((int)(_cstate-TABBASE));
  123. }
  124.  
  125.  
  126. /* define a video state */
  127. GLOBAL void vstsetdef(int state, int fgdcol, int bgdcol, int ulncol, int attr)
  128. {
  129.     FAST STATE  *p;
  130.  
  131.     if    ( (state >= 0) && (state < NSTATES) )
  132.         {   
  133.         p = TABBASE + state;
  134.         p->fgd = fgdcol;
  135.     p->bgd = bgdcol;
  136.         p->uln = ulncol;
  137.         p->battr = attr;
  138.     p->cattr = VA_NORMAL;
  139.     if  ( _cstate == p )
  140.         _setattr();
  141.         }
  142. }
  143.  
  144.  
  145. /* return a video state definition */
  146. vstgetdef (state, pfgdcol, pbgdcol, pulncol, pattr)
  147.     int  state;
  148.     int   *pfgdcol, *pbgdcol, *pulncol, *pattr;
  149. {
  150.     FAST STATE  *p;
  151.  
  152.     if    ( (state >= 0) && (state < NSTATES) )
  153.         {   
  154.         p = TABBASE + state;
  155.         *pfgdcol = p->fgd;
  156.         *pbgdcol = p->bgd;
  157.         *pulncol = p->uln;
  158.         *pattr = p->battr;
  159.     }
  160. }
  161.  
  162.  
  163. /* return the address and size of the state-table for external storage */
  164. char    *vstatgtable (pn)
  165.  
  166.     int   *pn;
  167. {
  168.     *pn = sizeof(_state);
  169.     return ( (char *)TABBASE );
  170. }
  171.  
  172.  
  173. /* fill the state table from external storage */
  174. GLOBAL void vsttbl(char *data, register int nbytes)
  175. {
  176.     if    (nbytes > 0)
  177.     {
  178.         if  (nbytes > sizeof(_state))    /* trying to overrun table area? */
  179.         nbytes = sizeof(_state);    /* reset N so we won't overrun.     */
  180.     memcpy(data, (char *)_state, nbytes);
  181.     _setattr();
  182.     }
  183. }
  184.  
  185.  
  186. /* return current attribute settings */
  187. int    vstattr()
  188. {
  189.     return ( _cstate->battr ^ _cstate->cattr );
  190. }
  191.  
  192.  
  193. /* turn off current attributes */
  194. vstoffattr ( attr )
  195.     int   attr;
  196. {
  197.     int    old;
  198.     old = _cstate->cattr;
  199.     _cstate->cattr &= ~attr;
  200.     _setattr();
  201.     return (old);
  202. }
  203.  
  204.  
  205. /* turn on current attributes */
  206. GLOBAL int vstonattr(int attr)
  207. {
  208.   register  int old;
  209.  
  210.     old = _cstate->cattr;
  211.     _cstate->cattr |= attr;
  212.     _setattr();
  213.     return (old);
  214. }
  215.  
  216.  
  217.  
  218. GLOBAL int vstgetattr(void)
  219. {
  220.     return(_cstate->cattr);
  221. }
  222.  
  223.  
  224.  
  225. GLOBAL int vstsetattr(int  attr)    /* set the current attribute */
  226. {
  227.     int    old;
  228.     old = _cstate->cattr;
  229.     _cstate->cattr = attr;
  230.     _setattr();
  231.     return (old);
  232. }
  233.  
  234.  
  235. /* toggle the current attribute */
  236. vsttogattr ( attr )
  237.     int   attr;
  238. {
  239.     int    old;
  240.     old = _cstate->cattr;
  241.     _cstate->cattr ^= attr;
  242.     _setattr();
  243.     return (old);
  244. }
  245.  
  246.  
  247. static    _setattr()
  248. {
  249.     _videncode( _cstate->battr ^ _cstate->cattr,
  250.             _cstate->fgd, _cstate->bgd, _cstate->uln );
  251. }
  252.  
  253.  
  254.  
  255. GLOBAL void vstibm(int state, int ibmattr)
  256. {
  257.   register int    attr;
  258.   int        fgdcol, bgdcol, ulncol;
  259.  
  260.     fgdcol = A_RGBBITS(ibmattr);
  261.     bgdcol = A_RGBBITS(ibmattr >> 4);
  262.     ulncol = VC_BLUE;
  263.  
  264.     attr = VA_NORMAL;
  265.     if    (ibmattr & A_BLINKBIT)
  266.         attr |= VA_BLINK;
  267.     if    (ibmattr & A_HIINTYBIT)
  268.         attr |= VA_HIINTY;
  269.  
  270.     vstsetdef(state, fgdcol, bgdcol, ulncol, attr);
  271. }
  272.  
  273.  
  274.  
  275. /* end of VST.C */
  276.