Compare commits

...

1 Commits

Author SHA1 Message Date
Yourtion
96a714a9be 改善FIFO缓冲区 2014-09-17 15:27:24 +08:00
3 changed files with 14 additions and 9 deletions

View File

@@ -29,13 +29,14 @@ void HariMain(void)
for (;;) {
io_cli();
if (keybuf.next == 0) {
if (keybuf.len == 0) {
io_stihlt();
} else {
i = keybuf.data[0];
keybuf.next--;
for (j = 0; j < keybuf.next; j++) {
keybuf.data[j] = keybuf.data[j + 1];
i = keybuf.data[keybuf.next_r];
keybuf.len--;
keybuf.next_r++;
if (keybuf.next_r == 32) {
keybuf.next_r = 0;
}
io_sti();
sprintf(s, "%02X", i);

View File

@@ -76,7 +76,7 @@ void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar);
/* int.c */
struct KEYBUF {
unsigned char data[32];
int next;
int next_r, next_w, len;
};
void init_pic(void);
void inthandler21(int *esp);

View File

@@ -35,9 +35,13 @@ void inthandler21(int *esp)
unsigned char data, s[4];
io_out8(PIC0_OCW2, 0x61); /* 通知PIC IRQ-01 已经受理完毕 */
data = io_in8(PORT_KEYDAT);
if (keybuf.next < 32) {
keybuf.data[keybuf.next] = data;
keybuf.next++;
if (keybuf.len < 32) {
keybuf.data[keybuf.next_w] = data;
keybuf.len++;
keybuf.next_w++;
if (keybuf.next_w == 32) {
keybuf.next_w = 0;
}
}
return;
}