Classic Computer Magazine Archive A.N.A.L.O.G. ISSUE 69 / FEBRUARY 1989 / PAGE 12

COLOR SET

by Jackson Beebe

Have you ever admired the colored text and screens in other people's programs and wished you could add them to your own BASIC programs? Have you given up trying to figure out Atari SETCOLOR statements and their relationship to POKE statements? Have you spent hours trying to design screens by POKEing in one number after another, writing small notes on the backs of envelopes with a pencil that kept getting lost, only to be dissatisfied with the results at the end?
    If you answered "Yes" to any of the above, then Color Set is the program for you. Color Set allows you to change the color and intensity of the screen, border or text using the arrow keys. The correct SETCOLOR and POKE statements to produce these colors are constantly updated and displayed on the screen. Experimenting and watching the results soon gives you a working knowledge of the color statements.
    Color Set will run on any Atari 8-bit computer. It will produce a printed record of screens you compose or will allow you to jot down settings shown on the screen. To quit the program, hit BREAK, and then clear the screen.

screen

Graphics Modes
    The Atari 800XL has 16 graphics modes, numbered 0-15. Each mode has its own resolution, number of lines, number of characters per line, and number of colors available. When you turn on Atari 8-bit computers, they come up in Graphics 0, their default mode. This mode is a text mode (like 1-2) as opposed to a graphics mode (like 3-15). This is the mode you use when you work in BASIC or with most text-oriented or utility functions. It has 40 characters per line, 24 lines per screen, and 16 colors of background or border, each with eight levels of intensity, ranging from dark to bright. The text will be the same color as the screen background, but vary in intensity against the screen. When the screen and text color are the same intensity, the text is invisible.

SETCOLOR Statements
    The intensity of the text, the color and intensity of the screen, and the color and intensity of the border are controlled in Graphics 0 by three SETCOLOR statements.
    SETCOLOR 1,0,Y = Text intensity
    Y can be any even number from 0-14, to change text from dark to bright.
    SETCOLOR 2,X Y = Screen color and intensity
    X can vary from 0 to 15 to change the color of the screen and text, and Y can be any even number from 0-14, to change intensity of screen color from dark to bright.
    SETCOLOR 4,X,Y = Border color and intensity
    X and Y are the same as when setting the screen colors.
    The first digit in the SETCOLOR statement specifies that text, screen or border are to be changed. This digit (in Graphics 0) may have a value of 1, 2, or 4 only. The second digit specifies color, and may vary from 0-15. This holds true for both screen and border. Colors selected by the second digit are as follows:
0 = Gray 8 = Blue
1 = Gold 9 = Light Blue
2 = Orange 10 = Turquoise
3 = Red-Orange 11 = Green-Blue
4 = Pink 12 = Green
5 = Pink-Purple 13 = Yellow-Green
6 = Purple-Blue 14 = Orange-Green
7 = Dark Blue 15 = Light Orange
    Note that in the SETCOLOR 1,X,Y statement, the digit X has no effect on the text. This is because the text color is always the same as the screen color. You may type numbers in if you wish, but the program always ignores the second digit in SETCOLOR 1,X,Y. For this reason, I have used zero as the second digit in my program and examples. This will satisfy the BASIC interpreter which needs a digit in that location and will remind you not to bother worrying about it for text.
    The third digit controls the intensity of the text, screen or border, and may be any even number from 0-14. Intensities are roughly:
    0-2 = Dark
    4-8 = Medium
10-14 = Bright
    For example, SETCOLOR 1, 0, 14, SET COLOR 2, 0, 0 and SETCOLOR 4, 7, 4 selects bright white text on a black screen with a dark blue border. SETCOLOR 1, 0, 14, SETCOLOR 2, 3, 4 and SETCOLOR 4, 7, 2 selects white text on a red-orange screen with a dark blue border. SETCOLOR 1, 0, 8, SETCOLOR 2,12, 0 and SETCOLOR 4, 3, 6 will produce green text on a black background with a red border.

Color Set will produce
a printed record of screens
you compose or will allow
you to jot down settings
shown on the screen.

