Skip to content

Commit

Permalink
实现字符输入
Browse files Browse the repository at this point in the history
  • Loading branch information
yourtion committed Apr 26, 2016
1 parent 9299bf0 commit 7ab551c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 19 deletions.
73 changes: 54 additions & 19 deletions 17_day/bootpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,29 @@ void HariMain(void)
if (256 <= i && i <= 511) { /* 键盘数据*/
sprintf(s, "%02X", i - 256);
putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2);
if (i < 0x54 + 256) {
if (keytable[i - 256] != 0 && cursor_x < 128) {
s[0] = keytable[i - 256];
s[1] = 0;
putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1);
cursor_x += 8;
if (i < 0x54 + 256 && keytable[i - 256] != 0) { /*一般字符*/
if (key_to == 0) { /*发送给任务A */
if (cursor_x < 128) {
/*显示一个字符之后将光标后移一位*/
s[0] = keytable[i - 256];
s[1] = 0;
putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1);
cursor_x += 8;
}
} else { /*发送给命令行窗口*/
fifo32_put(&task_cons->fifo, keytable[i - 256] + 256);
}
}
if (i == 256 + 0x0e && cursor_x > 8) { /* 退格键 */
/* 用空格键把光标消去后,后移1次光标 */
putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1);
cursor_x -= 8;
if (key_to == 0) { /*发送给任务A */
if (cursor_x > 8) {
/*用空白擦除光标后将光标前移一位*/
putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1);
cursor_x -= 8;
}
} else { /*发送给命令行窗口*/
fifo32_put(&task_cons->fifo, 8 + 256);
}
}
if (i == 256 + 0x0f) { /* Tab键*/
if (key_to == 0) {
Expand Down Expand Up @@ -291,36 +302,60 @@ void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c)

void console_task(struct SHEET *sheet)
{
struct FIFO32 fifo;
struct TIMER *timer;
struct TASK *task = task_now();

int i, fifobuf[128], cursor_x = 8, cursor_c = COL8_000000;
fifo32_init(&fifo, 128, fifobuf, task);
int i, fifobuf[128], cursor_x = 16, cursor_c = COL8_000000;
char s[2];

fifo32_init(&task->fifo, 128, fifobuf, task);
timer = timer_alloc();
timer_init(timer, &fifo, 1);
timer_init(timer, &task->fifo, 1);
timer_settime(timer, 50);

/*显示提示符*/
putfonts8_asc_sht(sheet, 8, 28, COL8_FFFFFF, COL8_000000, ">", 1);

for (;;) {
io_cli();
if (fifo32_status(&fifo) == 0) {
if (fifo32_status(&task->fifo) == 0) {
task_sleep(task);
io_sti();
} else {
i = fifo32_get(&fifo);
i = fifo32_get(&task->fifo);
io_sti();
if (i <= 1) { /*光标用定时器*/
if (i != 0) {
timer_init(timer, &fifo, 0); /*下次置0 */
timer_init(timer, &task->fifo, 0); /*下次置0 */
cursor_c = COL8_FFFFFF;
} else {
timer_init(timer, &fifo, 1); /*下次置1 */
timer_init(timer, &task->fifo, 1); /*下次置1 */
cursor_c = COL8_000000;
}
timer_settime(timer, 50);
boxfill8(sheet->buf, sheet->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43);
sheet_refresh(sheet, cursor_x, 28, cursor_x + 8, 44);
}
if (256 <= i && i <= 511) { /*键盘数据(通过任务A) */
if (i == 8 + 256) {
/*退格键*/
if (cursor_x > 16) {
/*用空白擦除光标后将光标前移一位*/
putfonts8_asc_sht(sheet, cursor_x, 28, COL8_FFFFFF, COL8_000000, " ", 1);
cursor_x -= 8;
}
} else {
/*一般字符*/
if (cursor_x < 240) {
/*显示一个字符之后将光标后移一位 */
s[0] = i - 256;
s[1] = 0;
putfonts8_asc_sht(sheet, cursor_x, 28, COL8_FFFFFF, COL8_000000, s, 1);
cursor_x += 8;
}
}
}
/*重新显示光标*/
boxfill8(sheet->buf, sheet->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43);
sheet_refresh(sheet, cursor_x, 28, cursor_x + 8, 44);
}
}
}
1 change: 1 addition & 0 deletions 17_day/bootpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ struct TSS32 {
struct TASK {
int sel, flags; /* sel用来存放GDT的编号*/
int level, priority; /* 优先级 */
struct FIFO32 fifo;
struct TSS32 tss;
};
struct TASKLEVEL {
Expand Down

0 comments on commit 7ab551c

Please sign in to comment.