Compare commits

...

5 Commits

Author SHA1 Message Date
Yourtion
041e2a4b52 键盘输入API 2016-05-10 15:36:01 +08:00
Yourtion
8de80dcee7 关闭窗口 2016-05-10 15:21:03 +08:00
Yourtion
975bb8c8b7 画直线 2016-05-10 15:14:15 +08:00
Yourtion
76e2a4a389 刷新窗口 2016-05-10 14:55:16 +08:00
Yourtion
dc29fff86f 画点 2016-05-10 14:31:35 +08:00
8 changed files with 308 additions and 7 deletions

View File

@@ -113,9 +113,38 @@ winhelo3.bim : winhelo3.obj a_nask.obj Makefile
winhelo3.hrb : winhelo3.bim Makefile
$(BIM2HRB) winhelo3.bim winhelo3.hrb 40k
star1.bim : star1.obj a_nask.obj Makefile
$(OBJ2BIM) @$(RULEFILE) out:star1.bim stack:1k map:star1.map \
star1.obj a_nask.obj
star1.hrb : star1.bim Makefile
$(BIM2HRB) star1.bim star1.hrb 47k
stars.bim : stars.obj a_nask.obj Makefile
$(OBJ2BIM) @$(RULEFILE) out:stars.bim stack:1k map:stars.map \
stars.obj a_nask.obj
stars.hrb : stars.bim Makefile
$(BIM2HRB) stars.bim stars.hrb 47k
stars2.bim : stars2.obj a_nask.obj Makefile
$(OBJ2BIM) @$(RULEFILE) out:stars2.bim stack:1k map:stars2.map \
stars2.obj a_nask.obj
stars2.hrb : stars2.bim Makefile
$(BIM2HRB) stars2.bim stars2.hrb 47k
lines.bim : lines.obj a_nask.obj Makefile
$(OBJ2BIM) @$(RULEFILE) out:lines.bim stack:1k map:lines.map \
lines.obj a_nask.obj
lines.hrb : lines.bim Makefile
$(BIM2HRB) lines.bim lines.hrb 48k
haribote.img : ipl10.bin haribote.sys Makefile \
hello.hrb hello2.hrb a.hrb hello3.hrb hello4.hrb hello5.hrb \
winhelo.hrb winhelo2.hrb winhelo3.hrb
winhelo.hrb winhelo2.hrb winhelo3.hrb star1.hrb stars.hrb stars2.hrb \
lines.hrb
$(EDIMG) imgin:../z_tools/fdimg0at.tek \
wbinimg src:ipl10.bin len:512 from:0 to:0 \
copy from:haribote.sys to:@: \
@@ -130,8 +159,12 @@ haribote.img : ipl10.bin haribote.sys Makefile \
copy from:winhelo.hrb to:@: \
copy from:winhelo2.hrb to:@: \
copy from:winhelo3.hrb to:@: \
copy from:star1.hrb to:@: \
copy from:stars.hrb to:@: \
copy from:stars2.hrb to:@: \
copy from:lines.hrb to:@: \
imgout:haribote.img
# 其他指令
%.gas : %.c bootpack.h Makefile

View File

@@ -12,6 +12,11 @@
GLOBAL _api_initmalloc
GLOBAL _api_malloc
GLOBAL _api_free
GLOBAL _api_point
GLOBAL _api_refreshwin
GLOBAL _api_linewin
GLOBAL _api_closewin
GLOBAL _api_getkey
[SECTION .text]
@@ -117,4 +122,67 @@ _api_free: ; void api_free(char *addr, int size);
INT 0x40
POP EBX
RET
_api_point: ; void api_point(int win, int x, int y, int col);
PUSH EDI
PUSH ESI
PUSH EBX
MOV EDX,11
MOV EBX,[ESP+16] ; win
MOV ESI,[ESP+20] ; x
MOV EDI,[ESP+24] ; y
MOV EAX,[ESP+28] ; col
INT 0x40
POP EBX
POP ESI
POP EDI
RET
_api_refreshwin: ; void api_refreshwin(int win, int x0, int y0, int x1, int y1);
PUSH EDI
PUSH ESI
PUSH EBX
MOV EDX,12
MOV EBX,[ESP+16] ; win
MOV EAX,[ESP+20] ; x0
MOV ECX,[ESP+24] ; y0
MOV ESI,[ESP+28] ; x1
MOV EDI,[ESP+32] ; y1
INT 0x40
POP EBX
POP ESI
POP EDI
RET
_api_linewin: ; void api_linewin(int win, int x0, int y0, int x1, int y1, int col);
PUSH EDI
PUSH ESI
PUSH EBP
PUSH EBX
MOV EDX,13
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
_api_closewin: ; void api_closewin(int win);
PUSH EBX
MOV EDX,14
MOV EBX,[ESP+8] ; win
INT 0x40
POP EBX
RET
_api_getkey: ; int api_getkey(int mode);
MOV EDX,15
MOV EAX,[ESP+4] ; mode
INT 0x40
RET

