Anonymous user
VGA Fonts: Difference between revisions
Jump to navigation
Jump to search
no edit summary
[unchecked revision] | [unchecked revision] |
No edit summary |
No edit summary |
||
Line 32:
Most modular way. You can use different fonts if you like. Downside you'll need a working filesystem implementation.
=== Get the copy stored in the VGA BIOS ===
It's a standard BIOS call (no need to check it's persistence). If you're still in real mode, it's quite easy to use.
<source lang="asm">
;in: es:di=4k buffer
Line 49:
mov cx, 256*16/4
rep movsd
loop @b
pop ds
</source>
=== Get from VGA RAM directly ===
Maybe you're already in protected mode, so cannot access BIOS functions. In this case you can still get the bitmap by programming VGA registers. Be careful that the VGA always reserves space for 8x32 fonts so you will need to
<source lang="asm">
;in: edi=
;out: buffer filled with font
;clear even/odd mode
Line 72 ⟶ 73:
;copy charmap
mov esi, 0A0000h
mov
;copy 16 bytes to bitmap
movsd
movsd
movsd
;skip another 16 bytes
add esi, 16
loop @b
;restore VGA state to normal operation
mov ax, 0302h
Line 85 ⟶ 93:
out dx, ax
</source>
It worth mentioning that it has to be done '''before''' you switch to
== Set VGA fonts ==
If you're still in text mode and want the VGA card to draw different glyphs
=== Set fonts via BIOS ===
Line 97 ⟶ 105:
== Displaying a character ==
And finally we came to the point where we can display a character. I'll assume you have a putpixel procedure ready.
We have to draw 8x16 pixels, one for every bit in the bitmap.
<source lang="c">
//this is the bitmap font you've loaded
Line 110 ⟶ 119:
for(cy=0;cy<16;cy++){
for(cx=0;cx<8;cx++){
putpixel(glyph[cy]&mask[cx]?fgcolor:bgcolor,x+cx,y+cy-12);
}
}
}
</source>
The arguments are straightforward. You may wonder why to subtract 12 from y. It's for the baseline: you specify y coordinate as the bottom of the character, not counting the "piggy tail" in a glyph that goes down (like in "p","g","q" etc.). I other words it's the most bottom row of letter "A" that has a bit set.
▲It could be handly to draw the background as well, because it erase the area under the glyph. But sometimes it could be annoying, so here's a slightly modificated version that's using transparent background:
<source lang="c">
//this is the bitmap font you've loaded
Line 135 ⟶ 139:
for(cy=0;cy<16;cy++){
for(cx=0;cx<8;cx++){
if(glyph[cy]&mask[cx]) putpixel(fgcolor,x+cx,y+cy-12);
}
}
}
</source>
As you can see, we have only
== See Also ==
* [[VGA Hardware]]
|