7 在窗口中描绘字符和方块(harib19g)
虽然时间已经很晚了,大家也很困了,不过看到成功显示出窗口,我们的精神又振奋了起来,所以我们再来试一下在窗口上显示字符和方块吧。这两个功能都是现成的,只要加在API上面就可以了。
在窗口上显示字符的API如下:
EDX = 6
EBX = 窗口句柄
ESI = 显示位置的x坐标
EDI = 显示位置的y坐标
EAX = 色号
ECX = 字符串长度
EBP = 字符串
描绘方块的API如下:
EDX = 7
EBX = 窗口句柄
EAX = x0
ECX = y0
ESI = x1
EDI = y1
EBP = 色号
哎哟,真悬,如果再多一个参数寄存器就要不够用了。
■■■■■
接下来就是写程序了,这个简单。
本次的console.c节选
int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax)
{
(中略)
if (edx == 1) {
cons_putchar(cons, eax & 0xff, 1);
} else if (edx == 2) {
cons_putstr0(cons, (char *) ebx + ds_base);
} else if (edx == 3) {
cons_putstr1(cons, (char *) ebx + ds_base, ecx);
} else if (edx == 4) {
return &(task->tss.esp0);
} else if (edx == 5) {
(中略)
} else if (edx == 6) { /*从此开始*/
sht = (struct SHEET *) ebx;
putfonts8_asc(sht->buf, sht->bxsize, esi, edi, eax, (char *) ebp + ds_base);
sheet_refresh(sht, esi, edi, esi + ecx * 8, edi + 16);
} else if (edx == 7) {
sht = (struct SHEET *) ebx;
boxfill8(sht->buf, sht->bxsize, ebp, eax, ecx, esi, edi);
sheet_refresh(sht, eax, ecx, esi + 1, edi + 1); /*到此结束*/
}
return 0;
}
操作系统的修改完成了,下面来修改应用程序。
本次的a_nask.nas节选
_api_putstrwin: ; void api_putstrwin(int win, int x, int y, int col, int len, char *str);
PUSH EDI
PUSH ESI
PUSH EBP
PUSH EBX
MOV EDX,6
MOV EBX,[ESP+20] ; win
MOV ESI,[ESP+24] ; x
MOV EDI,[ESP+28] ; y
MOV EAX,[ESP+32] ; col
MOV ECX,[ESP+36] ; len
MOV EBP,[ESP+40] ; str
INT 0x40
POP EBX
POP EBP
POP ESI
POP EDI
RET
_api_boxfilwin: ; void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col);
PUSH EDI
PUSH ESI
PUSH EBP
PUSH EBX
MOV EDX,7
MOV EBX,[ESP+20] ; win
MOV EAX,[ESP+24] ; x0
MOV ECX,[ESP+28] ; y0
MOV ESI,[ESP+32] ; x1
MOV EDI,[ESP+36] ; y1
MOV EBP,[ESP+40] ; col
INT 0x40
POP EBX
POP EBP
POP ESI
POP EDI
RET
本次的winhelo2.c节选
int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title);
void api_putstrwin(int win, int x, int y, int col, int len, char *str);
void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col);
void api_end(void);
char buf[150 * 50];
void HariMain(void)
{
int win;
win = api_openwin(buf, 150, 50, -1, "hello");
api_boxfilwin(win, 8, 36, 141, 43, 3 /*黄色*/);
api_putstrwin(win, 28, 28, 0 /*黑色*/, 12, "hello, world");
api_end();
}
■■■■■
大功告成,“make run”之后结果如下。对了,刚刚忘记说了,bug1.hrb已经没有用了,所以把它删掉了哦。
完成了!
运行得很顺利,心里相当满意呀。那么今天就到这里吧,大家晚安,明天见哦。