Skip to content

Commit

Permalink
键盘输入API
Browse files Browse the repository at this point in the history
  • Loading branch information
yourtion committed May 10, 2016
1 parent 8de80dc commit 041e2a4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
7 changes: 7 additions & 0 deletions 23_day/a_nask.nas
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
GLOBAL _api_refreshwin
GLOBAL _api_linewin
GLOBAL _api_closewin
GLOBAL _api_getkey

[SECTION .text]

Expand Down Expand Up @@ -179,3 +180,9 @@ _api_closewin: ; void api_closewin(int win);
INT 0x40
POP EBX
RET

_api_getkey: ; int api_getkey(int mode);
MOV EDX,15
MOV EAX,[ESP+4] ; mode
INT 0x40
RET
1 change: 1 addition & 0 deletions 23_day/bootpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions 23_day/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -375,6 +377,36 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int
}
} 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;
}
Expand Down
6 changes: 6 additions & 0 deletions 23_day/lines.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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)
Expand All @@ -18,6 +19,11 @@ void HariMain(void)
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();
}

0 comments on commit 041e2a4

Please sign in to comment.