Compare commits

..

3 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
5 changed files with 166 additions and 2 deletions

View File

@@ -134,9 +134,17 @@ stars2.bim : stars2.obj a_nask.obj Makefile
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 star1.hrb stars.hrb stars2.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:@: \
@@ -154,8 +162,9 @@ haribote.img : ipl10.bin haribote.sys Makefile \
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

@@ -14,6 +14,9 @@
GLOBAL _api_free
GLOBAL _api_point
GLOBAL _api_refreshwin
GLOBAL _api_linewin
GLOBAL _api_closewin
GLOBAL _api_getkey
[SECTION .text]
@@ -150,3 +153,36 @@ _api_refreshwin: ; void api_refreshwin(int win, int x0, int y0, int x1, int y1);
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) {
@@ -367,6 +369,44 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int
} 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;
}
@@ -392,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();
}