ps2base.c
资源名称:tizos.rar [点击查看]
上传用户:qddsws
上传日期:2022-06-22
资源大小:723k
文件大小:1k
源码类别:
操作系统开发
开发平台:
C/C++
- #include <devices/ps2base.h>
- void kbdWrite(word port, byte data) {
- dword timeout;
- byte stat;
- for (timeout = 500000L; timeout != 0; timeout--){
- stat = inportb(KEYB_CTRL);
- if ((stat & 0x02) == 0) break;
- }
- if (timeout != 0) outportb(port, data);
- }
- byte kbdRead() {
- unsigned long Timeout;
- byte Stat, Data;
- for (Timeout = 50000L; Timeout != 0; Timeout--) {
- Stat = inportb(KEYB_CTRL);
- /* loop until 8042 output buffer full */
- if ((Stat & 0x01) != 0) {
- Data = inportb(KEYB_PORT);
- /* loop if parity error or receive timeout */
- if((Stat & 0xC0) == 0) return Data;
- }
- }
- return -1;
- }
- byte kbdWriteRead(word port, byte data, const char* expect) {
- int RetVal;
- kbdWrite(port, data);
- for (; *expect; expect++) {
- RetVal = kbdRead();
- if ((byte) *expect != RetVal) {
- return RetVal;
- }
- }
- return 0;
- }