/* * Stuff a key into the keyboard buffer */ int ungetkey(unsigned short key) { int count; head = Peekw(0x40, 0x1a); tail = Peekw(0x40, 0x1c); start = Peekw(0x40, 0x80); end = Peekw(0x40, 0x82); count = tail - head; if (0 > count) count += (16 * sizeof(unsigned)); count >>= 1; if (15 > count) { disable(); keystack[idx][0] = Peekw(0x40, tail); keystack[idx][1] = tail; Pokew(0x40, tail, key); tail += sizeof(unsigned); if (end <= tail) tail = start; Pokew(0x40, 0x1c, tail); enable(); return key; } return EOF; }
int KB_stuff(char *str) { int ercode = Success_; idx = 0; while (*str) { if (EOF == ungetkey((unsigned)(*str++))) { disable(); while (0 <= --idx) { tail = keystack[idx][1]; Pokew(0x40, tail, keystack[idx][0]); } Pokew(0x40, 0x1c, tail); enable(); ercode = Error_; break; } else ++idx; } idx = 0; return ercode; }
/* * Stuff a string into the keyboard buffer */ int kb_stuff(char *str) { int ercode = 0; idx = 0; while (*str) { if (EOF == ungetkey((unsigned)(*str++))) { /* Check for EOF */ disable(); while (0 <= --idx) { tail = keystack[idx][1]; Pokew(0x40, tail, keystack[idx][0]); } Pokew(0x40, 0x1c, tail); enable(); ercode = -1; break; } else ++idx; } idx = 0; return ercode; }