QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

LONG HEX$ values can be used to set a _PALETTECOLOR instead of using _RGB32 or _RGBA32 values.

Where FF is the fully opaque _ALPHA and the 3 hex color values can range from 00 to FF (0 to 255) each.

Example(s)

Converting the color port RGB intensity palette values 0 to 63 to 32 bit hexadecimal STRING values.


SCREEN 12
DIM hex32$(15)
alpha$ = "FF"                              'solid alpha colors only
OUT &H3C8, 0: OUT &H3C9, 0: OUT &H3C9, 0: OUT &H3C9, 20 'set black background to dark blue

FOR attribute = 0 TO 15
  OUT &H3C7, attribute                     'set color attribute to read
  red$ = HEX$(INP(&H3C9) * 4)              'convert port setting to 32 bit values
  grn$ = HEX$(INP(&H3C9) * 4)
  blu$ = HEX$(INP(&H3C9) * 4)
  IF LEN(red$) = 1 THEN red$ = "0" + red$  'necessary for low or zero color intensities
  IF LEN(grn$) = 1 THEN grn$ = "0" + grn$
  IF LEN(blu$) = 1 THEN blu$ = "0" + blu$
  hex32$(attribute) = "&H" + alpha$ + red$ + grn$ + blu$
NEXT
PRINT "COLOR 0 = " + hex32$(0)
FOR i = 1 TO 15
  _PALETTECOLOR i, VAL(hex32$(i))
  COLOR i
  PRINT "COLOR" + STR$(i) + " = " + hex32$(i) 'returns closest attribute
NEXT 

Code by Ted Weissgerber

Explanation: VAL is used to convert the HEX$ STRING values to valid 32 bit color values for _PALETTECOLOR.

No VAL conversion is necessary if the LONG &H hexadecimal values are entered into the program directly by the programmer.

See Also