home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 01e / miscfunc.zip / ATTR2DB.PRG < prev    next >
Text File  |  1988-04-12  |  5KB  |  134 lines

  1. *** ATTR2DB.PRG -  translates DOS display attributes' numeric expression to
  2. ***                dBase string expressions for color
  3. PARAMETERS colorvar,decattr
  4. PRIVATE rbgattr,gbgattr,bbgattr,rfgattr,gfgattr,bfgattr
  5. PRIVATE hiattr,blinkattr,fgattr,bgattr,dbfg,dbbg
  6. clear
  7. **                    
  8. **  Copyright Steve Titterud 1988
  9. **  2157 Glenridge Ave.
  10. **  St. Paul, MN 55119                  
  11. **  (612)-739-7229                  
  12. **                    
  13. **  Sister routine is DB2ATTR.PRG.  Easily converted to QS function.
  14. **
  15. **  Usage:  do attr2db with "<color variable name>",<numeric variable>                  
  16. **
  17. **  These routines were written to solve a problem I have encountered.  I have                  
  18. **  occasion to use add-on assembler routines, either in .bin form for LOAD                  
  19. **  and CALL, or in .obj form for CCALLing.  When these routines have a display                  
  20. **  function, they often ask for a display attribute as a decimal number.  And                  
  21. **  further, what they are displaying needs be integrated, in terms of color,                  
  22. **  intensity, and so on, with the rest of the display, which is set with dBase                  
  23. **  color commands as strings.  The same is true in reverse - dBase color 
  24. **  commands need to correspond to color commands set by one of these routines                  
  25. **  with a decimal number attribute.  Therefore I created routines to both                  
  26. **  find a dBase color expression corresponding to a decimal attribute, and                  
  27. **  to find a decimal attribute corresponding to a dBase color expression.                  
  28. **  This allows these values to be set at run-time based upon the color
  29. **  context, as expressed in a different form (number or string).
  30. **                    
  31. **  This ought to be written in assembler or C, but I don't have the know-how.                  
  32. **                    
  33. **  Colorvar is the QUOTED NAME of the variable which will hold the                   
  34. **  calculated dBase expression for color corresponding to decattr, which                  
  35. **  is the decimal value of the attribute byte recognized by DOS.  This
  36. **  variable name is then macro-expanded for the assignment.                  
  37. **                    
  38. **  The eight bits of the attribute byte:
  39. **                    
  40. **  value  bit #   Attribute of component                 
  41. **  ─────  ─────  ────────────────────────────────────              
  42. **    128    (7)   Blinking component                 
  43. **     64    (6)   Red background component                 
  44. **     32    (5)   Green background component                 
  45. **     16    (4)   Blue background component                 
  46. **      8    (3)   Intensity component                 
  47. **      4    (2)   Red foreground component                 
  48. **      2    (1)   Green foreground component                 
  49. **      1    (0)   Blue foreground component                 
  50. **                    
  51. **                    
  52. **  These components combine to give all the possible FG and BG colors:
  53. **                    
  54. **  
  55. **                   Sum of values
  56. **                   ─────────────
  57. **                      FG    BG
  58. **                     ────  ────
  59. **   RGB = white         7   112
  60. **    RG = yellow        6    96
  61. **    RB = magenta       5    80
  62. **    GB = cyan          3    48
  63. **     R = red           4    64
  64. **     G = green         2    32
  65. **     B = blue          1    16
  66. **  none = black         0     0
  67. **
  68. **  Add the values of the color attributes you desire;
  69. **  Add 8 to get high intensity in the foreground;
  70. **  Add 128 to get blinking.
  71. **                                                                      
  72. **
  73. **  The algorithm then, to convert a decimal attribute value to a dBase 
  74. **  color expression involves decomposing the decimal number for the
  75. **  presence of each of these attributes, one by one.
  76. **  
  77. ** calculate background components
  78. **  
  79. rbgattr=iif(bitset(decattr,6),"R","")
  80. gbgattr=iif(bitset(decattr,5),"G","")
  81. bbgattr=iif(bitset(decattr,4),"B","")
  82. **  
  83. ** calculate foreground components
  84. **  
  85. rfgattr=iif(bitset(decattr,2),"R","")
  86. gfgattr=iif(bitset(decattr,1),"G","")
  87. bfgattr=iif(bitset(decattr,0),"B","")
  88. **  
  89. ** is high intensity on?
  90. **  
  91. hiattr=iif(bitset(decattr,3),"+","")
  92. **  
  93. ** is blink on?
  94. **  
  95. blinkattr=iif(bitset(decattr,7),"*","")
  96. **  
  97. ** now compose dBase expression for foreground from concatenated components:
  98. **  
  99. fgattr=rfgattr+gfgattr+bfgattr
  100. **
  101. do case
  102.    case fgattr="RGB"
  103.         dbfg="W"
  104.    case fgattr="RG"
  105.         dbfg="GR"
  106.    case fgattr=""
  107.         dbfg="N"
  108.    otherwise
  109.         dbfg=fgattr  && remaining values ready to use: RB,BG,R,G,B
  110. endcase
  111. **
  112. ** re-express dbfg to incorporate any values for intensity and blink
  113. **
  114. dbfg=dbfg+hiattr+blinkattr
  115. **
  116. ** now calculate dBase expression for background from concatenated components:
  117. **
  118. bgattr=rbgattr+gbgattr+bbgattr
  119. do case
  120.    case bgattr="RGB"
  121.         dbbg="W"
  122.    case bgattr="RG"
  123.         dbbg="GR"
  124.    case bgattr=""
  125.         dbbg="N"
  126.    otherwise
  127.         dbbg=bgattr  && remaining values ready to use: RB,BG,R,G,B
  128. endcase
  129. &colorvar=dbfg+"/"+dbbg
  130. ?
  131. ? &colorvar
  132. ?
  133. RETURN
  134.