POKE Statements
    There are corresponding POKE statements that achieve the same results as the SETCOLOR statements. Once you figure them out, they are easier and quicker to use than SETCOLOR. Their locations are:
    POKE 709 = Text intensity (0-14)
    POKE 710 = Screen color and intensity (0-238)
    POKE 712 = Border color and intensity (0-238)
    POKE 709 may be any even number from 0-14 to change the text intensity. The formula for the value of POKE 710 and 712 is:

    Value = Color * 16+Intensity

    For example, SETCOLOR 4,7,4 is equivalent to POKE 712,116. Both 710 and 712 may range in value from 0-238.
    Both statements are used in lines of BASIC code when you want to change a color parameter, as:
    120 SETCOLOR 2, 3, 8
or
    120 POKE 710,56
    Once set, the colors will stay set until another SETCOLOR or POKE statement is executed, a GRAPHICS 0 command is issued, or the computer is reset or rebooted.

How the Program Works
    Lines 10-140 INITIALIZE

    The default values for the text, screen and border colors and intensity are set at Line 110. Feel free to alter these to customize your version of this program's default colors. Line 120 dimensions variables for the 35-character printed comment (COM$), the 12-character color (COL$) and the six-character text intensity (LINT$). Line 130 calls the screenprinting menu subroutine at Line 1170, then goes to the LETTERS module to await input.

    Lines 150-310 LETTERS module

    The LETTERS module reprints the screenmenu lines that say SCREEN and BORDER and their arrows, in regular type, in case it just arrived here from the SCREEN or the BORDER module, then prints LETTERS and its arrows in inverse video. It opens a channel to the keyboard at Line 220 and gets a character. If the input is an up or down arrow, it increments or decrements the variable LINT that holds the text intensity, executes a new SETCOLOR statement, and reprints updated information on the screen.
    It uses POSITION statements to specify the exact X and Y coordinates to print at on the screen. Note that when the updated line is shorter (has fewer digits) than the line already on the screen, it avoids leaving the last digit of the old line on the screen by adding one blank character to the end of each print line at 230-260. Forced erasing by hanging extra blanks on the end of lines is a handy house-hold hack. Lines 270 and 280 will send control to the SCREEN or BORDER module, and Line 290 calls the PRINTOUT subroutine. On Return, or if an incorrect choice is entered, Line 300 sends control back to 220 to await more input. Both upper and lower case choices are checked for.

    Lines 320-520 SCREEN module

    This module accomplishes the same tasks for screen color and intensity.

    Lines 530-730 BORDER module

    This module updates the border.

    Lines 740-860 PRINTOUT module

    This prompts for a printed comment, then prints the current settings to a printer using LPRINT statements. Line 810 sets a variable COL equal to the value of the screen color variable SCOL. The program goes to a subroutine at 950 where a color name is assigned to the variable COL$ and printed at the end of the line on return. Line 830 does the same for BORDER. By using the variable COL and setting it equal to SCOL or BCOL, we can use the same subroutine for both modules. When printing is complete, the program goes to Line 1350 to reprint the bottom of the menu, and returns to the module it came from.

    Line 880-930 ERROR trapping

    Trying to print without having a printer on results in an error, normally crashing a program. Line 780 sets a TRAP statement for Line 890. If the printer is off and an error is generated, the program will go to Line 890. This line uses a PEEK statement to check memory location 195 which holds the error code and checks to see if it's Error 138, "Device did not respond." If so, it prompts you to turn on the printer, goes to Line 1350 to reprint the menu and returns to await input. This error trapping allows recovery whether a printer is present and turned on or not, without crashing the program.

    Lines 940-1140 COLOR subroutine

    This is a subroutine that assigns a name to the colors and text intensity. When finished, it returns to allow printing the names at the end of the print line.

    Lines 1160-1380 Screen menu

    These lines print the original screen menu and reprint the bottom portion when Line 1350 is used. Line 1170 begins with a "Clear the screen" command generated by using Esc-Ctrl+Clear. POKE 752,1 turns off the cursor for a neat screen appearance.

Conclusion
    I hope you enjoy Color Set and use it to figure out new screen and text colors for your own programs. You can sit at the keyboard and create a number of attractive screens, labeling them and printing them out for future use. You may add comments like "Green on Black with Blue Border" or "Intro screen for Mailing List 3/21/87" or "Screen # 14" etc. To use them in your programs, simply put in the SETCOLOR or POKE statements as printed. The use of color can add a whole new dimension to your new or existing programs.
    Jackson Beebe is a health-care center director in Champaign- Urbana, Illinois. He has owned his 800XL (upgraded to 256K) since the fall of 1984. He teaches Introduction to BASIC at Parkland College and is President of the Progressive Atari Computing User Group (PAC) of central Illinois. He remains a die-hard fan of BASIC and Atari 8-bit computers.