View File

@@ -237,6 +237,7 @@ void make_wtitle8(unsigned char *buf, int xsize, char *title, char act);
struct CONSOLE {
struct SHEET *sht;
int cur_x, cur_y, cur_c;
struct TIMER *timer;
};
void console_task(struct SHEET *sheet, unsigned int memtotal);
void cons_putchar(struct CONSOLE *cons, int chr, char move);

View File

@@ -321,6 +321,8 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int
/*强行改写通过PUSHAD保存的值*/
/* reg[0] : EDI, reg[1] : ESI, reg[2] : EBP, reg[3] : ESP */
/* reg[4] : EBX, reg[5] : EDX, reg[6] : ECX, reg[7] : EAX */
int i;
if (edx == 1) {
cons_putchar(cons, eax & 0xff, 1);
} else if (edx == 2) {
@@ -337,13 +339,17 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int
sheet_updown(sht, 3); /*背景层高度3位于task_a之上*/
reg[7] = (int) sht;
} else if (edx == 6) {
sht = (struct SHEET *) ebx;
sht = (struct SHEET *) (ebx & 0xfffffffe);
putfonts8_asc(sht->buf, sht->bxsize, esi, edi, eax, (char *) ebp + ds_base);
sheet_refresh(sht, esi, edi, esi + ecx * 8, edi + 16);
if ((ebx & 1) == 0) {
sheet_refresh(sht, esi, edi, esi + ecx * 8, edi + 16);
}
} else if (edx == 7) {
sht = (struct SHEET *) ebx;
sht = (struct SHEET *) (ebx & 0xfffffffe);
boxfill8(sht->buf, sht->bxsize, ebp, eax, ecx, esi, edi);
sheet_refresh(sht, eax, ecx, esi + 1, edi + 1);
if ((ebx & 1) == 0) {
sheet_refresh(sht, eax, ecx, esi + 1, edi + 1);
}
} else if (edx == 8) {
memman_init((struct MEMMAN *) (ebx + ds_base));
ecx &= 0xfffffff0; /*以16字节为单位*/
@@ -354,6 +360,53 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int
} else if (edx == 10) {
ecx = (ecx + 0x0f) & 0xfffffff0; /*以16字节为单位进位取整*/
memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx);
} else if (edx == 11) {
sht = (struct SHEET *) (ebx & 0xfffffffe);
sht->buf[sht->bxsize * edi + esi] = eax;
if ((ebx & 1) == 0) {
sheet_refresh(sht, esi, edi, esi + 1, edi + 1);
}
} else if (edx == 12) {
sht = (struct SHEET *) ebx;
sheet_refresh(sht, eax, ecx, esi, edi);
} else if (edx == 13) {
sht = (struct SHEET *) (ebx & 0xfffffffe);
hrb_api_linewin(sht, eax, ecx, esi, edi, ebp);
if ((ebx & 1) == 0) {
sheet_refresh(sht, eax, ecx, esi + 1, edi + 1);
}
} else if (edx == 14) {
sheet_free((struct SHEET *) ebx);
} else if (edx == 15) {
for (;;) {
io_cli();
if (fifo32_status(&task->fifo) == 0) {
if (eax != 0) {
task_sleep(task); /* FIFO为空休眠并等待*/
} else {
io_sti();
reg[7] = -1;
return 0;
}
}
i = fifo32_get(&task->fifo);
io_sti();
if (i <= 1) { /*光标用定时器*/
/*应用程序运行时不需要显示光标因此总是将下次显示用的值置为1*/
timer_init(cons->timer, &task->fifo, 1); /*下次置为1*/
timer_settime(cons->timer, 50);
}
if (i == 2) { /*光标ON */
cons->cur_c = COL8_FFFFFF;
}
if (i == 3) { /*光标OFF */
cons->cur_c = -1;
}
if (256 <= i && i <= 511) { /*键盘数据通过任务A*/
reg[7] = i - 256;
return 0;
}
}
}
return 0;
}
@@ -379,3 +432,52 @@ int *inthandler0d(int *esp)
cons_putstr0(cons, s);
return &(task->tss.esp0); /*强制结束程序*/
}
void hrb_api_linewin(struct SHEET *sht, int x0, int y0, int x1, int y1, int col)
{
int i, x, y, len, dx, dy;
dx = x1 - x0;
dy = y1 - y0;
x = x0 << 10;
y = y0 << 10;
if (dx < 0) {
dx = - dx;
}
if (dy < 0) {
dy = - dy;
}
if (dx >= dy) {
len = dx + 1;
if (x0 > x1) {
dx = -1024;
} else {
dx = 1024;
}
if (y0 <= y1) {
dy = ((y1 - y0 + 1) << 10) / len;
} else {
dy = ((y1 - y0 - 1) << 10) / len;
}
} else {
len = dy + 1;
if (y0 > y1) {
dy = -1024;
} else {
dy = 1024;
}
if (x0 <= x1) {
dx = ((x1 - x0 + 1) << 10) / len;
} else {
dx = ((x1 - x0 - 1) << 10) / len;
}
}
for (i = 0; i < len; i++) {
sht->buf[(y >> 10) * sht->bxsize + (x >> 10)] = col;
x += dx;
y += dy;
}
return;
}

