forked from yourtion/30dayMakeOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
129 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* 键盘控制代码 */ | ||
|
||
#include "bootpack.h" | ||
|
||
struct FIFO8 keyfifo; | ||
|
||
void inthandler21(int *esp) { | ||
/* 来自PS/2键盘的中断 */ | ||
struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; | ||
unsigned char data, s[4]; | ||
io_out8(PIC0_OCW2, 0x61); /* 通知PIC IRQ-01 已经受理完毕 */ | ||
data = io_in8(PORT_KEYDAT); | ||
fifo8_put(&keyfifo, data); | ||
return; | ||
} | ||
|
||
#define PORT_KEYSTA 0x0064 | ||
#define KEYSTA_SEND_NOTREADY 0x02 | ||
#define KEYCMD_WRITE_MODE 0x60 | ||
#define KBC_MODE 0x47 | ||
|
||
void wait_KBC_sendready(void) { | ||
/* 等待键盘控制电路准备完毕 */ | ||
for (;;) { | ||
if ((io_in8(PORT_KEYSTA) & KEYSTA_SEND_NOTREADY) == 0) { | ||
break; | ||
} | ||
} | ||
return; | ||
} | ||
|
||
void init_keyboard(void) { | ||
/* 初始化键盘控制电路 */ | ||
wait_KBC_sendready(); | ||
io_out8(PORT_KEYCMD, KEYCMD_WRITE_MODE); | ||
wait_KBC_sendready(); | ||
io_out8(PORT_KEYDAT, KBC_MODE); | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* 鼠标控制代码 */ | ||
|
||
#include "bootpack.h" | ||
|
||
struct FIFO8 mousefifo; | ||
|
||
void inthandler2c(int *esp) { | ||
/* 来自PS/2鼠标的中断 */ | ||
unsigned char data; | ||
io_out8(PIC1_OCW2, 0x64); /* 通知PIC IRQ-12 已经受理完毕 */ | ||
io_out8(PIC0_OCW2, 0x62); /* 通知PIC IRQ-02 已经受理完毕 */ | ||
data = io_in8(PORT_KEYDAT); | ||
fifo8_put(&mousefifo, data); | ||
return; | ||
} | ||
|
||
#define KEYCMD_SENDTO_MOUSE 0xd4 | ||
#define MOUSECMD_ENABLE 0xf4 | ||
|
||
void enable_mouse(struct MOUSE_DEC *mdec) { | ||
/* 鼠标有效 */ | ||
wait_KBC_sendready(); | ||
io_out8(PORT_KEYCMD, KEYCMD_SENDTO_MOUSE); | ||
wait_KBC_sendready(); | ||
io_out8(PORT_KEYDAT, MOUSECMD_ENABLE); | ||
/* 顺利的话,ACK(0xfa)会被送过来 */ | ||
mdec->phase = 0; /* 等待0xfa的阶段 */ | ||
return; | ||
} | ||
|
||
int mouse_decode(struct MOUSE_DEC *mdec, unsigned char dat) { | ||
if (mdec->phase == 0) { | ||
/* 等待鼠标的0xfa的阶段 */ | ||
if (dat == 0xfa) { | ||
mdec->phase = 1; | ||
} | ||
return 0; | ||
} | ||
if (mdec->phase == 1) { | ||
/* 等待鼠标第一字节的阶段 */ | ||
mdec->buf[0] = dat; | ||
mdec->phase = 2; | ||
return 0; | ||
} | ||
if (mdec->phase == 2) { | ||
/* 等待鼠标第二字节的阶段 */ | ||
mdec->buf[1] = dat; | ||
mdec->phase = 3; | ||
return 0; | ||
} | ||
if (mdec->phase == 3) { | ||
/* 等待鼠标第二字节的阶段 */ | ||
mdec->buf[2] = dat; | ||
mdec->phase = 1; | ||
mdec->btn = mdec->buf[0] & 0x07; | ||
mdec->x = mdec->buf[1]; | ||
mdec->y = mdec->buf[2]; | ||
if ((mdec->buf[0] & 0x10) != 0) { | ||
mdec->x |= 0xffffff00; | ||
} | ||
if ((mdec->buf[0] & 0x20) != 0) { | ||
mdec->y |= 0xffffff00; | ||
} | ||
/* 鼠标的y方向与画面符号相反 */ | ||
mdec->y = - mdec->y; | ||
return 1; | ||
} | ||
/* 应该不可能到这里来 */ | ||
return -1; | ||
} |