1.

Solve : Colors - one line in blue another in red??

Answer»

Are there any known methods that allow to show
one line of text in blue and
another one in red
from within a DOS batch?

E.g. A debug script created on the fly that does the job?

Or do I have to write my own debug script, poking into video memory?

Thanks in advance for any source you can provide!
That's gonna be great! @echo off
color 40
echo line red
color 80 (i think, not sure, test it)
echo line blue
pause
blackbarry!

If this question wouldn't be a real challenge, believe me, then I wouldn't have it posted here.
The color command changes the color for the whole screen not only for the next output.

I guess I will need to figure this out myself

Just wondering why nobody has ask this question before. There was just somebody asking for mutex via DOS but nobody ask for color ... strange...Quote

blackbarry!

If this question wouldn't be a real challenge, believe me, then I wouldn't have it posted here.
The color command changes the color for the whole screen not only for the next output.

I guess I will need to figure this out myself

Just wondering why nobody has ask this question before. There was just somebody asking for mutex via DOS but nobody ask for color ... strange...

sorry man, I just tried to help


btw its blackb>E<rry, not blackarry


at least you can work with colors on the forum (as seen you sentence) It is an amused question , here you has a possible SOLUTION:

Code: [Select]debug < %0.bat
GOTO fin

N ECHOBLUE.COM
A 100
MOV BL,1
MOV BH,0
MOV SI,0082
MOV AL,[SI]
MOV CX,1
MOV AH,09
INT 10
MOV AH,3
INT 10
INC DL
MOV AH,2
INT 10
INC SI
MOV AL,[SI]
CMP AL,0D
JNZ 109
RET

r cx
22
w


N ECHORED.COM
A 100
MOV BL,4
MOV BH,0
MOV SI,0082
MOV AL,[SI]
MOV CX,1
MOV AH,09
INT 10
MOV AH,3
INT 10
INC DL
MOV AH,2
INT 10
INC SI
MOV AL,[SI]
CMP AL,0D
JNZ 109
RET

r cx
22
w
q

:finCopy an execute the previous BAT, this code make two commands, ECHORED.COM and ECHOBLUE.COM:


ECHORED ¡Hola mundo!
ECHOBLUE Hello world!

¡Hola mundo!
Hello world!

It's obvious that the code could be improved doing that the first argument be the number of color:

ECHOCOLOR 4 ¡Hola mundo!
ECHOCOLOR 1 Hello world!

But now I'm very busy in my work, It's an exercise for you
I wait for your contribution




Here you have a brief explanation of the code:


The first line in the assembler code is the color:

MOV BL,1 : blue
MOV BL,4 : red

You can see the possible values for color with the MS-DOS command:
COLOR /?

You can read the BIOS Interrupts here:

http://www.uv.tietgen.dk/staff/mlha/PC/Prog/asm/int/INT10.htm

-------------------------------------------
INT 10, 9: write 'char'&attrib
AH = 9
AL = char
BH = display page (0)
BL = attribute
CX = no. of repetitions
= 2000(7D0h) to fill 80*25 screen

cursor not moved

-------------------------------------------

INT 10, 3: report cursor location, shape
AH = 3
BH = display page (normal = 0) CH, CL = starting, ending scan line
DH, DL = row, column
--------------------------------------------

INT 10, 2: set cursor location
AH = 2
BH = display page (normal=0)
DH,DL = row,col (0..24,0..39/79)
-------------------------------------------

GOOD LOOK !!Doesn't work for me. I get this error:

The system cannot find the file specified.
Thiss is right after the "debug" line. :-?Dilbert,
Try with quotes:
debug < "%0.bat"CARLOS!

This is awesome!

It works well in WinXP when the command window is 80x25. I will continue looking for a solution that works with bigger windows outside the 80x25 range. However this is a good start!
Using the concept of DOS functions described here http://www.cmdtips.com/dostips/DtTutoFunctions.php I came up with the following code that can easily be copied and distributed in a batch file. The helper file ECHOxx.COM will be created on the fly if not already there, whereas xx is the color.

Conditions for the correct EXECUTION are:
  • %temp% variable must point to a valid directory
  • command window must not exceed 80x25
Both conditions are enforced in the example and may be removed if not needed.
A dot appended to the color code will enforce a line break. Without the dot one can output different colors in one line.

Code: [Select]@echo off
rem enforce conditions
if not exist "%temp%" set temp=%tmp%
if not exist "%temp%" set temp=c:\temp
if not exist "%temp%" md "%temp%"
mode con: cols=80 lines=25

call:echo 9. one line of text in blue and
call:echo C. another one in red
call:echo 9 D
call:echo A O
call:echo B S
call:echo C T
call:echo D I
call:echo E P
call:echo F. S
pause

::---------------------------------------
:: FUNCTIONS START BELOW HERE
::---------------------------------------
goto:eof&:: keep this line in order to avoid running into the function

:echo col txt -- colors the previous line red
:: -- col : in - color call color /? for color codes
:: -- txt : in - text output
SETLOCAL
for /f "tokens=1,*" %%a in ("%*") do (
set col=%%a
set txt=%%b
)
set cr=N
if "%col:~-1%"=="." (
set cr=Y
set col=%col:~0,-1%
)
set com=%temp%.\color%col%.com
if not exist "%com%" (
echo.N %COM%
echo.A 100
echo.MOV BL,%col%
echo.MOV BH,0
echo.MOV SI,0082
echo.MOV AL,[SI]
echo.MOV CX,1
echo.MOV AH,09
echo.INT 10
echo.MOV AH,3
echo.INT 10
echo.INC DL
echo.MOV AH,2
echo.INT 10
echo.INC SI
echo.MOV AL,[SI]
echo.CMP AL,0D
echo.JNZ 109
echo.RET
echo.
echo.r cx
echo.22
echo.w
echo.q
)|debug>NUL
"%com%" %txt%
del "%com%" /q
if "%cr%"=="Y" echo.
goto:eof

To be continued ...Quote
Dilbert,
Try with quotes:
debug < "%0.bat"

C:\>debug 0<"echoX.bat"
The system cannot find the file specified.
C:\>goto fin
C:\>

The above is the total output, now, of the batch file.I mean try replacing it in the batch file.I did.DILBERT:

Do you have the debug program ?

If yes, you can assemble the code directly:

C:\colors>debug echored.com
No se encuentra el archivo (translate: File not found)
-a
1559:0100 MOV BL,1
1559:0102 MOV BH,0
1559:0104 MOV SI,0082
1559:0107 MOV AL,[SI]
1559:0109 MOV CX,1
1559:010C MOV AH,09
1559:010E INT 10
1559:0110 MOV AH,3
1559:0112 INT 10
1559:0114 INC DL
1559:0116 MOV AH,2
1559:0118 INT 10
1559:011A INC SI
1559:011B MOV AL,[SI]
1559:011D CMP AL,0D
1559:011F JNZ 109
1559:0121 RET
1559:0122
-R CX
CX 0000
:22
-w
Escribiendo 00022 bytes (translate: writing 22 bytes)
-q
C:\colors>echored hola
hola

P.S. If you don't want to write all the code in assembler, copy it from the Reply #4 (i.e. without address memory) and paste it in the debug.


Good work DosItHelp, a very pretty demostration of colors The .bat file works now, no clue why it didn't before. But now on a black background, I can barely see blue and red... I'm so picky...


Discussion

No Comment Found