DOS 2.0 COLOR (Star-Dot-Star PC World Vol 2 No 4 April 1984) BASIC provides a COLOR statement; but DOS 2.0 does not. However, the DOS 2.0 command PROMPT is used to implement ANSI.SYS escape sequences. This is possible because the PROMPT command uses $e to represent the ESCape code 27, which cannot be entered from the keyboard. Copy and save the batch file in the listing COLOR.BAT. In addition to the batch file, create a CONFIG.SYS file named containing the line DEVICE=ANSI.SYS. (You will also need the file ANSI.SYS, from your DOS 2.0 disk, on this disk.) Now reboot your PC to install the ANSI.SYS driver. COLOR.BAT can now be used to set screen colors. The command COLOR GREEN, for example, sets the display's characters to green, and the command COLOR BBLUE turns the background blue, keeping the current foreground (character) color. Notice that the letter B, indicating background, is prefixed to the name of the color. You can use more than one parameter in the same command, for example, COLOR GREEN BBLUE; however, if the foreground and background colors are the same, the characters will be invisible. Because all the background colors provided by COLOR.BAT are low intensity, you can restore visible characters by entering the command COLOR BRIGHT. (Work carefully, because what you type is invisible at this point.) This command sets the current foreground color to high intensity. To change characters from low intensity blue to high intensity green, use the command COLOR BRIGHT GREEN. When changing characters from high to low intensity, you must include the name of the color after the parameter NORMAL (for example, COLOR NORMAL CYAN) since the command COLOR NORMAL (without specifying a color), merely returns the display to its usual appearance. COLOR.BAT also works with the monochrome monitor to provide normal, bright (high intensity), and inverse video characters. COLOR.BAT can easily be modified to include blinking or underlining on the monochrome monitor. A table of the SGR (Set Graphics Rendition) escape code sequences are in the DOS manual. You can also combine PROMPT and other escape codes in batch files to define strings for key combinations such as - or - -- a poor man's version of ProKey. The following can be placed in a batch file, which then assigns the string DIR B: (with no carriage return) to -B. prompt $e[0;48;"DIR B:"p prompt Note that there is no semicolon after the second set of quotation marks, despite the SGR syntax shown in the documentation. If the semicolon is included before the final p, unexpected results occur. ASCII and extended ASCII codes can be found in the Technical Reference manual. If you don't have a manual, they are also in Appendix G of the BASIC manual. Unfortunately, many programs have their own keyboard and screen display routines, and the ANSI.SYS driver is locked out while these programs are active. Hopefully, they restore the previous state upon termination. BASICA and Peachtext are two programs that behave this way. COLOR.BAT: goto %1 :normal prompt $e[0m goto exit :bright prompt $e[1m goto exit :reverse prompt $e[7m goto exit :black prompt $e[30m goto exit :red prompt $e[31m goto exit :green prompt $e[32m goto exit :yellow prompt $e[33m goto exit :blue prompt $e[34m goto exit :magenta prompt $e[35m goto exit :cyan prompt $e[36m goto exit :white prompt $e[37m goto exit :bblack prompt $e[40m goto exit :bred prompt $e[41m goto exit :bgreen prompt $e[42m goto exit :byellow prompt $e[43m goto exit :bblue prompt $e[44m goto exit :bmagenta prompt $e[45m goto exit :bcyan prompt $e[46m goto exit :bwhite prompt $e[47m goto exit :exit shift if not .==.%1 goto %1 prompt echo off cls goto done :help .ANSI.SYS and CONFIG.SYS (containing . the line DEVICE=ANSI.SYS) must be . accessible when the PC is booted. .Type COLOR and then your choice of . character, intensity, and/or back- . ground color(s) selected from the . following list of parameters: .For color displays: . black bblack . red bred . green bgreen . yellow byellow . blue bblue . magenta bmagenta . cyan bcyan . white bwhite .For color and monochrome displays: . normal . bright . reverse :done ------------------------------------------------------------------ Hi-Res Magic (PC Magazine Vol 3 No 8 May 1, 1984 User-to-User) The program below displays unusual color effects on RGB monitors. If you want to be extremely weird, you can use OUT &H3D8,8 in line 130, but the characters as well as the line graphics will appear as "flags". For an even better display, include these additional three lines and tap any key a few times. Then hit any key several times and watch the effect. 250 I$=INKEY$:IF I$="" THEN 250 ELSE K=(K-1) MOD 128 260 OUT 985,K 270 GOTO 250 - - - - - - - - 100 'Hi-Res Color Demo 110 SCREEN 2:WIDTH 80:KEY OFF:CLS 120 OUT 985,0 130 OUT &H3D8,10 140 LOCATE 20,2 150 PRINT "0000 0001 0010 0011 0100 0101 0110 0111 "; 160 PRINT "1000 1001 1010 1011 1100 1101 1110 1111" 170 FOR COLR=0 TO 15 180 FOR N=0 TO 9 190 X=(40*COLR)+(4*N) 200 IF COLR >7 THEN LINE (X,0) -(X,150) 210 IF COLR AND 4 THEN LINE (X+1,0)-(X+1,150) 220 IF COLR AND 2 THEN LINE (X+2,0)-(X+2,150) 230 IF COLR AND 1 THEN LINE (X+3,0)-(X+3,150) 240 NEXT:NEXT ----------------------------------------------------------------- Changing Border Colors (PC Magazine Vol 3 No 24 Dec 11, 1984 User-to-User) Many programs allow you to adjust the foreground and background colors, but few offer the option to set border colors. So even if you can change the main colors, you end up running the program against a black border. A short BORDER.COM can be created using DEBUG to do this nicely. To see the results of this file, get into DOS, type BORDER, and hit Enter. A>DEBUG -n BORDER.COM -e100 xxxx:0100 5A.B0 8A.03 C7.BA 0A.D9 C0.03 74.EE 01.CD C3.20 -rcx CX 0000 :8 -w Writing 0008 bytes -q The border color in this case is light blue, but you can create different borders by substituting numbers other than 03 after the 8A. If you do this, give you different colored files different names; do this by substituting other names in the -n line. ----------------------------------------------------------------- Adding a Bit of Color (PC Magazine Vol 4 No 9 April 30, 1985 PC Tutor) ....add color output to software packages that weren't originally written to support it. According to the IBM Technical Reference manual, write an I/O command to port address 3D9. This port is the Color Select Register of the IBM color card. It allows setting a border color in alphanumeric modes, and that's about it. The functions of the bits addressed by this port are: Bits 0-2: B/G/R select the border color Bit 3: Intensify border color These 4 bits select the border color in alphanumeric modes. (In graphics mode these bits set the background color.) Bit 4: Select alternate background color set This selects an intensified set of background colors in alphanumeric and graphics modes. Bit 5: Color palette select (graphics only) This selects the set of screen colors (cyan/magenta/white) or (green/red/yellow). The 3D9 port is not going to be much use in character modes, except to set up a border color. The following program, created with DEBUG.COM, will set a dark-blue border when used with the normal IBM color monitor and color board. A>DEBUG BORDER.COM -file not found -A100 xxxx:0100 MOV AL,1 xxxx:0102 MOV DX,3D9 xxxx:0105 OUT DX,AL xxxx:0106 MOV AX,4C00 xxxx:0109 INT 21 xxxx:010B -R CX CX 0000 :0012 -W -Q More satisfactory methods for color output can range from simple to complex. The simplest answer is to just clear the screen to the desired color and then proceed, hoping that your program does not alter the screen coloring. A tougher approach is to use the ANSI.SYS method of sending escape sequences to set screen color. The final approach requires actually modifying the program in question to achieve color. To see whether the simple approach will work, try entering this program: A>DEBUG SCR.COM file not found -A100 1E9F:0100 MOV AX,600 1E9F:0103 MOV CX,0 1E9F:0106 MOV DX,183F 1E9F:0109 MOV BH,03 1E9F:010B INT 10 1E9B:010D MOV AX,4C00 1E9F:0110 INT 21 -R CX CX 0000 :0020 -W -Q Once you have created this program, you can just run it by name: at the A> simply type SCR. On a color display, it will change the screen color. The value 03 here for the screen color (light blue on black background) can be changed to other combinations of color settings. ----------------------------------------------------------------- Color-Conscious CLS (PC Magazine Vol 4 No 14 July 9, 1985 User-to-User) Users of RGB monitors often use utilities such as Peter Norton's SCRATR to set screen colors while in DOS. Unfortunately, the DOS CLS command not only clears the screen, it also resets the color adaptor back to the default white on black. Even Norton's CLEAR.COM program has the same effect. The short CL.COM program provides a solution to this problem. It will clear the screen but will not change the current screen attributes. - - - - - A>debug cl.com File not found -a 100 xxxx:0100 mov ah,08 xxxx:0102 mov,bh,00 xxxx:0104 int 10 xxxx:0106 mov bh,ah xxxx:0108 mov ax,0600 xxxx:010B mov cx,0000 xxxx:010E mov dx,184f xxxx:0111 int 10 xxxx:0113 mov ah,02 xxxx:0115 mov bh,00 xxxx:0117 mov dx,0000 xxxx:011A int 10 xxxx:011C int 20 xxxx:011E -rcx CX 0000 :le -w Writing 001E bytes -q - - - - - Editor's Note: CL.COM is an improvement over the CLS command for users with color systems. Most of us rely on a User-to-User oldie called COLOR.COM, which sets the colors and clears the screen. The COLOR.COM program sets screen colors in DOS. Don't actually enter ## and ** -- instead pick the colors you want by substituting the proper hex value of the background/foreground colors. For blue letters on white, replace the ## with 71; for white on blue replace it with 17; for brown on red, replace it with 46. Then replace the ** with the hex value of the border color. For a light-blue border, replace the ** with 03; for light green, replace it with 02; for bright red, replace it with 0C. A>debug -n color.com -e 100 2b c0 1e 50 b8 03 00 cd 10 b8 00 06 b9 00 00 ba -e 110 50 20 b7 ## cd 10 b4 02 ba 00 00 b7 00 cd 10 b0 -e 120 ** ba d9 03 ee cd 20 -rcx CX 0000 :27 -w Writing 0027 bytes -q Note: For another method and programs to use, see the ANSICOL.BAS and and ANSIMAKR.BAS programs along with the ANSIMAKR.DOC file. ----------------------------------------------------------------- Color Me Anything (PC Magazine Vol 4 No 20 Oct 1, 1985 PC Tutor) To change background and foreground display colors at the DOS command level, use the PROMPT command to write the ANSI control sequences that color the display. Be certain ANSI.SYS and a CONFIG.SYS file with the line: DEVICE=ANSI.SYS are in the root directory. Then, to create yellow on blue with a distinctive magenta DOS prompt, for example, use the prompt: PROMPT $e[35;44;1m$p$g$e[33;44;1m. The initial $e is PROMPT's lingo for the Escape code needed by ANSI.SYS, and the table below shows the numbers for ANSI.SYS screen attribute control sequences for the PROMPT command. $e[#;...;#m where # is shown below: Normal white on black: 0 High intensity: 1 Monochrome display underline: 4 Blink: 5 Reverse video: 7 Invisible: 8 Foreground Background Black: 30 40 Red: 31 41 Green: 32 42 Yellow: 33 43 Blue: 34 44 Magenta: 35 45 Cyan: 36 46 White: 37 47 ----------------------------------------------------------------- Better DOS Colors (PC Magazine Vol 4 No 23 Nov 12, 1985 User-to-User) The CSET.COM program, created with DEBUG, allows foreground, background and border colors on an RGB monitor to be set. The DOS CLS command wipes out the colors set by CSET, so instead of using CLS, use CSET to clear the screen. To enter your own border color, replace the * with a hex number from 0 to F (where 1=blue, 2=green, ...F=high- intensity white). To enter the foreground (text) and background colors, replace the ## with a two-digit hex number from 00 to FF. To calculate this number, multiply the background color by 16 and add it to the foreground, and convert the total to hex -- or simply use the individual hex values of the background as the first digit and the foreground as the second digit. A>DEBUG CSET.COM File not found -A 100 xxxx:0100 SUB AX,AX xxxx:xxxx PUSH DS xxxx:xxxx PUSH AX xxxx:xxxx MOV AX,0003 xxxx:xxxx INT 10 xxxx:xxxx MOV AX,0B00 xxxx:xxxx MOV BX,000* xxxx:xxxx INT 10 xxxx:xxxx MOV AX,0600 xxxx:xxxx MOV CX,0000 xxxx:xxxx MOV DX,2050 xxxx:xxxx MOV BH,## xxxx:xxxx INT 10 xxxx:xxxx MOV AH,02 xxxx:xxxx MOV DX,0000 xxxx:xxxx MOV BH,00 xxxx:xxxx INT 10 xxxx:xxxx RETF xxxx:xxxx -R CX CX 0000 :00xx -W Writing xxxx bytes -Q ----------------------------------------------------------------- Color CLS (PC Magazine Vol 4 No 25 Dec 10, 1985 User-to-User) The instructions below allow DOS users to patch COMMAND.COM so that CLS will set the screen to any color. This will work on both the standard and enhanced color graphics cards, and on the PC and AT. If you don't mind a black border, just use DEBUG to edit the appropriate screen attribute byte. Figure 1 below is instructions to patch just the foreground and background DOS 2.1 COMMAND.COM CLS command. With this patch the screen reverts to bright yellow text on a blue background whenever you type in CLS. You will no longer need a small .COM file or ANSI.SYS to run DOS in color. If you do use ANSI.SYS, the patch will be overridden. Figure 2 includes patches to change the border colors of all versions of DOS 2.0 and higher. Complications arise in each version because the original CLS command selects black as the border color by XORing the BX register. Inserting extra code to MOVe the desired number into the register would lengthen COMMAND.COM by one byte. This was avoided by rearranging the code of the CLS portion of COMMAND.COM and taking advantage of a zero that is left in the BH register. Figures 3 and 4 show the before and after CLS addresses. The border patch won't work on an EGA configured for the high- resolution 640 by 370 mode; BIOS prevents a border color from being set in this mode. It can be set, however, if the standard RGB monitor is attached. If you want to make additional color changes, edit the bytes shown in the table in Figure 4. If you are using a patched version of COMMAND.COM and are prompted to insert a disk containing COMMAND.COM in drive A:, you must insert a disk containing the patched version. Editor's Note: It's fairly easy to use colors other than the ones in the example (as shown here, an attribute byte of 1E and a border of 01 yields borth a border and background of dark blue with intense yellow text). The two-character hex attribute byte stores the foreground as the rightmost character and the background as the leftmost character. Pick a hex numbe from 0 to F for each, where 0 = black, 1 = blue, 2 = green, 3 = light blue (cyan), 4 = red, 5 = purple (magenta), 6 = either brown or yellow depending on your monitor (IBM's monitor produces a true brown; others may not), 7 = grayish white, 8 = dark gray, 9 = bright blue; A = bright green, B = bright light blue, C = bright red, D = bright purple, E = bright yellow, and F = overintense white. So green text on a purple background would be 52, and bright red text on a light blue background would be 3C. The border color is obviously just a single character from the above list. Figure 1: DOS 2.1 screen color change; black border A>debug command.com -e 2539 1e -w Writing 4580 bytes -q Figure 2: Change border and screen attributes DOS 2.0: DOS 2.1: A>debug command.com A>debug command.com -E 2346 1E -E 2359 1E -M CS:2337 2352 CS:2331 -M CS:234A 2365 CS:2344 -A 234d -A 2360 xxxx:234D MOV BL,01 xxxx:2360 MOV BL,01 xxxx:234F MOV AH,0B xxxx:2362 MOV AH,0B xxxx:2351 xxxx:2364 -W -W Writing 4500 bytes Writing 4580 bytes -Q -Q DOS 3.0: DOS 3.1 A>debug command.com A>debug command.com -E 2428 1E -E 2642 1E -M CS:2418 2434 CS:2412 -M CS:2632 264E CS:262C -A 242F -A 2649 xxxx:242F MOV BL,01 xxxx:2649 MOV BL,01 xxxx:2431 MOV AH,0B xxxx:264B MOV AH,0B xxxx:2433 xxxx:264D -W -W Writing 561A bytes Writing 5AAA bytes -Q -Q Figure 3: Standard patches before the border patch is made to COMMAND.COM DOS Location of Address of Screen Version CLS Command Attribute Byte 2.0 2331-2353 2346 2.1 2344-2366 2359 3.0 2412-2345 2428 3.1 262C-264F 2642 Figure 4: New addresses after border patch DOS Address of Screen Address of Border Version Attribute Byte Attribute Byte 2.0 2340 234E 2.1 2353 2361 3.0 2422 2430 3.1 263C 264A ----------------------------------------------------------------- Bordering on Madness (PC Magazine Vol 4 No 26 Dec 24, 1985 PC Tutor) Preference for color control at the DOS command level is to install ANSI.SYS and use the PROMPT command (see PC Mag Vol 4 No 20 PC Tutor "Color Me Anything" above). But you need not run COLOR.COM (see PC Mag Vol 4 No 14 PC Tutor "Color-Conscious CLS" above) if you have ANSI.SYS installed. ANSI.SYS maintains its own default video color attribute, which starts out as white on black. Until that attribute is changed (as with the PROMPT command), it will display white on black no matter what COLOR.COM tries to do. A read advantage of using ANSI.SYS is that it will not wipe out the border when you clear the screen with CLS. However, many programs reset the video mode (wiping out the border) when they load. KBORDER.COM changes the border color with a couple of keystrokes. Create KBORDER.COM using DEBUG 2.0 or later. Don't run the program while in DEBUG. Quit DEBUG first and then run it. The program will remain resident in memory until you reboot. After KBORDER.COM is loaded, you can hold down the Ctrl key and press the < key to step through all 16 border colors. Ctrl > steps backward through these border colors. It will work within most programs but not those (like XyWrite) that hog the keyboard interrupt. If a PC display is in medium-resolution graphics mode, KBORDER changes the background color. In high-resolution mode on a PC (which is normally white on black), KBORDER changes the foreground color. This provides a little variety when working with Microsoft Word or other programs that use high-resolution graphics. It's easy to return the border to the color you like best after it's been clobbered. Just type Ctrl < and Ctrl > quickly in succession. The CLS command works differently depending on whether ANSI.SYS has been loaded or not. Although seemingly a simple command, CLS has the unique distinction of being the only internal DOS command that calls the BIOS directly. All other internal commands use only DOS calls. Since the use of a BIOS call from within COMMAND.COM clearly violates the hierarchical structure of DOS, COMMAND.COM tries to avoid having to do so. If ANSI.SYS is loaded, COMMAND.COM executes CLS by simply sending the ANSI.SYS ED (Erase in Display) sequence to the display through DOS. ANSI.SYS intercepts this sequence and colors the whole screen with the last screen attribute. It does nothing to the border. If standard output has been redirected from the screen to another device (as with the CTTY command) or to a file, COMMAND.COM also avoids using BIOS calls for CLS. For instance, try running the command: CLS > CLRSCRN. Whether ANSI.SYS is loaded or not, COMMAND.COM will create a file called CLRSCRN, which contains the 4-byte ANSI ED sequence for clearing your screen. If you then enter: TYPE CLRSCRN your screen will be cleared if you have ANSI.SYS loaded. If not, you'll just see the ANSI sequence displayed on your screen. Only if COMMAND.COM actually has to clear your display -- without the benefit of ANSI.SYS to do the work -- will it make the BIOS calls to set the background to black and wipe out the border. This is a more literal interpretation of "Clear Screen" than most of us would prefer. A>DEBUG -A :0100 JMP 013E :0102 DB 0 :0103 DW 0,0 :0107 STI :0108 PUSH AX :0109 PUSH BX :010A PUSH DS :010B CS: :010C MOV BL,[0102] :0110 IN AL,60 :0112 CMP AL,33 :0114 JZ 011E :0116 CMP AL,34 :0118 JNZ 0136 :011A DEC BL :011C JMP 0120 :011E INC BL :0120 AND BL,0F :0123 MOV AH,2 :0125 INT 16 :0127 TEST AL,4 :0129 JZ 0136 :012B CS: :012C MOV [0102],BL :0130 SUB BH,BH :0132 MOV AH,0B :0134 INT 10 :0136 POP DS :0137 POP BX :0138 POP AX :0139 CS: :013A JMP FAR [0103] :013E MOV AX,3509 :0141 INT 21 :0143 MOV [0103],BX :0147 MOV [0105],ES :014B MOV DX,0107 :014E MOV AX,2509 :0151 INT 21 :0153 MOV DX,013E :0156 INT 27 :0158 -N KBORDER.COM -R CX CX 0000 :0058 -W Writing 0058 bytes -Q