LISTING 1: BASIC
Blue indicates inverse video

HY 10 REM ******************************
VA 20 REM *         COLOR SET          *
UO 30 REM *      by Jackson Beebe      *
OH 40 REM *       Copyright 1988       *
ZF 50 REM *     by ANALOG Computing    *
IM 55 REM ******************************
BP 60 REM << initialize & Screen menu >>
LV 70 REM < Change Defaults at Line 110 >
XZ 80 REM LINT=Ltr Int    SCOL=Screen Col
HY 90 REM SINT=Scr Int    BCOL=Bdr Col etc
QM 100 REM
PU 110 LINT=0:SCOL=0:SINT=12:BCOL=7:BINT=
   4
RS 120 DIM COM$(35),COL$(12),LINT$(6)
WS 130 GOSUB 1170:REM Print menu
QU 140 REM
BW 150 REM << LETTERS module >>
JK 160 POSITION 2,11:? " SCREEN |";CHR$(
   27);CHRS(30);" ";CHRS(27);CHRS(31);
BG 170 ? "|";CHR$(27);CHR$(28);" ";CHR$(2
   7);CHR$(29);"|";
LN 180 POSITION 2,15:? " BORDER |":CHR$(
   27):CHR$(30);" ":CHR$(27);CHR$(31);
BK 190 ? "|";CHR$(27);CHR$(28);" ";CHR$(2
   7);CHR$(29);"|";
EO 200 POSITION 2:7:? " LETTERS |";:POSIT
   ION 16,7:? CHR$(27);CHR$(156);" ":CHR$
   (27);CHR$(157)
RQ 210 REM << Input choice >>
EO 220 CLOSE #1:OPEN #1,4,0,"K:":GET #1,A
XE 230 IF LINT<14 AND A=45 THEN LINT=LINT
   +2:SETCOLOR 1,0,LINT:POSITION 34,7:? L
   INT:" "
NO 240 IF A=45 THEN POSITION 30,9"? LINT;
   " ";:GOTO 160
JT 250~IF LINT>0 AND A=61 THEN LINT=LINT-
   2:SETCOLOR 1,0,LINT:POSITION 34,7:? LI
   NT;" "
AE 260 IF A=61 THEN POSITION 30,9:? LINT:
   " ":GOTO 160
XX 270 IF A=83 OR A=115 THEN 330:REM Scr
LA 280 IF A=66 OR A=98 THEN 540:REM Bdr
SV 290 IF A=80 OR A=112 THEN GOSUB 750:RE
   M Prt
JT 300 GOTO 228:REM Wrong choice
QQ 310 REM
GB 320 REM << SCREEN Module >>
MR 330 POSITION 2,7:? " LETTERS ":POSITIO
   N 16,7:? CHR$(27);CHR$(28);" ";CHR$(27
   );CHR$(29)
LH 340 POSITION 2,15:? " BORDER |":CHR$(
   27);CHR$(30);" ";CHR$(27);CHR$(31);
BE 350 ? "|";CHR$(27);CHR$(28);" ";CHR$(2
   7);CHR$(29);"|";
TC 360 POSITION 2,11:? " SCREEN |";CHR$(
   27);CHR$(158)," ";CHR$(27);CHR$(159);
QO 370 ? "|";CHR$(27);CHR$(156);" ":CHR$(
   27);CHR$(157);"|"
SF 380 REM << Input choice >>
FD 390 CLOSE #1:OPEN #1,4,0."K:":GET #1,A
ZJ 400 IF SCOL>0 AND A=43 THEN SCOL=SCOL-
   1:SETCOLOR 2,SCOL,SINT:POSITION 32,11:
   ? SCOL;",";SINT;" "
GI 410 IF A=43 THEN POSITION 30,13:? SCOL
   *16+SINT;" "
QM 420 IF SCOL<14 AND A=42 THEN 5COL=5COL
   +1:SETCOLOR 2,SCOL,SINT:POSITION 32,11
   :? SCOL;","SINT;" "
