flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Write character on vga mode

Author
Thread Post new topic Reply to topic
Arturx87



Joined: 16 Mar 2023
Posts: 1
Arturx87 16 Mar 2023, 07:44
How to draw character in vga mode (13h) in my select position (example 2px x 4px)
Code:
Mov al,’a’
Mov ah,0eh
Int10h
    



Thanks for Help
Post 16 Mar 2023, 07:44
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 934
Location: Russia
macomics 16 Mar 2023, 09:17
If I remember correctly, there is no function for drawing text in an arbitrary position for VGA mode. But if you just need to output the text, then you can use the function AH=13h.
Code:
push es
push cs
pop es
mov ax, 1300h ; al = mode
mov bx, 0007h ; bh = page, bl = color
mov cx, text0.Length ; ...
mov dx, 0402h ; dh = row, dl = column
mov bp, text0 ; es:bp = string
int 10h
pop es

push es
push cs
pop es
mov ax, 1301h ; al = mode
mov bx, 0007h ; bh = page, bl = color
mov cx, text1.Length ; ...
mov dx, 0607h ; dh = row, dl = column
mov bp, text1 ; es:bp = string
int 10h
pop es

push es
push cs
pop es
mov ax, 1302h ; al = mode
mov bh, 00h ; bh = page
mov cx, text2.Length ; ...
mov dx, 0802h ; dh = row, dl = column
mov bp, text2 ; es:bp = string
int 10h
pop es

push es
push cs
pop es
mov ax, 1303h ; al = mode
mov bh, 00h ; bh = page
mov cx, text3.Length ; ...
mov dx, 0A04h ; dh = row, dl = column
mov bp, text3 ; es:bp = string
int 10h
pop es

text0 db 'Hello'
.Length = $ - text0
text1 db 'world'
.Length = $ - text1
text2 db 'H', 01h, 'e', 02h, 'l', 03h, 'l', 04h, 'o', 05h
.Length = ($ - text2) shr 1
text3 db 'w', 10h, 'o', 20h, 'r', 30h, 'l', 40h, 'd', 50h
.Length = ($ - text3) shr 1    
But if you need to output the text in a completely arbitrary position, then you should use the function AH=1130h. You get a pointer to the character generator table, use it to decipher the character and output it by points with the function AH=0Ch or by direct access to video memory.
Post 16 Mar 2023, 09:17
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 17 Mar 2023, 15:52
Code:
print:
.char:
        pushad
        movzx esi,al
        shl esi,3
        add esi,bioschars
        mov edi,.base
        mov eax,[edi+.x]
        mov ebx,[edi+.y]
        mov ch,8
.loadline:
        mov dh,[esi]
        mov dl,80h
.nextdot:
        test dh,dl
        je @f
        mov cl,[edi+.c];31
        call put.pixel
@@:
        inc eax
        shr dl,1
        jne .nextdot
        inc ebx
        mov eax,[edi+.x]
        inc esi
        dec ch
        jne .loadline
        add dword[edi+.x],8
        popad
        ret

.string:
;esi asciiz string
@@:
        lodsb
        or al,al
        je @f
        call .char
        jmp @b
@@:
        ret


.base = 10200h
.x    = 0
.y    = 4
.c    = 8

bioschars = 0ffa6eh
.xl=16
.yl=16
    


char table is at 0ffa6eh

putpixel is just like that:
Code:
.pixel:
        push ebx
        cmp eax,screen.xl
        jae @f
        cmp ebx,screen.yl
        jae @f
        imul ebx,screen.xl
        mov [screen.base+eax+ebx],cl
;        xor [screen.base+eax+ebx],cl
@@:
        pop ebx
        ret              
    


and screen.base can be the double buffer, or direct to vram, as you want.

for CGA mode, it starts at 0a0000h

this code is intended for protected mode but just whows how to print chars.
Post 17 Mar 2023, 15:52
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 17 Mar 2023, 20:17
There used to be functions that set/retrieve the current cursor position. Then one has to just add 1 plus 1.
Post 17 Mar 2023, 20:17
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 934
Location: Russia
macomics 17 Mar 2023, 20:43
edfed wrote:
char table is at 0ffa6eh
Only the first 128 characters.

To get pointers to the sign generator tables , there is a function AH=0x1130