29
23_day/lines.c Normal file
View File

@@ -0,0 +1,29 @@
int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title);
void api_initmalloc(void);
char *api_malloc(int size);
void api_refreshwin(int win, int x0, int y0, int x1, int y1);
void api_linewin(int win, int x0, int y0, int x1, int y1, int col);
void api_closewin(int win);
int api_getkey(int mode);
void api_end(void);
void HariMain(void)
{
char *buf;
int win, i;
api_initmalloc();
buf = api_malloc(160 * 100);
win = api_openwin(buf, 160, 100, -1, "lines");
for (i = 0; i < 8; i++) {
api_linewin(win + 1, 8, 26, 77, i * 9 + 26, i);
api_linewin(win + 1, 88, 26, i * 9 + 88, 89, i);
}
api_refreshwin(win, 6, 26, 154, 90);
for (;;) {
if (api_getkey(1) == 0x0a) {
break; /*按下回车键则break; */
}
}
api_closewin(win);
api_end();
}

18
23_day/star1.c Normal file
View File

@@ -0,0 +1,18 @@
int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title);
void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col);
void api_initmalloc(void);
char *api_malloc(int size);
void api_point(int win, int x, int y, int col);
void api_end(void);
void HariMain(void)
{
char *buf;
int win;
api_initmalloc();
buf = api_malloc(150 * 100);
win = api_openwin(buf, 150, 100, -1, "star1");
api_boxfilwin(win, 6, 26, 143, 93, 0);/*黑色*/
api_point(win, 75, 59, 3);/*黄色*/
api_end();
}

24
23_day/stars.c Normal file
View File

@@ -0,0 +1,24 @@
int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title);
void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col);
void api_initmalloc(void);
char *api_malloc(int size);
void api_point(int win, int x, int y, int col);
void api_end(void);
int rand(void); /*产生032767之间的随机数*/
void HariMain(void)
{
char *buf;
int win, i, x, y;
api_initmalloc();
buf = api_malloc(150 * 100);
win = api_openwin(buf, 150, 100, -1, "stars");
api_boxfilwin(win, 6, 26, 143, 93, 0);/*黑色*/
for (i = 0; i < 50; i++) {
x = (rand() % 137) + 6;
y = (rand() % 67) + 26;
api_point(win, x, y, 3);/*黄色*/
}
api_end();
}

26
23_day/stars2.c Normal file
View File

@@ -0,0 +1,26 @@
int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title);
void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col);
void api_initmalloc(void);
char *api_malloc(int size);
void api_point(int win, int x, int y, int col);
void api_refreshwin(int win, int x0, int y0, int x1, int y1);
void api_end(void);
int rand(void); /*产生032767的随机数*/
void HariMain(void)
{
char *buf;
int win, i, x, y;
api_initmalloc();
buf = api_malloc(150 * 100);
win = api_openwin(buf, 150, 100, -1, "stars2");
api_boxfilwin(win + 1, 6, 26, 143, 93, 0);/*黑色*/
for (i = 0; i < 50; i++) {
x = (rand() % 137) + 6;
y = (rand() % 67) + 26;
api_point(win + 1, x, y, 3);/*黄色*/
}
api_refreshwin(win, 6, 26, 144, 94);
api_end();
}