home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Phoenix CD 2.0
/
Phoenix_CD.cdr
/
01e
/
miscfunc.zip
/
ATTR2DB.PRG
< prev
next >
Wrap
Text File
|
1988-04-12
|
5KB
|
134 lines
*** ATTR2DB.PRG - translates DOS display attributes' numeric expression to
*** dBase string expressions for color
PARAMETERS colorvar,decattr
PRIVATE rbgattr,gbgattr,bbgattr,rfgattr,gfgattr,bfgattr
PRIVATE hiattr,blinkattr,fgattr,bgattr,dbfg,dbbg
clear
**
** Copyright Steve Titterud 1988
** 2157 Glenridge Ave.
** St. Paul, MN 55119
** (612)-739-7229
**
** Sister routine is DB2ATTR.PRG. Easily converted to QS function.
**
** Usage: do attr2db with "<color variable name>",<numeric variable>
**
** These routines were written to solve a problem I have encountered. I have
** occasion to use add-on assembler routines, either in .bin form for LOAD
** and CALL, or in .obj form for CCALLing. When these routines have a display
** function, they often ask for a display attribute as a decimal number. And
** further, what they are displaying needs be integrated, in terms of color,
** intensity, and so on, with the rest of the display, which is set with dBase
** color commands as strings. The same is true in reverse - dBase color
** commands need to correspond to color commands set by one of these routines
** with a decimal number attribute. Therefore I created routines to both
** find a dBase color expression corresponding to a decimal attribute, and
** to find a decimal attribute corresponding to a dBase color expression.
** This allows these values to be set at run-time based upon the color
** context, as expressed in a different form (number or string).
**
** This ought to be written in assembler or C, but I don't have the know-how.
**
** Colorvar is the QUOTED NAME of the variable which will hold the
** calculated dBase expression for color corresponding to decattr, which
** is the decimal value of the attribute byte recognized by DOS. This
** variable name is then macro-expanded for the assignment.
**
** The eight bits of the attribute byte:
**
** value bit # Attribute of component
** ───── ───── ────────────────────────────────────
** 128 (7) Blinking component
** 64 (6) Red background component
** 32 (5) Green background component
** 16 (4) Blue background component
** 8 (3) Intensity component
** 4 (2) Red foreground component
** 2 (1) Green foreground component
** 1 (0) Blue foreground component
**
**
** These components combine to give all the possible FG and BG colors:
**
**
** Sum of values
** ─────────────
** FG BG
** ──── ────
** RGB = white 7 112
** RG = yellow 6 96
** RB = magenta 5 80
** GB = cyan 3 48
** R = red 4 64
** G = green 2 32
** B = blue 1 16
** none = black 0 0
**
** Add the values of the color attributes you desire;
** Add 8 to get high intensity in the foreground;
** Add 128 to get blinking.
**
**
** The algorithm then, to convert a decimal attribute value to a dBase
** color expression involves decomposing the decimal number for the
** presence of each of these attributes, one by one.
**
** calculate background components
**
rbgattr=iif(bitset(decattr,6),"R","")
gbgattr=iif(bitset(decattr,5),"G","")
bbgattr=iif(bitset(decattr,4),"B","")
**
** calculate foreground components
**
rfgattr=iif(bitset(decattr,2),"R","")
gfgattr=iif(bitset(decattr,1),"G","")
bfgattr=iif(bitset(decattr,0),"B","")
**
** is high intensity on?
**
hiattr=iif(bitset(decattr,3),"+","")
**
** is blink on?
**
blinkattr=iif(bitset(decattr,7),"*","")
**
** now compose dBase expression for foreground from concatenated components:
**
fgattr=rfgattr+gfgattr+bfgattr
**
do case
case fgattr="RGB"
dbfg="W"
case fgattr="RG"
dbfg="GR"
case fgattr=""
dbfg="N"
otherwise
dbfg=fgattr && remaining values ready to use: RB,BG,R,G,B
endcase
**
** re-express dbfg to incorporate any values for intensity and blink
**
dbfg=dbfg+hiattr+blinkattr
**
** now calculate dBase expression for background from concatenated components:
**
bgattr=rbgattr+gbgattr+bbgattr
do case
case bgattr="RGB"
dbbg="W"
case bgattr="RG"
dbbg="GR"
case bgattr=""
dbbg="N"
otherwise
dbbg=bgattr && remaining values ready to use: RB,BG,R,G,B
endcase
&colorvar=dbfg+"/"+dbbg
?
? &colorvar
?
RETURN