VOGONS

Common searches


First post, by massasauga

User metadata
Rank Newbie
Rank
Newbie

I've gotten DOSBox to work and I have been able to tweak the parameters. But I have also noticed that on the Welcome Screen when DOSBox starts up, there are fields with blue background, colored titles, etc. I am sure there is an escape sequence that can be used to change colors in forground and background in the command line, but I can't find any documentation covering this. I have tried emulating Hercules Graphics and can switch between green, brown, or white, but control is limited with what you can do. I am familiar with ANSI escape sequences to tweak colors in prompts, but none of these work with DOSBox.

Is there any documentation explaining how to control command line font colors?

Attachments

Reply 1 of 5, by Dominus

User metadata
Rank DOSBox Moderator
Rank
DOSBox Moderator

You need to have 4dos or so to make use of the ansi codes. Dosbox on its own doesn't add them (except for the hardcoded stuff)

Windows 3.1x guide for DOSBox
60 seconds guide to DOSBox

Reply 2 of 5, by dreamer_

User metadata
Rank Member
Rank
Member
massasauga wrote on 2020-01-06, 01:22:

I've gotten DOSBox to work and I have been able to tweak the parameters. But I have also noticed that on the Welcome Screen when DOSBox starts up, there are fields with blue background, colored titles, etc. I am sure there is an escape sequence that can be used to change colors in forground and background in the command line, but I can't find any documentation covering this. I have tried emulating Hercules Graphics and can switch between green, brown, or white, but control is limited with what you can do. I am familiar with ANSI escape sequences to tweak colors in prompts, but none of these work with DOSBox.

Is there any documentation explaining how to control command line font colors?

AFAIK no, there's no documentation - but ANSI codes work fine… except you can't type them in DOSBox terminal. But if you'll type literal escape code in the file and display it (e.g. using C:\>type msg_file or echo inside autoexec section of .conf file) then the text will be coloured.

Example:

