/* vi: set sw=4 ts=4: */
/*
 * KON2 - Kanji ON Console -
 * Copyright (C) 1992-1996 Takashi MANABE (manabe@papilio.tutics.tut.ac.jp)
 *
 * CCE - Console Chinese Environment -
 * Copyright (C) 1998-2003 Rui He (rhe@3eti.com)
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * 
 */

/* key -- key processing module */
#ifndef	__CCE_KEY_H__
#define	__CCE_KEY_H__

#if defined(CCE_TARGETARCH_I386) && (defined(__NetBSD__) || defined(__OpenBSD__))

#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsksymdef.h>
 
#define CTRL_ALT_0      0xA9
#define CTRL_ALT_1      0xA1
#define CTRL_ALT_2      0xC0
#define CTRL_ALT_3      0xA3
#define CTRL_ALT_4      0xA4
#define CTRL_ALT_5      0xA5
#define CTRL_ALT_6      0xDE
#define CTRL_ALT_7      0xA6
#define CTRL_ALT_8      0xAA
#define CTRL_ALT_9      0xA8

#define CTRL_ALT_A      ((KS_A & 0x1F) | 0x80)  /* 0x41->0x81 */
#define CTRL_ALT_E      ((KS_E & 0x1F) | 0x80)  /* 0x45->0x85 */
#define CTRL_ALT_X      ((KS_X & 0x1F) | 0x80)  /* 0x58->0x98 */
#define CTRL_ALT_P      ((KS_P & 0x1F) | 0x80)  /* 0x50->0x90 */
#define CTRL_ALT_N      ((KS_N & 0x1F) | 0x80)  /* 0x4E->0x8E */
#define CTRL_ALT_R      ((KS_R & 0x1F) | 0x80)  /* 0x52->0x92 */
#define CTRL_ALT_L      ((KS_L & 0x1F) | 0x80)  /* 0x4C->0x8C */
#define CTRL_PERIOD	    (0xAE) /*  0x2E-> 0xAE   (ALT-PERIOD) */
#define CTRL_ALT_K      ((KS_K & 0x1F) | 0x80)  /* 0x4B->0x8B */

#define CTRL_SPACE      (0x00) /* 0x20-> 0x00  */
#define SHIFT_SPACE     (0xA0)   /* Shift-Alt-Space Shift-SPACE 0x20->0xA0 */
#define CTRL_SHIFT      (0xFF) /*  FIXME: how to do it ? Right now just 0xFF */

#elif defined(linux) || defined(__FreeBSD__) || defined(__SunOS__) || defined(__Lynx__) 

#define CTRL_ALT_0      200
#define CTRL_ALT_1      201
#define CTRL_ALT_2      202
#define CTRL_ALT_3      203
#define CTRL_ALT_4      204
#define CTRL_ALT_5      205
#define CTRL_ALT_6      206
#define CTRL_ALT_7      207
#define CTRL_ALT_8      208
#define CTRL_ALT_9      209

#define CTRL_ALT_A      210
#define CTRL_ALT_E      211
#define CTRL_ALT_X      212
#define CTRL_ALT_P      213
#define CTRL_ALT_N      214
#define CTRL_ALT_R      215
#define CTRL_ALT_L		216  /* enable/disable LianXiang */
#define CTRL_PERIOD		217  /* enable/disable Chinese Punctuation */
#define CTRL_ALT_K      218  /* change keyboard mapping pinyin/zhuyin */

#define ALT_F1			220
#define CTRL_ALT_F1		220
#define ALT_F2			221
#define	CTRL_ALT_F2		221
#define ALT_F3			222
#define	CTRL_ALT_F3		222
#define ALT_F4          223
#define CTRL_ALT_F4     223
#define ALT_F5          224
#define CTRL_ALT_F5     224
#define ALT_F6          225
#define CTRL_ALT_F6     225
#define ALT_F7          226
#define CTRL_ALT_F7     226

#define CTRL_SPACE      230
#define SHIFT_SPACE     231
#define CTRL_SHIFT      233

#else  /* All other OS use the Ctrl-Q prefix style */

#define USE_CCE_PREFIX_KEY  1  /* define to use CCE_PREFIX_KEY method */

#define CCE_PREFIX_KEY	0x11  /* Ctrl-Q */

#define CTRL_ALT_0      '0'
#define CTRL_ALT_1      '1'
#define CTRL_ALT_2      '2'
#define CTRL_ALT_3      '3'
#define CTRL_ALT_4      '4'
#define CTRL_ALT_5      '5'
#define CTRL_ALT_6      '6'
#define CTRL_ALT_7      '7'
#define CTRL_ALT_8      '8'
#define CTRL_ALT_9      '9'

#define CTRL_ALT_A      'a'
#define CTRL_ALT_E      'e'
#define CTRL_ALT_X      'x'
#define CTRL_ALT_P      'p'
#define CTRL_ALT_N      'n'
#define CTRL_ALT_R      'r'
#define CTRL_ALT_L      'l'
#define CTRL_PERIOD	    '.'
#define CTRL_ALT_K      'k'

#define CTRL_SPACE      ' '
#define SHIFT_SPACE     'w'   /* Ctrl-q w full/half width */
#define CTRL_SHIFT      (0xFF) /* FIXME: how to do it ? Right now just 0xFF */

#if defined(__SCO__)   /* special hacking for SCO OpenServer Unixware */

#define SCO_CTRL_SPACE_2      200
#define SCO_CTRL_F1      201
#define SCO_CTRL_F2      202
#define SCO_CTRL_F3      203
#define SCO_CTRL_F4      204
#define SCO_CTRL_F5      205
#define SCO_CTRL_F6      206
#define SCO_CTRL_F7      207
#define SCO_CTRL_F8      208
#define SCO_CTRL_F9      209
#define SCO_CTRL_F10     210
#define SCO_CTRL_F11     211
#define SCO_CTRL_F12     212

#endif  /* __SCO__ */

#endif

void SetupKeymap(void);
void RestoreKeymap(void);
void KeymapInit(void);
void KeymapCleanup(void);
void ProcessNormalModeKey(int tty_fd,unsigned char c);

#define KEYCODE_ENTER		'\x0D' /* ENTER key */
#define KEYCODE_ESCAPE  	'\033' /* ESCAPE key */
#define KEYCODE_CONTROL_H	'\010' /* Ctrl-H	 */
#define KEYCODE_BACKSPACE 	'\177' /* BackSpace */
#define KEYCODE_SPACE		' '

#endif  /* __CCE_KEY_H__ */

