flat assembler
Message board for the users of flat assembler.

Index > DOS > textmode colors

Author
Thread Post new topic Reply to topic
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
geekbasic@gmx.com 13 Nov 2022, 00:31
Is it possible to use the int 21h text output with colors?
So far, the only reference to colors I am finding goes with the BIOS interrupts for text output.

setting the foreground and background colors is my goal.

this is what I have so far:

Code:
mov bh,byte [color]
mov al,byte [scroll]
mov cl,byte [colorx1]
mov dl,byte [colorx2]
mov ch,byte [colory1]
mov dh,byte [colory2]
mov ah,6
int 16
    


It's limited, but gives some color possibilities.
Post 13 Nov 2022, 00:31
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1011
Location: Russia
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).
Post 13 Nov 2022, 02:56
View user's profile Send private message Reply with quote
sts-q



Joined: 29 Nov 2018
Posts: 57
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 Rolling Eyes )

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

Smile
Post 13 Nov 2022, 06:13
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
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.
Post 13 Nov 2022, 18:43
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
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    
The color given in BL is in fact a full attribute (with background+blink/brightness in the higher nibble).

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.
Post 13 Nov 2022, 18:55
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1011
Location: Russia
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    
Post 13 Nov 2022, 21:11
View user's profile Send private message Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
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!
Post 14 Nov 2022, 18:28
View user's profile Send private message Visit poster's website Reply with quote
FlierMate11



Joined: 13 Oct 2022
Posts: 94
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     


Description: Example output
Filesize: 9.19 KB
Viewed: 6270 Time(s)

Screenshot 2022-11-15 033641.png


Post 14 Nov 2022, 19:43
View user's profile Send private message Visit poster's website Reply with quote
FlierMate11



Joined: 13 Oct 2022
Posts: 94
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:
.....
.....               


Description: Example output
Filesize: 7.05 KB
Viewed: 6233 Time(s)

Screenshot 2022-11-15 161636.png


Post 15 Nov 2022, 08:17
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
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?
Post 26 Nov 2022, 22:24
View user's profile Send private message Visit poster's website Reply with quote
FlierMate11



Joined: 13 Oct 2022
Posts: 94
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!

Is there any way to control background color with these methods?


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.


Description: Example output with background color
Filesize: 6.26 KB
Viewed: 5969 Time(s)

Screenshot 2022-11-27 123211.png


Post 27 Nov 2022, 04:36
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1011
Location: Russia
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
Post 27 Nov 2022, 08:09
View user's profile Send private message Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
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.
Post 27 Nov 2022, 22:43
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.