30天自制操作系统-day8

30天自制操作系统-day8

这次我们更改main.c以及相关文件,生成彩色矩形框,只需要在main.c函数中添加如下代码

main.c

#include<header.h>
void bootmain(void){
	char* point = (char*)0xa0000;

	init_palette();
	
	for(int i = 0; i <= 0xffff; i++){
		*(point + i) = i & 0xf;
	}

	boxfill8(point, 320, 1, 20, 20, 120, 120);
	boxfill8(point, 320, 2, 70, 50, 170, 150);
	boxfill8(point, 320, 4, 120, 80, 220, 180);

	for(;;) {
		io_halt();
	}
}

screen.c

.......
.......

void boxfill8(char* vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1)
{
	int x, y;
	for(y=y0; y<=y1; y++){
		for(x=x0; x<=x1; x++){
			vram[y*xsize+x]=c;
		}
	}
	return;
}

header.h

.................
.................
extern void boxfill8(char* vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1);
效果如下:

源码链接:https://github.com/zchrissirhcz/osask-linux.git

原文地址:https://www.cnblogs.com/wangdongfang/p/14365023.html