DimonSoft wrote:
There used to be functions that set/retrieve the current cursor position. Then one has to just add 1 plus 1.
But not in graphical mode. The cursor works, of course, but you need to draw it yourself, but the coordinates continue to be tracked quite well. Although they work in text columns and rows, not in pixels.
Post 17 Mar 2023, 20:43
View user's profile Send private message Reply with quote
Stancliff



Joined: 30 Jun 2024
Posts: 54
Location: Florida
Stancliff 01 Jul 2024, 17:10
; "PC System Programming for developers" by Michael Tischer 1988,1989,1990
; Dates to the end of the AT or the beginning of the Pentium. PDF format. My only
; available source for BIOS and DOS interrupt calls. Curious if it still
; applies 34 years later. I can't seem to find a newer source.

I think BIOS calls still work but haven't has much chance to test. Not so sure about DOS calls since DOS is DEAD, isn't it?
I also wonder about reading disk sectors, isn't 512 byte obsolete after 40 years? I would expect modern
hard disks to use 2k or 4k for those 500 GB to 2 TB disks.
Your opinion?
Post 01 Jul 2024, 17:10
View user's profile Send private message Reply with quote
MatQuasar2



Joined: 10 Jun 2024
Posts: 26
MatQuasar2 01 Jul 2024, 19:35
Stancliff wrote:

I also wonder about reading disk sectors, isn't 512 byte obsolete after 40 years? I would expect modern
hard disks to use 2k or 4k for those 500 GB to 2 TB disks.
Your opinion?


My personal opinion is that while a bootloader itself is 512 bytes, it can read disk like for another 100 sectors (512 bytes each) to load OS kernel. I don't know the details and will leave it for more knowledgeable person to explain.

I am amazed you come back to Assembly programming after 40 years! Personally I only use BIOS interrupts in bootloader and DOS programs, and DOS interrupts in DOS programs. But those are for learning purposes only. In practice, I target for 32-bit and 64-bit Windows and Linux programming.

There is also UEFI now which is newer than BIOS.
Post 01 Jul 2024, 19:35
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4024
Location: vpcmpistri
bitRAKE 01 Jul 2024, 22:04
Stancliff wrote:
Not so sure about DOS calls since DOS is DEAD, isn't it?
There are people using DOS as their primary OS still:
https://www.freedos.org/

Or operate several virtual DOS machines in parallel:
https://www.dosbox.com/
https://dosbox-x.com/

Although there are modern drives with >512 bytes sectors, modern systems emulate legacy support for devices and drives. This allow PS/2 and COM interfaces for USB peripherals, too.

UEFI is kind of awesome compared to BIOS, imho.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 01 Jul 2024, 22:04
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20309
Location: In your JS exploiting you and your system
revolution 02 Jul 2024, 00:54
The native sector size for drives sold today is 4kB.

The drives also support emulating 512B sectors at the interface level. So you can still use DOS to read/write the drives. But you likely will have trouble to get DOS to access an entire multi-TB drive. Maybe if you write your own FS layer for DOS then you can?
Post 02 Jul 2024, 00:54
View user's profile Send private message Visit poster's website Reply with quote
Stancliff



Joined: 30 Jun 2024
Posts: 54
Location: Florida
Stancliff 04 Jul 2024, 01:33
Thanks for your response. This is the first time I got serious about asm programming but I am learning a fair amount so far.
It is interesting that drives can pretend to use 512 byte sectors, but how would you prove what sector size a hard disk or SSD has?
Especially if using bios calls... I guess I need to look up UEFI (never heard of it)!
Post 04 Jul 2024, 01:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20309
Location: In your JS exploiting you and your system
revolution 04 Jul 2024, 01:54
Drives have plenty of diagnostics and commands to query their properties.

In DOS you can directly access them.
Post 04 Jul 2024, 01:54
View user's profile Send private message Visit poster's website Reply with quote
Stancliff



Joined: 30 Jun 2024
Posts: 54
Location: Florida
Stancliff 04 Jul 2024, 14:17
My program needs to work under Windows, not DOS, so I have to learn to use the GUI routines.
I will stop making comments here since I have a thread in 'Windows' which has helped a lot.
Post 04 Jul 2024, 14:17
View user's profile Send private message 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.