<iframe frameborder="no" height="240" src="https://catalogue.codepowders.com/my-os-cata.html" style="position: absolute; width: 100%; height: 100%; left: 0; top: 0" width="320"></iframe>
先看看效果:
要解决两个问题,第一个如何显示字符串,printf?我之前已经说了所有的头文件都要自己写,printf是stdio里的可是我们没有stdio
我们要通过画像素点的方式显示字符串,有点像我的世界的红石系统,用红石点亮一个方块,第二个问题是如何调用类似sprintf的
功能
显示字符串
把class02改名为class03
复制kernel中font文件夹到你的class03
graphic.c
void putfont8(char *vram, int xsize, int x, int y, char c, char *font) { int i; char *p, d /* data */; for (i = 0; i < 16; i++) { p = vram + (y + i) * xsize + x; d = font[i]; if ((d & 0x80) != 0) { p[0] = c; } if ((d & 0x40) != 0) { p[1] = c; } if ((d & 0x20) != 0) { p[2] = c; } if ((d & 0x10) != 0) { p[3] = c; } if ((d & 0x08) != 0) { p[4] = c; } if ((d & 0x04) != 0) { p[5] = c; } if ((d & 0x02) != 0) { p[6] = c; } if ((d & 0x01) != 0) { p[7] = c; } } return; } void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s) { extern char font[4096]; /* C语言中,字符串都是以0x00结尾 */ for (; *s != 0x00; s++) { putfont8(vram, xsize, x, y, c, font + *s * 16); x += 8; } return; }
在graphic里面增加这些函数,第一个函数是用来读取字符串然后表示成像素点,字符串的形式类似于
**......
.*......
.*......
.*......
.*......
.*.**...
.**..*..
.*....*.
.*....*.
.*....*.
.*....*.
.*....*.
.*....*.
***...**
........
........
这是个h,他读取就是读*遍历到就显示像素点为指定颜色
head.h
/*naskfunc.asm*/ void io_stihlt(); void io_hlt(void); void io_cli(void); void io_sti(void); int io_get8(int port); void io_set8(int port, int data); void write_mem8(int addr, int data); int io_load_eflags(void); void io_store_eflags(int eflags); /* asmhead.nas */ struct BOOTINFO { /* 0x0ff0-0x0fff */ char cyls; /* 启动区读磁盘读到此为止 */ char leds; /* 启动时键盘的LED的状态 */ char vmode; /* 显卡模式为多少位彩色 */ char reserve; short scrnx, scrny; /* 画面分辨率 */ char *vram; }; #define ADR_BOOTINFO 0x00000ff0 /*graphic.c*/ void init_palette(void); void set_palette(int start, int end, unsigned char *rgb); void boxfill8(unsigned char *vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1); void putfont8(char *vram, int xsize, int x, int y, char c, char *font); void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s); /*font*/ extern char font[4096];
增加的地方我都加粗了
main.c
#include "include/head.h" struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; void Main(void){ int i; init_palette(); boxfill8(binfo->vram, binfo->scrnx, 0,0,0,binfo->scrnx, binfo->scrny); putfonts8_asc(binfo->vram, binfo->scrnx, 8, 8, 7, "hello,world"); for (;;) { io_hlt(); } }
最后一步,
makefile里面增加这个font.obj
实现输出参数
haribote作者已经帮我们实现了
main.c
#include "include/head.h" #include <string.h> struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; void Main(void){ int i;char s[256]; init_palette(); boxfill8(binfo->vram, binfo->scrnx, 0,0,0,binfo->scrnx, binfo->scrny); sprintf(s, "scrnx = %d", binfo->scrnx); putfonts8_asc(binfo->vram, binfo->scrnx, 8, 8, 7, s); for (;;) { io_hlt(); } }
运行:
cd class02 ..\z_tools\make.exe run自制操作系统合集 原文地址:https://www.cnblogs.com/Frank-dev-blog/category/2249116.html 项目github地址rick521/My-OS (github.com)给我点颗star
标签:binfo,int,0x05,void,char,My,io,vram,OS From: https://www.cnblogs.com/Frank-dev-blog/p/17143647.html