DECLARE SUB getColor (attr AS INTEGER, r AS INTEGER, g AS INTEGER, b AS INTEGER) DECLARE SUB setPalette () DECLARE SUB loadPalette (filename AS STRING) DECLARE SUB savePalette (filename AS STRING) DECLARE SUB setColor (attr AS INTEGER, r AS INTEGER, g AS INTEGER, b AS INTEGER) CONST DAC.PELMask = &H3C6 ' DAC (Digital/Analog Converter) PEL Mask Register CONST DAC.READ = &H3C7 ' DAC Read Port/DAC State Register CONST DAC.WRITE = &H3C8 ' DAC Write Port/DAC State Register CONST DAC.DATA = &H3C9 ' DAC Data Port DIM r AS INTEGER, g AS INTEGER, b AS INTEGER ' Enter mode 13 (320x200, 256 colors) SCREEN 13 ' Display the whole color palette FOR y% = 0 TO 15 FOR x% = 0 TO 15 LINE (x% * 8, y% * 8)-STEP(7, 7), x% + (y% * 16), BF NEXT x% NEXT y% ' Wait for user input COLOR 15: LOCATE 3, 25: PRINT "Press a key - 1": SLEEP ' Get color 254 and 255 getColor 254, r, g, b LOCATE 4, 25: PRINT "254:"; r; g; b getColor 255, r, g, b LOCATE 5, 25: PRINT "255:"; r; g; b ' Tweak attributes 254 and 255 to teal and orange setColor 254, 0, 29, 63 setColor 255, 63, 34, 0 ' Get color 254 and 255 again getColor 254, r, g, b LOCATE 6, 25: PRINT "254:"; r; g; b getColor 255, r, g, b LOCATE 7, 25: PRINT "254:"; r; g; b ' Wait for user input COLOR 15: LOCATE 3, 25: PRINT "Press a key - 2": SLEEP ' Modify the whole palette setPalette ' Wait for user input COLOR 255: LOCATE 3, 25: PRINT "Press a key - 3": SLEEP ' {attr} is the color attribute index, must be 0 - 255 ' {r}, {g} and {b} are Red, Green and Blue intensity SUB getColor (attr AS INTEGER, r AS INTEGER, g AS INTEGER, b AS INTEGER) OUT DAC.PELMask, &HFF ' Mask all registers OUT DAC.READ, attr ' Select attribute r = INP(DAC.DATA) ' Read red intensity g = INP(DAC.DATA) ' Read green intensity b = INP(DAC.DATA) ' Read blue intensity END SUB ' {attr} is the color attribute index, must be 0 - 255 ' {r}, {g} and {b} are Red, Green and Blue intensity, must be 0 - 63 SUB setColor (attr AS INTEGER, r AS INTEGER, g AS INTEGER, b AS INTEGER) OUT DAC.PELMask, &HFF ' Mask all registers OUT DAC.WRITE, attr ' Select attribute OUT DAC.DATA, r ' Feed red intensity OUT DAC.DATA, g ' Feed green intensity OUT DAC.DATA, b ' Feed blue intensity END SUB ' fill the whole palette with 64 shades of red, green, blue and grey SUB setPalette OUT DAC.PELMask, &HFF ' Mask all registers OUT DAC.WRITE, 0 ' Select first attribute ' Attributes 0 to 63: red shades FOR i% = 0 TO 63 OUT DAC.DATA, i% OUT DAC.DATA, 0 OUT DAC.DATA, 0 NEXT i% ' Attributes 64 to 127: green shades FOR i% = 0 TO 63 OUT DAC.DATA, 0 OUT DAC.DATA, i% OUT DAC.DATA, 0 NEXT i% ' Attributes 128 to 191: blue shades FOR i% = 0 TO 63 OUT DAC.DATA, 0 OUT DAC.DATA, 0 OUT DAC.DATA, i% NEXT i% ' Attributes 192 to 255: grey shades FOR i% = 0 TO 191 OUT DAC.DATA, i% \ 3 NEXT i% END SUB