同时显示ascii和gb2312,也许能行吧,没有试验很多,但愿一切正常!

同时显示ascii和gb2312,也许能行吧,没有试验很多,但愿一切正常!

 

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[] = "系统的名字叫做什么呢,暂定为SnailOS吧,真的佩服自己的速度,像蜗牛爬树!";
    print_gb2312(0xffffffff, 80 , 0, str0);
    unsigned char str1[] = "我的系统开始可以打印中文了,不过还不能换行,屏幕也是越界的,好在还是正确的显示了!";
    print_gb2312(0xffffffff, 80, 80, str1);
    
    unsigned char str2[] = "蜗牛(Snial)";
    print_gb2312(0xffffffff, 80 , 96, str2);
    unsigned char str3[] = "该不该搁下重重的壳";
    print_gb2312(0xffffffff, 80 , 112, str3);
    unsigned char str4[] = "寻找到底哪里有蓝天";
    print_gb2312(0xffffffff, 80 , 128, str4);
    unsigned char str5[] = "随着轻轻的风轻轻的飘";
    print_gb2312(0xffffffff, 80 , 144, str5);
    unsigned char str6[] = "历经的伤都不感觉疼";
    print_gb2312(0xffffffff, 80 , 160, str6);
    unsigned char str7[] = "我要一步一步往上爬";
    print_gb2312(0xffffffff, 80 , 176, str7);
    unsigned char str8[] = "等待阳光静静看着它的脸";
    print_gb2312(0xffffffff, 80 , 192, str8);
    unsigned char str9[] = "小小的天有大大的梦想";
    print_gb2312(0xffffffff, 80 , 208, str9);
    unsigned char str10[] = "重重的壳裹着轻轻的仰望";
    print_gb2312(0xffffffff, 80 , 224, str10);
    unsigned char str11[] = "我要一步一步往上爬";
    print_gb2312(0xffffffff, 80 , 240, str11);
    unsigned char str12[] = "在最高点乘着叶片往前飞";
    print_gb2312(0xffffffff, 80 , 256, str12);
    unsigned char str13[] = "让风吹干流过的泪和汗";
    print_gb2312(0xffffffff, 80 , 272, str13);
    unsigned char str14[] = "总有一天我有属于我的天";
    print_gb2312(0xffffffff, 80 , 288, str14);
    unsigned char str15[] = "我a的b梦想是c成为一个d梦想家e蜗牛先生f算了吧,g你你你你h";
    print_gb2312(0xffffffff, 80 , 304, str15);
    unsigned char str16[] = "aaa好梦成真,蜗牛先生,happy every day,哦,也许能打印ascii了";
    print_gb2312(0xffffffff, 80 , 320, str16);
    unsigned char str17[] = "HELLO, world$~!@##¥%…………&)(*_*)))))。。。^_^^_^";
    print_gb2312(0xffffffff, 80 , 336, str17);
    
    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 print_ascii (int color, int x, int y, char *font) {
    int *myfb = (int *)0xe0000000;
    int xsize = 800;
    char 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;}
    }
    return;
}

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];
    extern char myfont[0x1000];
    int i = 0, j = 0;
    unsigned char a, b;
    unsigned int offset;
    while (str[i] != 0) {
        if (str[i] < 0x80) {
            a = str[i];
            print_ascii (color, x + j, y, myfont + a * 16);
            if (str[i + 1] == 0)
                break;
            i++;
            j += 8;
        } else {    
            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;
        }
    }
    return;
}