/* * extcode: resolve Atari-ST extended character codes * encoding the proper sequences into emacs * printable character specifications * * Completely rewritten by Mike */ int extcode(sk, sc, key) unsigned int sk; /* Shift keys from event */ unsigned int sc; /* ST scancode */ unsigned int key; /* GEMDOS translation of the key */ { unsigned int code; /* Build up special function code */ int shift; /* CAPS LOCK flag doesn't come from EVENT_MULTI */ sc &= 0xff; code = 0; #ifdef __GNUC__ shift = Getshift(); #else shift = Getshift(-1); #endif if (key) /* Everything that returns a character */ { if (key > 0x1a) /* None of Ctrl-A to Ctrl-Z */ { switch ((sc << 8) | key) { case 0x4b34 : /* Shift cursor left */ code = SPEC; key = 'A'; break; case 0x4d36 : /* Shift cursor right */ code = SPEC; key = 'E'; break; case 0x5032 : /* Shift cursor down */ code = SPEC; key = 'V'; break; case 0x4838 : /* Shift cursor up */ code = SPEC; key = 'Z'; break; case 0x5230 : /* Shift insert */ code = SPEC; key = 'I'; break; case 0x4737 : /* Clr */ code = SPEC; key = '>'; break; case 0x537f : code = SPEC; if (shift & 3) /* Shift Del */ key = 'd'; else /* Del */ key = 'D'; break; default : if (sk & K_ALT) { switch (key) { case '\\' : case '@' : case '{' : case '}' : case '[' : case ']' : break; default : code |= ALTD; } } } } } else /* All non character keys */ { if (sc >= 0x54 && sc <= 0x5d) /* Shifted function keys */ { code = SHFT; sc -= 0x54 - 0x3b; } if (sc >= 0x3b && sc <= 0x44) /* Function keys */ { code |= SPEC; if (sk & K_ALT) code |= ALTD; else if (sk & K_CTRL) code |= CTRL; key = sc - 0x3b + '1'; if (key == '9' + 1) key = '0'; } else { if (sk & K_ALT) /* Alt pressed? */ { code = ALTD; key = kt->caps[sc]; if (key < 'A' || key > 'Z') /* Bogus key combination */ { code = CTRL; key = '@'; } } else { code = SPEC; switch (sc) { case 0x4b : /* Cursor left */ key = 'B'; break; case 0x73 : /* Ctrl cursor left */ code |= CTRL; key = 'B'; break; case 0x4d : /* Cursor right */ key = 'F'; break; case 0x74 : /* Ctrl cursor right */ code |= CTRL; key = 'F'; break; case 0x50 : if (sk & K_CTRL) /* Ctrl cursor down */ { code |= CTRL; key = 'V'; } else /* Cursor down */ key = 'N'; break; case 0x48 : if (sk & K_CTRL) /* Ctrl cursor up */ { code |= CTRL; key = 'Z'; } else /* Cursor up */ key = 'P'; break; case 0x52 : /* Insert */ key = 'C'; break; case 0x47 : /* Home */ key = '<'; break; case 0x77 : /* Ctrl home */ code |= CTRL; key = 'D'; break; case 0x62 : /* Help */ key = 'H'; break; case 0x61 : /* Undo */ key = 'X'; break; default : /* Bogus key combination */ code = CTRL; key = '@'; } } } } if (code) /* Enter a special key */ { in_put(0); in_put(code >> 8); in_put(key); } else /* Enter a normal key */ in_put(key); }