static word scan[0x61 * 6] = { /* scan code re-map table */ /* map-codes (norm, shift, ctrl, alt), hit-flag & extend */ 0, 0, 0, 0, 0, 0, 27, 27, 27, 0, 0, 0, /* Esc */ '1', '!', 0, 0x7800, 0, 0, '2', '@', 0x300, 0x7900, 0, 0, '3', '#', 0, 0x7a00, 0, 0, '4', '$', 0, 0x7b00, 0, 0, '5', '%', 0, 0x7c00, 0, 0, '6', '^', 0x1e, 0x7d00, 0, 0, '7', '&', 0, 0x7e00, 0, 0, '8', '*', 0, 0x7f00, 0, 0, '9', '(', 0, 0x8000, 0, 0, '0', ')', 0, 0x8100, 0, 0, '-', '_', 0x1f, 0x8200, 0, 0, '=', '+', 0, 0x8300, 0, 0, 8, 8, 127, 127, 0, 0, /* backspace */ 9, 0x0f00, 0, 0, 0, 0, /* tab */ /* 0x10 */ 'q', 'Q', 0x11, 0x1000, 0, 0, 'w', 'W', 0x17, 0x1100, 0, 0, 'e', 'E', 0x05, 0x1200, 0, 0, 'r', 'R', 0x12, 0x1300, 0, 0, 't', 'T', 0x14, 0x1400, 0, 0, 'y', 'Y', 0x19, 0x1500, 0, 0, 'u', 'U', 0x15, 0x1600, 0, 0, 'i', 'I', 0x09, 0x1700, 0, 0, 'o', 'O', 0x0f, 0x1800, 0, 0, 'p', 'P', 0x10, 0x1900, 0, 0, '[', '{', 0x1b, 0, 0, 0, ']', '}', 0x1d, 0, 0, 0, 13, 13, 10, 0, 0, 0, /* return */ /* #define CTRL 178 /* 29 * 6 + 4 */ /* 0, 0, 0, 0, 0, 0, /* Ctrl */ #define CAPS 178 /* 29 * 6 + 4 */ 0, 0, 0, 0, 0, 0, /* Caps Lock */ 'a', 'A', 0x01, 0x1e00, 0, 0, 's', 'S', 0x13, 0x1f00, 0, 0, /* 0x20 */ 'd', 'D', 0x04, 0x2000, 0, 0, 'f', 'F', 0x06, 0x2100, 0, 0, 'g', 'G', 0x07, 0x2200, 0, 0, 'h', 'H', 0x08, 0x2300, 0, 0, 'j', 'J', 0x0a, 0x2400, 0, 0, 'k', 'K', 0x0b, 0x2500, 0, 0, 'l', 'L', 0x0c, 0x2600, 0, 0, ';', ':', 0, 0, 0, 0, '\'', '"', 0, 0, 0, 0, '`', '~', 0, 0, 0, 0, #define LSHIFT 256 /* 42 * 6 + 4 */ 0, 0, 0, 0, 0, 0, /* left SHIFT */ '\\', '|', 0x1c, 0, 0, 0, 'z', 'Z', 0x1a, 0x2c00, 0, 0, 'x', 'X', 0x18, 0x2d00, 0, 0, 'c', 'C', 0x03, 0x2e00, 0, 0, 'v', 'V', 0x16, 0x2f00, 0, 0, /* 0x30 */ 'b', 'B', 0x02, 0x3000, 0, 0, 'n', 'N', 0x0e, 0x3100, 0, 0, 'm', 'M', 0x0d, 0x3200, 0, 0, ',', '<', 0, 0, 0, 0, '.', '>', 0, 0, 0, 0, '/', '?', 0, 0, 0, 0x8d00, /* [ext] -> PF2 */ #define RSHIFT 328 /* 54 * 6 + 4 */ 0, 0, 0, 0, 0, 0, /* right SHIFT */ 0x8e00, 0x8e00, 0x8e00, 0x8e00, 0, 0, /* * -> PF3 */ #define ALT 340 /* 56 * 6 + 4 */ 0, 0, 0, 0, 0, 0, /* ALT */ ' ', ' ', 0x300, ' ', 0, 0, /* space bar */ /* #define CAPS 352 /* 58 * 6 + 4 */ /* 0, 0, 0, 0, 0, 0, /* Caps Lock */ #define CTRL 352 /* 58 * 6 + 4 */ 0, 0, 0, 0, 0, 0, /* Ctrl */ 0x3b00, 0x5400, 0x5e00, 0x6800, 0, 0, /* F1 */ 0x3c00, 0x5500, 0x5f00, 0x6900, 0, 0, /* F2 */ 0x3d00, 0x5600, 0x6000, 0x6a00, 0, 0, /* F3 */ 0x3e00, 0x5700, 0x6100, 0x6b00, 0, 0, /* F4 */ 0x3f00, 0x5800, 0x6200, 0x6c00, 0, 0, /* F5 */ /* 0x40 */ 0x4000, 0x5900, 0x6300, 0x6d00, 0, 0, /* F6 */ 0x8600, 0x8600, 0x8600, 0x8600, 0, 0, /* F7 */ 0x8700, 0x8700, 0x8700, 0x8700, 0, 0, /* F8 */ 0x8800, 0x8800, 0x8800, 0x8800, 0, 0, /* F9 */ 0x8900, 0x8900, 0x8900, 0x8900, 0, 0, /* F10 */ 0x8c00, 0x8c00, 0x8c00, 0x8c00, 0, 0, /* Num Lock -> PF1 */ 0x4600, 0x4600, 0x100, 0x4600, 0, 0, /* Break */ 0x4700, 0x4700, 0x7700, 0x4700, 0, 0, /* 7/Home */ 0x4800, 0x4800, 0x4800, 0x6e00, 0, 0x6e00, /* 8/ */ 0x4900, 0x4900, 0x8400, 0x4900, 0, 0, /* 9/PgUp */ 0x8f00, 0x8f00, 0x8f00, 0x8f00, 0, 0, /* - -> PF4 */ 0x4b00, 0x4b00, 0x7300, 0x7000, 0, 0x7000, /* 4/ */ 0x4c00, 0x4c00, 0x4c00, 0x4c00, 0, 0, /* 5 */ 0x4d00, 0x4d00, 0x7400, 0x7100, 0, 0x7100, /* 6/ */ 0x4e00, 0x4e00, 0x4e00, 0x7200, 0, 0, /* + -> ,/- */ 0x4f00, 0x4f00, 0x7500, 0x4f00, 0, 0, /* 1/End */ /* 0x50 */ 0x5000, 0x5000, 0x5000, 0x6f00, 0, 0x, /* 2/ */ 0x5100, 0x5100, 0x7600, 0x5100, 0, 0, /* 3/PgDn */ 0x5200, 0x5200, 0x5200, 0x5200, 0, 0, /* 0/Ins */ 0x5300, 0x5300, 0x5300, 0x5300, 0, 0, /* ./Del */ 0x5400, 0x5400, 0x5400, 0x5400, 0, 0, 0x5500, 0x5500, 0x5500, 0x5500, 0, 0, 0x5600, 0x5600, 0x5600, 0x5600, 0, 0, 0x8b00, 0x8b00, 0x8b00, 0x8b00, 0, 0, /* F11 */ 0x8a00, 0x8a00, 0x8a00, 0x8a00, 0, 0, /* F12 */ 0x5900, 0x5900, 0x5900, 0x5900, 0, 0, 0x5a00, 0x5a00, 0x5a00, 0x5a00, 0, 0, 0x5b00, 0x5b00, 0x5b00, 0x5b00, 0, 0, 0x5c00, 0x5c00, 0x5c00, 0x5c00, 0, 0, 0x5d00, 0x5d00, 0x5d00, 0x5d00, 0, 0, 0x5e00, 0x5e00, 0x5e00, 0x5e00, 0, 0, 0x5f00, 0x5f00, 0x5f00, 0x5f00, 0, 0, /* 0x60 */ #define XTND0 576 /* 96 * 6 */ 0, 0, 0, 0, 0, 0, /* Extension 0 */ #define XTND1 577 /* 96 * 6 + 1 */ 0, 0, 0, 0, 0, 0 /* Extension 1 */ }; static word keybuf[256]; static uchar kbin=0, kbout=0, autorep; void interrupt (*o_int)(); void interrupt k_int(bp, di, si, ds, es, dx, cx, bx, ax) word bp, di, si, ds, es, dx, cx, bx, ax; { word code, hit; uchar ctl, ext = 0; code = inportb(KB_DATA); ctl = inportb(KB_CTL); outportb(KB_CTL, ctl | 0x80); outportb(KB_CTL, ctl); enable(); ctl = code; code = (code & 0x7f) * 6; hit = ((ctl & 0x80) == 0); /* 0x80: key up */ if (kb_mode & 0x30) { /* ext code */ ext = (kb_mode & 0x10) ? 0x10 : 0x20; kb_mode &= ~ext; } if (!hit || !scan[code]) { /* key has just lifted or it's a "shift" key */ code += 4; scan[code] = hit; ctl = 0; switch (code) { case XNTD0: ctl = 0x20; break; case XNTD1: ctl = 0x30; break; case ALT: ctl = 0x08; break; case CTRL: ctl = 0x04; break; case LSHIFT: ctl = 0x02; break; case RSHIFT: ctl = 0x01; break; case CAPS: ctl = 0x40; hit = (scan[CAPS-1] ^= hit); break; } if (ctl) { if (hit) kb_mode |= ctl; else kb_mode &= ~ctl; } } else if (!scan[code+4] || autorep) { scan[code+4] = hit; ctl = kb_mode & 0x43; if (ext) /* Ext */ code += 5; else if (kb_mode & 0x08) /* ALT */ code += 3; else if (kb_mode & 0x04) /* CTRL */ code += 2; else if (ctl == 0x40) /* CAPS */ code += 1; else if (0 < ctl && ctl < 4) /* SHIFT */ code += 1; code = scan[code]; if (code & 0xf0ff) keybuf[kbin++] = code; else switch (code >> 8) { /* special ! */ case 1: /* Ctrl Break */ keyboom++; /* we go bye now! */ break; case 0x3: /* ctrl-2@, ctrl-space */ case 0xf: /* back-tab */ keybuf[kbin++] = code; break; default: break; } } outportb(INTA00, EOI); }