GB 430 IF A=42 THEN POSITION 38,13:? 5COL
   *16+SINT:" "
IO 440 IF SINT<14 AND A=45 THEN SINT=SINT
   +2:SETCOLOR 2,SCOL,SINT:POSITION 32,11
   :? SCOL:" ":SINT:" "
HM 450 IF A=45 THEN POSITION 38,13:? SCOL
   *16+SINT;" "
NZ 460 IF SINT>0 AND A=61 THEN SINT=SINT-
   2:SETCOLOR 2,SCOL,SINT:POSITION 32,11:
   ? SCOL;",";SINT:" "
GS 470 If A=61 THEN POSITION 30,13:? SCOL
   *16+SINT;" "
PU 480 IF A=76 OR A=108 THEN 160:REM Ltr
LE 490 IF A=66 OR A=98 THEN 540:REM Bdr
SG 500 IF A=80 OR A=112 THEN GOSUB 750:RE
   M Prt
NG 510 GOTO 390:REM Wrong choice
QU 520 REM
GK 530 REM << BORDER module >>
MV 540 POSITION 2,7:? " LETTERS ":POSITIO
   N 16,7:? CHR$(27);CHR$(28);" ";CHR$(27
   );CHR$(29)
JM 550 POSITION 2,11:? " SCREEN |";CHR$(
   27);CHR$(30);" ";CHR$(27);CHR$(31):
BI 560 ? "|";CHR$(27);CHR$(28);" ";CHR$(2
   7);CHR$(29);"|";
VF 570 POSITION 2,15:? " BORDER |";CHR$(
   27);CHR$(158)" ":CHR$(27);CHR$(159)
NU 580 ? "|";CHR$(27);CHRS(156);" ";CHR$(
   27);CHR$(157);"|";
SJ 590 REM << Input choice >>
EO 600 CLOSE #1:OPEN #1,4,0,"K:":GET #1,A
WA 610 IF BCOL>0 AND A=43 THEN BCOL=BCOL-
   1:SETCOLOR 4,BCOL,BINT:POSITION 32,15:
   ? BCOL;",";BINT;" "
MG 620 IF A=43 THEN POSITION 30,17:? BCOL
   *16+BINT;" "
JL 630 IF BCOL<14 AND A=42 THEN BCOL=BCOL
   +1:5ETCOLOR 4,BCOL,BINT:POSITION 32,15
   :? BCOL;",";BINT;" "
LZ 640 IF A=42 THEN POSITION 30,17:? BCOL
   *16+BINT;" "
BN 650 IF BINT<14 AND A=45 THEN BINT=BINT
   +2:SETCOLOR 4,BCOL,BINT:POSITION 32,15
   :? BCOL;",";BINT;" "
NK 660 IF A=45 THEN POSITION 30,17:? BCOL
   *16+BINT;" "
KQ 670 IF BINT>0 AND A=61 THEN BINT=BINT-
   2:SETCOLOR 4,BCOL,BINT:POSITION 32,15:
   ? BCOL;","BINT;" "
MQ 680 IF A=61 THEN POSITION 30,17:? BCOL
   *16+BINT;" "
PY 690 IF A=76 OR A=108 THEN 160:REM Ltr
XO 700 IF A=83 OR A=115 THEN 330:REM Scr
SK 710 IF A=80 OR A=112 THEN GOSUB 750:RE
   M Prt
KT 720 GOTO 600:REM Wrong choice
QY 730 REM
AH 740 REM << PRINTOUT Subroutine >>
XY 750 POSITION 3,20:? "Add printed comme
   nt or push RETURN"
LM 760 ? " |
          |"
AM 770 ? "
   ":POSITION 2,21:INPUT COM$
NB 780 TRAP 890:LPRINT :LPRINT :LPRINT :L
   PRINT "*******************************
   *********"
GB 790 GOSUB 950:LPRINT :LPRINT "
   ";COM$:LPRINT :LPRINT "  LETTERS = SET
   COLOR 1,0,";LINT;" =   ";LINT$
WG 800 LPRINT "             POKE 709.";LI
   NT
SY 810 COL=SCOL:GOSUB 950:LPRINT :LPRINT
   "  SCREEN  = SETCOLOR 2,";SCOL;".";SIN
   T;" =  ":COL$