Create a new file using vi/vim (e.g. called msg) To type in escape code you need to: change to insert mode, press Ctrl-V, type in escape sequence, e.g.: i<Ctrl-V>27 will show up as ^[ (literally a byte containing 27 - ESC character in ASCII encoding). Knowing this, type in following text:

^[[32;1mCOLOUR^[[0m NOCOLOUR

Then:

$ dosbox .
C:\>type msg

(and word COLOUR will be coloured 😉)

| ← Ceci n'est pas une pipe
dosbox-staging

Reply 3 of 5, by massasauga

User metadata
Rank Newbie
Rank
Newbie

Thanks, dreamer.
I still need to play with this a little more, but I have been able to make a few quick test files. I am now able to switch the prompt colors by using the type command. This is pretty much what I was looking for. After I refine my process, I will get back and pass along what I have found out.

Thanks also to Dominus.

Reply 4 of 5, by massasauga

User metadata
Rank Newbie
Rank
Newbie

Here is some more information that I found out by experimenting.
The numbers corresponding to colors of type displayed are:

Foreground Background
30 black 40
31 red 41
32 green 42
33 yellow 43
34 blue 44
35 magenta 45
36 cyan 46
37 white 47

Colors in foreground can be brightened by preceding the color code with a 1 followed by a semicolon (;)
e.g. dark red with a yellow background would be coded as <esc>27[0;31;43mThis text is red with yellow background.<esc>27[0m
When you enter this in vi, it will appear as ^[[0;31;43mThis test is red with yellow background.^[[0m
The number "27" (which is the escape code for color) will not appear in vi when you type it.
The "m" at the end of each escape sequence is a terminator of the sequence. When you type the "[" character two of them will appear.
The "0;" preceding a foreground character is for the dark color of the character, and it can be left out, as far as I can tell.
If you replace the "0" with a "1" this will brighten the color. Background colors do not brighten.

I believe I have gotten this all down correctly. If anyone reading this has any changes or additions to this, please feel free
to comment or rewrite as needed.

Reply 5 of 5, by Gernot66

User metadata
Rank Newbie
Rank
Newbie

Massauga

Check this out if you like to change the color of the whole screen and not only for a single line or for any else ANSI code, while some won't work in DOSBox e.g. keyboard remapping which is an extra extra of IBM and doesn't belongs to ANSI it just uses similar escape sequences as the ANSI escape sequences (at least i couldn't use them, while a "soft" keyboard remapping would be cool because you could use one for one program and another mapping for another program without to restart DOSBox).

I wrapped it in a spoiler because it's a rather large excerpt of the IBM manual:

escape sequences
This  document  explains the how the ANSI escape sequences are
defined for the IBM PC.

Notes:

1. The default value is used when no explicit value is given
or a value of zero is given.

2. Pn - Numeric parameter. A decimal number specified
with ASCII digits.

3. Ps - Selective parameter. Any decimal number that is
is used to select a subfunction. Multiple subfunctions
may be selected by separating the parameters with
semi-colons.

C U R S O R F U N C T I O N S

CUP - Cursor Postion

ESC [ Pl ; Pc H

HVP - Horizontal & Vertical Postion

ESC [ Pl ; Pc f

CUP and HVP move the cursor to the position specified by
the parameters. The first parameter specifies the line number
and the second parameter specifies the column number. The
default value is one. When no parameters are given the cursor
is moved to the home postion.

CUU - Cursor Up

ESC [ Pn A

Moves the cursor up one line without changing columns. The
value of Pn determines the number of lines moved. The default
value for Pn is one. This sequence is ignored if the cursor
is already on the top line.

CUD - Cursor Down

ESC [ Pn B

Moves the cursor down one line without changing columns.
The value of Pn determines the number of lines moved. The
default value for Pn is one. This sequence is ignored if the
cursor is already on the bottom line.

CUF - Cursor Forward

ESC [ Pn C

Moves the cursor forword one column without changing lines.
The value of Pn determines the number of columns moved. The
default value for Pn is one. This sequence is ignored if the
cursor is already in the rightmost column.

ESC [ Pn D
Show last 166 lines

Moves the cursor back one column without changing lines. The
value of Pn determines the number of columns moved. The default
value for Pn is one. This sequence is ignored if the cursor
is already in the leftmost column.

DSR - Device Status Report

ESC [ 6 n

The console driver will output a CPR sequence on receipt of
DSR.

CPR - Cursor Position Report (from console driver to system)

ESC [ Pn ; Pn R

The CPR sequence reports current cursor position via
standard input. The first parameter specifies the current
line and the second parameter specifies the current column.

SCP - Save Cursor Postion

ESC [ s

The current cursor position is saved. This cursor position
can be restored with the RCP sequence.

RCP - Restore cursor position

ESC [ u

Restores the cursor position to the value it had when the
console driver received the SCP sequence.

E R A S I N G

ED - Erase Display

ESC [ 2 J

Erases all of the screen and the cursor goes to the home
position.

EL - Erase Line

ESC [ K

Erases from the cursor to the end of the line and includes
the cursor position.



M O D E S O F O P E R A T I O N

SGR - Set Graphics Rendition

ESC [ Ps ; ... ; Ps m

Invokes the graphic rendition specified by the parameter(s).
All following characters are rendered according to the
parameter(s) until the next occurence of SGR.

Parameter Parameter Function

0 All Attributes Off
1 Bold On
4 Underscore On (monochrome displays
only)
5 Blink On
7 Reverse Video On
8 Concealed On (ISO 6429 standard)
30 Black foreground (ISO 6429 standard)
31 Red foreground (ISO 6429 standard)
32 Green foreground (ISO 6429 standard)
33 Yellow foreground (ISO 6429 standard)
34 Blue foreground (ISO 6429 standard)
35 Magenta foreground (ISO 6429 standard)
36 Cyan foreground (ISO 6429 standard)
37 White foregound (ISO 6429 standard)
40 Black background (ISO 6429 standard)
41 Red background (ISO 6429 standard)
42 Green background (ISO 6429 standard)
43 Yellow background (ISO 6429 standard)
44 Blue background (ISO 6429 standard)
45 Magenta background (ISO 6429 standard)
46 Cyan background (ISO 6429 standard)
47 White backgound (ISO 6429 standard)

SM - Set Mode (IBM/MICROSOFT Private)

ESC [ = Ps h
or ESC [ = h
or ESC [ = 0 h
or ESC [ ? 7 h


Invokes the screen width or type specified by the parameter.

Parameter Parameter Function

0 40 x 25 black and white
1 40 x 25 color
2 80 x 25 black and white
3 80 x 25 color

4 320 x 200 color
5 320 x 200 black and white
6 640 x 200 black and white
7 wrap at end of line


RM - Reset Mode

ESC [ = Ps l
or ESC [ = l
or ESC [ = 0 l
or ESC [ ? 7 l


Parameters are the same as SM (Set Mode) except that
parameter 7 will reset wrap at end of line mode.


K E Y B O A R D R E - A S S I G N M E N T

Although not part of the ANSI 3.64-1979 or ISO 6429 standard
the IBM PC keyboard re-assignment was done in a compatible
way.

The control sequence is:

ESC [ Pn ; Pn ; ... Pn p
or ESC [ "string" ; p
or ESC [ Pn ; "string" ; Pn ; Pn ; "string" ; Pn p
or any other combination of strings and decimal numbers

The final code in the control sequence ("p") is one reserved
for private use the by ANSI 3.64-1979 standard.

The first ASCII code in the control sequence defines which
code is being mapped. The remaining numbers define the
sequence of ASCII codes generated when this key is
intercepted.

To every rule there is an exception, however! If the first
code in the sequence is zero (NUL) then the first and second
code make up an extended ASCII re-definition.

Here are some examples:

1. Reassign the Q and q key to the A and a key (and the other
way as well):

ESC [ 6 5 ; 8 1 p A becomes Q
ESC [ 9 7 ; 1 1 3 p a becomes q
ESC [ 8 1 ; 6 5 p Q becomes A
ESC [ 1 1 3 ; 9 7 p q becomes a

2. Reassign the F10 key to to a dir command followed by a
carriage return:

ESC [ 0 ; 6 8 ; " d i r " ; 1 3 p

The 0;68 is the extended ASCII code for the F10 key. 13
decimal is a carriage return

If you are a german speaking member i recommend this page, he explains most of what one will need very well:
http://www.antonis.de/dos/batchtut/bat-kurs/ ("Lektion #17" lesson 17 is the respective part of this batch tutorial)

The Wiki also offers some information while it's not relative for CGA colors and i guess this you will know for sure, just for completeness:
https://en.wikipedia.org/wiki/ANSI_escape_cod … scape_sequences

If you like to get creative with ANSI art i recommend "Pablo Draw" which is a ANSI art paint program and it's more as just helpful to create boxes and things.
What you can draw in Pablo Draw will be displayed proper in DOSBox thus you can use the output to learn from it what is possible in DOSBox.
To handle *.BAT and/or re-edit *.ANS produced by Pablo Draw i recommend Notepad++ because it can handle ANSI files well and it's quite easy to write an escape sequence
because "CTRL+key" will result in ANSI codes, i.e. CTRL+[ will be parsed to (inverted) "ESC" as it is needed for escape sequences. Other special sequences you can copy paste from Pablo Draws output notepad++ will accept most of it. Sometimes it can lose the whole ANSI sequences in a file take care especially if you convert UTF to ANSI or vice versa.
I.e. UTF (inverted) "XDC" (which is 0xDC in hex) is in ANSI a "Ü" and will be displayed on the screen as "▄" graphical symbol. It gets lost if you convert the UTF file to ANSI and set or load the file later on as UTF, notepad++ will display then a question mark, once i lost a whole ANSI art file and all characters turned to "?" - take care, notepad++ depends on if the file is UTF or ANSI and if it's set to the wrong code the described error can happen since it's not clear by nature what i.e. "0xDC" is, it means in each code something else, notepad++ needs to know for which "language" (code) it is meant.
Of course it didn't matters if you edit an ANSI art file as UTF, i found out it's even safer as to convert it to ANSI because the inverted CTRL commands are clearer to differ from glyphs as i.e. a "Ü" is, on the other hand you will have a better overview over the graphic in your file using ANSI because the UTF CTRL sequences use two to three glyphs and this will scramble a graphic visually much for editing. All in all you will use the escape sequences different as Pablo Draw does, it is very conservative because it can't know for which purpose the file will be and escape seqences to change i.e. foreground colors will be used useless often (as it seems). I.e. Pablo Draw would use four escape sequences for this:
"ESC[0;40;32"ESC[37m"A LIT TEXT"ESC[32m"A UNLIT TEXT""ESC[37m" depending on with what you start your ANSI art file.
A human would use it in this manner: "ESC[37m"A LIT TEXT"ESC[32m"A UNLIT TEXT and basta, i don't need to set the background color if it's black, neither i have to switch between normal and fat useless.
DOSBox by default interpretes "ESC[1m" as flashing, otherwise ("otherwise": means "ici colors" that means in fact if a foreground color is displayed on the bright version of the background color it will be flashing) it would be fat while "ESC[37m" is the "fat" (bright) color of "ESC[32m", while "ESC[1m" is flashing depending on your set background color. You can't switch in DOSBox to something else it uses always the so called "ici colors" no matter how you created it in Pablo Draw.
It adds a "sauce" to each ansi art file, which contains author, date, used display mode, color mode, font size, all this isn't relevant for DOSBox and can be stripped (or not).
If that sounds all very complicated - get Pablo Draw, examine the output and it gets obvious, it helped me far more as all information i found in the web, to see the result is something quite different as just to talk theoretically about it ("found kitten!" - "robot loves kitten!"). Still i use the above links as reference and they are always open in my browser.

DOSBox uses only the16 EGA colors!
The variuous releases of DOSBox have unfortunately a different palette handling.
Vanilla DOSBox uses the upper eight colors for foreground.
DOSBox ECE uses the lower eight colors for foreground.
And DOSBox-X uses.... gosh whatever it uses something different to both.

Imho DOSBox ECE uses the palette proper, the lower eight are for forground like in Pablo Draw.
Usually this isn't much of interest neither it's a problem to display ANSI art all three releases will display the colors of the ANSI art file proper

detailed explanation

It gets only obvious if you display a palletized image and detach the program without to clear the screen, when you start to overwrite the image DOSBox will use the colors from this palette, depending on which release the result differs. "PICTVIEW" is an image viewer which offers to detach without to clear the screen, with the help of it i display images and play music or sfx, or as in my recent project use it as screen to display limited ANSI art (and play sfx or music), limited because you can't use then any else as index 0 as background color but you can use 16 colors for the text while they will reflect the first 16 colors in the palette. It leads to that my recent project only works in DOSBox ECE in other releases you probably won't see any text or hardly but anyway it can be used with DOSBox ECE only since it depends on implemented Munt and Fluidsynth, for other similar but quite simpler projects i respected all three versions and set the brightest colors of the palette to index 1, 7 and 15. The images i display in my recent project use only the 16 EGA colors but in a different hierarchy because i like to have green and bright green instead of bright grey and white as text color, sometimes i use dark grey (quasi bright black) as background sometimes black.
In other terms index 0 is always background color, index 8 is foreground bright grey to DOSBox ECE, index 1 is foreground bright grey to DOSBox-X (the palette seems to be inverted to DOSBox ECE) and index 15 is foreground bright grey for vanilla DOSBox (i don't use vanilla DOSBox anymore thus i'm not so sure about it's behave, but as i remember if i set index 7 to a bright color the color won't be used instead of foreground bright grey). Proper is index 0 background (usually black), index 7 foreground white (bright grey), index 15 foreground "fat" (bright white or flashing).
While as you will know only the lower 8 can be used as background (and can't be used at all if you ovewrite a palettized image).

Some escape sequences only work when you type the ANSI art file to the screen using "TYPE" and won't work in a batch program or else.
I.e. "ESC[US" ("US" inverted, resp. ASCII code 31 "unit seperator" is interpreted as ANSI character "▲") you can't type it in notepad++ and would have to hack in the "31" at the respective position in the file but will lose that if you open and save it with any text editor. Thus it's easiest to put such characters in an ANSI art file and to specify them as global to use for your batch program. Since we can't use the pipe command in DOSBox you have to find another way to stuff this to the globales, "NSET" by Horst Schaeffer is very useful for this you can set anything in a very precise manner as globale. https://www.horstmuc.de/horstd.htm
"NSET" like most of his programs accepts not only "pipe" inputs it handles stdout and stdin (redirection like "ECHO thistext > this.txt") which makes it very useful for DOSBox.
Also the rest of his small programs is very handy for batch programs. The documentation is unfortunately only in german language also he respected german for inputs like yes/no (Ja/Nein, i can offer a hack of "choix" which respects y/n and doesn't rings the stupid bell if you press a different key as the ones you specified, otherwise it's major to CHOICE because of mouse support and the default "ESC or any key", all this in my thread "Pimp my DOS game" - in a couple of days, maybe a week).

In gerneral one could use all ASCII codes in ANSI or as escape sequence, in what it will end you have to figure out yourself if it's not described in the above linked ANSI & escape sequences explanations.
Table of ASCII codes: https://theasciicode.com.ar/

For extensive nearly abuse of ANSI art and escape sequences visit my "Pimp my DOS game" thread, i will update it soon with a batch which heavy uses the above escape sequences. Writes text over displayed images, requests user inputs in various ways, displays ANSI art, uses many escape sequences even to draw and lighten up symbols on the screen (the standard galactic alphabet from Commander Keen 😉 )
Sure it can be made better in this or that way and it is in a constant revision because daily i have a new idea and daily i learn something new.

This is mostly all i found out while i was fiddling around with this (extreme large) batch program.

My next project will be a similar one but i will use only ANSI art for it and the neat possibility of H. Scheaffers "CHOIX" to make selections with the mouse (the mouse scan doesn't works if an image is displayed, that's why i can't use it for the recent project).

RLOVESK.PNG
Filename
RLOVESK.PNG
File size
2.73 KiB
Views
644 views
File license
Fair use/fair dealing exception

(do what you like with it "license")

Erm yes,
In fact with ANSI art and the proper programs one could create a sort of "robot ♥ kitten" batch proggie, request user input, randomize meaning and position of abstract glyphs (hide kitten) hover with the mouse over the "items" (abstract glyphs) and click on them to receive a stupid message "a half bitten piece of pizza" or in case "# found kitten! - # ♥ kitten!"
All you will need for this are Horst's small programs and a little creativity.
NSET i.e. can extract a given line and column in a text (or ANSI art) file and store it as global variable, it also can randomize the line to request, half of the job is already done.
RANDOM doesn't have to be explained, "roll a dice".
LINEX will extract a given line from a file or stdin and outputs to stdout.
Create a table with the abstract glyphs and request with NSET and the random function.
Randomize position of item, exclude used positions by storing progress to a global or a temp file
Create a table with the meanings, means stupid sentences "en masse" and use again NSET to extract random from the table.
Maybe you will need a different SET replacement which can add variables to existing stored globals or stash the stuff in temp files.
Splatter the result on the screen again by use of NSET or LINEX
Use CHOIX to make use of the mouse in your batch, enter to it all used glyphs as "marker" for the mouse and start to search for kitten.

Advanced:
Randomize meaning of abstract glyphs (the boxes to examine) every n seconds or even random seconds.

Cosmetic:
Request at start user input for colors and/or random meaning frequency.
Ask for time limit.
Instead of given answers generate answers from different tables, maybe they will leak of any sense but on the other hand quite funny and rarely the same.
Use for this RANDOM or do it really procedural with a given math behind a very simple method is a given row of numbers from 0 to 9 and add 1 to each every turn.
This was used often in very past when computers leaked completely of a random function, it replaces rand hmmm yeah it can replace it, it won't be obvious if clever made
if simple you can guess the system behind the second time you try.
"RCA Studio II" was such a lame computer or game console to be true, they always had to use this method, in the quiz game for this console it gets very obvious how it's made and the second time you try you can guess the answers without to know them because you will know the rule.
If you have something different as a simple user request as a quiz game needs it won't be this obvious.
Procedural generation in simplest manner.

Happy roboting

To be honest in BASIC it would be a page of code, as batch it will fill quite many pages.

maintainer of "Phoenix" (Pioneer Space Sim derivate)
https://forums.frontier.co.uk/threads/phoenix … erivate.506984/