继续中文,晒代码,真的没什么新意,好在得意自满!

百度网盘下载地址:

https://pan.baidu.com/s/1_-IznMWL3z1CROziiD6mCw

图的下面是kernel.c boot.s Makefile 的代码了,开发环境的搭建及其他代码,请开以前的系列文章了。对了myfont.o是网上下载的叫HZK16的字模,字模的加载在程序代码中可,跟书上加载ascii的基本相同了。

 

 

kernel.c

 

void myhlt(void);
void fillbox(int color, int x0, int y0, int x1, int y1);
void myfillbox(int color, int x0, int y0, int x1, int y1);
void makefont16 (int color, int x, int y, short *font);
void print_gb2312(int color, int x, int y, unsigned char *str);

int mymain(int eax, int ebx) {
    int *myfb = (int *)0xe0000000;
    fillbox(0x001e90ff, 0, 0, 799, 599);
    myfillbox(0x00000000, 0, 0, 799, 599);
    
    unsigned char str0[] = "系统的名字叫做什么呢,暂定为蜗牛吧,真的佩服自己的速度,几天了中文还是很蹩脚!";
    print_gb2312(0x00000000, 80 , 0, str0);
    unsigned char str1[] = "我的系统开始可以打印中文了,不过还不能换行,屏幕也是越界的,好在还是正确的显示了!";
    print_gb2312(0xffffffff, 80, 80, str1);
    
    while(1) {
        myhlt();
    }
}

void myprintf(char *str) {
    
}

void fillbox(int color, int x0, int y0, int x1, int y1) {
    int *myfb = (int *)0xe0000000;
    int xsize = 800;
    int x, y;
    for (y = 0; y <= y1 - y0; y++) {
        for (x = 0; x <= x1 - x0; x++) {
            myfb[x0 + x + (y0 + y) * xsize] = color;
        }
    }
}


void myfillbox(int color, int x0, int y0, int x1, int y1) {
    int *myfb = (int *)0xe0000000;
    int xsize = 800;
    int x, y;
    if (x0 < 80 || y0 < 80 || x1 > 719 || y1 > 519) {
        x0 = 80;
        y0 = 80;
        x1 = 719;
        y1 = 519;
    }
    for (y = 0; y <= y1 - y0; y++) {
        for (x = 0; x <= x1 - x0; x++) {
            myfb[x0 + x + (y0 + y) * xsize] = color;
        }
    }
}

void makefont16 (int color, int x, int y, short *font) {
    int *myfb = (int *)0xe0000000;
    int xsize = 800;
    short d;
    int *p;
    int i;
    for (i = 0; i < 16; i++){
        p = myfb + (y + i) * xsize + x;
        d = font[i];
        if ((d & 0x80) != 0) {p[0] = color;}
        if ((d & 0x40) != 0) {p[1] = color;}
        if ((d & 0x20) != 0) {p[2] = color;}
        if ((d & 0x10) != 0) {p[3] = color;}
        if ((d & 0x08) != 0) {p[4] = color;}
        if ((d & 0x04) != 0) {p[5] = color;}
        if ((d & 0x02) != 0) {p[6] = color;}
        if ((d & 0x01) != 0) {p[7] = color;}
        if ((d & 0x8000) != 0) {p[8] = color;}
        if ((d & 0x4000) != 0) {p[9] = color;}
        if ((d & 0x2000) != 0) {p[10] = color;}
        if ((d & 0x1000) != 0) {p[11] = color;}
        if ((d & 0x800) != 0) {p[12] = color;}
        if ((d & 0x400) != 0) {p[13] = color;}
        if ((d & 0x200) != 0) {p[14] = color;}
        if ((d & 0x100) != 0) {p[15] = color;}
    }
    return;
}

void print_gb2312(int color, int x, int y, unsigned char *str) {
    extern short font[0x8000];
    int i = 0, j = 0;
    unsigned char a, b;
    unsigned int offset;
    i = 0; j = 0;
    while (str[i] != 0) {
        a = str[i] - 0xa0;
        b = str[i + 1] - 0xa0;
        offset = ((a - 1) * 94 + (b - 1)) * 16;
        makefont16 (color, x + j , y, font + offset);
        i += 2;
        j += 16;
    }
}
 

boot.s

 

MULTIBOOT2_HEADER_MAGIC = 0xe85250d6
GRUB_MULTIBOOT_ARCHITECTURE_I386 = 0x0
MULTIBOOT_HEADER_TAG_ADDRESS = 0x2
MULTIBOOT_HEADER_TAG_OPTIONAL = 0x1
MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS = 0x3
MULTIBOOT_HEADER_TAG_END = 0x0
MULTIBOOT_HEADER_TAG_FRAMEBUFFER = 0x5

.globl _start, _myhlt
.extern _mymain, _myprintf

_start:
    jmp multiboot_entry
.align 8

multiboot_header:
    .int MULTIBOOT2_HEADER_MAGIC
    .int GRUB_MULTIBOOT_ARCHITECTURE_I386
    .int multiboot_header_end - multiboot_header
    .int -(MULTIBOOT2_HEADER_MAGIC + GRUB_MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header))

.align 8
    
address_tag_start:
    .short MULTIBOOT_HEADER_TAG_ADDRESS
    .short MULTIBOOT_HEADER_TAG_OPTIONAL
    .int address_tag_end - address_tag_start
    .int multiboot_header
    .int _start
    .int 0x0
    .int 0x0
address_tag_end:

.align 8

entry_address_tag_start:
    .short MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS
    .short MULTIBOOT_HEADER_TAG_OPTIONAL
    .int entry_address_tag_end - entry_address_tag_start
    .int multiboot_entry
entry_address_tag_end:

.align 8

framebuffer_tag_start:
    .short MULTIBOOT_HEADER_TAG_FRAMEBUFFER
    .short MULTIBOOT_HEADER_TAG_OPTIONAL
    .int framebuffer_tag_end - framebuffer_tag_start
    .int 800
    .int 600
    .int 32
framebuffer_tag_end:

.align 8

undefined_tag:
    .short MULTIBOOT_HEADER_TAG_END
    .short 0
    .int 8
    
multiboot_header_end:
.align 8
multiboot_entry:

    movl $stack, %esp
    pushl $0
    popf
    
    pushl %ebx
    pushl %eax
    
    call _mymain
    
    pushl $str
    call _myprintf
    
1:
    hlt
    jmp 1b

str:
    .string "idealOS is halt!\n"

.align 0x1000    
.fill 0xf000, 4, 0
stack:
    
_myhlt:
    cli
    hlt
    ret

 

Makefile

AS = as
C = gcc
ASF = 
CF = -c
LD = ld
LDF = -Ttext 0x100000
OBJ = boot.o kernel.o myfont.o

default: $(OBJ)
    make boot.o
    make myfont.o
    make kernel.o

boot.o: boot.s
    $(AS) -o $@ $<
    
#myfont.o: myfont.s
#    $(AS) -o $@ $<

kernel.o: kernel.c
    $(C) $(CF) -o $@ $<
    
kernel:    $(OBJ)
    $(LD) $(LDF) -o kernel $(OBJ)
    objcopy -I pe-i386 -O elf32-i386 kernel
    mount.cmd
  
run: kernel
    make default
    start virtualbox --startvm "C:\Users\Administrator\VirtualBox VMs\newos\newos.vbox" 

clean:
    del boot.o
    del kernel.o
    del kernel

    
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_39410618

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值