Day7

FIFO and mouse control

GET key stroke code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//int.c
#define PORT_KEYDAT 0x0060
//key code port

void inthandler21(int * esp ){
struct BOOTINFO * binfo = (struct BOOTINFO*) ADR_BOOTINFO ;
unsigned char data ;
unsigned char s [4] ;
io_out8(PIC0_OCW2 , 0x61 ) ; //notify PIC handling of IRQ-01 is finished
data = io_in8(PORT_KEYDAT); //read the key code

sprintf(s , "%02x" , data);
boxfill8(binfo->vram , binfo->scrnx , COL8_008484, 0, 16 , 15 , 32);
putfonts8_asc(binfo->vram , binfo->scrnx , 0 , 16 , COL8_FFFFFF , s);
return ;
}

送中断结束命令字

interrupt end

Accelerate interrupt handling

since interrupt handler work at very low level and is invoked frequently, they should be fast and elegant

Shift show text code from handler to main function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//int.c 
struct KEYBUF {
unsigned char data , flag ;
};

#define PORT_KEYDAT 0x0060

struct KEYBUF keybuf;

void inthandler21(int *esp)
{
unsigned char data;
io_out8(PIC0_OCW2, 0x61);
data = io_in8(PORT_KEYDAT);
if (keybuf.flag == 0) {
keybuf.data = data;
keybuf.flag = 1;
}
return;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//bootpack.c
for (;;) {
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);
}
}
}

Use loop queue to buffer key stroke code

通过查资料2得知,当按下右Ctrl键时,会产生两个字节的键码值“E0 1D”,而松开这个键之后,会产生两个字节的键码值“E0 9D”。在一次产生两个字节键码值的情况下,因为键盘内部电路一次只能发送一个字节,所以一次按键就会产生两次中断,第一次中断时发送E0,第二次中断时发送1D。