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?
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:
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.
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.
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
1This document explains the how the ANSI escape sequences are 2defined for the IBM PC. 3 4Notes: 5 61. The default value is used when no explicit value is given 7 or a value of zero is given. 8 92. Pn - Numeric parameter. A decimal number specified 10 with ASCII digits. 11 123. Ps - Selective parameter. Any decimal number that is 13 is used to select a subfunction. Multiple subfunctions 14 may be selected by separating the parameters with 15 semi-colons. 16 17C U R S O R F U N C T I O N S 18 19CUP - Cursor Postion 20 21 ESC [ Pl ; Pc H 22 23HVP - Horizontal & Vertical Postion 24 25 ESC [ Pl ; Pc f 26 27 CUP and HVP move the cursor to the position specified by 28the parameters. The first parameter specifies the line number 29and the second parameter specifies the column number. The 30default value is one. When no parameters are given the cursor 31is moved to the home postion. 32 33CUU - Cursor Up 34 35 ESC [ Pn A 36 37 Moves the cursor up one line without changing columns. The 38value of Pn determines the number of lines moved. The default 39value for Pn is one. This sequence is ignored if the cursor 40is already on the top line. 41 42CUD - Cursor Down 43 44 ESC [ Pn B 45 46 Moves the cursor down one line without changing columns. 47The value of Pn determines the number of lines moved. The 48default value for Pn is one. This sequence is ignored if the 49cursor is already on the bottom line. 50 51CUF - Cursor Forward 52 53 ESC [ Pn C 54 55 Moves the cursor forword one column without changing lines. 56The value of Pn determines the number of columns moved. The 57default value for Pn is one. This sequence is ignored if the 58cursor is already in the rightmost column. 59 60 ESC [ Pn D
…Show last 166 lines
61 62Moves the cursor back one column without changing lines. The 63value of Pn determines the number of columns moved. The default 64value for Pn is one. This sequence is ignored if the cursor 65is already in the leftmost column. 66 67DSR - Device Status Report 68 69 ESC [ 6 n 70 71The console driver will output a CPR sequence on receipt of 72DSR. 73 74CPR - Cursor Position Report (from console driver to system) 75 76 ESC [ Pn ; Pn R 77 78 The CPR sequence reports current cursor position via 79standard input. The first parameter specifies the current 80line and the second parameter specifies the current column. 81 82SCP - Save Cursor Postion 83 84 ESC [ s 85 86 The current cursor position is saved. This cursor position 87can be restored with the RCP sequence. 88 89RCP - Restore cursor position 90 91 ESC [ u 92 93 Restores the cursor position to the value it had when the 94console driver received the SCP sequence. 95 96E R A S I N G 97 98ED - Erase Display 99 100 ESC [ 2 J 101 102Erases all of the screen and the cursor goes to the home 103position. 104 105EL - Erase Line 106 107 ESC [ K 108 109 Erases from the cursor to the end of the line and includes 110the cursor position. 111 112 113 114M O D E S O F O P E R A T I O N 115 116SGR - Set Graphics Rendition 117 118 ESC [ Ps ; ... ; Ps m 119 120Invokes the graphic rendition specified by the parameter(s). 121All following characters are rendered according to the 122parameter(s) until the next occurence of SGR. 123 124Parameter Parameter Function 125 126 0 All Attributes Off 127 1 Bold On 128 4 Underscore On (monochrome displays 129 only) 130 5 Blink On 131 7 Reverse Video On 132 8 Concealed On (ISO 6429 standard) 133 30 Black foreground (ISO 6429 standard) 134 31 Red foreground (ISO 6429 standard) 135 32 Green foreground (ISO 6429 standard) 136 33 Yellow foreground (ISO 6429 standard) 137 34 Blue foreground (ISO 6429 standard) 138 35 Magenta foreground (ISO 6429 standard) 139 36 Cyan foreground (ISO 6429 standard) 140 37 White foregound (ISO 6429 standard) 141 40 Black background (ISO 6429 standard) 142 41 Red background (ISO 6429 standard) 143 42 Green background (ISO 6429 standard) 144 43 Yellow background (ISO 6429 standard) 145 44 Blue background (ISO 6429 standard) 146 45 Magenta background (ISO 6429 standard) 147 46 Cyan background (ISO 6429 standard) 148 47 White backgound (ISO 6429 standard) 149 150SM - Set Mode (IBM/MICROSOFT Private) 151 152 ESC [ = Ps h 153or ESC [ = h 154or ESC [ = 0 h 155or ESC [ ? 7 h 156 157 158Invokes the screen width or type specified by the parameter. 159 160Parameter Parameter Function 161 162 0 40 x 25 black and white 163 1 40 x 25 color 164 2 80 x 25 black and white 165 3 80 x 25 color 166 167 4 320 x 200 color 168 5 320 x 200 black and white 169 6 640 x 200 black and white 170 7 wrap at end of line 171 172 173RM - Reset Mode 174 175 ESC [ = Ps l 176or ESC [ = l 177or ESC [ = 0 l 178or ESC [ ? 7 l 179 180 181 Parameters are the same as SM (Set Mode) except that 182parameter 7 will reset wrap at end of line mode. 183 184 185K E Y B O A R D R E - A S S I G N M E N T 186 187Although not part of the ANSI 3.64-1979 or ISO 6429 standard 188the IBM PC keyboard re-assignment was done in a compatible 189way. 190 191The control sequence is: 192 193 ESC [ Pn ; Pn ; ... Pn p 194or ESC [ "string" ; p 195or ESC [ Pn ; "string" ; Pn ; Pn ; "string" ; Pn p 196or any other combination of strings and decimal numbers 197 198The final code in the control sequence ("p") is one reserved 199for private use the by ANSI 3.64-1979 standard. 200 201The first ASCII code in the control sequence defines which 202code is being mapped. The remaining numbers define the 203sequence of ASCII codes generated when this key is 204intercepted. 205 206To every rule there is an exception, however! If the first 207code in the sequence is zero (NUL) then the first and second 208code make up an extended ASCII re-definition. 209 210Here are some examples: 211 2121. Reassign the Q and q key to the A and a key (and the other 213 way as well): 214 215 ESC [ 6 5 ; 8 1 p A becomes Q 216 ESC [ 9 7 ; 1 1 3 p a becomes q 217 ESC [ 8 1 ; 6 5 p Q becomes A 218 ESC [ 1 1 3 ; 9 7 p q becomes a 219 2202. Reassign the F10 key to to a dir command followed by a 221 carriage return: 222 223 ESC [ 0 ; 6 8 ; " d i r " ; 1 3 p 224 225 The 0;68 is the extended ASCII code for the F10 key. 13 226 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)
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).
(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.