MZ 820 LPRINT "            POKE 710,";SCO
   L*16+SINT
CX 830 COL=BCOL:GOSUB 950:LPRINT :LPRINT
   "  BORDER  = SETCOLOR 4,";BCOL;",";BIN
   T;" =  ";COL$
PH 840 LPRINT "            POKE 712.";BCO
   L*16+BINT
FQ 850 LPRINT :LPRINT "******************
   **********************":LPRINT :LPRINT
    :LPRINT
BQ 860 GOTO 1350:REM Reset
RH 870 REM
KE 880 REM << Error >>
UU 890 IF PEEK(195)=138 THEN POSITION 2,2
   0:? "
      "
NW 900 IF PEEK(195)=138 THEN POSITION 2,2
   1:? "  TURN ON PRINTER AND PUSH RETURN
      "
ET 910" CLOSE #1:OPEN #1,4,0,"K:":GET #1,A
MV 920 TRAP 40000:GOTO 1350:REM Reset
RA 930 REM
00 940 REM << COLOR Subroutine >>
XO 950 IF COL=0 THEN COL$="GRAY"
JX 960 IF COL=1 THEN COL$="GOLD"
ZX 970 IF COL=2 THEN COL$="ORANGE"
CX 980 IF COL=3 THEN COL$="RED-ORANGE"
XU 990 IF COL=4 THEN COLS="PINK"
FX 1000 IF COL=5 THEN COL$="PINK-PURPLE"
OW 1010 IF COL=6 THEN COL$="PURPLE-BLUE"
XI 1020 IF COL=7 THEN COL$="DARK BLUE"
GC 1030 IF COL=8 THEN COL$="BLUE"
GN 1040 IF COL=9 THEN COL$="LIGHT BLUE"
JD 1050 IF COL=10 THEN COL$="TURQUOISE"
OW 1060 IF COL=11 THEN COL$="GREEN-BLUE"
CM 1070 IF COL=12 THEN COL$="GREEN"
HF 1080 IF COL=13 THEN COL$="YELLOW-GREEN
   "
VV 1090 IF COL=14 THEN COL$="ORANGE-GREEN
   "
PD 1100 IF COL=15 THEN COL$="LIGHT ORANGE
   "
AM 1110 IF LINT<6 THEN LINT$="DARK"
HO 1120 IF LINT>4 AND LINT<18 THEN LINT$=
   "MEDIUM"
UH 1130 IF LINT>8 THEN LINT$="BRIGHT"
AN 1140 RETURN
IN 1150 REM
MS 1160 REM << Screen Menu Subroutine >>
NO 1170 ? "":POKE 82,0:POKE 752,1:SETCOL
   OR 1,8,LINT:SETCOLOR 2,SCOL,SINT:SETCO
   LOR 4,BCOL,BINT
WH 1180 POSITION 0 i:? "
  
AW 1190 ? :? "     Use L,S,B keys to sele
   ct item "
VA 1200 ? :? "   ITEM   COLOR INTEN.   SE
   TTING"
OD 1210 ? "
   "
XS 1220 ? " |         |   |   | SETCOLOR
   1,0,";LINT:P05ITION 38,7:? "|"
NK 1230 ? "
   "
LS 1240 POSITION 19,9:? "| POKE 709,";LIN
   T;:POSITION 38,9:? "|"
IM 1250 ? "
   "
NO 1260 ? " |         |   |   |  SETCOLOR
   2,";SCOL;",";SINT;:POSITION 38,11:? "|
   "
NW 1270 ? "
   "
WB 1280 P05ITION 19,13:? "| POKE 710,";SC
   OL*16+SINT;:POSITION 38,13:? "|"
IY 1290 ? "
   "
QT 1300 ? " |         |   |   |  SETCOLOR
   4,";BCOL;",";BINT;:POSITION 38,15:? "|
   "
NG 1310 ? "
   "
JD 1320 POS1TION 19,17:? "| POKE 712,";BC
   OL*16+BINT;:POSITION 38 17,? "|"
DG 1330 POSITION 19,18:? "
   "
AS 1340 ? "
   "
BF 1350 POSITION 0,20:? " |  Push P  to P
   RINT these settings   |"
AU 1360 ? "
   "
KC 1370 ? "
            "
BD 1380 RETURN