Advertisement

Coloring text in DOS!

Started by November 23, 2000 12:43 PM
5 comments, last by Peter Svensson 24 years, 1 month ago
Hello... Does anyone remember how to color text in textmode in dos or actually, the console in win98. Is it possible to do it in the console? C source would be prefered! // Thanx!
Oh, jeez... I can't remember exactly but I believe it went something like this:

mem location
0xb8000000 - top left corner of screen
1st byte - ascii character code
2nd byte - attribute ( color, flashing, etc... )

I believe you will have to compile with borlands compiler or some other compiler that can make 16bit/dos code. I dont think Microsofts Visual C++ compiler will allow you to make old dos code.

Ya, you can run it in a console window.

ao

Edited by - ao on November 23, 2000 2:05:57 PM
Play free Java games at: www.infinitepixels.com
Advertisement
It's quite easy to do. I'm not sure if it'll work on VC++ but it does work on Borland products. Try this:

#include conio.h
/* tried using the angle brackets and it didn't show up on the post, you should know to use them.*/

int main() {
textattr(int); // Replace int with a number from 1 to 15 for
// the desired color.

cprintf("hello");

return 0;
}

If you wish to find out what color each number represents, use for loop to print it all out one at a time. Hope this helps.

~~What the hell have I done now?~~

Edited by - Silent Error on November 23, 2000 2:31:02 PM

Edited by - Silent Error on November 23, 2000 2:32:06 PM
If only debugging were as easy as killing cockroaches... *sigh*
I just tested it on VC++ Intro. Edition and my solution doesn''t work on it, however it works on Borland C++ 3.1 and the Borland command line tools. I suspect it''ll work on DJGPP.

I can''t figure out how to do it in VC++ but there is a function called SetConsoleTextAttribute that I think will do it, I just don''t remember how to use it.

~~What the hell have I done now?~~
If only debugging were as easy as killing cockroaches... *sigh*
change ao''s words into function (real mode 80x25 - 0x03h):
void color(int x,int y,int bg_color,int text_color)
{ char far *text_buffer=(char far*)0xb8000000L;

if (x<0||y<0||x>=80||y>=25) return;
text_buffer[(y*80+x)*2+1]=((bg_color&0x0f)<<4)|(text_color&0x0f);
}
Life is :-(Life is :-)
Here is some old code, it should work, but not in microslobs compiler.

code

ao
Play free Java games at: www.infinitepixels.com
Advertisement
http://msdn.microsoft.com/library/psdk/winbase/conchar_2tid.htm

This topic is closed to new replies.

Advertisement