自制操作系统10:绘制字体 - 使用字库

参考:
https://blog.csdn.net/tyler_download/article/details/52636761
https://www.bilibili.com/video/BV1VJ41157wq?p=10
https://github.com/wycl16514/os-kernel-draw-ascii-chars
原理是按像素绘图,不过分辨率比较低的VGA模式下,怎么绘制都有锯齿的感觉,太粗糙,聊胜于无吧,谁让我们自己做呢,只能糙点,凑合着。
这个操作系统就是一个玩具,学习原理为主。
8×16,搞一个数组就行了。按数组画就行了。

实验开始,新建立目录,把上节的write_vga_desktop.c拷贝过来修改,增加
先显示一个A:
static char fontA[16] = {
0x00, 0x18, 0x18, 0x18,0x18,0x24,0x24,0x24,
0x24, 0x7e, 0x42, 0x42,0x42, 0xe7, 0x00, 0x00
};
showFont8(vram, xsize, 8, 8, COL8_FFFFFF, fontA);
编译试试:
gcc -m32 -fno-pie -s -c -o write_vga_desktop.o write_vga_desktop.c
../objconv-new/objconv/objconv -fnasm write_vga_desktop.o -o write_vga_desktop.asm
delete:
global
extern
section
endbr32 
kernel.asm
%include "write_vga_desktop.asm"
nasm -o kernel.bat kernel.asm
Load file boot.bat to floppy with cylinder: 0 and sector:1
Load file kernel.bat to floppy with cylinder: 1 and sector:2
Load file kernel.bat to floppy with cylinder: 1 and sector:3
Load file kernel.bat to floppy with cylinder: 1 and sector:4
Load file kernel.bat to floppy with cylinder: 1 and sector:5
Load file kernel.bat to floppy with cylinder: 1 and sector:6
5个扇区,修改boot.asm -- 注意录像中是2-14,共13个扇区,难道是我用新的nasm版本后,编译的目标文件变小了。

名字改一下:write_vga_desktop_single_char.c--这次就不改了。

A可以显示,但整个字符集,就不需要自己设计了,需要弄个字库,一些艺术家(是不是冒牌的?)设计了font.txt
里面就是.和*
MakeFont工具将txt转换成fontData.inc,把艺术家的图案转换成16进制数组,每行db定义一个图案,原理和前面的A字符相同

write_vga_desktop_systemFont.c
gcc -m32 -fno-pie -s -c -o write_vga_desktop_systemFont.o write_vga_desktop_systemFont.c
../objconv-new/objconv/objconv -fnasm write_vga_desktop_systemFont.o -o write_vga_desktop_systemFont.asm
delete:
global
extern
section
endbr32 
kernel.asm
%include "write_vga_desktop_systemFont.asm"
%include "fontData.inc" ---  在文集末尾加上字体数据
nasm -o kernel.bat kernel.asm
Load file boot.bat to floppy with cylinder: 0 and sector:1
Load file kernel.bat to floppy with cylinder: 1 and sector:2
Load file kernel.bat to floppy with cylinder: 1 and sector:3
Load file kernel.bat to floppy with cylinder: 1 and sector:4
Load file kernel.bat to floppy with cylinder: 1 and sector:5
Load file kernel.bat to floppy with cylinder: 1 and sector:6
Load file kernel.bat to floppy with cylinder: 1 and sector:7
Load file kernel.bat to floppy with cylinder: 1 and sector:8
Load file kernel.bat to floppy with cylinder: 1 and sector:9
Load file kernel.bat to floppy with cylinder: 1 and sector:10
Load file kernel.bat to floppy with cylinder: 1 and sector:11
Load file kernel.bat to floppy with cylinder: 1 and sector:12
Load file kernel.bat to floppy with cylinder: 1 and sector:13
Load file kernel.bat to floppy with cylinder: 1 and sector:14
13个扇区,修改boot.asm -- 注意录像中是2-14,共13个扇区,难道是我用新的nasm版本后,编译的目标文件变小了。
运行可以显示ABC123

add function
void showString(char* vram, int xsize, int x, int y, char color, unsigned char *s ) {
    for (; *s != 0x00; s++) {
       showFont8(vram, xsize, x, y,color, systemFont+ *s * 16);
       x += 8;
    }
}
showString(vram, xsize, 72, 8, COL8_FFFFFF, "Show my String");
可以显示


但是好丑啊,这是艺术家的字体吗?

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值