MacOS环境-手写操作系统-09-绘制系统字体

简介: MacOS环境-手写操作系统-09-绘制系统字体

给系统绘制字体

1.简介

如果我们把字体的大小限定在一个8*16的长方形区域,那么我们在这个区域内,将特定位置的像素点设置成黑色,其他点设置成白色,那么我们就可以得到一个白底黑色的字体: 2.单字体实现

如果我们把8*16区域当做一个二维数组,白色的像素我们用0表示,黑色像素我们用1表示,


那么上图的字符A, 最顶层的一行全是白色,所以用8个0表示,


第二行,8个像素中,中间两个像素设置成黑色,


于是对应的二进制数就是000 11 000, 对应的16进制数就是0x18,


依次类推,这样对整个字符A, 我们就有可以设置一个对应的数组:

static char fontA[16] = {
0x00, 0x18, 0x18, 0x18,0x18,0x24,0x24,0x24,
0x24, 0x7e, 0x42, 0x42,0x42, 0xe7, 0x00, 0x00
};

拿到字体数组后,绘制时,把数组中的每一个数值取出来,看该数值的二进制形式中,哪一位设置成1,那么就给对应的像素赋予黑色,如果设置成0,就给对应的像素设置成白色,代码如下:

void showFont8(char *vram, int xsize, int x, int y, char c, char* font) {
    int i;
    char d;

    for (i = 0; i < 16; i++) {
        d = font[i]; 
        if ((d & 0x80) != 0) {vram[(y+i)*xsize + x + 0] = c;}
        if ((d & 0x40) != 0) {vram[(y+i)*xsize + x + 1] = c;}
        if ((d & 0x20) != 0) {vram[(y+i)*xsize + x + 2] = c;}
        if ((d & 0x10) != 0) {vram[(y+i)*xsize + x + 3] = c;}
        if ((d & 0x08) != 0) {vram[(y+i)*xsize + x + 4] = c;}
        if ((d & 0x04) != 0) {vram[(y+i)*xsize + x + 5] = c;}
        if ((d & 0x02) != 0) {vram[(y+i)*xsize + x + 6] = c;}
        if ((d & 0x01) != 0) {vram[(y+i)*xsize + x + 7] = c;}
    }

接着 在write_vga_desktop.c的主函数中,在for(;;)死循环前加入一句:


showFont8(vram, xsize, 20, 20, COL8_FFFFFF, fontA);


对其进行一些列的编译、反汇编、汇编、java操作后


编译C文件

i386-elf-gcc -m32 -fno-asynchronous-unwind-tables -s -c -o write_vga_desktop_single_char.o write_vga_desktop_single_char.c


反汇编o文件

./objconv -fnasm write_vga_desktop_single_char.o write_vga_desktop_single_char.asm


删除无用部分


修改kernel

%include "write_vga_desktop_single_char.asm"


修改boot(直接放大一点)直接读了20个扇区 肯定够用了

mov          AL,  20        ; AL 表示要练习读取几个扇区

编译boot

nasm -o boot.bat boot.asm


编译kernel

nasm -o kernel.bat kernel.asm


运行java

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

运行:

相关文章
|
1天前
|
开发框架 人工智能 物联网
移动应用与系统:探索移动应用开发与操作系统的融合之道
本文旨在深入探讨移动应用开发与移动操作系统之间的紧密联系,分析它们如何相互影响、共同推动移动互联网的发展。通过阐述移动应用开发的关键技术、主流移动操作系统的特点以及两者在实际应用中的融合案例,本文揭示了移动应用与系统之间的共生关系,并展望了未来发展趋势。
|
1天前
|
存储 C语言 iOS开发
MacOS环境-手写操作系统-48-让内核从错误中恢复
MacOS环境-手写操作系统-48-让内核从错误中恢复
9 0
|
1天前
|
存储 API C语言
MacOS环境-手写操作系统-46,47-C语言开发应用程序
MacOS环境-手写操作系统-46,47-C语言开发应用程序
8 0
|
1天前
|
编译器 API C语言
MacOS环境-手写操作系统-45-C语言开发应用程序
MacOS环境-手写操作系统-45-C语言开发应用程序
10 0
|
1天前
|
小程序 iOS开发 MacOS
MacOS环境-手写操作系统-44-运行简单的程序
MacOS环境-手写操作系统-44-运行简单的程序
7 0
|
1天前
|
存储 Java iOS开发
MacOS环境-手写操作系统-43-dir命令的实现 和 文件写入
MacOS环境-手写操作系统-43-dir命令的实现 和 文件写入
9 0
|
2月前
|
关系型数据库 MySQL 数据库
【Mac os系统】安装MySQL数据库
本文详细介绍了在Mac OS系统上安装MySQL数据库的步骤,包括下载、安装、配置环境变量、启动服务、授权设置以及解决常见问题,并提供了一些常用的MySQL命令。
104 0
【Mac os系统】安装MySQL数据库
|
3月前
|
Linux 虚拟化 iOS开发
部署06--MacOS安装VMware Fusion安装
部署06--MacOS安装VMware Fusion安装
|
2月前
|
测试技术 Linux 虚拟化
iOS自动化测试方案(五):保姆级VMware虚拟机安装MacOS
详细的VMware虚拟机安装macOS Big Sur的保姆级教程,包括下载VMware和macOS镜像、图解安装步骤和遇到问题时的解决方案,旨在帮助读者顺利搭建macOS虚拟机环境。
68 3
iOS自动化测试方案(五):保姆级VMware虚拟机安装MacOS
|
2月前
|
虚拟化 数据安全/隐私保护 iOS开发
VMware——安装MacOS 系统教程(仅供学习交流)
VMware——安装MacOS 系统教程(仅供学习交流)
55 4