From 22bda5f82c500cb1ea193dd24747243d40c26470 Mon Sep 17 00:00:00 2001 From: Yourtion Date: Wed, 17 Sep 2014 10:59:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=BF=AB=E4=B8=AD=E6=96=AD=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 07_day/bootpack.c | 26 +++++++++++++++++++------- 07_day/bootpack.h | 3 +++ 07_day/int.c | 15 +++++++++------ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/07_day/bootpack.c b/07_day/bootpack.c index 58547ae..adaf0b0 100644 --- a/07_day/bootpack.c +++ b/07_day/bootpack.c @@ -1,31 +1,43 @@ -/* bootpack */ +/* bootpackのメイン */ #include "bootpack.h" #include +extern struct KEYBUF keybuf; + void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; char s[40], mcursor[256]; - int mx, my; + int mx, my, i; init_gdtidt(); init_pic(); io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */ + io_out8(PIC0_IMR, 0xf9); /* PIC1とキーボードを許可(11111001) */ + io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ + init_palette(); init_screen8(binfo->vram, binfo->scrnx, binfo->scrny); - mx = (binfo->scrnx - 16) / 2; /* 计算画面的中心坐标*/ + mx = (binfo->scrnx - 16) / 2; /* 计算画面中心坐标 */ my = (binfo->scrny - 28 - 16) / 2; init_mouse_cursor8(mcursor, COL8_008484); putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16); sprintf(s, "(%d, %d)", mx, my); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, s); - io_out8(PIC0_IMR, 0xf9); /* PIC1とキーボードを許可(11111001) */ - io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ - for (;;) { - io_hlt(); + io_cli(); + if (keybuf.flag == 0) { + io_stihlt(); + } else { + i = keybuf.data; + keybuf.flag = 0; + io_sti(); + sprintf(s, "%02X", i); + boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 16, 15, 31); + putfonts8_asc(binfo->vram, binfo->scrnx, 0, 16, COL8_FFFFFF, s); + } } } diff --git a/07_day/bootpack.h b/07_day/bootpack.h index 26de49b..847fc16 100644 --- a/07_day/bootpack.h +++ b/07_day/bootpack.h @@ -74,6 +74,9 @@ void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar); #define AR_INTGATE32 0x008e /* int.c */ +struct KEYBUF { + unsigned char data, flag; +}; void init_pic(void); void inthandler21(int *esp); void inthandler27(int *esp); diff --git a/07_day/int.c b/07_day/int.c index 708d97d..aaf6e8c 100644 --- a/07_day/int.c +++ b/07_day/int.c @@ -24,18 +24,21 @@ void init_pic(void) return; } +#define PORT_KEYDAT 0x0060 + +struct KEYBUF keybuf; + void inthandler21(int *esp) /* 来自PS/2键盘的中断 */ { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; unsigned char data, s[4]; - io_out8(PIC0_OCW2, 0x61); /* IRQ-01受付完了をPICに通知 */ + io_out8(PIC0_OCW2, 0x61); /* 通知PIC IRQ-01 已经受理完毕 */ data = io_in8(PORT_KEYDAT); - - sprintf(s, "%02X", data); - boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 16, 15, 31); - putfonts8_asc(binfo->vram, binfo->scrnx, 0, 16, COL8_FFFFFF, s); - + if (keybuf.flag == 0) { + keybuf.data = data; + keybuf.flag = 1; + } return; }