flat assembler
Message board for the users of flat assembler.
Index
> DOS > Writing with colors |
Author |
|
Tomasz Grysztar 24 Apr 2004, 23:25
From the old kelvar example:
Code: display_character: ; al = character ; bl = color xor bh,bh mov cx,1 mov ah,9 int 10h mov ah,0Eh int 10h ret display_text: ; ds:si - text ; bl = color xor bh,bh mov cx,1 .display: lodsb or al,al jz .end cmp al,0Dh je .type cmp al,0Ah je .type mov ah,9 int 10h .type: mov ah,0Eh int 10h jmp .display .end: ret |
|||
24 Apr 2004, 23:25 |
|
OzzY 24 Apr 2004, 23:56
It worked!! Thanks!! But how to know the color number to put on bl?
I mean how to how the number of red, blue, yellow...,red on blue, white on red.... Thanks |
|||
24 Apr 2004, 23:56 |
|
vid 25 Apr 2004, 07:55
there are 2 colors: foreground (in low order 4 bits) and background (in high order 4 bits). Each 4 bits escribe color like this:
0: red 1: green 2: blue 3: add light so, for example 0001b is red, 0010b is green, 0011b is red + green etc. But i think it is easier to remember these 16 colors. and then just combine values in bl: Code: mov bl,foregound + (background shl 4) |
|||
25 Apr 2004, 07:55 |
|
Tomasz Grysztar 25 Apr 2004, 10:31
This can be also described this way: the four-bit values for colors are as following (the highest bit is the brightness bit, so to get the value of light red you add value of red to 8, getting 0Ch, etc.):
Normal: 0 black 1 blue 2 green 3 cyan 4 red 5 magenta 6 brown 7 light gray Bright: 8 dark gray 9 light blue A light green B light cyan C light red D light magenta E yellow F white The pair 6 and 0Eh of colors is a small exception, where bright color has a bit different hue that the normal one. To get the attribute for a character (the byte that you pass to the function 9 of interrupt 10h, or write directly into screen memory), you put the color for a background into the high nibble, and color for the text into the low nibble of byte value. For example 1Bh is the light cyan text on the blue background and 7Fh is white text on the light gray background. But there are few more tricks about the attributes - first, the brightess bit in the nibble describing the color for the background may have different meaning (and it has by default) - it makes the character blink instead of making the backround color brigther. So depending of the current setting 9Fh may mean white text on the light blue background, or blinking white text on the normal blue background. You can toogle this setting with function 1003h of interrupt 10h. Pass BX=0 to that function to enable background brightening, or BX=1 to enable blinking. And the last, a bit less well-known trick is that on the VGA you can enable highest bit of low nibble (the one describing text color) to choose one of the two character sets instead of brigthening the text color. This way you can use two different fonts at the same time in text mode. This one is a bit more tricky, you do it with 11xxh functions. |
|||
25 Apr 2004, 10:31 |
|
neonz 25 Apr 2004, 11:43
Also there is alternative way, by using ANSI escape sequences (control codes) with DOS (Int21h) functions. But it requires that ANSI driver (ansi.sys on MS-DOS, nansi.sys on FreeDOS) is loaded.
http://www.delmar.edu/Courses/CIS415L/ANSIsys.htm - here is list of DOS ANSI sequences. |
|||
25 Apr 2004, 11:43 |
|
OzzY 25 Apr 2004, 22:41
Thanks, it's working... but how can I clean the screen paint it with blue, for example (I don't want the black background)?
Thanks!! |
|||
25 Apr 2004, 22:41 |
|
vid 26 Apr 2004, 04:55
In DOS, you can write directly to video ram screen buffer.
It is *usually* located at segment B800. Here follows 2D array that describes screen array[1..y] of array [1..x] of word where word (2 bytes) describes one character. first byte is character ASCII code and second is color. So clearing screen could be: Code: mov ax,((1 shl 4) shl 16) ;blue mov cx,x*y rep stosw i just don't remember how to get "x" and "y", i think there is some BIOS procedure for it. |
|||
26 Apr 2004, 04:55 |
|
OzzY 26 Apr 2004, 19:03
I isn't working... and I don't want to write directly to video ram buffer... Can't use interrupt to do it?
|
|||
26 Apr 2004, 19:03 |
|
Tomasz Grysztar 26 Apr 2004, 19:23
You can do it this way:
Code: mov ax,0600h ; scroll up window, AL=0 means: clear entire window mov bh,4Ch ; attribute used to fill the window mov cx,0000h ; row and column of upper left corner mov dx,184Fh ; row and column of lower right corner int 10h You can look up all the VGA functions in the Ralph Brown's Interrupt List. |
|||
26 Apr 2004, 19:23 |
|
OzzY 26 Apr 2004, 19:39
Thanks Privalov!! It worked allright!!
|
|||
26 Apr 2004, 19:39 |
|
neonz 01 May 2004, 20:12
vid wrote: In DOS, you can write directly to video ram screen buffer. Well, it's basically only in two places - segment B800 (for CGA and compatible adapters in text mode) or B000 (for MDA and compatible adapters). So, you simply need to detect MDA (for example, using BIOS equipment word), and use B000 instead of B800 if adapter is MDA. |
|||
01 May 2004, 20:12 |
|
Gambino 07 Jul 2004, 18:44
Hey i have some code to help you out !
You can find it here http://board.flatassembler.net/topic.php?t=1806 Don't worry it's working very well but i want to improve it so i need some help, but that should allow you to print text anywhere on the screen, with any combination of backgroun/foreground color, and the strings can be long as u want ( almost ) and don't have to be terminated by a character like '0' or '$' |
|||
07 Jul 2004, 18:44 |
|
Matrix 09 Sep 2004, 17:22
|
|||
09 Sep 2004, 17:22 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.