/* * keyin.c -- PC/AT keyin routine * * Copyright (C) 1997 by Sony Computer Entertainment * All rights Reserved */ #include #include #include #include #include #include #include #include "dosint.h" /*---------------------------------------------------- * IBM-PC keyboard memo * * up arrow NULL H * down arrow NULL P * left arrow NULL K * right arrow NULL M * insert NULL R * delete NULL S * home NULL G * end NULL O * page up NULL I * page down NULL Q * F1...F10 NULL 0x3B...0x44 * F11,F12 NULL 0x85, 0x86 */ struct fkeys { int code; int raw; } fkeytbl[] = { { KEY_UP, 'H' }, { KEY_DOWN, 'P' }, { KEY_LEFT, 'K' }, { KEY_RIGHT, 'M' }, { KEY_INSERT, 'R' }, { KEY_DELETE, 'S' }, { KEY_HOME, 'G' }, { KEY_END, 'O' }, { KEY_PUP, 'I' }, { KEY_PDOWN, 'Q' }, { KEY_F1, 0x3b }, { KEY_F2, 0x3c }, { KEY_F3, 0x3d }, { KEY_F4, 0x3e }, { KEY_F5, 0x3f }, { KEY_F6, 0x40 }, { KEY_F7, 0x41 }, { KEY_F8, 0x42 }, { KEY_F9, 0x43 }, { KEY_F10, 0x44 }, { KEY_F11, 0x85 }, { KEY_F12, 0x86 }, { 0,0 } }; extern void check_exit(); static cbuffer keybuf = {0,0,0,{0}}; static int rawgetkey() { // short result; /* keyin check and keyin without echo & check ctrl-c */ /* __asm { mov ah,6 mov dl,0ffh int 21h jnz keyin mov ax,0ffffh jmp inend keyin: mov ah,0 inend: mov result, ax } return result;*/ return 0; } static int function(int ch) { struct fkeys *fp; for( fp = fkeytbl; fp->raw > 0; fp++ ) { if( fp->raw == ch ) { ch = fp->code; break; } } return ch; } int keyhit() { int key; if( !is_full_cbuffer(keybuf) ) { if (_kbhit()) { key = _getch(); if( key == 0 ) { key = function(_getch()); } put_cbuffer(keybuf,(unsigned char)key); if( key == 27) breakflag = 1; } } return !is_empty_cbuffer(keybuf); } int getkey() { int result; while( !keyhit()); get_cbuffer(keybuf,result); if( result == 27) { breakflag = 1; check_exit(0); exit(1); } return result; }