/*
ascii.h
Written by D'Arcy J.M. Cain
darcy@druid.net

Copyright by D'Arcy J.M. Cain.
Feel free to use this file for any purpose as long as you retain this
message and copyright.

ASCII control codes (including extended IBM codes)

This file is mainly a handy place to keep the standard names of ASCII
control characters as well as a simple macro to return a control character.
Further, if used on an MSDOS system it creates defines for the extended
characters on the IBM keyboard.  The number defined is the scan code of
the key shifted left 8 bits.  To use this create a simple function
something like this:
*/

#if 0
int
getkey(void)
{
	int c;

	if (!(c = getch()))		/* don't forget to include conio.h */
		c = getch() << 8;

	return(c);
}

Now you can do the following:

	switch (c = getkey())
	{
		case UP_ARROW:
			/* up arrow stuff */
			break;

		case DOWN_ARROW:
			/* down arrow stuff */
			break;

		case F1:
		case ALT_H:
			/* present help */
			break;

		case CR:
			/* do carriage return stuff */
			break;

		/* etc ... */

		default:
			if (isprint(c))
				/* put character into string or whatever */
			break;
	}
#endif

#ifndef		__ASCII_H
#define		__ASCII_H

#ifndef		CTRL
#define		CTRL(x)	((x) & 0x1f)
#endif

#define		NUL				0x00
#define		SOH				0x01
#define		STX				0x02
#define		ETX				0x03
#define		EOT				0x04
#define		ENQ				0x05
#define		ACK				0x06
#define		BEL				0x07
#define		BS				0x08
#define		HT				0x09
#define		TAB				0x09	/* alternate name for HT */
#define		LF				0x0a
#define		VT				0x0b
#define		FF				0x0c
#define		CR				0x0d
#define		SO				0x0e
#define		SI				0x0f
#define		DLE				0x10
#define		DC1				0x11
#define		XON				0x11	/* alternate name for DC1 */
#define		DC2				0x12
#define		DC3				0x13
#define		XOFF			0x13	/* alternate name for DC3 */
#define		DC4				0x14
#define		NAK				0x15
#define		SYN				0x16
#define		ETB				0x17
#define		CAN				0x18
#define		EM				0x19
#define		SUB				0x1a
#define		ESC				0x1b
#define		FS				0x1c
#define		GS				0x1d
#define		RS				0x1e
#define		US				0x1f


#if defined(__MSDOS__) || defined(__WIN32__) || defined(__EXTENDED_KEYS__)
#define		F1				0x3b00
#define		F2				0x3c00
#define		F3				0x3d00
#define		F4				0x3e00
#define		F5				0x3f00
#define		F6				0x4000
#define		F7				0x4100
#define		F8				0x4200
#define		F9				0x4300
#define		F10				0x4400

#define		SHIFT_F1		0x5400
#define		SHIFT_F2		0x5500
#define		SHIFT_F3		0x5600
#define		SHIFT_F4		0x5700
#define		SHIFT_F5		0x5800
#define		SHIFT_F6		0x5900
#define		SHIFT_F7		0x5a00
#define		SHIFT_F8		0x5b00
#define		SHIFT_F9		0x5c00
#define		SHIFT_F10		0x5d00

#define		CTL_F1			0x5e00
#define		CTL_F2			0x5f00
#define		CTL_F3			0x6000
#define		CTL_F4			0x6100
#define		CTL_F5			0x6200
#define		CTL_F6			0x6300
#define		CTL_F7			0x6400
#define		CTL_F8			0x6500
#define		CTL_F9			0x6600
#define		CTL_F10			0x6700

#define		ALT_F1			0x6800
#define		ALT_F2			0x6900
#define		ALT_F3			0x6a00
#define		ALT_F4			0x6b00
#define		ALT_F5			0x6c00
#define		ALT_F6			0x6d00
#define		ALT_F7			0x6e00
#define		ALT_F8			0x6f00
#define		ALT_F9			0x7000
#define		ALT_F10			0x7100

#define		ALT_1			0x7800
#define		ALT_2			0x7900
#define		ALT_3			0x7a00
#define		ALT_4			0x7b00
#define		ALT_5			0x7c00
#define		ALT_6			0x7d00
#define		ALT_7			0x7e00
#define		ALT_8			0x7f00
#define		ALT_9			0x8000
#define		ALT_10			0x8100

#define		ALT_A			0x1e00
#define		ALT_B			0x3000
#define		ALT_C			0x2e00
#define		ALT_D			0x2000
#define		ALT_E			0x1200
#define		ALT_F			0x2100
#define		ALT_G			0x2200
#define		ALT_H			0x2300
#define		ALT_I			0x1700
#define		ALT_J			0x2400
#define		ALT_K			0x2500
#define		ALT_L			0x2600
#define		ALT_M			0x3200
#define		ALT_N			0x3100
#define		ALT_O			0x1800
#define		ALT_P			0x1900
#define		ALT_Q			0x1000
#define		ALT_R			0x1300
#define		ALT_S			0x1f00
#define		ALT_T			0x1400
#define		ALT_U			0x1600
#define		ALT_V			0x2f00
#define		ALT_W			0x1100
#define		ALT_X			0x2d00
#define		ALT_Y			0x1500
#define		ALT_Z			0x2c00

#define		ALT_HYPHEN		0x8200
#define		ALT_EQUAL		0x8300

#define		SHIFT_TAB		0x0f00
#define		HOME			0x4700
#define		UP_ARROW		0x4800
#define		PG_UP			0x4900
#define		LEFT_ARROW		0x4b00
#define		RIGHT_ARROW		0x4d00
#define		END				0x4f00
#define		DOWN_ARROW		0x5000
#define		PG_DOWN			0x5100
#define		INSERT			0x5200
#define		DELETE			0x5300

#define		CTL_PR_SCR		0x7200
#define		CTL_LEFT_ARROW	0x7300
#define		CTL_RIGHT_ARROW	0x7400
#define		CTL_END			0x7500
#define		CTL_PG_DOWN		0x7600
#define		CTL_HOME		0x7700
#define		CTL_PG_UP		0x8400

#endif		/* __MSDOS__ */
#endif		/* __ASCII_H	*/
