flat assembler
Message board for the users of flat assembler.
Index
> DOS > textmode colors |
Author |
|
macomics 13 Nov 2022, 02:56
To work with colors under DOS, you should install the ANSI.SYS driver. Then escape-sequences can be used through the standard interrupt 21h.
Also, to output text with color, the BIOS interrupt 16h has a function 13h (EGA/VGA mode), which can output text in different versions with color attributes. At the very least, you can access the video memory directly. It is available starting from linear address 0B8000h (segment 0B800h). The parameters of the video memory page can be read from the addresses 044Ah and 0484h (check the latter, it's from my memory - maybe not exactly). |
|||
13 Nov 2022, 02:56 |
|
sts-q 13 Nov 2022, 06:13
This is not exactly assembly
but ansi escape sequences: (it was a lot of work to pick them out of wikipedia etc, maybe you can use them, too ) https://codeberg.org/sts-q/oberon/src/branch/main/vishaps-voc/modules/Dot.Mod#L67 https://codeberg.org/sts-q/oberon/src/branch/main/vishaps-voc/modules/Ink.Mod |
|||
13 Nov 2022, 06:13 |
|
geekbasic@gmx.com 13 Nov 2022, 18:43
That makes sense. Sort of.
I tried this with int 21h... echodata1 db '\033[31;1;4mHello, world!\033[0m',13,10,36 Just prints as is. Am I doing something wrong? Is it just not supported on my Windows XP? How does QBasic color command work? I really appreciate all your help, y'all. |
|||
13 Nov 2022, 18:43 |
|
Tomasz Grysztar 13 Nov 2022, 18:55
In my (already ancient) Kelvar engine (you can find it among the old examples) there are some simple routines that use the BIOS interface:
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:esi - 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 It writes every character twice, using different functions. The function 09h allows to write both character and attribute at cursor position, but it does not advance the cursor. The function 0Eh ("teletype") writes a character and advances the cursor, and does not touch the attribute at all. So whatever attribute was written by the function 09h, it stays there while 0Eh just rewrites the character once more and advances the cursor. |
|||
13 Nov 2022, 18:55 |
|
macomics 13 Nov 2022, 21:11
Code: ; '\033' <> 033o = 1Bh = 27 = ESCAPE code echodata1 db 033o,'[31;1;4mHello, world!',27,'[0m',13,10,36 |
|||
13 Nov 2022, 21:11 |
|
geekbasic@gmx.com 14 Nov 2022, 18:28
I am trying the code, but am not sure how to load text into ds.
It looks very interesting how you are using two functions to achieve the result. I also tried the ansi again. Doesn't work on Windows XP. I need to try DOS. I see now that I need to use hex dec or oct for the escape character. Thank you! |
|||
14 Nov 2022, 18:28 |
|
FlierMate11 14 Nov 2022, 19:43
My solution using direct screen buffer access (not thoroughly tested):
Code: org 100h use16 lea bx, [text1] mov [x], 50 mov [y], 13 mov [color], 13 call print lea bx, [text2] mov [x], 10 mov [y], 20 mov [color], 12 call print mov ax, 4c00h int 21h print: ; bx = pointer to text string push 0b800h pop es mov ax, word [y] mov dx, 80 mul dx add ax, word [x] mov dx, 2 mul dx mov di, ax mov ah, byte [color] redo: mov al, byte [bx] cmp al, 0 jz quit stosw inc bx jmp redo quit: ret x dw ? y dw ? color db ? txt dw ? text1 db 'Hello World',0 text2 db 'We are here.',0
|
||||||||||
14 Nov 2022, 19:43 |
|
FlierMate11 15 Nov 2022, 08:17
geekbasic@gmx.com wrote: I am trying the code, but am not sure how to load text into ds. Example code using Tomasz's solution: Code: org 100h use16 mov al,65 mov bl,15 call display_character lea si, [text1] mov bl, 15 call display_text mov ax, 4c00h int 21h text1 db "Hello World",0 display_character: ..... ..... display_text: ..... .....
|
||||||||||
15 Nov 2022, 08:17 |
|
geekbasic@gmx.com 26 Nov 2022, 22:24
Thank you for showing how to use Tomasz's code and for your example. It looks powerful!
Is there any way to control background color with these methods? |
|||
26 Nov 2022, 22:24 |
|
FlierMate11 27 Nov 2022, 04:36
geekbasic@gmx.com wrote: Thank you for showing how to use Tomasz's code and for your example. It looks powerful! You're most welcome. Yes, as mentioned by Tomasz: Quote: The color given in BL is in fact a full attribute (with background+blink/brightness in the higher nibble). ...You can set the leftmost 4 bits as background color. This applies to Tomasz's example and mine. Example using Tomasz's code: Code: mov al,65 mov bl,15 + (7 shl 4) call display_character lea si, [text1] mov bl, 15 + (3 shl 4) call display_text You can also make it blink with higher value for the background color.
|
||||||||||
27 Nov 2022, 04:36 |
|
macomics 27 Nov 2022, 08:09
Video BIOS func ax=1003h: bl = 0 - intensity; bl = 1 - blinking
Code: xor bl, bl ; intensity mov ax, 1003h int 16 mov bl, 1 ; blinking mov ax, 1003h int 16 Last edited by macomics on 28 Nov 2022, 04:11; edited 1 time in total |
|||
27 Nov 2022, 08:09 |
|
geekbasic@gmx.com 27 Nov 2022, 22:43
Good information. This way it is easier to control colors.
I see that I need to spend time learning about the shifting instructions. |
|||
27 Nov 2022, 22:43 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.